diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index fdc706f4b043b..913f56eba36f5 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -47,7 +47,9 @@ use rustc_span::{DUMMY_SP, Ident, Span, Symbol, bug, kw, sym}; use rustc_structures::{CrateType, Limit}; use rustc_type_ir::TyKind::*; pub use rustc_type_ir::lift::Lift; -use rustc_type_ir::{CollectAndApply, WithCachedTypeInfo, elaborate, search_graph}; +use rustc_type_ir::{ + CollectAndApply, PlaceholderType, WithCachedTypeInfo, elaborate, search_graph, +}; use tracing::{debug, instrument}; use crate::arena::Arena; @@ -284,28 +286,22 @@ impl<'tcx> CtxtInterners<'tcx> { // For these preinterned values, an alternative would be to have // variable-length vectors that grow as needed. But that turned out to be // slightly more complex and no faster. +// +// All numbers have been chosen based on profiling data. + +const NUM_PREINTERNED_INFER_TY_VARS: u32 = 512; +const NUM_PREINTERNED_INFER_FRESH_TYS: u32 = 20; +const NUM_PREINTERNED_INFER_FRESH_INT_TYS: u32 = 3; +const NUM_PREINTERNED_INFER_FRESH_FLOAT_TYS: u32 = 3; +const NUM_PREINTERNED_BOUND_BOUND_ANONS_I: u32 = 3; +const NUM_PREINTERNED_BOUND_BOUND_ANONS_V: u32 = 20; +const NUM_PREINTERNED_BOUND_CANONICAL_ANONS: u32 = 128; +const NUM_PREINTERNED_PLACEHOLDER_ROOT_ANONS: u32 = 128; -const NUM_PREINTERNED_TY_VARS: u32 = 100; -const NUM_PREINTERNED_FRESH_TYS: u32 = 20; -const NUM_PREINTERNED_FRESH_INT_TYS: u32 = 3; -const NUM_PREINTERNED_FRESH_FLOAT_TYS: u32 = 3; -const NUM_PREINTERNED_ANON_BOUND_TYS_I: u32 = 3; - -// From general profiling of the *max vars during canonicalization* of a value: -// - about 90% of the time, there are no canonical vars -// - about 9% of the time, there is only one canonical var -// - there are rarely more than 3-5 canonical vars (with exceptions in particularly pathological -// cases) -// This may not match the number of bound vars found in `for`s. -// Given that this is all heap interned, it seems likely that interning fewer -// vars here won't make an appreciable difference. Though, if we were to inline the data (in an -// array), we may want to consider reducing the number for canonicalized vars down to 4 or so. -const NUM_PREINTERNED_ANON_BOUND_TYS_V: u32 = 20; - -// This number may seem high, but it is reached in all but the smallest crates. const NUM_PREINTERNED_RE_VARS: u32 = 500; -const NUM_PREINTERNED_ANON_RE_BOUNDS_I: u32 = 3; -const NUM_PREINTERNED_ANON_RE_BOUNDS_V: u32 = 20; +const NUM_PREINTERNED_RE_BOUND_BOUND_ANONS_I: u32 = 3; +const NUM_PREINTERNED_RE_BOUND_BOUND_ANONS_V: u32 = 20; +const NUM_PREINTERNED_RE_BOUND_CANONICAL_ANONS: u32 = 20; pub struct CommonTypes<'tcx> { pub unit: Ty<'tcx>, @@ -360,26 +356,37 @@ pub struct CommonTypes<'tcx> { pub trait_object_dummy_self: Ty<'tcx>, /// Pre-interned `Infer(ty::TyVar(n))` for small values of `n`. - pub ty_vars: Vec>, + pub infer_ty_vars: Vec>, /// Pre-interned `Infer(ty::FreshTy(n))` for small values of `n`. - pub fresh_tys: Vec>, + pub infer_fresh_tys: Vec>, /// Pre-interned `Infer(ty::FreshIntTy(n))` for small values of `n`. - pub fresh_int_tys: Vec>, + pub infer_fresh_int_tys: Vec>, /// Pre-interned `Infer(ty::FreshFloatTy(n))` for small values of `n`. - pub fresh_float_tys: Vec>, + pub infer_fresh_float_tys: Vec>, + + /// Pre-interned values of the form: + /// `Bound( + /// BoundVarIndexKind::Bound(DebruijnIndex(i)), + /// BoundTy { var: v, kind: BoundTyKind::Anon } + /// )` + /// for small values of `i` and `v`. + pub bound_bound_anons: Vec>>, /// Pre-interned values of the form: - /// `Bound(BoundVarIndexKind::Bound(DebruijnIndex(i)), BoundTy { var: v, kind: - /// BoundTyKind::Anon})` for small values of `i` and `v`. - pub anon_bound_tys: Vec>>, - - // Pre-interned values of the form: - // `Bound(BoundVarIndexKind::Canonical, BoundTy { var: v, kind: BoundTyKind::Anon })` - // for small values of `v`. - pub anon_canonical_bound_tys: Vec>, + /// `Bound(BoundVarIndexKind::Canonical, BoundTy { var: v, kind: BoundTyKind::Anon })` + /// for small values of `v`. + pub bound_canonical_anons: Vec>, + + /// Pre-interned values of the form: + /// `Placeholder(Placeholder { + /// universe: UniverseIndex::ROOT, + /// bound: BoundTy { var: v, kind: BoundTyKind::Anon } + /// })` + /// for small values of `v`. + pub placeholder_root_anons: Vec>, } pub struct CommonLifetimes<'tcx> { @@ -389,18 +396,18 @@ pub struct CommonLifetimes<'tcx> { /// Erased region, used outside of type inference. pub re_erased: Region<'tcx>, - /// Pre-interned `ReVar(ty::RegionVar(n))` for small values of `n`. + /// Pre-interned `ReVar(ty::RegionVid(n))` for small values of `n`. pub re_vars: Vec>, /// Pre-interned values of the form: /// `ReBound(BoundVarIndexKind::Bound(DebruijnIndex(i)), BoundRegion { var: v, kind: BoundRegionKind::Anon })` /// for small values of `i` and `v`. - pub anon_re_bounds: Vec>>, + pub re_bound_bound_anons: Vec>>, - // Pre-interned values of the form: - // `ReBound(BoundVarIndexKind::Canonical, BoundRegion { var: v, kind: BoundRegionKind::Anon })` - // for small values of `v`. - pub anon_re_canonical_bounds: Vec>, + /// Pre-interned values of the form: + /// `ReBound(BoundVarIndexKind::Canonical, BoundRegion { var: v, kind: BoundRegionKind::Anon })` + /// for small values of `v`. + pub re_bound_canonical_anons: Vec>, } pub struct CommonConsts<'tcx> { @@ -415,18 +422,21 @@ impl<'tcx> CommonTypes<'tcx> { fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> { let mk = |ty| interners.intern_ty(ty); - let ty_vars = - (0..NUM_PREINTERNED_TY_VARS).map(|n| mk(Infer(ty::TyVar(TyVid::from(n))))).collect(); - let fresh_tys: Vec<_> = - (0..NUM_PREINTERNED_FRESH_TYS).map(|n| mk(Infer(ty::FreshTy(n)))).collect(); - let fresh_int_tys: Vec<_> = - (0..NUM_PREINTERNED_FRESH_INT_TYS).map(|n| mk(Infer(ty::FreshIntTy(n)))).collect(); - let fresh_float_tys: Vec<_> = - (0..NUM_PREINTERNED_FRESH_FLOAT_TYS).map(|n| mk(Infer(ty::FreshFloatTy(n)))).collect(); + let infer_ty_vars = (0..NUM_PREINTERNED_INFER_TY_VARS) + .map(|n| mk(Infer(ty::TyVar(TyVid::from(n))))) + .collect(); + let infer_fresh_tys: Vec<_> = + (0..NUM_PREINTERNED_INFER_FRESH_TYS).map(|n| mk(Infer(ty::FreshTy(n)))).collect(); + let infer_fresh_int_tys: Vec<_> = (0..NUM_PREINTERNED_INFER_FRESH_INT_TYS) + .map(|n| mk(Infer(ty::FreshIntTy(n)))) + .collect(); + let infer_fresh_float_tys: Vec<_> = (0..NUM_PREINTERNED_INFER_FRESH_FLOAT_TYS) + .map(|n| mk(Infer(ty::FreshFloatTy(n)))) + .collect(); - let anon_bound_tys = (0..NUM_PREINTERNED_ANON_BOUND_TYS_I) + let bound_bound_anons = (0..NUM_PREINTERNED_BOUND_BOUND_ANONS_I) .map(|i| { - (0..NUM_PREINTERNED_ANON_BOUND_TYS_V) + (0..NUM_PREINTERNED_BOUND_BOUND_ANONS_V) .map(|v| { mk(ty::Bound( ty::BoundVarIndexKind::Bound(ty::DebruijnIndex::from(i)), @@ -437,7 +447,7 @@ impl<'tcx> CommonTypes<'tcx> { }) .collect(); - let anon_canonical_bound_tys = (0..NUM_PREINTERNED_ANON_BOUND_TYS_V) + let bound_canonical_anons = (0..NUM_PREINTERNED_BOUND_CANONICAL_ANONS) .map(|v| { mk(ty::Bound( ty::BoundVarIndexKind::Canonical, @@ -446,6 +456,15 @@ impl<'tcx> CommonTypes<'tcx> { }) .collect(); + let placeholder_root_anons = (0..NUM_PREINTERNED_PLACEHOLDER_ROOT_ANONS) + .map(|v| { + mk(ty::Placeholder(PlaceholderType::new_anon( + ty::UniverseIndex::ROOT, + ty::BoundVar::from(v), + ))) + }) + .collect(); + CommonTypes { unit: mk(Tuple(List::empty())), bool: mk(Bool), @@ -470,14 +489,15 @@ impl<'tcx> CommonTypes<'tcx> { str_: mk(Str), self_param: mk(ty::Param(ty::ParamTy { index: 0, name: kw::SelfUpper })), - trait_object_dummy_self: fresh_tys[0], + trait_object_dummy_self: infer_fresh_tys[0], - ty_vars, - fresh_tys, - fresh_int_tys, - fresh_float_tys, - anon_bound_tys, - anon_canonical_bound_tys, + infer_ty_vars, + infer_fresh_tys, + infer_fresh_int_tys, + infer_fresh_float_tys, + bound_bound_anons, + bound_canonical_anons, + placeholder_root_anons, } } } @@ -493,9 +513,9 @@ impl<'tcx> CommonLifetimes<'tcx> { let re_vars = (0..NUM_PREINTERNED_RE_VARS).map(|n| mk(ty::ReVar(ty::RegionVid::from(n)))).collect(); - let anon_re_bounds = (0..NUM_PREINTERNED_ANON_RE_BOUNDS_I) + let re_bound_bound_anons = (0..NUM_PREINTERNED_RE_BOUND_BOUND_ANONS_I) .map(|i| { - (0..NUM_PREINTERNED_ANON_RE_BOUNDS_V) + (0..NUM_PREINTERNED_RE_BOUND_BOUND_ANONS_V) .map(|v| { mk(ty::ReBound( ty::BoundVarIndexKind::Bound(ty::DebruijnIndex::from(i)), @@ -509,7 +529,7 @@ impl<'tcx> CommonLifetimes<'tcx> { }) .collect(); - let anon_re_canonical_bounds = (0..NUM_PREINTERNED_ANON_RE_BOUNDS_V) + let re_bound_canonical_anons = (0..NUM_PREINTERNED_RE_BOUND_CANONICAL_ANONS) .map(|v| { mk(ty::ReBound( ty::BoundVarIndexKind::Canonical, @@ -522,8 +542,8 @@ impl<'tcx> CommonLifetimes<'tcx> { re_static: mk(ty::ReStatic), re_erased: mk(ty::ReErased), re_vars, - anon_re_bounds, - anon_re_canonical_bounds, + re_bound_bound_anons, + re_bound_canonical_anons, } } } diff --git a/compiler/rustc_middle/src/ty/context/impl_interner.rs b/compiler/rustc_middle/src/ty/context/impl_interner.rs index a6688b668aab3..e43d2c7f10b07 100644 --- a/compiler/rustc_middle/src/ty/context/impl_interner.rs +++ b/compiler/rustc_middle/src/ty/context/impl_interner.rs @@ -207,9 +207,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> { ty::AliasConstKind::Anon { .. } => None, } } - fn anon_const_kind(self, def_id: DefId) -> ty::AnonConstKind { - self.anon_const_kind(def_id) - } fn def_span(self, def_id: DefId) -> Span { self.def_span(def_id) @@ -494,10 +491,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.is_lang_item(def_id, solver_trait_lang_item_to_lang_item(lang_item)) } - fn is_adt_lang_item(self, def_id: DefId, lang_item: SolverAdtLangItem) -> bool { - self.is_lang_item(def_id, solver_adt_lang_item_to_lang_item(lang_item)) - } - fn is_default_trait(self, def_id: DefId) -> bool { self.is_default_trait(def_id) } @@ -604,10 +597,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> { self.trait_def(trait_def_id).safety.is_unsafe() } - fn is_impl_trait_in_trait(self, def_id: DefId) -> bool { - self.is_impl_trait_in_trait(def_id) - } - fn delay_bug(self, msg: impl ToString) -> ErrorGuaranteed { self.dcx().span_delayed_bug(DUMMY_SP, msg.to_string()) } @@ -683,18 +672,6 @@ impl<'tcx> Interner for TyCtxt<'tcx> { }) } - fn get_anon_re_bounds_lifetime(self, idx: usize, var_idx: usize) -> Option> { - if let Some(inner) = self.lifetimes.anon_re_bounds.get(idx) { - inner.get(var_idx).copied() - } else { - None - } - } - - fn get_anon_re_canonical_bounds_lifetime(self, idx: usize) -> Option> { - self.lifetimes.anon_re_canonical_bounds.get(idx).copied() - } - fn get_re_static_lifetime(self) -> Region<'tcx> { self.lifetimes.re_static } @@ -719,7 +696,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { ) -> Region<'tcx> { // Use a pre-interned one when possible. if let ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon } = bound_region - && let Some(inner) = self.lifetimes.anon_re_bounds.get(debruijn.as_usize()) + && let Some(inner) = self.lifetimes.re_bound_bound_anons.get(debruijn.as_usize()) && let Some(re) = inner.get(var.as_usize()).copied() { re @@ -730,7 +707,7 @@ impl<'tcx> Interner for TyCtxt<'tcx> { fn intern_canonical_bound(self, var: BoundVar) -> Region<'tcx> { // Use a pre-interned one when possible. - if let Some(re) = self.lifetimes.anon_re_canonical_bounds.get(var.as_usize()).copied() { + if let Some(re) = self.lifetimes.re_bound_canonical_anons.get(var.as_usize()).copied() { re } else { self.intern_region(ty::ReBound( diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 925915c88cdb4..4673ff428934b 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -378,7 +378,7 @@ impl<'tcx> Ty<'tcx> { pub fn new_var(tcx: TyCtxt<'tcx>, v: ty::TyVid) -> Ty<'tcx> { // Use a pre-interned one when possible. tcx.types - .ty_vars + .infer_ty_vars .get(v.as_usize()) .copied() .unwrap_or_else(|| Ty::new(tcx, Infer(TyVar(v)))) @@ -398,7 +398,7 @@ impl<'tcx> Ty<'tcx> { pub fn new_fresh(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> { // Use a pre-interned one when possible. tcx.types - .fresh_tys + .infer_fresh_tys .get(n as usize) .copied() .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshTy(n))) @@ -408,7 +408,7 @@ impl<'tcx> Ty<'tcx> { pub fn new_fresh_int(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> { // Use a pre-interned one when possible. tcx.types - .fresh_int_tys + .infer_fresh_int_tys .get(n as usize) .copied() .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshIntTy(n))) @@ -418,7 +418,7 @@ impl<'tcx> Ty<'tcx> { pub fn new_fresh_float(tcx: TyCtxt<'tcx>, n: u32) -> Ty<'tcx> { // Use a pre-interned one when possible. tcx.types - .fresh_float_tys + .infer_fresh_float_tys .get(n as usize) .copied() .unwrap_or_else(|| Ty::new_infer(tcx, ty::FreshFloatTy(n))) @@ -437,7 +437,7 @@ impl<'tcx> Ty<'tcx> { ) -> Ty<'tcx> { // Use a pre-interned one when possible. if let ty::BoundTy { var, kind: ty::BoundTyKind::Anon } = bound_ty - && let Some(inner) = tcx.types.anon_bound_tys.get(index.as_usize()) + && let Some(inner) = tcx.types.bound_bound_anons.get(index.as_usize()) && let Some(ty) = inner.get(var.as_usize()).copied() { ty @@ -449,7 +449,7 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: BoundVar) -> Ty<'tcx> { // Use a pre-interned one when possible. - if let Some(ty) = tcx.types.anon_canonical_bound_tys.get(var.as_usize()).copied() { + if let Some(ty) = tcx.types.bound_canonical_anons.get(var.as_usize()).copied() { ty } else { Ty::new( @@ -464,7 +464,15 @@ impl<'tcx> Ty<'tcx> { #[inline] pub fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderType<'tcx>) -> Ty<'tcx> { - Ty::new(tcx, Placeholder(placeholder)) + if placeholder.universe.is_root() + && placeholder.bound.kind == ty::BoundTyKind::Anon + && let Some(ty) = + tcx.types.placeholder_root_anons.get(placeholder.bound.var.as_usize()).copied() + { + ty + } else { + Ty::new(tcx, Placeholder(placeholder)) + } } #[inline] diff --git a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs index ea19d36f5d0cf..3899397e6d8c3 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs @@ -178,14 +178,12 @@ impl<'a, D: SolverDelegate, I: Interner> Canonicalizer<'a, D, I> { delegate, CanonicalizeMode::Input(CanonicalizeInputKind::Predicate), ); - rest_canonicalizer.state.variables.extend(e.variables.iter().copied()); - rest_canonicalizer.state.var_kinds.extend(e.var_kinds.iter().copied()); - // SAFETY: The iterated elements go straight back into a hashmap. - #[allow(rustc::potential_query_instability)] + rest_canonicalizer.state.variables.clone_from(&e.variables); + rest_canonicalizer.state.var_kinds.clone_from(&e.var_kinds); rest_canonicalizer .state .variable_lookup_table - .extend(e.variable_lookup_table.iter().map(|(&arg, &idx)| (arg, idx))); + .clone_from(&e.variable_lookup_table); (e.param_env, rest_canonicalizer) } }) diff --git a/compiler/rustc_next_trait_solver/src/canonical/mod.rs b/compiler/rustc_next_trait_solver/src/canonical/mod.rs index 00dfc146db50a..45587d717b418 100644 --- a/compiler/rustc_next_trait_solver/src/canonical/mod.rs +++ b/compiler/rustc_next_trait_solver/src/canonical/mod.rs @@ -499,6 +499,10 @@ fn unify_query_var_values( assert_eq!(original_values.len(), var_values.len()); for (&orig, response) in iter::zip(original_values, var_values.iter()) { + if orig == response { + continue; + } + let mut must_eq = ResponseRelating::new(&**delegate, span); must_eq.relate(orig, response).unwrap(); } diff --git a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs index ae538441499e0..aaa2d723460d5 100644 --- a/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs +++ b/compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs @@ -92,7 +92,8 @@ where // and `assumption`'s trait refs directly inside this function in // order to prevent unsoundness (see below). - Self::fast_reject_assumption(ecx, goal, assumption)?; + let goal_lang_item = ecx.cx().as_trait_lang_item(goal.predicate.trait_def_id(ecx.cx())); + Self::fast_reject_assumption(ecx, goal, goal_lang_item, assumption)?; ecx.probe_trait_candidate(source).enter(|ecx| { let cx = ecx.cx(); @@ -178,11 +179,6 @@ where goal: Goal, assumption: I::Clause, ) -> Result, CandidateHeadUsages>, RerunNonErased> { - match Self::fast_reject_assumption(ecx, goal, assumption) { - Ok(()) => {} - Err(NoSolution) => return Ok(Err(CandidateHeadUsages::default())), - } - // Dealing with `ParamEnv` candidates is a bit of a mess as we need to lazily // check whether the candidate is global while considering normalization. // @@ -228,7 +224,8 @@ where assumption: I::Clause, then: impl FnOnce(&mut EvalCtxt<'_, D>) -> QueryResultOrRerunNonErased, ) -> Result, NoSolutionOrRerunNonErased> { - Self::fast_reject_assumption(ecx, goal, assumption)?; + let goal_lang_item = ecx.cx().as_trait_lang_item(goal.predicate.trait_def_id(ecx.cx())); + Self::fast_reject_assumption(ecx, goal, goal_lang_item, assumption)?; ecx.probe_trait_candidate(source) .enter(|ecx| Self::match_assumption(ecx, goal, assumption, then)) @@ -239,6 +236,7 @@ where fn fast_reject_assumption( ecx: &mut EvalCtxt<'_, D>, goal: Goal, + goal_lang_item: Option, assumption: I::Clause, ) -> Result<(), NoSolution>; @@ -740,12 +738,19 @@ where candidates: &mut Vec>, failed_candidate_info: &mut FailedCandidateInfo, ) -> Result<(), RerunNonErased> { + let goal_lang_item = self.cx().as_trait_lang_item(goal.predicate.trait_def_id(self.cx())); + for assumption in goal.param_env.caller_bounds() { - match G::probe_and_consider_param_env_candidate(self, goal, assumption)? { - Ok(candidate) => candidates.push(candidate), - Err(head_usages) => { - failed_candidate_info.param_env_head_usages.merge_usages(head_usages) + match G::fast_reject_assumption(self, goal, goal_lang_item, assumption) { + Ok(()) => { + match G::probe_and_consider_param_env_candidate(self, goal, assumption)? { + Ok(candidate) => candidates.push(candidate), + Err(head_usages) => { + failed_candidate_info.param_env_head_usages.merge_usages(head_usages) + } + } } + Err(NoSolution) => {} } } diff --git a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs index 04d1376d20b9f..bb6fce7691222 100644 --- a/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/effect_goals.rs @@ -42,6 +42,7 @@ where fn fast_reject_assumption( ecx: &mut EvalCtxt<'_, D>, goal: Goal, + _goal_lang_item: Option, assumption: I::Clause, ) -> Result<(), NoSolution> { if let Some(host_clause) = assumption.as_host_effect_clause() diff --git a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs index 4203ae8c509cc..f8c4597dce654 100644 --- a/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs +++ b/compiler/rustc_next_trait_solver/src/solve/normalizes_to.rs @@ -183,6 +183,7 @@ where fn fast_reject_assumption( ecx: &mut EvalCtxt<'_, D>, goal: Goal, + _goal_lang_item: Option, assumption: I::Clause, ) -> Result<(), NoSolution> { let alias_def_id = match goal.predicate.alias.kind { diff --git a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs index 31c0f72af8a28..14f1eb939b2db 100644 --- a/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs +++ b/compiler/rustc_next_trait_solver/src/solve/trait_goals.rs @@ -136,6 +136,7 @@ where fn fast_reject_assumption( ecx: &mut EvalCtxt<'_, D>, goal: Goal, + goal_lang_item: Option, assumption: I::Clause, ) -> Result<(), NoSolution> { fn trait_def_id_matches( @@ -143,6 +144,7 @@ where clause_def_id: I::TraitId, goal_def_id: I::TraitId, polarity: ClausePolarity, + goal_lang_item: Option, ) -> bool { clause_def_id == goal_def_id // PERF(sized-hierarchy): Sizedness supertraits aren't elaborated to improve perf, so @@ -150,8 +152,8 @@ where // // `PointeeSized` bounds are syntactic sugar for a lack of bounds so don't need this. || (polarity == ClausePolarity::Positive - && cx.is_trait_lang_item(clause_def_id, SolverTraitLangItem::Sized) - && cx.is_trait_lang_item(goal_def_id, SolverTraitLangItem::MetaSized)) + && goal_lang_item == Some(SolverTraitLangItem::MetaSized) + && cx.is_trait_lang_item(clause_def_id, SolverTraitLangItem::Sized)) } if let Some(trait_clause) = assumption.as_trait_clause() @@ -161,6 +163,7 @@ where trait_clause.def_id(), goal.predicate.def_id(), goal.predicate.polarity, + goal_lang_item, ) && DeepRejectCtxt::relate_rigid_rigid(ecx.cx()).args_may_unify( goal.predicate.trait_ref.args, diff --git a/compiler/rustc_type_ir/src/interner.rs b/compiler/rustc_type_ir/src/interner.rs index e3bf97dfebd26..1bfaa869cbabb 100644 --- a/compiler/rustc_type_ir/src/interner.rs +++ b/compiler/rustc_type_ir/src/interner.rs @@ -290,7 +290,6 @@ pub trait Interner: self, alias: ty::AliasConstKind, ) -> Option>>; - fn anon_const_kind(self, def_id: Self::DefId) -> ty::AnonConstKind; fn def_span(self, def_id: Self::DefId) -> Self::Span; @@ -445,8 +444,6 @@ pub trait Interner: fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool; - fn is_adt_lang_item(self, def_id: Self::AdtId, lang_item: SolverAdtLangItem) -> bool; - fn is_default_trait(self, def_id: Self::TraitId) -> bool; fn is_sizedness_trait(self, def_id: Self::TraitId) -> bool; @@ -504,8 +501,6 @@ pub trait Interner: /// Returns `true` if this is an `unsafe trait`. fn trait_is_unsafe(self, trait_def_id: Self::TraitId) -> bool; - fn is_impl_trait_in_trait(self, def_id: Self::DefId) -> bool; - fn delay_bug(self, msg: impl ToString) -> Self::ErrorGuaranteed; fn span_delayed_bug(self, span: Self::Span, msg: impl ToString) -> Self::ErrorGuaranteed; @@ -539,10 +534,6 @@ pub trait Interner: fn item_name(self, item_index: Self::DefId) -> Self::Symbol; - fn get_anon_re_bounds_lifetime(self, idx: usize, var_idx: usize) -> Option>; - - fn get_anon_re_canonical_bounds_lifetime(self, idx: usize) -> Option>; - fn get_re_static_lifetime(self) -> Region; fn intern_re_var(self, rv: RegionVid) -> Region;