Open
Description
I tried this code:
closure_test.rs
fn main() {
let x = "hello world";
foo(x);
}
#[inline(never)]
pub fn foo(x: &str) {
bar(|z|
if x.len() == 0 { Ok(()) } else { Ok(()) });
}
#[inline(never)]
fn bar(f: impl FnOnce(&mut dyn Debug) -> Result<(), ()>) {
let mut x = 10i32;
f(&mut x);
}
https://rust.godbolt.org/z/8ErnGbG9z
When compiled with --edition 2021
, it produces invalid debug info for capture of variable x
.
rustc --edition 2021 -g closure_test.rs -Copt-level=0
gdb ./closure_test
...
(gdb) b closure_test.rs:12
Breakpoint 1 at 0x69f7: file closure_test.rs, line 12.
(gdb) r
...
Breakpoint 1, closure_test::foo::{{closure}} (z=...) at closure_test.rs:12
12 if x.len() == 0 { Ok(()) } else { Ok(()) });
(gdb) p x
$1 = 104
When compiled with --edition 2018
, debug info is valid:
$ rustc --edition 2018 -g closure_test.rs -Copt-level=0
$ gdb ./closure_test
...
(gdb) b closure_test.rs:12
Breakpoint 1 at 0x69f3: file closure_test.rs, line 12.
(gdb) r
...
Breakpoint 1, closure_test::foo::{{closure}} (z=...) at closure_test.rs:12
12 if x.len() == 0 { Ok(()) } else { Ok(()) });
(gdb) p x
$1 = "hello world"
Problem seems to be in an addition dereference in MIR debug info:
Meta
rustc --version --verbose
:
<version>
Backtrace
<backtrace>