-
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
Duplicated errors on UB inside a promoted #61821
Comments
This comment has been minimized.
This comment has been minimized.
One of the two errors is coming from evaluating the What is surprising here is that the evaluation of the place expression even happens even though that should be dead code. @oli-obk @wesleywiser any idea? (This is not fixed by #66927.) |
The reason is that the MIR of the promoted actually looks like this:
Notice the unchecked array access. That's how this is not dead code. I assume the other error comes from ConstProp (likely of the |
Cc @ecstatic-morse @eddyb because promotion is involved |
I don't think But also, if we constant-fold the assert, we can know that using the promoted is dead code (I guess this doesn't apply to codegen generating those warnings instead of constant folding). |
@eddyb so basically, |
You could still have warnings inside a promoted that are not from things covered by Basically "this expression will panic at runtime" type warnings shouldn't be emitted from a promoted, others might be fine. |
Actually, I think the first ("error: index out of bounds") is not a warning in any meaningful way... trying to evaluate that promoted fails with a hard const-error ("UB: OOB array access") and produces no result. I does not seem wise to me to not report such hard errors. I am pretty sure the "reaching this expression at runtime will panic or abort" part is not from inside the promoted. That one gets raised by const-prop when partially evaluating the So @eddyb I don't think any of your proposals so far actually solves this problem. Or do you suggest we ignore UB in promoteds? |
Also, in latest master a third warning crept in again:
The third error was added by #67000 |
FWIW, this affects not just array indexing but also div-by-zero. At least the two are consistent. ;) |
If we want to be clever we could only check promoteds that are still reachable after constant folding + Actually, do we have an unconditional |
Unify and improve const-prop lints Add a single helper method for all lints emitted by const-prop, and make that lint different from the CTFE `const_err` lint. Also consistently check overflow on *arithmetic*, not on the assertion, to make behavior the same for debug and release builds. See [this summary comment](rust-lang#69185 (comment)) for details and the latest status. In terms of lint formatting, I went for what seems to be the better style: have a general message above the code, and then a specific message at the span: ``` error: this arithmetic operation will overflow --> $DIR/const-err2.rs:21:18 | LL | let a_i128 = -std::i128::MIN; | ^^^^^^^^^^^^^^^ attempt to negate with overflow ``` We could also just have the specific message above and no text at the span if that is preferred. I also converted some of the existing tests to use compiletest revisions, so that the same test can check a bunch of different compile flags. Fixes rust-lang#69020. Helps with rust-lang#69021: debug/release are now consistent, but the assoc-const test in that issue still fails (there is a FIXME in the PR for this). The reason seems to be that const-prop notices the assoc const in `T::N << 42` and does not even bother calling `const_prop` on that operation. Has no effect on rust-lang#61821; the duplication there has entirely different reasons.
Triage: no change |
#80579 will solve this by not promoting division and array indexing any more when they could fail. |
The following output should only emit the error once:
Follow up to #61598
The text was updated successfully, but these errors were encountered: