Skip to content

Commit 4d9451b

Browse files
committed
Fix an ICE that I just made worse
1 parent a9f3c22 commit 4d9451b

File tree

3 files changed

+29
-9
lines changed

3 files changed

+29
-9
lines changed

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

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc_errors::DelayDm;
22
use rustc_hir as hir;
33
use rustc_index::vec::Idx;
4-
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
54
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
65
use rustc_middle::mir::{self, Field};
76
use rustc_middle::thir::{FieldPat, Pat, PatKind};
@@ -227,21 +226,14 @@ impl<'tcx> ConstToPat<'tcx> {
227226
// using `PartialEq::eq` in this scenario in the past.)
228227
let partial_eq_trait_id =
229228
self.tcx().require_lang_item(hir::LangItem::PartialEq, Some(self.span));
230-
let any_ty = self
231-
.infcx
232-
.next_ty_var(TypeVariableOrigin {
233-
kind: TypeVariableOriginKind::MiscVariable,
234-
span: self.span,
235-
})
236-
.into();
237229
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
238230
self.tcx(),
239231
self.param_env,
240232
ObligationCause::misc(self.span, self.id),
241233
partial_eq_trait_id,
242234
0,
243235
ty,
244-
[any_ty],
236+
[ty.into()],
245237
);
246238
// FIXME: should this call a `predicate_must_hold` variant instead?
247239

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![allow(warnings)]
2+
3+
struct MyType;
4+
5+
impl PartialEq<usize> for MyType {
6+
fn eq(&self, y: &usize) -> bool {
7+
true
8+
}
9+
}
10+
11+
const CONSTANT: &&MyType = &&MyType;
12+
13+
fn main() {
14+
if let CONSTANT = &&MyType {
15+
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
16+
println!("semantic!");
17+
} else {
18+
println!("structural!");
19+
}
20+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: to use a constant of type `MyType` in a pattern, `MyType` must be annotated with `#[derive(PartialEq, Eq)]`
2+
--> $DIR/const-partial_eq-fallback-ice.rs:14:12
3+
|
4+
LL | if let CONSTANT = &&MyType {
5+
| ^^^^^^^^
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)