diff --git a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs index 068e5a5eb77..07a33bcbb50 100644 --- a/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs +++ b/compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs @@ -102,8 +102,8 @@ fn check_def_id(&mut self, impl_def_id: LocalDefId, self_ty: Ty<'tcx>, ty_def_id if let Some(simp) = simplify_type( self.tcx, self_ty, - TreatParams::AsInfer, - TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ) { self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id); } else { @@ -164,9 +164,12 @@ fn check_primitive_impl(&mut self, impl_def_id: LocalDefId, ty: Ty<'tcx>) { } } - if let Some(simp) = - simplify_type(self.tcx, ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate) - { + if let Some(simp) = simplify_type( + self.tcx, + ty, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, + ) { self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id); } else { bug!("unexpected primitive type: {:?}", ty); diff --git a/compiler/rustc_hir_typeck/src/method/probe.rs b/compiler/rustc_hir_typeck/src/method/probe.rs index e9d4f9282a3..562dd2caae3 100644 --- a/compiler/rustc_hir_typeck/src/method/probe.rs +++ b/compiler/rustc_hir_typeck/src/method/probe.rs @@ -700,7 +700,7 @@ fn assemble_probe(&mut self, self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'t } fn assemble_inherent_candidates_for_incoherent_ty(&mut self, self_ty: Ty<'tcx>) { - let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate) else { + let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsCandidateKey, TreatProjections::AsCandidateKey) else { bug!("unexpected incoherent type: {:?}", self_ty) }; for &impl_def_id in self.tcx.incoherent_impls(simp) { diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index da0d180987a..7055d9257ec 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -1258,7 +1258,7 @@ fn suggest_associated_call_syntax( let target_ty = self .autoderef(sugg_span, rcvr_ty) .find(|(rcvr_ty, _)| { - DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer } + DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey } .types_may_unify(*rcvr_ty, impl_ty) }) .map_or(impl_ty, |(ty, _)| ty) @@ -1517,7 +1517,7 @@ fn suggest_constraining_numerical_ty( .into_iter() .any(|info| self.associated_value(info.def_id, item_name).is_some()); let found_assoc = |ty: Ty<'tcx>| { - simplify_type(tcx, ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate) + simplify_type(tcx, ty, TreatParams::AsCandidateKey, TreatProjections::AsCandidateKey) .and_then(|simp| { tcx.incoherent_impls(simp) .iter() @@ -2649,8 +2649,8 @@ enum Introducer { } else if let Some(simp_rcvr_ty) = simplify_type( self.tcx, rcvr_ty, - TreatParams::AsPlaceholder, - TreatProjections::DefaultLookup, + TreatParams::ForLookup, + TreatProjections::ForLookup, ) { let mut potential_candidates = Vec::new(); let mut explicitly_negative = Vec::new(); @@ -2667,8 +2667,8 @@ enum Introducer { let imp_simp = simplify_type( self.tcx, imp.self_ty(), - TreatParams::AsPlaceholder, - TreatProjections::DefaultLookup, + TreatParams::ForLookup, + TreatProjections::ForLookup, ); imp_simp.map_or(false, |s| s == simp_rcvr_ty) }) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index ccadb0bada2..bbab8a62a2b 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -1858,8 +1858,8 @@ fn encode_impls(&mut self) -> LazyArray { let simplified_self_ty = fast_reject::simplify_type( self.tcx, trait_ref.self_ty(), - TreatParams::AsInfer, - TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ); fx_hash_map diff --git a/compiler/rustc_middle/src/ty/fast_reject.rs b/compiler/rustc_middle/src/ty/fast_reject.rs index d672c6cc803..ee505742be9 100644 --- a/compiler/rustc_middle/src/ty/fast_reject.rs +++ b/compiler/rustc_middle/src/ty/fast_reject.rs @@ -51,9 +51,12 @@ pub enum SimplifiedType { /// generic parameters as if they were inference variables in that case. #[derive(PartialEq, Eq, Debug, Clone, Copy)] pub enum TreatParams { - /// Treat parameters as placeholders in the given environment. - AsPlaceholder, - AsInfer, + /// Treat parameters as infer vars. This is the correct mode for caching + /// an impl's type for lookup. + AsCandidateKey, + /// Treat parameters as placeholders in the given environment. This is the + /// correct mode for *lookup*, as during candidate selection. + ForLookup, } /// During fast-rejection, we have the choice of treating projection types @@ -67,13 +70,13 @@ pub enum TreatProjections { /// We must assume that the `impl Trait for ::This` /// can apply to all self types so we don't return a simplified type /// for `::This`. - DefaultCandidate, + AsCandidateKey, /// In the old solver we don't try to normalize projections /// when looking up impls and only access them by using the /// current self type. This means that if the self type is /// a projection which could later be normalized, we must not /// treat it as rigid. - DefaultLookup, + ForLookup, /// We can treat projections in the self type as opaque as /// we separately look up impls for the normalized self type. NextSolverLookup, @@ -133,13 +136,13 @@ pub fn simplify_type<'tcx>( ty::FnPtr(f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())), ty::Placeholder(..) => Some(PlaceholderSimplifiedType), ty::Param(_) => match treat_params { - TreatParams::AsPlaceholder => Some(PlaceholderSimplifiedType), - TreatParams::AsInfer => None, + TreatParams::ForLookup => Some(PlaceholderSimplifiedType), + TreatParams::AsCandidateKey => None, }, ty::Alias(..) => match treat_projections { - TreatProjections::DefaultLookup if !ty.needs_infer() => Some(PlaceholderSimplifiedType), + TreatProjections::ForLookup if !ty.needs_infer() => Some(PlaceholderSimplifiedType), TreatProjections::NextSolverLookup => Some(PlaceholderSimplifiedType), - TreatProjections::DefaultCandidate | TreatProjections::DefaultLookup => None, + TreatProjections::AsCandidateKey | TreatProjections::ForLookup => None, }, ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)), ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None, @@ -307,8 +310,8 @@ pub fn types_may_unify<'tcx>(self, obligation_ty: Ty<'tcx>, impl_ty: Ty<'tcx>) - // Depending on the value of `treat_obligation_params`, we either // treat generic parameters like placeholders or like inference variables. ty::Param(_) => match self.treat_obligation_params { - TreatParams::AsPlaceholder => false, - TreatParams::AsInfer => true, + TreatParams::ForLookup => false, + TreatParams::AsCandidateKey => true, }, ty::Infer(_) => true, @@ -345,8 +348,8 @@ pub fn consts_may_unify(self, obligation_ct: ty::Const<'_>, impl_ct: ty::Const<' let k = impl_ct.kind(); match obligation_ct.kind() { ty::ConstKind::Param(_) => match self.treat_obligation_params { - TreatParams::AsPlaceholder => false, - TreatParams::AsInfer => true, + TreatParams::ForLookup => false, + TreatParams::AsCandidateKey => true, }, // As we don't necessarily eagerly evaluate constants, diff --git a/compiler/rustc_middle/src/ty/trait_def.rs b/compiler/rustc_middle/src/ty/trait_def.rs index dec6011fe38..bf2b121f704 100644 --- a/compiler/rustc_middle/src/ty/trait_def.rs +++ b/compiler/rustc_middle/src/ty/trait_def.rs @@ -127,7 +127,7 @@ pub fn for_each_relevant_impl( self.for_each_relevant_impl_treating_projections( trait_def_id, self_ty, - TreatProjections::DefaultLookup, + TreatProjections::ForLookup, f, ) } @@ -156,8 +156,8 @@ pub fn non_blanket_impls_for_ty( if let Some(simp) = fast_reject::simplify_type( self, self_ty, - TreatParams::AsInfer, - TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ) { if let Some(impls) = impls.non_blanket_impls.get(&simp) { return impls.iter().copied(); @@ -196,7 +196,7 @@ pub fn find_map_relevant_impl( // `T: Clone` this is incredibly useful as we would otherwise look at all the impls // of `Clone` for `Option`, `Vec`, `ConcreteType` and so on. if let Some(simp) = - fast_reject::simplify_type(self, self_ty, TreatParams::AsPlaceholder, treat_projections) + fast_reject::simplify_type(self, self_ty, TreatParams::ForLookup, treat_projections) { if let Some(impls) = impls.non_blanket_impls.get(&simp) { for &impl_def_id in impls { @@ -261,8 +261,8 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait if let Some(simplified_self_ty) = fast_reject::simplify_type( tcx, impl_self_ty, - TreatParams::AsInfer, - TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ) { impls.non_blanket_impls.entry(simplified_self_ty).or_default().push(impl_def_id); } else { diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index e3e8a57caf1..b0f6127baa5 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -368,7 +368,7 @@ pub fn calculate_dtor( drop_trait, ty, // FIXME: This could also be some other mode, like "unexpected" - TreatProjections::DefaultLookup, + TreatProjections::ForLookup, |impl_did| { if let Some(item_id) = self.associated_item_def_ids(impl_did).first() { if validate(self, impl_did).is_ok() { diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 5ef3e13eff8..c8d371dd084 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -2215,7 +2215,7 @@ fn check_proc_macro(&self, hir_id: HirId, target: Target, kind: ProcMacroKind) { // `fn(TokenStream) -> TokenStream` after some substitution of generic arguments. // // Properly checking this means pulling in additional `rustc` crates, so we don't. - let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }; + let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey }; if sig.abi != Abi::Rust { tcx.sess.emit_err(errors::ProcMacroInvalidAbi { diff --git a/compiler/rustc_trait_selection/src/solve/project_goals.rs b/compiler/rustc_trait_selection/src/solve/project_goals.rs index e206658b4b9..dbb8e722c8f 100644 --- a/compiler/rustc_trait_selection/src/solve/project_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/project_goals.rs @@ -184,7 +184,7 @@ fn consider_impl_candidate( let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); - let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder }; + let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup }; if iter::zip(goal_trait_ref.substs, impl_trait_ref.skip_binder().substs) .any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp)) { diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index e8696c7d0f5..7878539817c 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -36,7 +36,7 @@ fn consider_impl_candidate( let tcx = ecx.tcx(); let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap(); - let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder }; + let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup }; if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs) .any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp)) { diff --git a/compiler/rustc_trait_selection/src/traits/coherence.rs b/compiler/rustc_trait_selection/src/traits/coherence.rs index 6b688c322c7..96a4b76af55 100644 --- a/compiler/rustc_trait_selection/src/traits/coherence.rs +++ b/compiler/rustc_trait_selection/src/traits/coherence.rs @@ -75,7 +75,7 @@ pub fn overlapping_impls( // Before doing expensive operations like entering an inference context, do // a quick check via fast_reject to tell if the impl headers could possibly // unify. - let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }; + let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey }; let impl1_ref = tcx.impl_trait_ref(impl1_def_id); let impl2_ref = tcx.impl_trait_ref(impl2_def_id); let may_overlap = match (impl1_ref, impl2_ref) { diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index 4ceec0d6a57..41ffaeeac1c 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -1803,7 +1803,7 @@ fn report_projection_error( self.tcx.find_map_relevant_impl( id, proj.projection_ty.self_ty(), - TreatProjections::DefaultLookup, + TreatProjections::ForLookup, |did| { self.tcx .associated_items(did) @@ -2185,7 +2185,7 @@ fn note_version_mismatch( self.tcx.find_map_relevant_impl( trait_def_id, trait_ref.skip_binder().self_ty(), - TreatProjections::DefaultLookup, + TreatProjections::ForLookup, Some, ) }; diff --git a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs index 4305171aa80..3182af989f0 100644 --- a/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs +++ b/compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs @@ -784,7 +784,7 @@ fn assemble_const_destruct_candidates( let relevant_impl = self.tcx().find_map_relevant_impl( self.tcx().require_lang_item(LangItem::Drop, None), obligation.predicate.skip_binder().trait_ref.self_ty(), - TreatProjections::DefaultLookup, + TreatProjections::ForLookup, Some, ); diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index d7ce0078124..38cdaddc1e7 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2558,7 +2558,7 @@ fn fast_reject_trait_refs( // We can avoid creating type variables and doing the full // substitution if we find that any of the input types, when // simplified, do not match. - let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder }; + let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup }; iter::zip(obligation.predicate.skip_binder().trait_ref.substs, impl_trait_ref.substs) .any(|(obl, imp)| !drcx.generic_args_may_unify(obl, imp)) } diff --git a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs index bebaa885cf7..cd665d9471d 100644 --- a/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs +++ b/compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs @@ -52,8 +52,8 @@ fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { if let Some(st) = fast_reject::simplify_type( tcx, trait_ref.self_ty(), - TreatParams::AsInfer, - fast_reject::TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ) { debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st); self.non_blanket_impls.entry(st).or_default().push(impl_def_id) @@ -72,8 +72,8 @@ fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) { if let Some(st) = fast_reject::simplify_type( tcx, trait_ref.self_ty(), - TreatParams::AsInfer, - TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ) { debug!("remove_existing: impl_def_id={:?} st={:?}", impl_def_id, st); vec = self.non_blanket_impls.get_mut(&st).unwrap(); @@ -313,8 +313,8 @@ fn insert( let simplified = fast_reject::simplify_type( tcx, trait_ref.self_ty(), - TreatParams::AsInfer, - TreatProjections::DefaultCandidate, + TreatParams::AsCandidateKey, + TreatProjections::AsCandidateKey, ); // Descend the specialization tree, where `parent` is the current parent node. diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index bd5e05770fe..358f6ad566c 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -735,7 +735,7 @@ fn trait_impls_for<'a>( trace!("considering explicit impl for trait {:?}", trait_); // Look at each trait implementation to see if it's an impl for `did` - tcx.find_map_relevant_impl(trait_, ty, TreatProjections::DefaultLookup, |impl_| { + tcx.find_map_relevant_impl(trait_, ty, TreatProjections::ForLookup, |impl_| { let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl"); // Check if these are the same type. let impl_type = trait_ref.skip_binder().self_ty();