Description
When debugging Rust code with LLDB, Option containing an empty string (Some(String::from(""))) is incorrectly displayed as None in the debugger. However, Option<&str> with an empty string displays correctly as Some("").
This appears to be a regression in the LLDB formatters (rustlib/etc/lldb_providers.py).
Environment
- OS: macOS (Apple Silicon / aarch64-apple-darwin)
- Rust: 1.83.0 stable (and nightly)
- LLDB: bundled with Xcode
- IDE: VSCode + CodeLLDB v1.12.0
Affected Versions
| Rust Version |
CodeLLDB Version |
Status |
| ~1.80 |
v1.10.0 |
✅ Works correctly |
| 1.81+ |
v1.11.0+ |
❌ Bug present |
Steps to Reproduce
fn main() {
// Case 1: String - BROKEN
let ss = String::from("");
let v = Some(ss);
let is_none = v.is_none();
println!("{v:?} {is_none}"); // Prints: Some("") false
// Case 2: &str - WORKS
let ss2 = "";
let v2 = Some(ss2);
println!("{v2:?}"); // Prints: Some("")
}
Set a breakpoint at println! and inspect variables in LLDB.
Expected Behavior
| Variable |
Expected Display |
| v (OptionString) |
Some("") |
| is_none |
false |
Actual Behavior
| Variable |
Actual Display |
| v (OptionString) |
None ❌ |
| is_none |
false ✅ |
The fact that is_none = false proves that v is actually Some, but the debugger displays it as None.
Screenshots
Analysis
The issue likely lies in rustlib/etc/lldb_providers.py, specifically in how ClangEncodedEnumProvider handles niche-optimized enums like Option. When the String is empty, the memory layout may be misinterpreted as None.
Related
Description
When debugging Rust code with LLDB, Option containing an empty string (Some(String::from(""))) is incorrectly displayed as None in the debugger. However, Option<&str> with an empty string displays correctly as Some("").
This appears to be a regression in the LLDB formatters (rustlib/etc/lldb_providers.py).
Environment
Affected Versions
Steps to Reproduce
fn main() {
// Case 1: String - BROKEN
let ss = String::from("");
let v = Some(ss);
let is_none = v.is_none();
println!("{v:?} {is_none}"); // Prints: Some("") false
}
Set a breakpoint at println! and inspect variables in LLDB.
Expected Behavior
Actual Behavior
The fact that is_none = false proves that v is actually Some, but the debugger displays it as None.
Screenshots
Analysis
The issue likely lies in rustlib/etc/lldb_providers.py, specifically in how ClangEncodedEnumProvider handles niche-optimized enums like Option. When the String is empty, the memory layout may be misinterpreted as None.
Related