about summary refs log tree commit diff
path: root/tests/ui/pattern
AgeCommit message (Collapse)AuthorLines
2025-02-17Rename `pattern_complexity` attr as `pattern_complexity_limit`.Nicholas Nethercote-2/+2
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-16/+16
2025-02-14Consider add-prefix replacements tooMichael Goulet-36/+24
2025-02-14Use underline suggestions for purely 'additive' replacementsMichael Goulet-12/+8
2025-02-10Show diff suggestion format on verbose replacementEsteban Küber-226/+339
``` 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-02-07Add comment for regression #136223 on borrowck-errors.rsShunpoco-5/+7
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
2025-02-07Rollup merge of #136577 - dianne:simple-pat-migration-simplification, ↵Matthias Krüger-171/+813
r=Nadrieril Pattern Migration 2024: try to suggest eliding redundant binding modifiers This is based on #136475. Only the last commit is new. This is a simpler, more restrictive alternative to #136496, meant to partially address #136047. If a pattern can be migrated to Rust 2024 solely by removing redundant binding modifiers, this will make that suggestion; otherwise, it uses the old suggestion of making the pattern fully explicit. Relevant tracking issue: #131414 ``@rustbot`` label A-diagnostics A-patterns A-edition-2024 r? ``@Nadrieril``
2025-02-05add more pattern migration testsdianne-1/+400
Most of these are meant to test possible future improvements, but since they cover cases the existing test suite didn't, I figure including them now may be helpful.
2025-02-05try to suggest eliding redundant binding modifiersdianne-10/+13
2025-02-05reword default binding mode notesdianne-82/+82
2025-02-05Uniformly handle HIR literals in visitors and lintsOli Scherer-1/+10
2025-02-05Add regression testOli Scherer-0/+49
2025-02-05separate labels for default binding mode spans into their own notesdianne-165/+253
2025-02-04don't include trailing open parens in labels for reference patternsdianne-1/+1
2025-02-04experimentally label the spans for default binding modesdianne-166/+165
2025-02-03highlight the whole problem subpattern when pointing out the default binding ↵dianne-43/+161
mode
2025-02-03add tests for label formattingdianne-1/+47
2025-02-03use more specific wording for subpatterns from macro expansionsdianne-1/+1
2025-02-03reword pattern migration diagnostic to make sense in all editionsdianne-160/+149
This aligns the main error message a bit more with the phrasing in the Edition Guide and provides a bit more information on the labels to (hopefully!) aid in understanding.
2025-01-30Rollup merge of #135434 - dianne:match-2024-for-edition-2024, r=NadrierilMatthias Krüger-303/+1832
Match Ergonomics 2024: update edition 2024 behavior of feature gates This updates the edition 2024 behavior of the feature gates `ref_pat_eat_one_layer_2024_structural` and `ref_pat_eat_one_layer_2024` to correspond to the left and right typing rules compared [here](https://nadrieril.github.io/typing-rust-patterns/?compare=true&opts2=AQEBAAABAQABAgIAAQEBAAEBAAABAAA%3D&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=rules&do_cmp=true&ty_d=3&style=SequentBindingMode), respectively. I'll implement the proposed new behavior for editions ≤ 2021 in another PR. The tests are split up a bit awkwardly for practical reasons, but I've added new tests from 3 places: - I got tests for where the typing rules differ from the "Compare" tab of the page linked above. These had to be split up based on where the errors are emitted and how rustfixable they are, so they've ended up in different files to keep tidy. Within each file, though, the order of the tests matches the order the typing differences appear in that comparison (as of when this was written). - I used [this other comparison](https://nadrieril.github.io/typing-rust-patterns/?q=%5B%26mut+%26%28mut+x%29%5D%3A+%26mut+%5B%26CT%5D&compare=true&opts2=AQEBAgABAQEBAgIAAQEBAAEBAAABAAA%3D&opts1=AQEBAgEBAQEBAgIAAAAAAAAAAAAAAAA%3D&mode=compare&do_cmp=true&ty_d=3&style=SequentBindingMode) to test the `Deref(EatInner, FallbackToOuter)` rule of the left/"structural"/eat-inner ruleset. These are all in `well-typed-edition-2024.rs`. - I added some select tests for cases where the new typing rules differ from current stable Rust. I had to be pickier about what I included here, but I tried to make sure each typing rule got some coverage. That said, my approach for these tests was a bit ad-hoc, so I may have missed something. Relevant tracking issue: #123076 r? ````@ghost````
2025-01-29Handle all `PatExpr`s in dead code analysisOli Scherer-18/+3
2025-01-29Add regression test showing we don't realize some consts are usedOli Scherer-1/+24
2025-01-27Remove all dead files inside tests/ui/León Orell Valerian Liehr-778/+0
2025-01-21add tests differing between stable and new rules (with errors on new rules)dianne-18/+155
Since there are so many ways to write these, I've opted to only include two sorts of test: simple tests that directly target the rules differing between rulesets and nuanced tests that produce different errors under different rulesets. I've also tried not to add any duplicate tests. `well-typed-edition-2024.rs` already has tests disagreeing with stable, so I've opted not to include any in this commit that are well-typed under the new rules.
2025-01-21organize old well-typed-edition-2024 testsdianne-85/+100
This doesn't (or at least shouldn't!) add, remove, or change any test cases. I've grouped them by which rule variants they test.
2025-01-21add a stable edition 2021 revision to pattern typing testsdianne-198/+1103
This serves two purposes. First, they're additional tests that stable Rust behavior hasn't been messed with. There's plenty of other pattern tests, so this is less important, but these at least are targeted at what's being changed. Second, this helps document exactly where the new rulesets agree and disagree with stable pattern typing. This will be especially important after the new rules for old editions are updated, since they need to be strictly more permissive; any patterns well-typed on stable should also be well-typed with the same resultant bindings on the (upcoming) new new old-edition rules. The unusual test ordering on `borrowck-errors.rs` and `ref-binding-on-inh-ref-errors.rs` are to hopefully reduce how much adding new tests will mess with line numbers in their stderr.
2025-01-21add more information to old testsdianne-28/+36
2025-01-21minor test cleanupdianne-59/+26
- Removes some excess parens - Removes 3 duplicated tests
2025-01-20rename tests' revisions to allow testing multiple editionsdianne-93/+93
2025-01-20"structural" ruleset: match against the inherited ref when a reference ↵dianne-62/+61
pattern doesn't match the mutability of an inner reference This is the `Deref(EatInner, FallbackToOuter)` rule in Typing Rust Patterns.
2025-01-20"structural" ruleset: use the "classic" ruleset's diagnostic and fallback ↵dianne-355/+120
for inherited ref mutability mismatches I think the diagnostic could use some work, but it's more helpful than the alternative. The previous error was misleading, since it ignored the inherited reference altogether.
2025-01-20"structural" ruleset: account for dbm mutability cap in Deref(EatInner) rulesdianne-12/+106
2025-01-20add more tests where the rulesets disagreedianne-6/+659
These come directly from the "Compare" tab of Typing Rust Patterns, though they had to be split across multiple files. They're not comprehensive, but they do provide some previously-missing coverage and are easier to check against the spec. Possibly they should be split up some more, since `pattern-errors.rs` is getting a bit unwieldy, but I'm not sure how best to go about that.
2025-01-20remove Rule 3 from `ref_pat_eat_one_layer_2024`dianne-31/+17
The debug assertion ensuring that the pattern mutability cap holds assumes the presence of Rule 3, so it now checks for that. I considered going back to only tracking the mutability cap when Rule 3 is present, but since the mutability cap is used in Rule 5's implementation too, the debug assertion would still need to check which typing rules are present. This also required some changes to tests: - `ref_pat_eat_one_layer_2021.rs` had a test for Rule 3; I'll be handling tests for earlier editions in a later commit, so as a stopgap I've #[cfg]ed it out. - One test case had to be moved from `well-typed-edition-2024.rs` to `borrowck-errors.rs` in order to get borrowck to run on it and emit an error.
2025-01-20Auto merge of #135754 - jieyouxu:rollup-j4q1hpr, r=jieyouxubors-1/+1
Rollup of 7 pull requests Successful merges: - #135542 (Add the concrete syntax for precise capturing to 1.82 release notes.) - #135700 (Emit single privacy error for struct literal with multiple private fields and add test for `default_field_values` privacy) - #135722 (make it possible to use ci-rustc on tarball sources) - #135729 (Add debug assertions to compiler profile) - #135736 (rustdoc: Fix flaky doctest test) - #135738 (Replace usages of `map_or(bool, ...)` with `is_{some_and|none_or|ok_and}`) - #135747 (Rename FileName::QuoteExpansion to CfgSpec) r? `@ghost` `@rustbot` modify labels: rollup
2025-01-20Rollup merge of #135237 - dianne:match-2024-cleanup, r=Nadrieril许杰友 Jieyou Xu (Joe)-9/+1150
Match Ergonomics 2024: document and reorganize the currently-implemented feature gates The hope here is to make it easier to adjust, understand, and test the experimental pattern typing rules implemented in the compiler. This PR doesn't (or at isn't intended to) change any behavior or add any new tests; I'll be handling that later. I've also included some reasoning/commentary on the more involved changes in the commit messages. Relevant tracking issue: #123076 r? `@Nadrieril`
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 ```
2025-01-12remove `tests/ui/pattern/no_ref_mut_behind_and.rs`dianne-9/+0
This was a test for `ref_pat_eat_one_layer_2024` downgrading a `mut ref` default binding mode to `ref` within a shared reference pattern (i.e. Rule 3) on edition 2021 specifically. Since it's near-identical to another existing test (currently in `ref_pat_eat_one_layer_2021.rs` in the "experimental" rfc 3627 subdirectory) and that particular feature gate's typing rulesets are planned to no longer have Rule 3, I'm opting to remove it rather than continue maintaining it separately.
2025-01-12rename and comment the test for "Rule 5"-related mutability errorsdianne-7/+91
This also makes it test the "structural" ruleset, in preparation for additional tests where the rulesets disagree.
2025-01-08Rollup merge of #135222 - estebank:issue-135209, r=compiler-errorsMatthias Krüger-3/+64
Ensure that we don't try to access fields on a non-struct pattern type Fix #135209.
2025-01-08reorganize and comment some of the experimental pattern typing testsdianne-497/+529
This only includes previously existing tests (with a couple duplicates removed). I plan on adding more comprarisons where the rules differ once I've updated the pattern typing rules. I also haven't touched the tests for new rules in old editions; I'll see how best to handle that once those rules are updated as well.
2025-01-08move the experimental match ergonomics tests to be with the other rfc 3627 testsdianne-0/+1034
2025-01-08Rename PatKind::Lit to ExprOli Scherer-1/+1
2025-01-08modify test to side-step platform-dependent stderr outputEsteban Küber-18/+27
2025-01-08Add check for missing fields in enum variant patternEsteban Küber-3/+20
2025-01-07Ensure that we don't try to access fields on a non-struct pattern type in ↵Esteban Küber-0/+35
diagnostic Fix #135209.
2024-12-31Rollup merge of #133486 - dianne:fix-move-error-suggestion, r=estebankTrevor Gross-0/+10
borrowck diagnostics: make `add_move_error_suggestions` use the HIR rather than `SourceMap` This PR aims to fix #132806 by rewriting `add_move_error_suggestions`[^1]. Previously, it manually scanned the source text to find a leading `&`, which isn't always going to produce a correct result (see: that issue). Admittedly, the HIR visitor in this PR introduces a lot of boilerplate, but hopefully the logic at its core isn't too complicated (I go over it in the comments). I also tried a simpler version that didn't use a HIR visitor and suggested adding `ref` always, but the `&ref x` suggestions really didn't look good. As a bonus for the added complexity though, it's now able to produce nice `&`-removing suggestions in more cases. I tried to do this such that it avoids edition-dependent checks and its suggestions can be applied together with those from the match ergonomics 2024 migration lint. I haven't added tests for that since the details of match ergonomics 2024 are still being sorted out, but I can try if desired once that's finalized. [^1]: In brief, it fires on patterns where users try to bind by-value in such a way that moves out of a reference to a non-Copy type (including slice references with non-copy elements). The suggestions are to change the binding's mode to be by-reference, either by removing[^2] an enclosing `&`/`&mut` or adding `ref` to the binding. [^2]: Incidentally, I find the terminology of "consider removing the borrow" a bit confusing for a suggestion to remove a `&` pattern in order to make bindings borrow rather than move. I'm not sure what a good, concise way to explain that would be though, and that should go in a separate PR anyway.
2024-12-19Rollup merge of #134474 - oli-obk:push-yomnkntvzlxw, r=compiler-errors许杰友 Jieyou Xu (Joe)-11/+15
Forbid overwriting types in typeck While trying to figure out some type setting logic in https://github.com/rust-lang/rust/pull/134248 I realized that we sometimes set a type twice. While hopefully that would have been the same type, we didn't ensure that at all and just silently accepted it. So now we reject setting it twice, unless errors are happening, then we don't care. Best reviewed commit by commit. No behaviour change is intended.
2024-12-18Forbid overwriting types in typeckOli Scherer-11/+15
2024-12-17Add the edition guide link from the match 2024 migration lint to the error ↵dianne-0/+8
as well