ty::Adt(adt_def, _) if adt_def.is_union() => {
// Matching on union fields is unsafe, we can't hide it in constants
self.saw_const_match_error.set(true);
- tcx.sess.span_err(span, "cannot use unions in constant patterns");
+ let msg = "cannot use unions in constant patterns";
+ if self.include_lint_checks {
+ tcx.sess.span_err(span, msg);
+ } else {
+ tcx.sess.delay_span_bug(span, msg)
+ }
PatKind::Wild
}
ty::Adt(..)
cv.ty, cv.ty,
);
self.saw_const_match_error.set(true);
- self.tcx().sess.span_err(self.span, &msg);
+ if self.include_lint_checks {
+ tcx.sess.span_err(self.span, &msg);
+ } else {
+ tcx.sess.delay_span_bug(self.span, &msg)
+ }
PatKind::Wild
}
// If the type is not structurally comparable, just emit the constant directly,
path, path,
);
self.saw_const_match_error.set(true);
- tcx.sess.span_err(span, &msg);
+ if self.include_lint_checks {
+ tcx.sess.span_err(span, &msg);
+ } else {
+ tcx.sess.delay_span_bug(span, &msg)
+ }
PatKind::Wild
}
ty::Adt(adt_def, substs) if adt_def.is_enum() => {
// These are not allowed and will error elsewhere anyway.
ty::Dynamic(..) => {
self.saw_const_match_error.set(true);
- tcx.sess.span_err(span, &format!("`{}` cannot be used in patterns", cv.ty));
+ let msg = format!("`{}` cannot be used in patterns", cv.ty);
+ if self.include_lint_checks {
+ tcx.sess.span_err(span, &msg);
+ } else {
+ tcx.sess.delay_span_bug(span, &msg)
+ }
PatKind::Wild
}
// `&str` and `&[u8]` are represented as `ConstValue::Slice`, let's keep using this
}
_ => {
self.saw_const_match_error.set(true);
- tcx.sess.span_err(span, &format!("`{}` cannot be used in patterns", cv.ty));
+ let msg = format!("`{}` cannot be used in patterns", cv.ty);
+ if self.include_lint_checks {
+ tcx.sess.span_err(span, &msg);
+ } else {
+ tcx.sess.delay_span_bug(span, &msg)
+ }
PatKind::Wild
}
};
match None {
consts::SOME => panic!(),
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
- //~| must be annotated with `#[derive(PartialEq, Eq)]`
_ => {}
}
match None {
<Defaulted as consts::AssocConst>::SOME => panic!(),
//~^ must be annotated with `#[derive(PartialEq, Eq)]`
- //~| must be annotated with `#[derive(PartialEq, Eq)]`
_ => {}
}
| ^^^^^^^^^^^^
error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/cross-crate-fail.rs:21:9
+ --> $DIR/cross-crate-fail.rs:20:9
|
LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/cross-crate-fail.rs:13:9
- |
-LL | consts::SOME => panic!(),
- | ^^^^^^^^^^^^
-
-error: to use a constant of type `CustomEq` in a pattern, `CustomEq` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/cross-crate-fail.rs:21:9
- |
-LL | <Defaulted as consts::AssocConst>::SOME => panic!(),
- | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
match Foo::Qux(NoEq) {
BAR_BAZ => panic!(),
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => {}
}
}
LL | BAR_BAZ => panic!(),
| ^^^^^^^
-error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/no-eq-branch-fail.rs:21:9
- |
-LL | BAR_BAZ => panic!(),
- | ^^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
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"),
}
}
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
| ^^^^^^^^^^^^^^^^^^
-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
+error: aborting due to previous error
const ENUM: Derive<NoDerive> = Derive::Some(NoDerive);
match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const FIELD: OND = TrivialEq(Some(NoDerive)).0;
match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const NO_DERIVE_SOME: OND = Some(NoDerive);
const INDIRECT: OND = NO_DERIVE_SOME;
match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const TUPLE: (OND, OND) = (None, Some(NoDerive));
match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const TYPE_ASCRIPTION: OND = Some(NoDerive): OND;
match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const ARRAY: [OND; 2] = [None, Some(NoDerive)];
match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const REPEAT: [OND; 2] = [Some(NoDerive); 2];
match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
//~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
trait Trait: Sized { const ASSOC: Option<Self>; }
impl Trait for NoDerive { const ASSOC: Option<NoDerive> = Some(NoDerive); }
match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const BLOCK: OND = { NoDerive; Some(NoDerive) };
match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
const ADDR_OF: &OND = &Some(NoDerive);
match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };
| ^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:45:28
+ --> $DIR/reject_non_structural.rs:44:28
|
LL | match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
| ^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:51:27
+ --> $DIR/reject_non_structural.rs:49:27
|
LL | match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
| ^^^^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:56:36
+ --> $DIR/reject_non_structural.rs:53:36
|
LL | match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
| ^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:61:28
+ --> $DIR/reject_non_structural.rs:57:28
|
LL | match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:66:36
+ --> $DIR/reject_non_structural.rs:61:36
|
LL | match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
| ^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:71:33
+ --> $DIR/reject_non_structural.rs:65:33
|
LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
| ^^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:71:33
+ --> $DIR/reject_non_structural.rs:65:33
|
LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
| ^^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:79:28
+ --> $DIR/reject_non_structural.rs:71:28
|
LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
| ^^^^^^^^^^^^^^^
error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:84:28
+ --> $DIR/reject_non_structural.rs:75:28
|
LL | match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
| ^^^^^
warning: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:89:29
+ --> $DIR/reject_non_structural.rs:79:29
|
LL | match &Some(NoDerive) { ADDR_OF => dbg!(ADDR_OF), _ => panic!("whoops"), };
| ^^^^^^^
= 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>
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:40:36
- |
-LL | match Derive::Some(NoDerive) { ENUM => dbg!(ENUM), _ => panic!("whoops"), };
- | ^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:45:28
- |
-LL | match Some(NoDerive) { FIELD => dbg!(FIELD), _ => panic!("whoops"), };
- | ^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:51:27
- |
-LL | match Some(NoDerive) {INDIRECT => dbg!(INDIRECT), _ => panic!("whoops"), };
- | ^^^^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:56:36
- |
-LL | match (None, Some(NoDerive)) { TUPLE => dbg!(TUPLE), _ => panic!("whoops"), };
- | ^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:61:28
- |
-LL | match Some(NoDerive) { TYPE_ASCRIPTION => dbg!(TYPE_ASCRIPTION), _ => panic!("whoops"), };
- | ^^^^^^^^^^^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:66:36
- |
-LL | match [None, Some(NoDerive)] { ARRAY => dbg!(ARRAY), _ => panic!("whoops"), };
- | ^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:71:33
- |
-LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
- | ^^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:71:33
- |
-LL | match [Some(NoDerive); 2] { REPEAT => dbg!(REPEAT), _ => panic!("whoops"), };
- | ^^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:79:28
- |
-LL | match Some(NoDerive) { NoDerive::ASSOC => dbg!(NoDerive::ASSOC), _ => panic!("whoops"), };
- | ^^^^^^^^^^^^^^^
-
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/reject_non_structural.rs:84:28
- |
-LL | match Some(NoDerive) { BLOCK => dbg!(BLOCK), _ => panic!("whoops"), };
- | ^^^^^
-
-error: aborting due to 20 previous errors; 1 warning emitted
+error: aborting due to 10 previous errors; 1 warning emitted
match a {
F => panic!(),
//~^ ERROR `&dyn Send` cannot be used in patterns
- //~| ERROR `&dyn Send` cannot be used in patterns
_ => {}
}
}
LL | F => panic!(),
| ^
-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
+error: aborting due to previous error
const C: impl Copy = 0;
match C {
C => {} //~ ERROR: `impl Copy` cannot be used in patterns
- //~^ ERROR: `impl Copy` cannot be used in patterns
_ => {}
}
}
LL | C => {}
| ^
-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
+error: aborting due to previous error
match WRAP_DIRECT_INLINE {
WRAP_DIRECT_INLINE => { panic!("WRAP_DIRECT_INLINE matched itself"); }
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => { println!("WRAP_DIRECT_INLINE did not match itself"); }
}
}
LL | WRAP_DIRECT_INLINE => { panic!("WRAP_DIRECT_INLINE matched itself"); }
| ^^^^^^^^^^^^^^^^^^
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/cant-hide-behind-direct-struct-embedded.rs:22:9
- |
-LL | WRAP_DIRECT_INLINE => { panic!("WRAP_DIRECT_INLINE matched itself"); }
- | ^^^^^^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
match WRAP_DIRECT_PARAM {
WRAP_DIRECT_PARAM => { panic!("WRAP_DIRECT_PARAM matched itself"); }
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => { println!("WRAP_DIRECT_PARAM did not match itself"); }
}
}
LL | WRAP_DIRECT_PARAM => { panic!("WRAP_DIRECT_PARAM matched itself"); }
| ^^^^^^^^^^^^^^^^^
-error: to use a constant of type `NoDerive` in a pattern, `NoDerive` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/cant-hide-behind-direct-struct-param.rs:22:9
- |
-LL | WRAP_DIRECT_PARAM => { panic!("WRAP_DIRECT_PARAM matched itself"); }
- | ^^^^^^^^^^^^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
match y {
FOO => { }
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => { }
}
| ^^^
warning: floating-point types cannot be used in patterns
- --> $DIR/match-forbidden-without-eq.rs:21:9
+ --> $DIR/match-forbidden-without-eq.rs:20:9
|
LL | f32::INFINITY => { }
| ^^^^^^^^^^^^^
= 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 #41620 <https://github.com/rust-lang/rust/issues/41620>
-error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/match-forbidden-without-eq.rs:13:9
- |
-LL | FOO => { }
- | ^^^
-
warning: floating-point types cannot be used in patterns
- --> $DIR/match-forbidden-without-eq.rs:21:9
+ --> $DIR/match-forbidden-without-eq.rs:20:9
|
LL | f32::INFINITY => { }
| ^^^^^^^^^^^^^
= 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 #41620 <https://github.com/rust-lang/rust/issues/41620>
-error: aborting due to 2 previous errors; 2 warnings emitted
+error: aborting due to previous error; 2 warnings emitted
match [B(1)] {
FOO => { }
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
}
}
LL | FOO => { }
| ^^^
-error: to use a constant of type `B` in a pattern, `B` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/match-nonempty-array-forbidden-without-eq.rs:16:9
- |
-LL | FOO => { }
- | ^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
match y {
FOO => { }
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
- //~| ERROR must be annotated with `#[derive(PartialEq, Eq)]`
_ => { }
}
}
LL | FOO => { }
| ^^^
-error: to use a constant of type `Foo` in a pattern, `Foo` must be annotated with `#[derive(PartialEq, Eq)]`
- --> $DIR/match-requires-both-partialeq-and-eq.rs:17:9
- |
-LL | FOO => { }
- | ^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
match todo!() {
LEAK_FREE => (),
//~^ `impl Send` cannot be used in patterns
- //~| `impl Send` cannot be used in patterns
_ => (),
}
}
LL | LEAK_FREE => (),
| ^^^^^^^^^
-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
+error: aborting due to previous error
match todo!() {
VALUE => (),
//~^ `impl Send` cannot be used in patterns
- //~| `impl Send` cannot be used in patterns
_ => (),
}
}
LL | VALUE => (),
| ^^^^^
-error: `impl Send` cannot be used in patterns
- --> $DIR/structural-match.rs:15:9
- |
-LL | VALUE => (),
- | ^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
fn main() {
match C {
C => {} //~ ERROR cannot use unions in constant patterns
- //~| ERROR cannot use unions in constant patterns
_ => {}
}
}
LL | C => {}
| ^
-error: cannot use unions in constant patterns
- --> $DIR/union-const-pat.rs:10:9
- |
-LL | C => {}
- | ^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error