Commit Graph

318 Commits

Author SHA1 Message Date
dianne
36ff87e90e EUV: fix place of deref pattern's interior's scrutinee
The place previously used here was that of the temporary holding the
reference returned by `Deref::deref` or `DerefMut::deref_mut`. However,
since the inner pattern of `deref!(inner)` expects the deref-target type
itself, this would ICE when that type was inspected (e.g. by the EUV
case for slice patterns). This adds a deref projection to fix that.

Since current in-tree consumers of EUV (upvar inference and clippy)
don't care about Rvalues, the place could be simplified to
`self.cat_rvalue(pat.hir_id, self.pat_ty_adjusted(subpat)?)` to save
some cycles. I personally find EUV to be a bit fragile, so I've opted
for pedantic correctness. Maybe a `HACK` comment would suffice though?
2025-03-13 01:01:26 -07:00
Oli Scherer
cb4751d4b8 Implement #[define_opaque] attribute for functions. 2025-03-11 12:05:02 +00:00
Esteban Küber
7302dc660b Make E0614 a structured error
```
error[E0614]: type `(..., ..., ..., ...)` cannot be dereferenced
  --> $DIR/long-E0614.rs:10:5
   |
LL |     *x;
   |     ^^ can't be dereferenced
   |
   = note: the full name for the type has been written to '$TEST_BUILD_DIR/$FILE.long-type-hash.txt'
   = note: consider using `--verbose` to print the full type name to the console
```
2025-02-25 16:56:04 +00:00
Michael Goulet
160905b625 Trim suggestion part before generating highlights 2025-02-21 00:54:01 +00:00
Michael Goulet
0a7ab1d6df More sophisticated span trimming 2025-02-21 00:41:17 +00:00
bors
6d3c050de8 Auto merge of #137295 - matthiaskrgr:rollup-tdu3t39, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #135296 (interpret: adjust vtable validity check for higher-ranked types)
 - #137106 (Add customized compare for Link in rustdoc)
 - #137253 (Restrict `bevy_ecs` `ParamSet` hack)
 - #137262 (Make fewer crates depend on `rustc_ast_ir`)
 - #137263 (Register `USAGE_OF_TYPE_IR_INHERENT`, remove inherent usages)
 - #137266 (MIR visitor tweaks)
 - #137269 (Pattern Migration 2024: properly label `&` patterns whose subpatterns are from macro expansions)
 - #137277 (stabilize `inherent_str_constructors`)
 - #137281 (Tweak "expected ident" parse error to avoid talking about doc comments)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-02-20 02:39:28 +00:00
dianne
51a2ee3252 don't get trapped inside of expansions when trimming labels 2025-02-19 01:43:38 -08:00
dianne
ef6df3b713 add a failing test 2025-02-19 00:56:45 -08:00
dianne
20149629ba "classic2021" ruleset: experimentally add fallback-to-outer (eat both)
My reasoning: the ruleset implemented by the same feature gate in
Edition 2024 always tries to eat the inherited reference first. For
consistency, it makes sense to me to say across all editions that users
should consider the inherited reference's mutability when wondering if a
`&mut` pattern will type.
2025-02-18 18:00:17 -08:00
dianne
1ed74aaf0c add mixed-edition tests 2025-02-18 18:00:11 -08:00
dianne
443c51d5d6 "structural2021" ruleset: add fallback-to-outer (eat both) deref rule 2025-02-18 17:44:28 -08:00
dianne
8dc64a405d "classic2021" and "structural2021" rulesets: add eat-inherited-ref-alone deref rules 2025-02-18 17:44:28 -08:00
dianne
3e77657312 remove old edition-2021-specific tests
These are superseded by the old-edition revisions on the shared tests.
2025-02-18 17:44:28 -08:00
dianne
e24833a4a8 add test revisions for old-edition behavior of feature gates
This also adds `#[cfg]` attributes to tests for bindings' types,
to make it visually clearer which revisions type successfully.
2025-02-18 17:44:28 -08:00
Matthias Krüger
54db888355
Rollup merge of #137161 - dianne:pat-migration-bookkeeping-for-macros, r=Nadrieril
Pattern Migration 2024: fix incorrect messages/suggestions when errors arise in macro expansions

