about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2019-07-12 15:32:12 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2019-07-12 15:32:12 +0200
commit44d27ba28df30f80d039f0486cac46d7fb265fa3 (patch)
treec96630c229523aefebba8f42ab00ecaffaa8e888
parent00e0d8790dc7cffc4466fe3c9784a582d6367027 (diff)
downloadrust-44d27ba28df30f80d039f0486cac46d7fb265fa3.tar.gz
rust-44d27ba28df30f80d039f0486cac46d7fb265fa3.zip
Change `indirect_structural_match` lint to allow-by-default.
This is a way to address the regression aspect of rust-lang/rust#62614 in the
short term without actually fixing the bug. (My thinking is that the bug that
this lint detects has gone undetected for this long, it can wait a bit longer
until I or someone else has a chance to put in a proper fix that accounts for
rust-lang/rust#62614.)
-rw-r--r--src/librustc/lint/builtin.rs4
-rw-r--r--src/test/ui/rfc1445/allow-use-behind-cousin-variant.rs59
2 files changed, 62 insertions, 1 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs
index 9b4b97202d9..d1cae76de60 100644
--- a/src/librustc/lint/builtin.rs
+++ b/src/librustc/lint/builtin.rs
@@ -350,7 +350,8 @@ declare_lint! {
 
 declare_lint! {
     pub INDIRECT_STRUCTURAL_MATCH,
-    Warn,
+    // defaulting to allow until rust-lang/rust#62614 is fixed.
+    Allow,
     "pattern with const indirectly referencing non-`#[structural_match]` type"
 }
 
@@ -451,6 +452,7 @@ declare_lint_pass! {
         AMBIGUOUS_ASSOCIATED_ITEMS,
         NESTED_IMPL_TRAIT,
         MUTABLE_BORROW_RESERVATION_CONFLICT,
+        INDIRECT_STRUCTURAL_MATCH,
     ]
 }
 
diff --git a/src/test/ui/rfc1445/allow-use-behind-cousin-variant.rs b/src/test/ui/rfc1445/allow-use-behind-cousin-variant.rs
new file mode 100644
index 00000000000..dca8aaef150
--- /dev/null
+++ b/src/test/ui/rfc1445/allow-use-behind-cousin-variant.rs
@@ -0,0 +1,59 @@
+// rust-lang/rust#62614: we want to allow matching on constants of types that
+// have non-structural-match variants, *if* the constant itself does not use
+// any such variant.
+
+// NOTE: for now, deliberately leaving the lint `indirect_structural_match` set
+// to its default, so that we will not issue a diangostic even if
+// rust-lang/rust#62614 remains an open issue.
+
+// run-pass
+
+struct Sum(u32, u32);
+
+impl PartialEq for Sum {
+    fn eq(&self, other: &Self) -> bool { self.0 + self.1 == other.0 + other.1 }
+}
+
+impl Eq for Sum { }
+
+#[derive(PartialEq, Eq)]
+enum Eek {
+    TheConst,
+    UnusedByTheConst(Sum)
+}
+
+const THE_CONST: Eek = Eek::TheConst;
+const SUM_THREE: Eek = Eek::UnusedByTheConst(Sum(3,0));
+
+const EEK_ZERO: &[Eek] = &[];
+const EEK_ONE: &[Eek] = &[THE_CONST];
+
+pub fn main() {
+    match Eek::UnusedByTheConst(Sum(1,2)) {
+        ref sum if sum == &SUM_THREE => { println!("Hello 0"); }
+        _ => { println!("Gbye"); }
+    }
+
+    match Eek::TheConst {
+        THE_CONST => { println!("Hello 1"); }
+        _ => { println!("Gbye"); }
+    }
+
+
+    match & &Eek::TheConst {
+        & & THE_CONST => { println!("Hello 2"); }
+        _ => { println!("Gbye"); }
+    }
+
+    match & & &[][..] {
+        & & EEK_ZERO => { println!("Hello 3"); }
+        & & EEK_ONE => { println!("Gbye"); }
+        _ => { println!("Gbye"); }
+    }
+
+    match & & &[Eek::TheConst][..] {
+        & & EEK_ZERO => { println!("Gby"); }
+        & & EEK_ONE => { println!("Hello 4"); }
+        _ => { println!("Gbye"); }
+    }
+}