我在檢查 if-let 陳述句設定的變數時遇到問題,例如,在一個名為“iflet-rust”的新創建的貨物專案中的以下 main.rs:
#[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 build
和rust-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
這是一個已知的限制還是我錯過了什么?
uj5u.com熱心網友回復:
這是編譯器中的一個問題,將 Rust 從 1.60 更新到 1.63 解決了這個問題。
我不應該將我的搜索限制在未解決的問題上,不幸的時機。
見https://github.com/rust-lang/rust/issues/97799
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/506741.html