rust-lang / rust-lang/rust-analyzer
`replace_let_with_if_let` panics on unterminated string literal
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
when invoking Replace let with if let on a let binding whose initializer is an unterminated string literal r-a panics inside the assist handler. the syntax tree is parseable but incomplete and SyntaxFactory::expr_if calls ast.then_branch().unwrap() on the constructed node without guarding against the case where the branch is absent returning None for malformed input and causing an unconditional unwrap failure.
reproduce:
let s = "foo
place cursor on the l of let and apply Replace let with if let.
expected:
the assist should either transform the binding correctly or report that it cannot handle the incomplete expression, without crashing the server.
actual:
thread 'main' panicked at 'called Option::unwrap() on a None value', crates/syntax/src/ast/syntax_factory/constructors.rs:1141
the language server crashes and the editor loses all diagnostics and completions until it restarts.
env:
- rustc: 1.94.0
- rust-analyzer: 0.3.2854
- OS: Ubuntu
- Editor: VS Code
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the crash by applying Replace let with if let to the unterminated string example, then inspect crates/syntax/src/ast/syntax_factory/constructors.rs:1141 and the SyntaxFactory::expr_if path. Done means malformed input no longer panics and the assist either transforms the binding or reports that it cannot handle the incomplete expression.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100