Skip to content

Commit

Permalink
HIR Typecheck - Tweaked logic around casting &[T; N] to *const T
Browse files Browse the repository at this point in the history
…so it doesn't need a known type
  • Loading branch information
thepowersgang committed Dec 8, 2024
1 parent aba9acf commit 72c9283
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Notes/UpgradeQuirks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,5 @@
- References to `Self` in `impl Foo`
- Requires zero-sized functions?
- `#[derive(::core::cmp::PartialEq, ::core::cmp::Eq)]` (in the `windows` crate)
- `#[repr(C, packed(1))]`
- `#[repr(C, packed(1))]`
- `&mut [] as *mut u16` (in cargo)
12 changes: 10 additions & 2 deletions src/hir_typeck/expr_cs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,13 +343,21 @@ namespace {
// If either the source or the destination inner tyes are infer - add back rules
if( const auto* s_e_i = src_inner.data().opt_Infer() )
{
this->context.possible_equate_ivar(sp, s_e_i->index, e.inner, Context::PossibleTypeSource::UnsizeTo);
this->context.possible_equate_ivar(sp, s_e_i->index, ity, Context::PossibleTypeSource::UnsizeTo);
}
if( const auto* d_e_i = ity.data().opt_Infer() )
{
this->context.possible_equate_ivar(sp, d_e_i->index, s_e.inner, Context::PossibleTypeSource::UnsizeFrom);
}

// If this looks like `&mut [?; N]` -> `*mut ?` then do a possible equate between the two types
if( src_inner.data().is_Array() ) {
if( const auto* s_e_i = this->context.get_type(src_inner.data().as_Array().inner).data().opt_Infer() ) {
this->context.possible_equate_ivar(sp, s_e_i->index, ity, Context::PossibleTypeSource::UnsizeTo);
return ;
}
}

// NOTE: &mut T -> *mut U where T: Unsize<U> is allowed
// TODO: Wouldn't this be better served by a coercion point?

Expand All @@ -358,7 +366,7 @@ namespace {
// Either side is infer, keep going
}
// - NOTE: Crude, and likely to break if ether inner isn't known.
else if( src_inner.data().is_Array() && src_inner.data().as_Array().inner == e.inner )
else if( src_inner.data().is_Array() && src_inner.data().as_Array().inner == ity )
{
// Allow &[T; n] -> *const T - Convert into two casts
auto ty = ::HIR::TypeRef::new_pointer(e.type, src_inner.clone());
Expand Down

0 comments on commit 72c9283

Please sign in to comment.