Skip to content

Commit 036b5fe

Browse files
committed
Auto merge of rust-lang#73446 - ecstatic-morse:issue-73431, r=pnkfelix
Make novel structural match violations not a `bug` Fixes (on master) rust-lang#73431. Ideally, `CustomEq` would emit a strict subset of the structural match errors that are found by `search_for_structural_match_violation`, since it allows more cases due to value-based reasoning. However, const qualification is more conservative than `search_for_structural_match_violation` around associated constants, since qualification does not try to substitute type parameters. In the long term, we should probably make const qualification work for generic associated constants, but I don't like extending its capabilities even further. r? @pnkfelix
2 parents e55d3f9 + 3a1207f commit 036b5fe

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/librustc_mir_build/hair/pattern/const_to_pat.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,15 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
107107
cv.ty, structural
108108
);
109109

110+
// This can occur because const qualification treats all associated constants as
111+
// opaque, whereas `search_for_structural_match_violation` tries to monomorphize them
112+
// before it runs.
113+
//
114+
// FIXME(#73448): Find a way to bring const qualification into parity with
115+
// `search_for_structural_match_violation`.
110116
if structural.is_none() && mir_structural_match_violation {
111-
bug!("MIR const-checker found novel structural match violation");
117+
warn!("MIR const-checker found novel structural match violation. See #73448.");
118+
return inlined_const_as_pat;
112119
}
113120

114121
if let Some(non_sm_ty) = structural {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// run-pass
2+
3+
// Regression test for https://github.com/rust-lang/rust/issues/73431.
4+
5+
pub trait Zero {
6+
const ZERO: Self;
7+
}
8+
9+
impl Zero for usize {
10+
const ZERO: Self = 0;
11+
}
12+
13+
impl<T: Zero> Zero for Wrapper<T> {
14+
const ZERO: Self = Wrapper(T::ZERO);
15+
}
16+
17+
#[derive(Debug, PartialEq, Eq)]
18+
pub struct Wrapper<T>(T);
19+
20+
fn is_zero(x: Wrapper<usize>) -> bool {
21+
match x {
22+
Zero::ZERO => true,
23+
_ => false,
24+
}
25+
}
26+
27+
fn main() {
28+
let _ = is_zero(Wrapper(42));
29+
}

0 commit comments

Comments
 (0)