Fix an ICE that I just made worse

This commit is contained in:
Oli Scherer 2022-11-17 15:30:42 +00:00
parent a9f3c2209c
commit 4d9451b1d1
3 changed files with 29 additions and 9 deletions

View File

@ -1,7 +1,6 @@
use rustc_errors::DelayDm;
use rustc_hir as hir;
use rustc_index::vec::Idx;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_middle::mir::{self, Field};
use rustc_middle::thir::{FieldPat, Pat, PatKind};
@ -227,13 +226,6 @@ fn type_may_have_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
// using `PartialEq::eq` in this scenario in the past.)
let partial_eq_trait_id =
self.tcx().require_lang_item(hir::LangItem::PartialEq, Some(self.span));
let any_ty = self
.infcx
.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
span: self.span,
})
.into();
let obligation: PredicateObligation<'_> = predicate_for_trait_def(
self.tcx(),
self.param_env,
@ -241,7 +233,7 @@ fn type_may_have_partial_eq_impl(&self, ty: Ty<'tcx>) -> bool {
partial_eq_trait_id,
0,
ty,
[any_ty],
[ty.into()],
);
// FIXME: should this call a `predicate_must_hold` variant instead?

View File

@ -0,0 +1,20 @@
#![allow(warnings)]
struct MyType;
impl PartialEq<usize> for MyType {
fn eq(&self, y: &usize) -> bool {
true
}
}
const CONSTANT: &&MyType = &&MyType;
fn main() {
if let CONSTANT = &&MyType {
//~^ ERROR must be annotated with `#[derive(PartialEq, Eq)]`
println!("semantic!");
} else {
println!("structural!");
}
}

View File

@ -0,0 +1,8 @@
error: to use a constant of type `MyType` in a pattern, `MyType` must be annotated with `#[derive(PartialEq, Eq)]`
--> $DIR/const-partial_eq-fallback-ice.rs:14:12
|
LL | if let CONSTANT = &&MyType {
| ^^^^^^^^
error: aborting due to previous error