rust-lang / rust-lang/rust-clippy

single_match_else suggestion introduces violation of semicolon_if_nothing_returned

Open
#16,579 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

When applying the single_match_else suggestion, the output introduces a violation of semicolon_if_nothing_returned.

Reproducer

Code:

            match parse_char_escape(line) {
                Some(decoded) => result.push(decoded),
                None => {
                    result.push('\\');
                    result.push(line.current());
                    line.advance();
                }
            }

Current output:

            if let Some(decoded) = parse_char_escape(line) {
                result.push(decoded) // semicolon_if_nothing_returned
            } else {
                result.push('\\');
                result.push(line.current());
                line.advance();
            }

Desired output:

            if let Some(decoded) = parse_char_escape(line) {
                result.push(decoded);
            } else {
                result.push('\\');
                result.push(line.current());
                line.advance();
            }
Version
nightly
Additional Labels

No response

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 reproducing the interaction between the single_match_else suggestion and the semicolon_if_nothing_returned lint using the Rust example in this issue. Trace the suggestion's generated output and verify that the resulting if-let branch includes the required semicolon and no longer triggers the second lint.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.