From 00e0d8790dc7cffc4466fe3c9784a582d6367027 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 12 Jul 2019 15:27:21 +0200 Subject: [PATCH 1/2] Turn `indirect_structural_match` lint on explicitly in ui tests. --- src/test/ui/issues/issue-55511.rs | 2 +- src/test/ui/issues/issue-55511.stderr | 6 +++++- src/test/ui/rfc1445/cant-hide-behind-direct-struct-param.rs | 2 +- .../ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.rs | 2 +- .../cant-hide-behind-doubly-indirect-embedded.stderr | 6 +++++- .../ui/rfc1445/cant-hide-behind-doubly-indirect-param.rs | 2 +- .../rfc1445/cant-hide-behind-doubly-indirect-param.stderr | 6 +++++- .../ui/rfc1445/cant-hide-behind-indirect-struct-embedded.rs | 2 +- .../cant-hide-behind-indirect-struct-embedded.stderr | 6 +++++- .../ui/rfc1445/cant-hide-behind-indirect-struct-param.rs | 2 +- .../rfc1445/cant-hide-behind-indirect-struct-param.stderr | 6 +++++- .../issue-62307-match-ref-ref-forbidden-without-eq.rs | 2 +- .../issue-62307-match-ref-ref-forbidden-without-eq.stderr | 6 +++++- 13 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/test/ui/issues/issue-55511.rs b/src/test/ui/issues/issue-55511.rs index 42c6f24b36a0c..055886bf3676c 100644 --- a/src/test/ui/issues/issue-55511.rs +++ b/src/test/ui/issues/issue-55511.rs @@ -1,5 +1,5 @@ +#![warn(indirect_structural_match)] use std::cell::Cell; - trait Foo<'a> { const C: Option>; } diff --git a/src/test/ui/issues/issue-55511.stderr b/src/test/ui/issues/issue-55511.stderr index c0f702e4fab23..e094256f5c827 100644 --- a/src/test/ui/issues/issue-55511.stderr +++ b/src/test/ui/issues/issue-55511.stderr @@ -4,7 +4,11 @@ warning: to use a constant of type `std::cell::Cell` in a pattern, `std::cell::C LL | <() as Foo<'static>>::C => { } | ^^^^^^^^^^^^^^^^^^^^^^^ | - = note: #[warn(indirect_structural_match)] on by default +note: lint level defined here + --> $DIR/issue-55511.rs:1: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 #62411 diff --git a/src/test/ui/rfc1445/cant-hide-behind-direct-struct-param.rs b/src/test/ui/rfc1445/cant-hide-behind-direct-struct-param.rs index a3a615ea748cb..584e7a00f0993 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-direct-struct-param.rs +++ b/src/test/ui/rfc1445/cant-hide-behind-direct-struct-param.rs @@ -4,7 +4,7 @@ // through that we had intended to reject. // // See discussion on rust-lang/rust#62307 and rust-lang/rust#62339 - +#![warn(indirect_structural_match)] struct NoDerive(i32); // This impl makes NoDerive irreflexive. diff --git a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.rs b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.rs index b6d9c52b298b6..0328db5a49cf3 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.rs +++ b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-embedded.rs @@ -4,7 +4,7 @@ // through that we had intended to reject. // // See discussion on rust-lang/rust#62307 and rust-lang/rust#62339 - +#![warn(indirect_structural_match)] // run-pass struct NoDerive(i32); 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 3de63f43ecbb6..5281d576066da 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 @@ -4,7 +4,11 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a LL | WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: #[warn(indirect_structural_match)] on by default +note: lint level 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 #62411 diff --git a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.rs b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.rs index 804d336b3ea61..54579e487a6b9 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.rs +++ b/src/test/ui/rfc1445/cant-hide-behind-doubly-indirect-param.rs @@ -4,7 +4,7 @@ // through that we had intended to reject. // // See discussion on rust-lang/rust#62307 and rust-lang/rust#62339 - +#![warn(indirect_structural_match)] // run-pass struct NoDerive(i32); 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 ee4652d153283..5d601c2c006f7 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 @@ -4,7 +4,11 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a LL | WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | - = note: #[warn(indirect_structural_match)] on by default +note: lint level 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 #62411 diff --git a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.rs b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.rs index 85d2e65a9a080..2a24316898b5d 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.rs +++ b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.rs @@ -4,7 +4,7 @@ // through that we had intended to reject. // // See discussion on rust-lang/rust#62307 and rust-lang/rust#62339 - +#![warn(indirect_structural_match)] // run-pass struct NoDerive(i32); diff --git a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.stderr b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.stderr index eb7468499316f..4ac19afa706b0 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.stderr +++ b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-embedded.stderr @@ -4,7 +4,11 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a LL | WRAP_INDIRECT_INLINE => { panic!("WRAP_INDIRECT_INLINE matched itself"); } | ^^^^^^^^^^^^^^^^^^^^ | - = note: #[warn(indirect_structural_match)] on by default +note: lint level defined here + --> $DIR/cant-hide-behind-indirect-struct-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 #62411 diff --git a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.rs b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.rs index 849aa14776697..64e777f232234 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.rs +++ b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.rs @@ -4,7 +4,7 @@ // through that we had intended to reject. // // See discussion on rust-lang/rust#62307 and rust-lang/rust#62339 - +#![warn(indirect_structural_match)] // run-pass struct NoDerive(i32); diff --git a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.stderr b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.stderr index 8a16556844454..4000a47987854 100644 --- a/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.stderr +++ b/src/test/ui/rfc1445/cant-hide-behind-indirect-struct-param.stderr @@ -4,7 +4,11 @@ warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be a LL | WRAP_INDIRECT_PARAM => { panic!("WRAP_INDIRECT_PARAM matched itself"); } | ^^^^^^^^^^^^^^^^^^^ | - = note: #[warn(indirect_structural_match)] on by default +note: lint level defined here + --> $DIR/cant-hide-behind-indirect-struct-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 #62411 diff --git a/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.rs b/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.rs index 7646f7558a396..98943a9666a9a 100644 --- a/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.rs +++ b/src/test/ui/rfc1445/issue-62307-match-ref-ref-forbidden-without-eq.rs @@ -10,7 +10,7 @@ // Issue 62307 pointed out a case where the checking for // `#[structural_match]` was too shallow. - +#![warn(indirect_structural_match)] // run-pass #[derive(Debug)] 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 ba0275f5f9f93..0e158c2fda560 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 @@ -4,7 +4,11 @@ warning: to use a constant of type `B` in a pattern, `B` must be annotated with LL | RR_B1 => { println!("CLAIM RR0: {:?} matches {:?}", RR_B1, RR_B0); } | ^^^^^ | - = note: #[warn(indirect_structural_match)] on by default +note: lint level defined here + --> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13: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 #62411 From 44d27ba28df30f80d039f0486cac46d7fb265fa3 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 12 Jul 2019 15:32:12 +0200 Subject: [PATCH 2/2] 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.) --- src/librustc/lint/builtin.rs | 4 +- .../allow-use-behind-cousin-variant.rs | 59 +++++++++++++++++++ 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/rfc1445/allow-use-behind-cousin-variant.rs diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs index 9b4b97202d96d..d1cae76de60a1 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 0000000000000..dca8aaef1500d --- /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"); } + } +}