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
Compiling with -C debuginfo=2 reduces warnings unexpectedly #48900
Passing -C debuginfo=2 to rustc gives fewer warnings than debuginfo={0,1}. I expected to see the same output regardless of debug symbols.
Example
% rustc src/main.rs -C debuginfo=1
warning: this expression will panic at run-time
--> src/main.rs:4:19
|
4 |let element = a[index];| ^^^^^^^^ index out of bounds: the len is 3 but the index is 10
% rustc src/main.rs -C debuginfo=2
% rustc src/main.rs
warning: this expression will panic at run-time
--> src/main.rs:4:19
|
4 |let element = a[index];| ^^^^^^^^ index out of bounds: the len is 3 but the index is 10
% rustup show
Default host: x86_64-unknown-linux-gnu
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu
nightly-2017-12-21-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.26.0-nightly (2789b067d 2018-03-06)
% cat src/main.rs
fn main() {
let a = [1, 2, 3];let index = 10;let element = a[index];
println!("element is {}", element);
}
% rustc src/main.rs -C debuginfo=2
% rustc src/main.rs -C debuginfo=1
warning: this expression will panic at run-time
--> src/main.rs:4:19
|
4 |let element = a[index];| ^^^^^^^^ index out of bounds: the len is 3 but the index is 10
If dbg == false (i.e. debuginfo != 2), then the first return is hit and everything works. Otherwise, the returned value is constructed differently (LocalRef::Place(place)) and the warnings henceforth do not appear.
This example doesn't warn, but the one from #48920 does; and does so regardless of debuginfo level. Given @varkor's comment above, I believe that to be true as well, and so I'm closing. Let me know if you've found this behavior elsewhere!
Activity
jyn514 commentedon Mar 10, 2018
By the way, this must have existed for quite some time, because the second version of the Book does something similar without a warning from
rustc.varkor commentedon Mar 10, 2018
I can't reproduce this on 1.26.0 — are you able to check it still occurs on nightly?
jyn514 commentedon Mar 10, 2018
Definitely present on
1.26.0.varkor commentedon Mar 10, 2018
Ah, interesting: it occurs for your test program, but not for this one (i.e. here the warning is always displayed):
jyn514 commentedon Mar 11, 2018
Afraid I'm new to rust - is that a type annotation that
ais an array of length1and typei32? Isn't the right side assigning an array of length 2?sfackler commentedon Mar 11, 2018
[0; 1]means "an array of length 1 filled with0values".varkor commentedon Mar 11, 2018
Just from a little looking around, the check here seems to be the cause:
rust/src/librustc_trans/mir/mod.rs
Lines 266 to 281 in c90f682
If
dbg == false(i.e.debuginfo != 2), then the first return is hit and everything works. Otherwise, the returned value is constructed differently (LocalRef::Place(place)) and the warnings henceforth do not appear.varkor commentedon Mar 11, 2018
My suspicion is that this issue is specific to the old constant evaluation system, which has recently been completely replaced by miri. It's hard to be completely sure, because the array indexing warning has not yet been implemented in miri, but it seems very likely.
Have you spotted any other kinds of warnings that also disappear for
debuginfo = 2?steveklabnik commentedon Oct 21, 2019
This example doesn't warn, but the one from #48920 does; and does so regardless of debuginfo level. Given @varkor's comment above, I believe that to be true as well, and so I'm closing. Let me know if you've found this behavior elsewhere!