diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-11-20 20:10:12 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-20 20:10:12 +0100 |
| commit | 7fc2b337229dfb4bc2e410317af271c1b8dbfe6b (patch) | |
| tree | 08d5c5b85c484deb0435fe99ea5bcbef2f3bc217 /library/alloc/src/lib.rs | |
| parent | 71d3c7790f7bcbfc254270ef76c3d772104321e1 (diff) | |
| parent | 29acf8b422ab446fa4cd51fbb0e5a145f30c1cfc (diff) | |
| download | rust-7fc2b337229dfb4bc2e410317af271c1b8dbfe6b.tar.gz rust-7fc2b337229dfb4bc2e410317af271c1b8dbfe6b.zip | |
Rollup merge of #132708 - estebank:const-as-binding, r=Nadrieril
Point at `const` definition when used instead of a binding in a `let` statement Modify `PatKind::InlineConstant` to be `ExpandedConstant` standing in not only for inline `const` blocks but also for `const` items. This allows us to track named `const`s used in patterns when the pattern is a single binding. When we detect that there is a refutable pattern involving a `const` that could have been a binding instead, we point at the `const` item, and suggest renaming. We do this for both `let` bindings and `match` expressions missing a catch-all arm if there's at least one single binding pattern referenced. After: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | const PAT: u32 = 0; | -------------- missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable ... LL | let PAT = v1; | ^^^ pattern `1_u32..=u32::MAX` not covered | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` help: introduce a variable instead | LL | let PAT_var = v1; | ~~~~~~~ ``` Before: ``` error[E0005]: refutable pattern in local binding --> $DIR/bad-pattern.rs:19:13 | LL | let PAT = v1; | ^^^ | | | pattern `1_u32..=u32::MAX` not covered | missing patterns are not covered because `PAT` is interpreted as a constant pattern, not a new variable | help: introduce a variable instead: `PAT_var` | = note: `let` bindings require an "irrefutable pattern", like a `struct` or an `enum` with only one variant = note: for more information, visit https://doc.rust-lang.org/book/ch18-02-refutability.html = note: the matched value is of type `u32` ``` CC #132582.
Diffstat (limited to 'library/alloc/src/lib.rs')
0 files changed, 0 insertions, 0 deletions
