File tree 3 files changed +36
-0
lines changed
compiler/rustc_mir_build/src/thir/pattern
3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change @@ -197,6 +197,13 @@ impl<'tcx> ConstToPat<'tcx> {
197
197
// All branches above emitted an error. Don't print any more lints.
198
198
// The pattern we return is irrelevant since we errored.
199
199
return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
200
+ } else if let ty:: Adt ( ..) = cv. ty ( ) . kind ( ) && matches ! ( cv, mir:: Const :: Val ( ..) ) {
201
+ // This branch is only entered when the current `cv` is `mir::Const::Val`.
202
+ // This is because `mir::Const::ty` has already been handled by `Self::recur`
203
+ // and the invalid types may be ignored.
204
+ let err = TypeNotStructural { span : self . span , non_sm_ty } ;
205
+ self . tcx ( ) . sess . emit_err ( err) ;
206
+ return Box :: new ( Pat { span : self . span , ty : cv. ty ( ) , kind : PatKind :: Wild } ) ;
200
207
} else if !self . saw_const_match_lint . get ( ) {
201
208
if let Some ( mir_structural_match_violation) = mir_structural_match_violation {
202
209
match non_sm_ty. kind ( ) {
Original file line number Diff line number Diff line change
1
+ const CONST_STRING : String = String :: new ( ) ;
2
+
3
+ fn main ( ) {
4
+ let empty_str = String :: from ( "" ) ;
5
+ if let CONST_STRING = empty_str { }
6
+ //~^ ERROR to use a constant of type `Vec<u8>` in a pattern, `Vec<u8>` must be annotated with `#[derive(PartialEq, Eq)]`
7
+ //~| WARN irrefutable `if let` pattern
8
+ }
Original file line number Diff line number Diff line change
1
+ error: to use a constant of type `Vec<u8>` in a pattern, `Vec<u8>` must be annotated with `#[derive(PartialEq, Eq)]`
2
+ --> $DIR/issue-115599.rs:5:12
3
+ |
4
+ LL | if let CONST_STRING = empty_str {}
5
+ | ^^^^^^^^^^^^
6
+ |
7
+ = note: the traits must be derived, manual `impl`s are not sufficient
8
+ = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralEq.html for details
9
+
10
+ warning: irrefutable `if let` pattern
11
+ --> $DIR/issue-115599.rs:5:8
12
+ |
13
+ LL | if let CONST_STRING = empty_str {}
14
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
15
+ |
16
+ = note: this pattern will always match, so the `if let` is useless
17
+ = help: consider replacing the `if let` with a `let`
18
+ = note: `#[warn(irrefutable_let_patterns)]` on by default
19
+
20
+ error: aborting due to previous error; 1 warning emitted
21
+
You can’t perform that action at this time.
0 commit comments