From c9dc73d757003c58430d759b6e567afa356470a7 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Wed, 17 Jun 2020 09:29:33 -0700 Subject: [PATCH 1/3] Make novel structural match violations a warning --- src/librustc_mir_build/hair/pattern/const_to_pat.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/librustc_mir_build/hair/pattern/const_to_pat.rs b/src/librustc_mir_build/hair/pattern/const_to_pat.rs index 087c2c064cfaf..8c4230dfa5d6d 100644 --- a/src/librustc_mir_build/hair/pattern/const_to_pat.rs +++ b/src/librustc_mir_build/hair/pattern/const_to_pat.rs @@ -107,8 +107,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> { cv.ty, structural ); + // This can occur because const qualification treats all associated constants as + // opaque, whereas `search_for_structural_match_violation` tries to monomorphize them + // before it runs. See #73431 for an example. if structural.is_none() && mir_structural_match_violation { - bug!("MIR const-checker found novel structural match violation"); + warn!("MIR const-checker found novel structural match violation"); + return inlined_const_as_pat; } if let Some(non_sm_ty) = structural { From 38e921b2c134015b8eb5542f271a4f9e104ddaaf Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Wed, 17 Jun 2020 09:29:50 -0700 Subject: [PATCH 2/3] Add regression test for #73431 --- .../ui/consts/const_in_pattern/issue-73431.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/ui/consts/const_in_pattern/issue-73431.rs diff --git a/src/test/ui/consts/const_in_pattern/issue-73431.rs b/src/test/ui/consts/const_in_pattern/issue-73431.rs new file mode 100644 index 0000000000000..fa18a3af1b09f --- /dev/null +++ b/src/test/ui/consts/const_in_pattern/issue-73431.rs @@ -0,0 +1,29 @@ +// run-pass + +// Regression test for https://github.com/rust-lang/rust/issues/73431. + +pub trait Zero { + const ZERO: Self; +} + +impl Zero for usize { + const ZERO: Self = 0; +} + +impl Zero for Wrapper { + const ZERO: Self = Wrapper(T::ZERO); +} + +#[derive(Debug, PartialEq, Eq)] +pub struct Wrapper(T); + +fn is_zero(x: Wrapper) -> bool { + match x { + Zero::ZERO => true, + _ => false, + } +} + +fn main() { + let _ = is_zero(Wrapper(42)); +} From 3a1207f6883f799af13027ceb1715ff492382e87 Mon Sep 17 00:00:00 2001 From: Dylan MacKenzie Date: Wed, 17 Jun 2020 10:02:09 -0700 Subject: [PATCH 3/3] Add issue number to novel violation warning --- src/librustc_mir_build/hair/pattern/const_to_pat.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir_build/hair/pattern/const_to_pat.rs b/src/librustc_mir_build/hair/pattern/const_to_pat.rs index 8c4230dfa5d6d..1aed8e844b60b 100644 --- a/src/librustc_mir_build/hair/pattern/const_to_pat.rs +++ b/src/librustc_mir_build/hair/pattern/const_to_pat.rs @@ -109,9 +109,12 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> { // This can occur because const qualification treats all associated constants as // opaque, whereas `search_for_structural_match_violation` tries to monomorphize them - // before it runs. See #73431 for an example. + // before it runs. + // + // FIXME(#73448): Find a way to bring const qualification into parity with + // `search_for_structural_match_violation`. if structural.is_none() && mir_structural_match_violation { - warn!("MIR const-checker found novel structural match violation"); + warn!("MIR const-checker found novel structural match violation. See #73448."); return inlined_const_as_pat; }