Fix ICE when indirect_structural_match
is allowed
This commit is contained in:
parent
3bb9eecf07
commit
402ebc72b3
2 changed files with 30 additions and 6 deletions
|
@ -322,16 +322,18 @@ impl<'a, 'tcx> ConstToPat<'a, 'tcx> {
|
||||||
&& !self.saw_const_match_lint.get()
|
&& !self.saw_const_match_lint.get()
|
||||||
{
|
{
|
||||||
self.saw_const_match_lint.set(true);
|
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(
|
tcx.struct_span_lint_hir(
|
||||||
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
|
lint::builtin::INDIRECT_STRUCTURAL_MATCH,
|
||||||
id,
|
id,
|
||||||
span,
|
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
|
// Since we are behind a reference, we can just bubble the error up so we get a
|
||||||
|
|
22
src/test/ui/consts/issue-89088.rs
Normal file
22
src/test/ui/consts/issue-89088.rs
Normal file
|
@ -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!()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue