debugging 无法检查gdb中“if let”变量

yftpprvb  于 2022-11-14  发布在  其他
关注(0)|答案(1)|浏览(159)

我在检查由if-let语句设置的变量时遇到了麻烦,例如下面的main.rs在一个新创建的名为“iflet-rust”的货物项目中:

#[derive(Debug)]
struct Stuff;
fn maybe() -> Option<Stuff> {
    Some(Stuff {})
}
fn main() {
    if let Some(first) = maybe() {
        println!("first {:?}", first); // line 8, cannot inspect 'first' here
    }

    let maybe_stuff = maybe();
    if maybe_stuff.is_some() {
        let second = maybe_stuff.unwrap();
        println!("second {:?}", second); // no problem here
    }
}

然后运行cargo buildrust-gdb target/debug/iflet-rust

Reading symbols from target/debug/iflet-rust...
(gdb) b main.rs:8
Breakpoint 1 at 0x83f1: file src/main.rs, line 8.
(gdb) b main.rs:14
Breakpoint 2 at 0x848b: file src/main.rs, line 14.
(gdb) r
Starting program: iflet-rust/target/debug/iflet-rust 

Breakpoint 1, iflet_rust::main () at src/main.rs:8
8               println!("first {:?}", first); // cannot inspect 'first' here
(gdb) p first
No symbol 'first' in current context
(gdb) info locals
No locals.
(gdb) c
Continuing.
first Stuff

Breakpoint 2, iflet_rust::main () at src/main.rs:14
14              println!("second {:?}", second); // no problem here
(gdb) info locals
second = iflet_rust::Stuff
maybe_stuff = core::option::Option::Some

这是一个已知的限制还是我遗漏了什么?

2o7dmzc5

2o7dmzc51#

这是编译器中的一个问题,将Rust从1.60更新到1.63修复了该问题。
我不应该把我的搜索局限于开放的问题,不幸的时机。
请参阅https://github.com/rust-lang/rust/issues/97799

相关问题