Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit rebinding only for interpolations that refer to a field #379

Merged
merged 4 commits into from
Nov 8, 2024

Conversation

dtolnay
Copy link
Owner

@dtolnay dtolnay commented Nov 8, 2024

For something like:

const CODE: usize = 9;

#[derive(Error, Debug)]
#[error("{id:?} (code {CODE:?})")]
pub struct Error {
    pub id: &'static str,
}

Before:

let Self { id } = self;
match (id, CODE) {
    (__field_id, __field_CODE) => {
        __formatter.write_fmt(format_args!("{__field_id:?} (code {__field_CODE:?})"))
    }
}

After:

let Self { id } = self;
match (id,) {
    (__field_id,) => {
        __formatter.write_fmt(format_args!("{__field_id:?} (code {CODE:?})"))
    }
}

    warning: returning the result of a `let` binding from a block
      --> impl/src/fmt.rs:67:21
       |
    63 | /                     let member = match int.parse::<u32>() {
    64 | |                         Ok(index) => MemberUnraw::Unnamed(Index { index, span }),
    65 | |                         Err(_) => return Ok(()),
    66 | |                     };
       | |______________________- unnecessary `let` binding
    67 |                       member
       |                       ^^^^^^
       |
       = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_and_return
       = note: `-W clippy::let-and-return` implied by `-W clippy::all`
       = help: to override `-W clippy::all` add `#[allow(clippy::let_and_return)]`
    help: return the expression directly
       |
    63 ~
    64 ~                     match int.parse::<u32>() {
    65 +                         Ok(index) => MemberUnraw::Unnamed(Index { index, span }),
    66 +                         Err(_) => return Ok(()),
    67 +                     }
       |
@dtolnay dtolnay merged commit 5dfd2cc into master Nov 8, 2024
20 checks passed
@dtolnay dtolnay deleted the binding branch November 8, 2024 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant