Skip to content

Commit

Permalink
Fix ICE when indirect_structural_match is allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianWolff committed Sep 20, 2021
1 parent 3bb9eec commit 402ebc7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,18 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
&& !self.saw_const_match_lint.get()
{
self.saw_const_match_lint.set(true);
let msg = format!(
"to use a constant of type `{}` in a pattern, \
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
cv.ty, cv.ty,
);
tcx.struct_span_lint_hir(
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
id,
span,
|lint| lint.build(&msg).emit(),
|lint| {
let msg = format!(
"to use a constant of type `{}` in a pattern, \
`{}` must be annotated with `#[derive(PartialEq, Eq)]`",
cv.ty, cv.ty,
);
lint.build(&msg).emit()
},
);
}
// Since we are behind a reference, we can just bubble the error up so we get a
Expand Down
22 changes: 22 additions & 0 deletions src/test/ui/consts/issue-89088.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Regression test for the ICE described in #89088.

// check-pass

#![allow(indirect_structural_match)]
use std::borrow::Cow;

const FOO: &A = &A::Field(Cow::Borrowed("foo"));

#[derive(PartialEq, Eq)]
enum A {
Field(Cow<'static, str>)
}

fn main() {
let var = A::Field(Cow::Borrowed("bar"));

match &var {
FOO => todo!(),
_ => todo!()
}
}

0 comments on commit 402ebc7

Please sign in to comment.