Open spernsteiner opened 1 year ago
I was going to open a separate issue for this case, but I think it has the same root cause as the examples above:
struct S {
p: *mut u8,
}
unsafe fn foo(s: *const S, cond: bool) -> *const u8 {
if cond {
(*s).p.offset(1)
} else {
(*s).p
}
}
The MIR where the error occurs looks very similar to the bb0[4]-bb0[5] pattern above.
All four variants produce the same error:
Relevant MIR (from
cast_ptr_implicit
):Here, we copy the argument
p
/_1
into the temporary_4
, then cast the result and store it in_3
, which is later passed as the argument toread
. We wrongly identify the rvalue ofbb0[5]
,move _4 as *const u8
, as theExpr
(thep
inread(p)
), but really the_1
inbb0[4]
is theExpr
. (This is easier to see in the struct field examples, where the expr(*s).p
becomes the MIR rvalue((*_1).0: *mut u8)
.)The MIR looks the same for both the implicit coercion and explicit cast versions. For the implicit version in particular, we may need a new
MirOriginDesc
variant to describe exactly howbb0[4]
andbb0[5]
relate to the expressionp
.