-
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
Taking a shared reference of an array suppresses the unconditional_panic lint #98444
Comments
See also this thread on URLO. |
@rustbot claim |
Note this is a problem because the book has an example which is supposed to fail to compile but this bug makes it fail at runtime instead |
In case no one has dug into it yet, the error is suppressed in
|
@rustbot label +regression-from-stable-to-stable |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-medium |
This is caused by #94934. It only ever worked because the lint ran after optimizations. I made a fix here. It specializes the length of arrays as constant, even if the array isn't. I'm going to open a PR when I have time, probably tomorrow. In the long term, I'd like to implement some more extensive tracking of "what parts of a value are constant". For example, the compiler currently assumes that anything that had its reference taken can change, but actually, this can only happen inside |
…nt, r=oli-obk const_prop_lint: Consider array length constant even if array is not Fixes rust-lang#98444.
Fixed on stable |
I claim the add test part |
This lint only appears on full builds (not check), but this will be fixed once #108730 lands. |
…rieb Add regression test for rust-lang#98444 cc rust-lang#108730 this will need to be changed to a `check-fail` test once it lands. Fixes rust-lang#98444
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#107801 (const_eval: `implies_by` in `rustc_const_unstable`) - rust-lang#108750 (Fix `ObligationCtxt::sub`) - rust-lang#108780 (Add regression tests for issue 70919) - rust-lang#108786 (Check for free regions in MIR validation) - rust-lang#108790 (Do not ICE when interpreting a cast between non-monomorphic types) - rust-lang#108803 (Do not ICE when failing to normalize in ConstProp.) - rust-lang#108807 (Emit the suspicious_auto_trait_impls for negative impls as well) - rust-lang#108812 (Add regression test for rust-lang#98444) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Reopening because I feel this is not yet solved, see Zulip notes on #114840. As per the prev. comment, #108730 should nail down this issue? |
MRE: fn main() {
let slice = &[0, 1];
let _ = slice[2];
} Also, duplicate of #38035 |
Another variant of this same issue: #109260 |
Rollup merge of rust-lang#129517 - cjgillot:known-panic-array, r=pnkfelix Compute array length from type for unconditional panic lint. Fixes rust-lang#98444 The cases that involve slicing are harder, so rust-lang#38035 remains open.
Compute array length from type for unconditional panic lint. Fixes rust-lang/rust#98444 The cases that involve slicing are harder, so rust-lang/rust#38035 remains open.
I tried this code:
I expected to see this happen:
Instead, this happened:
Apparently, taking a shared reference of
xs
will suppress theunconditional_panic
lint. This seems like a false negative. While false negatives can't be avoided entirely, this case seems to be avoidable as taking a shared reference shouldn't change the type ofxs
(which is[i32; 5]
) or modify any data in this example.Note that
will trigger the lint properly.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: