about summary refs log tree commit diff
path: root/tests/ui/pattern
AgeCommit message (Collapse)AuthorLines
2024-12-17Improve the pattern migration 2024 migration lint's messagedianne-62/+62
2024-12-17Clarify the match ergonomics 2024 migration lint's outputdianne-150/+203
2024-12-17Rollup merge of #134368 - ehuss:edition-links, r=jieyouxuJacob Pratt-15/+15
Use links to edition guide for edition migrations This switches the migration lints for the 2024 edition to point to the edition guide documentation instead of the tracking issues. I expect the documentation should be easier to understand for a user, compared to most of the issues which don't have any direct information, and can be a bit confusing to navigate, or have outdated information.
2024-12-15Use links to edition guide for edition migrationsEric Huss-15/+15
2024-12-15Use `span_label` as it looks better when we show pattern missing binding in ↵Esteban Küber-17/+5
order
2024-12-13Keep track of patterns that could have introduced a binding, but didn'tEsteban Küber-0/+52
When we recover from a pattern parse error, or a pattern uses `..`, we keep track of that and affect resolution error for missing bindings that could have been provided by that pattern. We differentiate between `..` and parse recovery. We silence resolution errors likely caused by the pattern parse error. ``` error[E0425]: cannot find value `title` in this scope --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:19:30 | LL | println!("[{}]({})", title, url); | ^^^^^ not found in this scope | note: `Website` has a field `title` which could have been included in this pattern, but it wasn't --> $DIR/struct-pattern-with-missing-fields-resolve-error.rs:17:12 | LL | / struct Website { LL | | url: String, LL | | title: Option<String> , | | ----- defined here LL | | } | |_- ... LL | if let Website { url, .. } = website { | ^^^^^^^^^^^^^^^^^^^ this pattern doesn't include `title`, which is available in `Website` ``` Fix #74863.
2024-12-08Rollup merge of #133424 - Nadrieril:guard-patterns-parsing, r=fee1-deadMatthias Krüger-2/+22
Parse guard patterns This implements the parsing of [RFC3637 Guard Patterns](https://rust-lang.github.io/rfcs/3637-guard-patterns.html) (see also [tracking issue](https://github.com/rust-lang/rust/issues/129967)). This PR is extracted from https://github.com/rust-lang/rust/pull/129996 with minor modifications. cc `@max-niederman`
2024-12-07Address review commentsNadrieril-0/+20
2024-12-04Add additional context for non-sructural type constant used in patternEsteban Küber-9/+17
- 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-04Specify type kind of constant that can't be used in patternsEsteban Küber-6/+6
``` error: trait object `dyn Send` cannot be used in patterns --> $DIR/issue-70972-dyn-trait.rs:6:9 | LL | const F: &'static dyn Send = &7u32; | -------------------------- constant defined here ... LL | F => panic!(), | ^ trait object can't be used in patterns ```
2024-12-04Tweak output of some const pattern errorsEsteban Küber-4/+10
- Add primary span labels. - Point at const generic parameter used as pattern. - Point at statics used as pattern. - Point at let bindings used in const pattern.
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/+33
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-25`add_move_error_suggestions`: use a HIR visitor rather than `SourceMap`dianne-0/+10
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-24parse guard patternsNadrieril-2/+2
Co-authored-by: Max Niederman <max@maxniederman.com>
2024-11-23Auto merge of #131859 - chriskrycho:update-trpl, r=onur-ozkanbors-25/+25
Update TRPL to add new Chapter 17: Async and Await - Add support to `rustbook` to pass through the `-L`/`--library-path` flag to `mdbook` so that references to the `trpl` crate - Build the `trpl` crate as part of the book tests. Make it straightforward to add other such book dependencies in the future if needed by implementing that in a fairly general way. - Update the submodule for the book to pull in the new chapter on async and await, as well as a number of other fixes. This will happen organically/automatically in a week, too, but this lets me group this change with the next one: - Update the compiler messages which reference the existing chapters 17–20, which are now chapters 18-21. There are only two, both previously referencing chapter 18. - Update the UI tests which reference the compiler message outputs.
2024-11-23Update tests for new TRPL chapter orderChris Krycho-25/+25
2024-11-23Rollup merge of #133286 - jieyouxu:bug-ourselves, r=compiler-errors许杰友 Jieyou Xu (Joe)-0/+36
Re-delay a resolve `bug` related to `Self`-ctor in patterns For the code pattern reported in <https://github.com/rust-lang/rust/issues/133272>, ```rs impl Foo { fn fun() { let S { ref Self } = todo!(); } } ``` <https://github.com/rust-lang/rust/pull/121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a targeted test case. Follow-up to #121208, cc ``@nnethercote`` (very good exercise to expose our test coverage gaps). Fixes #133272.
2024-11-22Stabilize the 2024 editionEric Huss-20/+16
2024-11-21Re-delay a resolve `bug`Jieyou Xu-0/+36
For the code pattern reported in <https://github.com/rust-lang/rust/issues/133272>, ```rs impl Foo { fn fun() { let S { ref Self } = todo!(); } } ``` <https://github.com/rust-lang/rust/pull/121208> converted this to a `span_bug` from a `span_delayed_bug` because this specific self-ctor code pattern lacked test coverage. It turns out this can be hit but we just lacked test coverage, so change it back to a `span_delayed_bug` and add a target tested case.
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-10-16Rollup merge of #131381 - Nadrieril:min-match-ergonomics, r=pnkfelixMatthias Krüger-211/+699
Implement edition 2024 match ergonomics restrictions This implements the minimalest version of [match ergonomics for edition 2024](https://rust-lang.github.io/rfcs/3627-match-ergonomics-2024.html). This minimal version makes it an error to ever reset the default binding mode. The implemented proposal is described precisely [here](https://hackmd.io/zUqs2ISNQ0Wrnxsa9nhD0Q#RFC-3627-nano), where it is called "RFC 3627-nano". Rules: - Rule 1C: When the DBM (default binding mode) is not `move` (whether or not behind a reference), writing `mut`, `ref`, or `ref mut` on a binding is an error. - Rule 2C: Reference patterns can only match against references in the scrutinee when the DBM is `move`. This minimal version is forward-compatible with the main proposals for match ergonomics 2024: [RFC3627](https://rust-lang.github.io/rfcs/3627-match-ergonomics-2024.html) itself, the alternative [rule 4-early variant](https://rust-lang.github.io/rfcs/3627-match-ergonomics-2024.html), and [others](https://hackmd.io/zUqs2ISNQ0Wrnxsa9nhD0Q). The idea is to give us more time to iron out a final proposal. This includes a migration lint that desugars any offending pattern into one that doesn't make use of match ergonomics. Such patterns have identical meaning across editions. This PR insta-stabilizes the proposed behavior onto edition 2024. r? `@ghost` Tracking: - https://github.com/rust-lang/rust/issues/123076
2024-10-08Change error messageNadrieril-53/+53
2024-10-08Stabilize `min_match_ergonomics_2024`Nadrieril-36/+101
2024-10-08Also disallow `ref`/`ref mut` overriding the binding modeNadrieril-18/+54
2024-10-08Error on resetted binding mode in edition 2024Nadrieril-23/+225
2024-10-07Prepare testsNadrieril-71/+256
2024-09-24Move existing rfc3627 tests to a dedicated folderNadrieril-21/+21
2024-09-23Parser: better error messages for `@` in struct patternsPavel Grigorenko-0/+83
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-26Don't make pattern nonterminals match statement nonterminalsMichael Goulet-0/+19
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-392/+392
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-08-03Revert "Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix"Michael Goulet-1/+11
This reverts commit 2724aeaaeb127a8073e39461caacbe21a128ce7b, reversing changes made to d929a42a664c026167800801b26d734db925314f.
2024-07-26Peel off explicit (or implicit) deref before suggesting clone on move error ↵Michael Goulet-16/+0
in borrowck
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