about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2020-09-23 18:04:44 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2020-09-23 18:04:44 +0200
commit017423179a9ea3267d0fab7bd20fd73b0cd8a528 (patch)
tree179f501af4b04220416e22fee3ea7cfd7de35688
parent6a33de017007233346c26a6f7b20c3e35e6b9e90 (diff)
downloadrust-017423179a9ea3267d0fab7bd20fd73b0cd8a528.tar.gz
rust-017423179a9ea3267d0fab7bd20fd73b0cd8a528.zip
Make sure we report a future incompat error in all cases
-rw-r--r--compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs20
-rw-r--r--src/test/ui/consts/match_ice.stderr6
-rw-r--r--src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.stderr10
-rw-r--r--src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.stderr10
-rw-r--r--src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.stderr12
5 files changed, 42 insertions, 16 deletions
diff --git a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
index 78b0a5a82eb..cf731a076ff 100644
--- a/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
+++ b/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
@@ -408,7 +408,25 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
                 // 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
diff --git a/src/test/ui/consts/match_ice.stderr b/src/test/ui/consts/match_ice.stderr
index 915111b3ce4..c46f2c2e972 100644
--- a/src/test/ui/consts/match_ice.stderr
+++ b/src/test/ui/consts/match_ice.stderr
@@ -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
diff --git a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.stderr b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.stderr
index eb13eed6ec1..659a9812672 100644
--- a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.stderr
+++ b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.stderr
@@ -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
 
diff --git a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.stderr b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.stderr
index ddee99e76bb..c8c36510542 100644
--- a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.stderr
+++ b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.stderr
@@ -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
 
diff --git a/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.stderr b/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.stderr
index 7f4b4923332..a50093a5b11 100644
--- a/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.stderr
+++ b/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.stderr
@@ -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