rust-lang / rust-lang/rust

[lldb] Option<String> with empty string incorrectly displayed as None

Open
#150,392 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-debuggers-lldb C-bug T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

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

Image

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading rustlib/etc/lldb_providers.py, especially ClangEncodedEnumProvider, then reproduce the Rust sample with LLDB and compare Option with Option<&str>. Done means a Some(String::from("")) value is displayed as Some("") while is_none remains false, without regressing the working &str case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.