You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Raw pointer deref of uninhabited type allowed in const fn #77694
The code below compiles as of 1.46, but I'm not sure it should, since it dereferences a raw pointer in a const block, which is only allowed in nightly with the #![feature(const_raw_ptr_deref)] flag:
I don't believe this is an unsoundness. Unsafe code is required to cause anything here.
The MIR for unreachable is
That's the final MIR, since without unsafe fn this will fail to compile, it must be there for unsafety checking, thus it must also be there for const checking. Not sure why we fail to catch this.
Activity
ohsayan commentedon Oct 8, 2020
@rustbot modify labels to +A-raw-pointers +A-const-fn
jonas-schievink commentedon Oct 8, 2020
cc @rust-lang/wg-const-eval
RalfJung commentedon Oct 8, 2020
Ah, that looks like the const version of the old "uninhabited match" problem...
The MIR for
unreachableisSo somehow the deref already vanished, and hence the const analysis cannot catch it.
But doesn't unsafety checking also happen on the MIR? Why does that work?
DutchGhost commentedon Oct 8, 2020
It seems that whenever the dereference is not bound to a variable, it compiles, but whenever bound to a variable, it fails to compile:
oli-obk commentedon Oct 8, 2020
I don't believe this is an unsoundness. Unsafe code is required to cause anything here.
That's the final MIR, since without
unsafe fnthis will fail to compile, it must be there for unsafety checking, thus it must also be there for const checking. Not sure why we fail to catch this.RalfJung commentedon Oct 8, 2020
Agreed. This is a case of "oops a nightly-only feature is available on stable", which is bad, but it is not an unsoundness.
camelid commentedon Oct 8, 2020
Assigning
P-highand removingI-prioritizeas discussed in the prioritization working group.RalfJung commentedon Dec 7, 2020
The initial MIR looks like this:
So probably the issue is that const-checking ignores
FakeRead?oli-obk commentedon Dec 7, 2020
oh... yea.. we ignored it on purpose... "because it doesn't actually do anything" 🙃
I guess we should visit all places within statements that we otherwise ignore during const-checking?
RalfJung commentedon Dec 7, 2020
Well, at least we need to visit
FakeRead. ;)RalfJung commentedon Dec 19, 2020
Do we really? The
Derefcheck is done invisit_projection_elem, which should be called even for the projection in the place in the fake read.RalfJung commentedon Dec 19, 2020
Oh wait, we don't call
super_statementunconditionally! That seems like... a problem.^^RalfJung commentedon Dec 19, 2020
Proposed a fix: #80199
Rollup merge of rust-lang#80199 - RalfJung:const-fake, r=oli-obk
Rollup merge of rust-lang#80199 - RalfJung:const-fake, r=oli-obk