-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
warning for UB !
exprs is too light
#56190
Comments
I think what we want to be doing is distinguishing between unreachable code due to (control-flow) divergence and due to undefined behaviour in the diagnostics, whereas currently they're treated as the same thing. |
|
Ralf seemed to think this was materially different from transmuting to a reference, but I don't know why. |
Hm, good question actually. I've been thinking that we should assert validity of a value on a dereference (i.e., when evaluating a But actually, miri only asserts validity when a value is copied at a certain type. That does not happen here. And your example code (after fixing syntax errors) actually has no "unreachable":
So there is no UB here, that miri sees anyway. Things are very different if you use
|
I don't see a general principle here, but someone decided that a mere deref-without-actual-access on I think we should probably discuss this as part of rust-lang/unsafe-code-guidelines#8 in the UCG discussions. IMO, if we decide that references do not have to point to initialized data, then |
The current output for enum Void { }
fn process(input: *const Void) {
let _input = unsafe { &*input };
}
fn main() {} is
|
The thing is, if you replace |
How? Making a raw pointer is safe: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6beb0e3e63565a4034d51cc342476bee
|
As I said above, it is unclear whether your example code has UB or not. If you run your code in Miri, you can see that it is currently not considered UB. My current stanza on validity of references is that |
Oh, yes. I'm sorry, I wanted to say I don't think the pointer parameter case was unreachable, regardless of whether or not it is UB, unlike the reference case, which already requires an instance of a reference to an uninhabited type (So it can be considered unreachable if such a reference were uninhabited AFAIK), and not sure if I was misunderstanding something. Reading back I think by |
TBH, I am not entirely sure any more what I meant more than a year ago. ;) |
Hello guys! May I ask what the status of this issue is? What exactly should you do, if you'd like to claim this issue? |
@TornaxO7 I no longer recall what my rationale/understanding was back then, and rereading this thread I fear I might have misunderstood back then what the scope of the work is. A clarification of what the desired outcome would be useful regardless :) |
Hm... I think that I'm the wrong person to see how much work has to be done to fix this issue, since I'm lookin for a first-contribution xD |
@TornaxO7 no worries, sorry for the categorization :) |
Current status: this doesn't compile as-written on nightly, as the dereferencing is unsafe, even if you change it to
Adding the So here's my guess at what the work here might be:
|
So this code produces a warning about the
&*input
expression being unreachable:I can imagine this needs to "only" be a warning so someone can write some really janky macro code that very carefully ensures the expression isn't ever evaluated. Even if that's the case, I would appreciate that this get its own error-code, or just stronger language to indicate to the user that they are doing something Very Bad. In particular I believe evaluating this expr is Undefined Behaviour.
The text was updated successfully, but these errors were encountered: