Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make novel structural match violations not a bug #73446

Merged
merged 3 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/librustc_mir_build/hair/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,15 @@ 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.
//
// 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 {
bug!("MIR const-checker found novel structural match violation");
warn!("MIR const-checker found novel structural match violation. See #73448.");
return inlined_const_as_pat;
}

if let Some(non_sm_ty) = structural {
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/consts/const_in_pattern/issue-73431.rs
Original file line number Diff line number Diff line change
@@ -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<T: Zero> Zero for Wrapper<T> {
const ZERO: Self = Wrapper(T::ZERO);
}

#[derive(Debug, PartialEq, Eq)]
pub struct Wrapper<T>(T);

fn is_zero(x: Wrapper<usize>) -> bool {
match x {
Zero::ZERO => true,
_ => false,
}
}

fn main() {
let _ = is_zero(Wrapper(42));
}