Use precise errors during const to pat conversion instead of a catch-all on the main constant

This commit is contained in:
Oliver Scherer 2020-09-20 17:22:33 +02:00
parent aba5ea1430
commit adf98ab2dc
28 changed files with 240 additions and 115 deletions

View file

@ -1,8 +1,5 @@
// check-pass
#![warn(indirect_structural_match)]
//~^ NOTE lint level is defined here
struct CustomEq;
impl Eq for CustomEq {}
@ -32,7 +29,8 @@ fn main() {
BAR_BAZ => panic!(),
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
//~| WARN this was previously accepted
//~| NOTE see issue #62411
//~| NOTE see issue #73448
//~| NOTE `#[warn(nontrivial_structural_match)]` on by default
_ => {}
}
}

View file

@ -1,16 +1,12 @@
warning: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/custom-eq-branch-warn.rs:32:9
warning: to use a constant of type `Foo` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/custom-eq-branch-warn.rs:29:9
|
LL | BAR_BAZ => panic!(),
| ^^^^^^^
|
note: the lint level is defined here
--> $DIR/custom-eq-branch-warn.rs:3:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(nontrivial_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 #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: 1 warning emitted

View file

@ -1,9 +1,7 @@
// FIXME: This still ICEs.
//
// ignore-test
#![deny(indirect_structural_match)]
// check-pass
#[derive(PartialEq, Eq)]
enum O<T> {
Some(*const T), // Can also use PhantomData<T>

View file

@ -1,15 +0,0 @@
error[E0601]: `main` function not found in crate `issue_65466`
--> $DIR/issue-65466.rs:1:1
|
LL | / #![deny(indirect_structural_match)]
LL | |
LL | | #[derive(PartialEq, Eq)]
LL | | enum O<T> {
... |
LL | | }
LL | | }
| |_^ consider adding a `main` function to `$DIR/issue-65466.rs`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0601`.

View file

@ -27,6 +27,7 @@ fn main() {
match None {
NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => panic!("whoops"),
}
}

View file

@ -1,8 +1,14 @@
error: to use a constant of type `NoPartialEq` in a pattern, `NoPartialEq` must be annotated with `#[derive(PartialEq, Eq)]`
error: to use a constant of type `Option<NoPartialEq>` in a pattern, `Option<NoPartialEq>` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_partial_eq.rs:28:9
|
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
| ^^^^^^^^^^^^^^^^^^
error: aborting due to previous error
error: to use a constant of type `Option<NoPartialEq>` in a pattern, `Option<NoPartialEq>` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/reject_non_partial_eq.rs:28:9
|
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
| ^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -1,34 +1,30 @@
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
warning: to use a constant of type `Option<NoDerive>` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/warn_corner_cases.rs:26:47
|
LL | match None { Some(_) => panic!("whoops"), INDEX => dbg!(INDEX), };
| ^^^^^
|
note: the lint level is defined here
--> $DIR/warn_corner_cases.rs:15:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(nontrivial_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 #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
warning: to use a constant of type `Option<NoDerive>` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/warn_corner_cases.rs:32:47
|
LL | match None { Some(_) => panic!("whoops"), CALL => dbg!(CALL), };
| ^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
warning: to use a constant of type `Option<NoDerive>` in a pattern, the constant's initializer must be trivial or all types in the constant must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/warn_corner_cases.rs:38:47
|
LL | match None { Some(_) => panic!("whoops"), METHOD_CALL => dbg!(METHOD_CALL), };
| ^^^^^^^^^^^
|
= 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 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: 3 warnings emitted

View file

@ -8,8 +8,10 @@ struct T;
fn main() {
const C: &S = &S;
match C {
//~^ non-exhaustive patterns: `&S` not covered
C => {}
//~^ ERROR to use a constant of type `S` in a pattern, `S` must be annotated with
//~^ WARN must be annotated with `#[derive(PartialEq, Eq)]`
//~| WARN was previously accepted by the compiler
}
const K: &T = &T;
match K {

View file

@ -1,8 +1,25 @@
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
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)]`
--> $DIR/match_ice.rs:12:9
|
LL | C => {}
| ^
|
= note: `#[warn(nontrivial_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>
error: aborting due to previous error
error[E0004]: non-exhaustive patterns: `&S` not covered
--> $DIR/match_ice.rs:10:11
|
LL | struct S;
| --------- `S` defined here
...
LL | match C {
| ^ pattern `&S` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `&S`
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0004`.

View file

@ -1,4 +1,6 @@
// run-pass
#![warn(pointer_structural_match)]
#![allow(dead_code)]
const C: *const u8 = &0;

View file

@ -4,7 +4,8 @@ fn main() {
let a: &dyn Send = &7u32;
match a {
F => panic!(),
//~^ ERROR trait objects cannot be used in patterns
//~^ ERROR `&dyn Send` cannot be used in patterns
//~| ERROR `&dyn Send` cannot be used in patterns
_ => {}
}
}

View file

@ -1,8 +1,14 @@
error: trait objects cannot be used in patterns
error: `&dyn Send` cannot be used in patterns
--> $DIR/issue-70972-dyn-trait.rs:6:9
|
LL | F => panic!(),
| ^
error: aborting due to previous error
error: `&dyn Send` cannot be used in patterns
--> $DIR/issue-70972-dyn-trait.rs:6:9
|
LL | F => panic!(),
| ^
error: aborting due to 2 previous errors

View file

@ -4,6 +4,8 @@
fn main() {
const C: impl Copy = 0;
match C {
C | _ => {} //~ ERROR: opaque types cannot be used in patterns
C => {} //~ ERROR: `impl Copy` cannot be used in patterns
//~^ ERROR: `impl Copy` cannot be used in patterns
_ => {}
}
}

View file

@ -1,8 +1,14 @@
error: opaque types cannot be used in patterns
error: `impl Copy` cannot be used in patterns
--> $DIR/issue-71042-opaquely-typed-constant-used-in-pattern.rs:7:9
|
LL | C | _ => {}
LL | C => {}
| ^
error: aborting due to previous error
error: `impl Copy` cannot be used in patterns
--> $DIR/issue-71042-opaquely-typed-constant-used-in-pattern.rs:7:9
|
LL | C => {}
| ^
error: aborting due to 2 previous errors

View file

@ -3,6 +3,8 @@
// run-pass
#![warn(pointer_structural_match)]
struct NoDerive(i32);
// This impl makes NoDerive irreflexive

View file

@ -3,6 +3,8 @@
// run-pass
#![warn(pointer_structural_match)]
struct NoDerive(i32);
// This impl makes NoDerive irreflexive

View file

@ -3,6 +3,8 @@
// run-pass
#![warn(pointer_structural_match)]
struct NoDerive(i32);
// This impl makes NoDerive irreflexive

View file

@ -3,6 +3,8 @@
// run-pass
#![warn(pointer_structural_match)]
struct NoDerive(i32);
// This impl makes NoDerive irreflexive

View file

@ -1,16 +1,12 @@
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
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)]`
--> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:24:9
|
LL | WRAP_DOUBLY_INDIRECT_INLINE => { panic!("WRAP_DOUBLY_INDIRECT_INLINE matched itself"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/cant-hide-behind-doubly-indirect-embedded.rs:7:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(nontrivial_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 #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: 1 warning emitted

View file

@ -1,16 +1,12 @@
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
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)]`
--> $DIR/cant-hide-behind-doubly-indirect-param.rs:24:9
|
LL | WRAP_DOUBLY_INDIRECT_PARAM => { panic!("WRAP_DOUBLY_INDIRECT_PARAM matched itself"); }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> $DIR/cant-hide-behind-doubly-indirect-param.rs:7:9
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[warn(nontrivial_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 #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: 1 warning emitted

View file

@ -10,7 +10,7 @@
// Issue 62307 pointed out a case where the structural-match checking
// was too shallow.
#![warn(indirect_structural_match)]
#![warn(indirect_structural_match, nontrivial_structural_match)]
// run-pass
#[derive(Debug)]

View file

@ -1,25 +1,25 @@
warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
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)]`
--> $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:9
--> $DIR/issue-62307-match-ref-ref-forbidden-without-eq.rs:13:36
|
LL | #![warn(indirect_structural_match)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
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 #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
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)]`
--> $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 #62411 <https://github.com/rust-lang/rust/issues/62411>
= note: for more information, see issue #73448 <https://github.com/rust-lang/rust/issues/73448>
warning: 2 warnings emitted

View file

@ -12,9 +12,10 @@ const LEAK_FREE: Bar = leak_free();
fn leak_free_test() {
match todo!() {
LEAK_FREE => (),
//~^ opaque types cannot be used in patterns
//~^ `impl Send` cannot be used in patterns
//~| `impl Send` cannot be used in patterns
_ => (),
}
}
fn main() { }
fn main() {}

View file

@ -1,8 +1,14 @@
error: opaque types cannot be used in patterns
error: `impl Send` cannot be used in patterns
--> $DIR/structural-match-no-leak.rs:14:9
|
LL | LEAK_FREE => (),
| ^^^^^^^^^
error: aborting due to previous error
error: `impl Send` cannot be used in patterns
--> $DIR/structural-match-no-leak.rs:14:9
|
LL | LEAK_FREE => (),
| ^^^^^^^^^
error: aborting due to 2 previous errors

View file

@ -13,9 +13,10 @@ const VALUE: Foo = value();
fn test() {
match todo!() {
VALUE => (),
//~^ opaque types cannot be used in patterns
//~^ `impl Send` cannot be used in patterns
//~| `impl Send` cannot be used in patterns
_ => (),
}
}
fn main() { }
fn main() {}

View file

@ -1,8 +1,14 @@
error: opaque types cannot be used in patterns
error: `impl Send` cannot be used in patterns
--> $DIR/structural-match.rs:15:9
|
LL | VALUE => (),
| ^^^^^
error: aborting due to previous error
error: `impl Send` cannot be used in patterns
--> $DIR/structural-match.rs:15:9
|
LL | VALUE => (),
| ^^^^^
error: aborting due to 2 previous errors