]> git.lizzy.rs Git - rust.git/commitdiff
Make sure we report a future incompat error in all cases
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 23 Sep 2020 16:04:44 +0000 (18:04 +0200)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Wed, 23 Sep 2020 16:04:44 +0000 (18:04 +0200)
compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
src/test/ui/consts/match_ice.stderr
src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.stderr
src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.stderr
src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.stderr

index 78b0a5a82eb55eec5e64387f16c92b4e0ff4e096..cf731a076ff0a3dce59493809083965bffcfcf38 100644 (file)
@@ -408,7 +408,25 @@ fn recur(
                 // this pattern to a `PartialEq::eq` comparison and `PartialEq::eq` takes a
                 // reference. This makes the rest of the matching logic simpler as it doesn't have
                 // to figure out how to get a reference again.
-                ty::Adt(..) if !self.type_marked_structural(pointee_ty) => {
+                ty::Adt(adt_def, _) if !self.type_marked_structural(pointee_ty) => {
+                    if self.include_lint_checks
+                        && !self.saw_const_match_error.get()
+                        && !self.saw_const_match_lint.get()
+                    {
+                        self.saw_const_match_lint.set(true);
+                        let path = self.tcx().def_path_str(adt_def.did);
+                        let msg = format!(
+                            "to use a constant of type `{}` in a pattern, \
+                             `{}` must be annotated with `#[derive(PartialEq, Eq)]`",
+                            path, path,
+                        );
+                        self.tcx().struct_span_lint_hir(
+                            lint::builtin::INDIRECT_STRUCTURAL_MATCH,
+                            self.id,
+                            self.span,
+                            |lint| lint.build(&msg).emit(),
+                        );
+                    }
                     PatKind::Constant { value: cv }
                 }
                 // All other references are converted into deref patterns and then recursively
index 915111b3ce4b49e9b00aab779fde313b7a99d951..c46f2c2e972368afa6fb961c5cea767aed270e84 100644 (file)
@@ -1,12 +1,12 @@
-warning: to use a constant of type `&S` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
+warning: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/match_ice.rs:11:9
    |
 LL |         C => {}
    |         ^
    |
-   = note: `#[warn(nontrivial_structural_match)]` on by default
+   = note: `#[warn(indirect_structural_match)]` on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+   = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
 
 error: to use a constant of type `S` in a pattern, `S` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/match_ice.rs:11:9
index eb13eed6ec11b7047c572da0a4da7830d5a06ed5..659a9812672330b8ead5893c3e64a67e2629fb4e 100644 (file)
@@ -1,12 +1,16 @@
-warning: to use a constant of type `&&WrapInline` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
+warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:24:9
    |
 LL |         WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); }
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: `#[warn(nontrivial_structural_match)]` on by default
+note: the lint level is defined here
+  --> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:7:9
+   |
+LL | #![warn(indirect_structural_match)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+   = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
 
 warning: 1 warning emitted
 
index ddee99e76bbb9fc5ded5f5653de4396a05f68d6f..c8c36510542a2d47378b60bda79bd661a23c9d45 100644 (file)
@@ -1,12 +1,16 @@
-warning: to use a constant of type `&&WrapParam<NoDerive>` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
+warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/cant-hide-behind-doubly-indirect-param.rs:24:9
    |
 LL |         WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
    |
-   = note: `#[warn(nontrivial_structural_match)]` on by default
+note: the lint level is defined here
+  --> $DIR/cant-hide-behind-doubly-indirect-param.rs:7:9
+   |
+LL | #![warn(indirect_structural_match)]
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+   = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
 
 warning: 1 warning emitted
 
index 7f4b4923332a4bf3efabe8bb6a34f2beb65727f2..a50093a5b1128bc225f42adc76f561ff6a083342 100644 (file)
@@ -1,25 +1,25 @@
-warning: to use a constant of type `&&B` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
+warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:31:9
    |
 LL |         RR_B1 => { println!("CLAIM RR0: {:?} matches {:?}", RR_B1, RR_B0); }
    |         ^^^^^
    |
 note: the lint level is defined here
-  --> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13:36
+  --> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13:9
    |
 LL | #![warn(indirect_structural_match, nontrivial_structural_match)]
-   |                                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+   = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
 
-warning: to use a constant of type `&&B` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
+warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
   --> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:38:9
    |
 LL |         RR_B1 => { println!("CLAIM RR1: {:?} matches {:?}", RR_B1, RR_B1); }
    |         ^^^^^
    |
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
-   = note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
+   = note: for more information, see issue #62411 <https://github.com/rust-lang/rust/issues/62411>
 
 warning: 2 warnings emitted