首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法检查gdb中的"if“变量

无法检查gdb中的"if“变量
EN

Stack Overflow用户
提问于 2022-09-10 16:25:38
回答 1查看 52关注 0票数 1

我在检查由if-let语句设置的变量时遇到了困难,例如,在一个名为“IFlet-锈迹”的新创建的货运项目中,有以下main.rs:

代码语言:javascript
复制
#[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

代码语言:javascript
复制
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

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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-12 17:01:38

这是编译器中的一个问题,从1.60更新到1.63修复了这个问题。

我不应该把我的搜索限制在公开问题上,这是一个不幸的时机。

请参阅https://github.com/rust-lang/rust/issues/97799

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73673424

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档