about summary refs log tree commit diff
path: root/tests/ui/pattern/usefulness
AgeCommit message (Collapse)AuthorLines
2025-09-25usize/isize range matching error clarificationhelldawg-23/+23
2025-07-28In rustc_pattern_analysis, put `true` witnesses before `false` witnessesChayim Refael Friedman-3/+3
In rustc it doesn't really matter what the order of the witnesses is, but I'm planning to use the witnesses for implementing the "add missing match arms" assist in rust-analyzer, and there `true` before `false` is the natural order (like `Some` before `None`), and also what the current assist does. The current order doesn't seem to be intentional; the code was created when bool ctors became their own thing, not just int ctors, but for integer, 0 before 1 is indeed the natural order.
2025-06-30Remove let_chains featureCameron Steffen-10/+12
2025-06-03Use non-2015 edition paths in tests that do not test for their resolutionLukas Wirth-1/+1
This allows for testing these tests on editions other than 2015
2025-05-03compiletest: Do not require annotations on empty labels and suggestionsVadim Petrochenkov-2/+1
2025-04-30compiletest: Make diagnostic kind mandatory on line annotationsVadim Petrochenkov-12/+20
2025-04-08UI tests: add missing diagnostic kinds where possibleVadim Petrochenkov-28/+28
2025-03-11Implement `#[define_opaque]` attribute for functions.Oli Scherer-40/+46
2025-02-21Trim suggestion part before generating highlightsMichael Goulet-21/+21
2025-02-21More sophisticated span trimmingMichael Goulet-18/+12
2025-02-17Rename `pattern_complexity` attr as `pattern_complexity_limit`.Nicholas Nethercote-1/+1
For consistency with `recursion_limit`, `move_size_limit`, and `type_length_limit`.
2025-02-14Trim suggestion parts to the subset that is purely additiveMichael Goulet-12/+12
2025-02-14Consider add-prefix replacements tooMichael Goulet-36/+24
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-36/+54
``` error[E0610]: `{integer}` is a primitive type and therefore doesn't have fields --> $DIR/attempted-access-non-fatal.rs:7:15 | LL | let _ = 2.l; | ^ | help: if intended to be a floating point literal, consider adding a `0` after the period and a `f64` suffix | LL - let _ = 2.l; LL + let _ = 2.0f64; | ```
2025-01-27Remove all dead files inside tests/ui/León Orell Valerian Liehr-778/+0
2025-01-18Emit a single privacy error for multiple fields on the same struct expressionEsteban Küber-1/+1
Collect all unreachable fields in a single struct literal struct and emit a single error, instead of one error per private field. ``` error[E0451]: fields `beta` and `gamma` of struct `Alpha` are private --> $DIR/visibility.rs:18:13 | LL | let _x = Alpha { | ----- in this type LL | beta: 0, | ^^^^^^^ private field LL | .. | ^^ field `gamma` is private ```
2024-12-04Add additional context for non-sructural type constant used in patternEsteban Küber-5/+11
- Point at type that should derive `PartialEq` to be structural. - Point at manual `impl PartialEq`, explaining that it is not sufficient to be structural. ``` error: constant of non-structural type `MyType` in a pattern --> $DIR/const-partial_eq-fallback-ice.rs:14:12 | LL | struct MyType; | ------------- `MyType` must be annotated with `#[derive(PartialEq)]` to be usable in patterns ... LL | const CONSTANT: &&MyType = &&MyType; | ------------------------ constant defined here ... LL | if let CONSTANT = &&MyType { | ^^^^^^^^ constant of non-structural type | note: the `PartialEq` trait must be derived, manual `impl`s are not sufficient; see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details --> $DIR/const-partial_eq-fallback-ice.rs:5:1 | LL | impl PartialEq<usize> for MyType { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ```
2024-12-04Tweak ptr in pattern errorEsteban Küber-16/+32
Conform to error style guide.
2024-12-04On `const` pattern errors, point at the `const` item definitionEsteban Küber-0/+27
Centralize emitting an error in `const_to_pat` so that all errors from that evaluating a `const` in a pattern can add addditional information. With this, now point at the `const` item's definition: ``` error[E0158]: constant pattern depends on a generic parameter --> $DIR/associated-const-type-parameter-pattern.rs:20:9 | LL | pub trait Foo { | ------------- LL | const X: EFoo; | ------------- constant defined here ... LL | A::X => println!("A::X"), | ^^^^ ```
2024-11-26tests: remove `//@ pretty-expanded` usages许杰友 Jieyou Xu (Joe)-2/+0
Done with ```bash sd '//@ pretty-expanded.*\n' '' tests/ui/**/*.rs ``` and ``` sd '//@pretty-expanded.*\n' '' tests/ui/**/*.rs ```
2024-11-23Update tests for new TRPL chapter orderChris Krycho-21/+21
2024-11-20Rollup merge of #132708 - estebank:const-as-binding, r=NadrierilMatthias Krüger-0/+84
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.
2024-11-17Unify expanded constants and named constants in `PatKind`Esteban Küber-0/+84
2024-11-16Also check if let chains with multiple lets in these two testsest31-5/+15
2024-11-08Get rid of check_opaque_type_well_formedMichael Goulet-28/+28
2024-10-24add third help hint to diagnostic error E0027Duncan Proctor-0/+24
2024-09-13Add a machine-applicable suggestion to "unreachable pattern"Nadrieril-84/+433
2024-09-11Revert warning empty patterns as unreachableNadrieril-427/+57
2024-08-20Move the "matches no value" note to be a span labelNadrieril-248/+124
2024-08-19Cap the number of patterns pointed to by the lintNadrieril-9/+52
2024-08-19Add a note with a link to explain empty typesNadrieril-17/+148
2024-08-19Reword the "unreachable pattern" explanationsNadrieril-391/+391
2024-08-13Remove a no-longer-true `assert`Nadrieril-95/+132
2024-08-10Test that 0/unknown-length arrays are nonemptyNadrieril-47/+144
2024-08-10Update testsNadrieril-451/+612
2024-08-10Stabilize `min_exhaustive_patterns`Nadrieril-1/+0
2024-07-24Improve "covered_by_many" errorNadrieril-21/+102
2024-07-24Explain why a given pattern is considered unreachableNadrieril-122/+824
2024-07-21Explain why we require `_` for empty patternsNadrieril-0/+10
2024-06-23Replace `f16` and `f128` pattern matching stubs with real implementationsTrevor Gross-23/+97
This section of code depends on `rustc_apfloat` rather than our internal types, so this is one potential ICE that we should be able to melt now. This also fixes some missing range and match handling in `rustc_middle`.
2024-05-26Auto merge of #124661 - RalfJung:only-structural-consts-in-patterns, r=pnkfelixbors-176/+24
Turn remaining non-structural-const-in-pattern lints into hard errors This completes the implementation of https://github.com/rust-lang/rust/issues/120362 by turning our remaining future-compat lints into hard errors: indirect_structural_match and pointer_structural_match. They have been future-compat lints for a while (indirect_structural_match for many years, pointer_structural_match since Rust 1.75 (released Dec 28, 2023)), and have shown up in dependency breakage reports since Rust 1.78 (just released on May 2, 2024). I don't expect a lot of code will still depend on them, but we will of course do a crater run. A lot of cleanup is now possible in const_to_pat, but that is deferred to a later PR. Fixes https://github.com/rust-lang/rust/issues/70861
2024-05-03turn pointer_structural_match into a hard errorRalf Jung-164/+24
2024-05-03remove IndirectStructuralMatch lint, emit the usual hard error insteadRalf Jung-12/+0
2024-05-02Stabilize exclusive_rangeRoss Smyth-96/+89
2024-04-01Fix union handling in exhaustivenessNadrieril-11/+12
2024-03-31Add testsNadrieril-0/+68
2024-03-18Rollup merge of #121823 - Nadrieril:never-witnesses, r=compiler-errorsMatthias Krüger-187/+880
never patterns: suggest `!` patterns on non-exhaustive matches When a match is non-exhaustive we now suggest never patterns whenever it makes sense. r? ``@compiler-errors``
2024-03-13Remove `MaybeInfiniteInt::JustAfterMax`Nadrieril-4/+4
It was inherited from before half-open ranges, but it doesn't pull its weight anymore. We lose a tiny bit of diagnostic precision.
2024-03-13Rollup merge of #121908 - Nadrieril:dynamic-variant-collection, r=matthewjasperMatthias Krüger-0/+14
match lowering: don't collect test alternatives ahead of time I'm very happy with this one. Before this, when sorting candidates into the possible test branches, we manually computed `usize` indices to determine in which branch each candidate goes. To make this work we had a first pass that collected the possible alternatives we'd have to deal with, and a second pass that actually sorts the candidates. In this PR, I replace `usize` indices with a dedicated enum. This makes `sort_candidates` easier to follow, and we don't need the first pass anymore. r? ``@matthewjasper``
2024-03-12Don't suggest an arm when suggesting a never patternNadrieril-15/+15