Commit Graph

215 Commits

Author SHA1 Message Date
Michael Goulet c61f85b6dd Don't make pattern nonterminals match statement nonterminals 2024-08-26 18:30:15 -04:00
Nadrieril f30392a985 Move the "matches no value" note to be a span label 2024-08-20 21:53:47 +02:00
Nadrieril 36eced444e Cap the number of patterns pointed to by the lint 2024-08-19 21:57:40 +02:00
Nadrieril efb28bdd90 Add a note with a link to explain empty types 2024-08-19 21:57:37 +02:00
Nadrieril 25964b541e Reword the "unreachable pattern" explanations 2024-08-19 21:39:57 +02:00
Nadrieril 249a588cad Remove a no-longer-true assert 2024-08-13 23:00:42 +02:00
Nadrieril 8615a6b006 Test that 0/unknown-length arrays are nonempty 2024-08-10 12:07:17 +02:00
Nadrieril 99468bb760 Update tests 2024-08-10 12:07:17 +02:00
Nadrieril cd40769c02 Stabilize min_exhaustive_patterns 2024-08-10 12:07:17 +02:00
Michael Goulet 22da616245 Revert "Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix"
This reverts commit 2724aeaaeb, reversing
changes made to d929a42a66.
2024-08-03 07:57:31 -04:00
Michael Goulet 91acacf85b Peel off explicit (or implicit) deref before suggesting clone on move error in borrowck 2024-07-26 14:41:56 -04:00
Nadrieril 940769a79b Improve "covered_by_many" error 2024-07-24 08:46:52 +02:00
Nadrieril 64ac2b8082 Explain why a given pattern is considered unreachable 2024-07-24 08:02:55 +02:00
Nadrieril 8a49d83db7 Explain why we require _ for empty patterns 2024-07-21 15:24:27 +02:00
Ralf Jung 67c99d6338 avoid creating an Instance only to immediately disassemble it again 2024-07-18 11:58:16 +02:00
Esteban Küber 692bc344d5 Make parse error suggestions verbose and fix spans
Go over all structured parser suggestions and make them verbose style.

When suggesting to add or remove delimiters, turn them into multiple suggestion parts.
2024-07-12 03:02:57 +00:00
yukang 07e6dd95bd report pat no field error no recoverd struct variant 2024-07-11 00:18:47 +08:00
Esteban Küber ff92ab0903 More accurate mutability suggestion 2024-07-04 05:36:34 +00:00
Esteban Küber 89ecae5d85 Better span for "make binding mutable" suggestion 2024-07-04 02:02:21 +00:00
Michael Goulet 789ee88bd0 Tighten spans for async blocks 2024-06-27 15:19:08 -04:00
Matthias Krüger 95332b8918 Rollup merge of #126925 - surechen:fix_125631, r=compiler-errors
Change E0369 to give note informations for foreign items.

Change E0369 to give note informations for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes #125631
2024-06-26 07:50:18 +02:00
Matthias Krüger 2724aeaaeb Rollup merge of #126618 - mu001999-contrib:dead/enhance, r=pnkfelix
Mark assoc tys live only if the corresponding trait is live

r? ````@pnkfelix````
2024-06-25 18:02:58 +02:00
surechen 2a6a42329f Change E0369 diagnostic give note information for foreign items.
Make it easy for developers to understand why the binop cannot be applied.

fixes #125631
2024-06-25 10:00:30 +08:00
Trevor Gross 6fb6c19c96 Replace f16 and f128 pattern matching stubs with real implementations
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-06-23 04:28:42 -05:00
mu001999 a264bff9d5 Mark assoc tys live only if the trait is live 2024-06-18 16:00:57 +08:00
Oli Scherer a6217011f6 Replace some Option<Diag> with Result<(), Diag> 2024-06-13 06:16:12 +00:00
Oli Scherer 2733b8ab8d Avoid follow-up errors on erroneous patterns 2024-06-13 06:14:32 +00:00
Matthias Krüger 2611b292c4 Rollup merge of #125168 - Jules-Bertholet:match-ergonomics-2024-align-with-rfc, r=Nadrieril
Match ergonomics 2024: align implementation with RFC

- Remove eat-two-layers (`ref_pat_everywhere`)
- Consolidate `mut_preserve_binding_mode_2024` into `ref_pat_eat_one_layer_2024`
- `&mut` no longer peels off `&`
- Apply "no `ref mut` behind `&`" rule on all editions with `ref_pat_eat_one_layer_2024`
- Require `mut_ref` feature gate for all mutable by-reference bindings

r? ``@Nadrieril``

cc https://github.com/rust-lang/rust/issues/123076

