Skip to content

Commit 8d95bb2

Browse files
authored
Rollup merge of #89126 - FabianWolff:issue-89088, r=petrochenkov
Fix ICE when `indirect_structural_match` is allowed Fixes #89088. The ICE is caused by `delay_good_path_bug()`, which is called (indirectly) from a `format!()` macro invocation. I have moved the macro invocation into the `decorate` closure of `struct_span_lint_hir()`, so that the macro is only invoked if the lint is not allowed (i.e., causes at least a warning, and thus prevents `delay_good_path_bug()` from firing).
2 parents 74cdd64 + 402ebc7 commit 8d95bb2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,18 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
322322
&& !self.saw_const_match_lint.get()
323323
{
324324
self.saw_const_match_lint.set(true);
325-
let msg = format!(
326-
"to use a constant of type `{}` in a pattern, \
327-
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
328-
cv.ty, cv.ty,
329-
);
330325
tcx.struct_span_lint_hir(
331326
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
332327
id,
333328
span,
334-
|lint| lint.build(&msg).emit(),
329+
|lint| {
330+
let msg = format!(
331+
"to use a constant of type `{}` in a pattern, \
332+
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
333+
cv.ty, cv.ty,
334+
);
335+
lint.build(&msg).emit()
336+
},
335337
);
336338
}
337339
// Since we are behind a reference, we can just bubble the error up so we get a

src/test/ui/consts/issue-89088.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for the ICE described in #89088.
2+
3+
// check-pass
4+
5+
#![allow(indirect_structural_match)]
6+
use std::borrow::Cow;
7+
8+
const FOO: &A = &A::Field(Cow::Borrowed("foo"));
9+
10+
#[derive(PartialEq, Eq)]
11+
enum A {
12+
Field(Cow<'static, str>)
13+
}
14+
15+
fn main() {
16+
let var = A::Field(Cow::Borrowed("bar"));
17+
18+
match &var {
19+
FOO => todo!(),
20+
_ => todo!()
21+
}
22+
}

0 commit comments

Comments
 (0)