Skip to content

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

Merged
dtolnay merged 4 commits intomasterfrom
binding
Nov 8, 2024
Merged

Emit rebinding only for interpolations that refer to a field#379
dtolnay merged 4 commits intomasterfrom
binding

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
@dtolnay dtolnay deleted the binding branch November 8, 2024 18:25
takumi-earth pushed a commit to earthlings-dev/thiserror that referenced this pull request Jan 27, 2026
Emit rebinding only for interpolations that refer to a field
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