``@rustbot`` label A-edition-2024 A-patterns
2024-06-06 04:17:26 +02:00
bors 5fe5543502 Auto merge of #124661 - RalfJung:only-structural-consts-in-patterns, r=pnkfelix
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-26 07:55:47 +00:00
Jubilee Young d89500843c Move 100 entries from tests/ui into subdirs
- Move super-fast-paren-parsing test into ui/parser
- Move stmt_expr_attrs test into ui/feature-gates
- Move macro tests into ui/macros
- Move global_asm tests into ui/asm
- Move env tests into ui/process
- Move xcrate tests into ui/cross-crate
- Move unop tests into ui/unop
- Move backtrace tests into ui/backtrace
- Move check-static tests into ui/statics
- Move expr tests into ui/expr
- Move optimization fuel tests into ui/fuel
- Move ffi attribute tests into ui/ffi-attrs
- Move suggestion tests into ui/suggestions
- Move main tests into ui/fn-main
- Move lint tests into ui/lint
- Move repr tests into ui/repr
- Move intrinsics tests into ui/intrinsics
- Move tool lint tests into ui/tool-attributes
- Move return tests into ui/return
- Move pattern tests into ui/patttern
- Move range tests into ui/range
- Move foreign-fn tests into ui/foreign
- Move orphan-check tests into ui/coherence
- Move inference tests into ui/inference
- Reduce ROOT_ENTRY_LIMIT
2024-05-20 19:55:59 -07:00
Jules Bertholet af75014cc5 "No ref mut behind &" on all editions 2024-05-15 17:20:18 -04:00
Jules Bertholet 0746577fa2 Gate implicit mutable by-reference bindings behind mut ref 2024-05-15 16:55:54 -04:00
Jules Bertholet fe8f66e4bc rustc_hir_typeck: Account for skipped_ref_pats in expr_use_visitor
Fixes #125058
2024-05-13 18:36:49 -04:00
Jules Bertholet 9d92a7f355 Match ergonomics 2024: migration lint
Unfortunately, we can't always offer a machine-applicable suggestion when there are subpatterns from macro expansion.

Co-Authored-By: Guillaume Boisseau <Nadrieril@users.noreply.github.com>
2024-05-12 11:13:33 -04:00
Ralf Jung cbd682beeb turn pointer_structural_match into a hard error 2024-05-03 15:56:59 +02:00
Ralf Jung 179a6a08b1 remove IndirectStructuralMatch lint, emit the usual hard error instead 2024-05-03 15:56:59 +02:00
Ross Smyth 6967d1c0fc Stabilize exclusive_range 2024-05-02 19:42:31 -04:00
est31 c6e946d0f0 Change wording 2024-04-29 14:53:38 +02:00
est31 4284bca720 Add a note to the ArbitraryExpressionInPattern error 2024-04-28 21:27:26 +02:00
bors 31e6e8c6c5 Auto merge of #119650 - chenyukang:yukang-fix-118596-ref-mut, r=wesleywiser
Suggest ref mut for pattern matching assignment

Fixes #118596
2024-04-25 08:52:19 +00:00
Esteban Küber d68f2a6b71 Mention when type parameter could be Clone
```
error[E0382]: use of moved value: `t`
  --> $DIR/use_of_moved_value_copy_suggestions.rs:7:9
   |
LL | fn duplicate_t<T>(t: T) -> (T, T) {
   |                   - move occurs because `t` has type `T`, which does not implement the `Copy` trait
...
LL |     (t, t)
   |      -  ^ value used here after move
   |      |
   |      value moved here
   |
help: if `T` implemented `Clone`, you could clone the value
  --> $DIR/use_of_moved_value_copy_suggestions.rs:4:16
   |
LL | fn duplicate_t<T>(t: T) -> (T, T) {
   |                ^ consider constraining this type parameter with `Clone`
...
LL |     (t, t)
   |      - you could clone this value
help: consider restricting type parameter `T`
   |
LL | fn duplicate_t<T: Copy>(t: T) -> (T, T) {
   |                 ++++++
```

The `help` is new. On ADTs, we also extend the output with span labels:

```
error[E0507]: cannot move out of static item `FOO`
  --> $DIR/issue-17718-static-move.rs:6:14
   |
LL |     let _a = FOO;
   |              ^^^ move occurs because `FOO` has type `Foo`, which does not implement the `Copy` trait
   |
note: if `Foo` implemented `Clone`, you could clone the value
  --> $DIR/issue-17718-static-move.rs:1:1
   |
LL | struct Foo;
   | ^^^^^^^^^^ consider implementing `Clone` for this type
...
LL |     let _a = FOO;
   |              --- you could clone this value
help: consider borrowing here
   |
LL |     let _a = &FOO;
   |              +
```
2024-04-24 22:21:15 +00:00
yukang be9dbe9102 Suggest ref mut for pattern matching assignment 2024-04-25 04:54:25 +08:00
Nadrieril 217a4dff7d Test or-patterns inside deref patterns 2024-04-20 16:04:06 +02:00
Nadrieril 436c61266c Use deep fake borrows for deref patterns 2024-04-20 16:04:05 +02:00
Nadrieril b55afe475a Address closure-related review 2024-04-20 15:59:54 +02:00
Nadrieril 377e095371 Allow mutable bindings inside deref patterns 2024-04-20 15:59:54 +02:00
Nadrieril 1dabacd059 Don't fake borrow inside a deref pattern 2024-04-20 15:59:54 +02:00
Nadrieril c623319a30 Lower deref patterns to MIR
This handles using deref patterns to choose the correct match arm. This
does not handle bindings or guards.

Co-authored-by: Deadbeef <ent3rm4n@gmail.com>
2024-04-20 15:59:54 +02:00
Jules Bertholet 7a3211726b Fix tests 2024-04-15 23:27:22 -04:00
Jules Bertholet e13911e6e8 Rename feature gate 2024-04-15 23:27:21 -04:00