See the diff between the two commits for how this affected the error message and suggestion. In order to decide how to format those, the pattern migration diagnostic keeps track of which parts of the user's pattern cause problems in Edition 2024. However, it neglected to do some of this bookkeeping when pointing to macro expansion sites. This fixes that.
2025-02-18 18:40:52 +01:00
dianne
82678df0de bookkeep properly when pointing into macro expansions 2025-02-16 19:27:48 -08:00
dianne
7af4630770 add a failing test 2025-02-16 19:17:52 -08:00
Nicholas Nethercote
7a8c0fc117 Rename pattern_complexity attr as pattern_complexity_limit.
For consistency with `recursion_limit`, `move_size_limit`, and
`type_length_limit`.
2025-02-17 09:30:40 +11:00
Michael Goulet
6d71251cf9 Trim suggestion parts to the subset that is purely additive 2025-02-14 00:44:10 -08:00
Michael Goulet
f6406dfd4e Consider add-prefix replacements too 2025-02-14 00:27:17 -08:00
Michael Goulet
b480a9214a Use underline suggestions for purely 'additive' replacements 2025-02-14 00:27:13 -08:00
Esteban Küber
f0845adb0c Show diff suggestion format on verbose replacement
```
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-10 20:21:39 +00:00
Shunpoco
ba124898c0 Add comment for regression #136223 on borrowck-errors.rs
Signed-off-by: Shunpoco <tkngsnsk313320@gmail.com>
2025-02-07 21:40:58 +00:00
Matthias Krüger
20f9e973d9
Rollup merge of #136577 - dianne:simple-pat-migration-simplification, 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-07 18:26:27 +01:00
dianne
f1e4d94fa4 add more pattern migration tests
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-05 19:21:38 -08:00
dianne
b32a5331dc try to suggest eliding redundant binding modifiers 2025-02-05 09:17:25 -08:00
dianne
a5cc4cbe64 reword default binding mode notes 2025-02-05 09:05:39 -08:00
Oli Scherer
9a2073d500 Uniformly handle HIR literals in visitors and lints 2025-02-05 11:28:24 +00:00
Oli Scherer
d1231eabf9 Add regression test 2025-02-05 11:25:44 +00:00
dianne
767f82039c separate labels for default binding mode spans into their own notes 2025-02-05 01:12:40 -08:00
dianne
a064e78663 don't include trailing open parens in labels for reference patterns 2025-02-04 03:27:59 -08:00
dianne
203d3109d8 experimentally label the spans for default binding modes 2025-02-04 03:18:10 -08:00
dianne
4331f55b72 highlight the whole problem subpattern when pointing out the default binding mode 2025-02-03 22:23:35 -08:00
dianne
9202001c1c add tests for label formatting 2025-02-03 22:06:42 -08:00
dianne
bbe40acb9a use more specific wording for subpatterns from macro expansions 2025-02-03 19:56:46 -08:00
dianne
bdc6c4d07b reword pattern migration diagnostic to make sense in all editions
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-02-03 01:50:14 -08:00
Matthias Krüger
a3663577f2
Rollup merge of #135434 - dianne:match-2024-for-edition-2024, r=Nadrieril
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-30 12:45:18 +01:00
Oli Scherer
559648a0a4 Handle all PatExprs in dead code analysis 2025-01-29 15:45:13 +00:00
Oli Scherer
8f09abb497 Add regression test showing we don't realize some consts are used 2025-01-29 15:45:13 +00:00
León Orell Valerian Liehr
0b18b4fbbc
Remove all dead files inside tests/ui/ 2025-01-27 02:28:04 +01:00
dianne
e288cff5cf add tests differing between stable and new rules (with errors on new rules)
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-21 06:39:08 -08:00
dianne
f5567e1132 organize old well-typed-edition-2024 tests
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-21 06:37:30 -08:00
dianne
4ed44c9bd6 add a stable edition 2021 revision to pattern typing tests
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-21 05:17:22 -08:00
dianne
afd976b2b0 add more information to old tests 2025-01-21 05:17:22 -08:00
dianne
fdcbd7111b minor test cleanup
- Removes some excess parens

- Removes 3 duplicated tests
2025-01-21 05:17:22 -08:00
dianne
3f9b198dcb rename tests' revisions to allow testing multiple editions 2025-01-20 20:19:11 -08:00
dianne
586ff158a2 "structural" ruleset: match against the inherited ref when a reference pattern doesn't match the mutability of an inner reference
This is the `Deref(EatInner, FallbackToOuter)` rule in Typing Rust Patterns.
2025-01-20 16:03:37 -08:00
dianne
f8315ae3b5 "structural" ruleset: use the "classic" ruleset's diagnostic and fallback 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 16:03:37 -08:00
dianne
c03769524b "structural" ruleset: account for dbm mutability cap in Deref(EatInner) rules 2025-01-20 16:03:37 -08:00
dianne
c57708a58d add more tests where the rulesets disagree
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-20 16:03:37 -08:00