Skip to content

Commit 84d254e

Browse files
committedMar 13, 2023
Better names?
1 parent 868aa42 commit 84d254e

File tree

16 files changed

+55
-49
lines changed

16 files changed

+55
-49
lines changed
 

‎compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ impl<'tcx> InherentCollect<'tcx> {
102102
if let Some(simp) = simplify_type(
103103
self.tcx,
104104
self_ty,
105-
TreatParams::AsInfer,
106-
TreatProjections::DefaultCandidate,
105+
TreatParams::AsCandidateKey,
106+
TreatProjections::AsCandidateKey,
107107
) {
108108
self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id);
109109
} else {
@@ -164,9 +164,12 @@ impl<'tcx> InherentCollect<'tcx> {
164164
}
165165
}
166166

167-
if let Some(simp) =
168-
simplify_type(self.tcx, ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate)
169-
{
167+
if let Some(simp) = simplify_type(
168+
self.tcx,
169+
ty,
170+
TreatParams::AsCandidateKey,
171+
TreatProjections::AsCandidateKey,
172+
) {
170173
self.impls_map.incoherent_impls.entry(simp).or_default().push(impl_def_id);
171174
} else {
172175
bug!("unexpected primitive type: {:?}", ty);

‎compiler/rustc_hir_typeck/src/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
700700
}
701701

702702
fn assemble_inherent_candidates_for_incoherent_ty(&mut self, self_ty: Ty<'tcx>) {
703-
let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate) else {
703+
let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::AsCandidateKey, TreatProjections::AsCandidateKey) else {
704704
bug!("unexpected incoherent type: {:?}", self_ty)
705705
};
706706
for &impl_def_id in self.tcx.incoherent_impls(simp) {

‎compiler/rustc_hir_typeck/src/method/suggest.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
12581258
let target_ty = self
12591259
.autoderef(sugg_span, rcvr_ty)
12601260
.find(|(rcvr_ty, _)| {
1261-
DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer }
1261+
DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey }
12621262
.types_may_unify(*rcvr_ty, impl_ty)
12631263
})
12641264
.map_or(impl_ty, |(ty, _)| ty)
@@ -1517,7 +1517,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15171517
.into_iter()
15181518
.any(|info| self.associated_value(info.def_id, item_name).is_some());
15191519
let found_assoc = |ty: Ty<'tcx>| {
1520-
simplify_type(tcx, ty, TreatParams::AsInfer, TreatProjections::DefaultCandidate)
1520+
simplify_type(tcx, ty, TreatParams::AsCandidateKey, TreatProjections::AsCandidateKey)
15211521
.and_then(|simp| {
15221522
tcx.incoherent_impls(simp)
15231523
.iter()
@@ -2649,8 +2649,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26492649
} else if let Some(simp_rcvr_ty) = simplify_type(
26502650
self.tcx,
26512651
rcvr_ty,
2652-
TreatParams::AsPlaceholder,
2653-
TreatProjections::DefaultLookup,
2652+
TreatParams::ForLookup,
2653+
TreatProjections::ForLookup,
26542654
) {
26552655
let mut potential_candidates = Vec::new();
26562656
let mut explicitly_negative = Vec::new();
@@ -2667,8 +2667,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26672667
let imp_simp = simplify_type(
26682668
self.tcx,
26692669
imp.self_ty(),
2670-
TreatParams::AsPlaceholder,
2671-
TreatProjections::DefaultLookup,
2670+
TreatParams::ForLookup,
2671+
TreatProjections::ForLookup,
26722672
);
26732673
imp_simp.map_or(false, |s| s == simp_rcvr_ty)
26742674
})

‎compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1858,8 +1858,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18581858
let simplified_self_ty = fast_reject::simplify_type(
18591859
self.tcx,
18601860
trait_ref.self_ty(),
1861-
TreatParams::AsInfer,
1862-
TreatProjections::DefaultCandidate,
1861+
TreatParams::AsCandidateKey,
1862+
TreatProjections::AsCandidateKey,
18631863
);
18641864

18651865
fx_hash_map

‎compiler/rustc_middle/src/ty/fast_reject.rs

+16-13
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,12 @@ pub enum SimplifiedType {
5151
/// generic parameters as if they were inference variables in that case.
5252
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
5353
pub enum TreatParams {
54-
/// Treat parameters as placeholders in the given environment.
55-
AsPlaceholder,
56-
AsInfer,
54+
/// Treat parameters as infer vars. This is the correct mode for caching
55+
/// an impl's type for lookup.
56+
AsCandidateKey,
57+
/// Treat parameters as placeholders in the given environment. This is the
58+
/// correct mode for *lookup*, as during candidate selection.
59+
ForLookup,
5760
}
5861

5962
/// During fast-rejection, we have the choice of treating projection types
@@ -67,13 +70,13 @@ pub enum TreatProjections {
6770
/// We must assume that the `impl<T> Trait<T> for <T as Id>::This`
6871
/// can apply to all self types so we don't return a simplified type
6972
/// for `<T as Id>::This`.
70-
DefaultCandidate,
73+
AsCandidateKey,
7174
/// In the old solver we don't try to normalize projections
7275
/// when looking up impls and only access them by using the
7376
/// current self type. This means that if the self type is
7477
/// a projection which could later be normalized, we must not
7578
/// treat it as rigid.
76-
DefaultLookup,
79+
ForLookup,
7780
/// We can treat projections in the self type as opaque as
7881
/// we separately look up impls for the normalized self type.
7982
NextSolverLookup,
@@ -133,13 +136,13 @@ pub fn simplify_type<'tcx>(
133136
ty::FnPtr(f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())),
134137
ty::Placeholder(..) => Some(PlaceholderSimplifiedType),
135138
ty::Param(_) => match treat_params {
136-
TreatParams::AsPlaceholder => Some(PlaceholderSimplifiedType),
137-
TreatParams::AsInfer => None,
139+
TreatParams::ForLookup => Some(PlaceholderSimplifiedType),
140+
TreatParams::AsCandidateKey => None,
138141
},
139142
ty::Alias(..) => match treat_projections {
140-
TreatProjections::DefaultLookup if !ty.needs_infer() => Some(PlaceholderSimplifiedType),
143+
TreatProjections::ForLookup if !ty.needs_infer() => Some(PlaceholderSimplifiedType),
141144
TreatProjections::NextSolverLookup => Some(PlaceholderSimplifiedType),
142-
TreatProjections::DefaultCandidate | TreatProjections::DefaultLookup => None,
145+
TreatProjections::AsCandidateKey | TreatProjections::ForLookup => None,
143146
},
144147
ty::Foreign(def_id) => Some(ForeignSimplifiedType(def_id)),
145148
ty::Bound(..) | ty::Infer(_) | ty::Error(_) => None,
@@ -307,8 +310,8 @@ impl DeepRejectCtxt {
307310
// Depending on the value of `treat_obligation_params`, we either
308311
// treat generic parameters like placeholders or like inference variables.
309312
ty::Param(_) => match self.treat_obligation_params {
310-
TreatParams::AsPlaceholder => false,
311-
TreatParams::AsInfer => true,
313+
TreatParams::ForLookup => false,
314+
TreatParams::AsCandidateKey => true,
312315
},
313316

314317
ty::Infer(_) => true,
@@ -345,8 +348,8 @@ impl DeepRejectCtxt {
345348
let k = impl_ct.kind();
346349
match obligation_ct.kind() {
347350
ty::ConstKind::Param(_) => match self.treat_obligation_params {
348-
TreatParams::AsPlaceholder => false,
349-
TreatParams::AsInfer => true,
351+
TreatParams::ForLookup => false,
352+
TreatParams::AsCandidateKey => true,
350353
},
351354

352355
// As we don't necessarily eagerly evaluate constants,

‎compiler/rustc_middle/src/ty/trait_def.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl<'tcx> TyCtxt<'tcx> {
127127
self.for_each_relevant_impl_treating_projections(
128128
trait_def_id,
129129
self_ty,
130-
TreatProjections::DefaultLookup,
130+
TreatProjections::ForLookup,
131131
f,
132132
)
133133
}
@@ -156,8 +156,8 @@ impl<'tcx> TyCtxt<'tcx> {
156156
if let Some(simp) = fast_reject::simplify_type(
157157
self,
158158
self_ty,
159-
TreatParams::AsInfer,
160-
TreatProjections::DefaultCandidate,
159+
TreatParams::AsCandidateKey,
160+
TreatProjections::AsCandidateKey,
161161
) {
162162
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
163163
return impls.iter().copied();
@@ -196,7 +196,7 @@ impl<'tcx> TyCtxt<'tcx> {
196196
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
197197
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
198198
if let Some(simp) =
199-
fast_reject::simplify_type(self, self_ty, TreatParams::AsPlaceholder, treat_projections)
199+
fast_reject::simplify_type(self, self_ty, TreatParams::ForLookup, treat_projections)
200200
{
201201
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
202202
for &impl_def_id in impls {
@@ -261,8 +261,8 @@ pub(super) fn trait_impls_of_provider(tcx: TyCtxt<'_>, trait_id: DefId) -> Trait
261261
if let Some(simplified_self_ty) = fast_reject::simplify_type(
262262
tcx,
263263
impl_self_ty,
264-
TreatParams::AsInfer,
265-
TreatProjections::DefaultCandidate,
264+
TreatParams::AsCandidateKey,
265+
TreatProjections::AsCandidateKey,
266266
) {
267267
impls.non_blanket_impls.entry(simplified_self_ty).or_default().push(impl_def_id);
268268
} else {

‎compiler/rustc_middle/src/ty/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl<'tcx> TyCtxt<'tcx> {
368368
drop_trait,
369369
ty,
370370
// FIXME: This could also be some other mode, like "unexpected"
371-
TreatProjections::DefaultLookup,
371+
TreatProjections::ForLookup,
372372
|impl_did| {
373373
if let Some(item_id) = self.associated_item_def_ids(impl_did).first() {
374374
if validate(self, impl_did).is_ok() {

‎compiler/rustc_passes/src/check_attr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ impl CheckAttrVisitor<'_> {
22152215
// `fn(TokenStream) -> TokenStream` after some substitution of generic arguments.
22162216
//
22172217
// Properly checking this means pulling in additional `rustc` crates, so we don't.
2218-
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
2218+
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey };
22192219

22202220
if sig.abi != Abi::Rust {
22212221
tcx.sess.emit_err(errors::ProcMacroInvalidAbi {

‎compiler/rustc_trait_selection/src/solve/project_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
184184

185185
let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx);
186186
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
187-
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
187+
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
188188
if iter::zip(goal_trait_ref.substs, impl_trait_ref.skip_binder().substs)
189189
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
190190
{

‎compiler/rustc_trait_selection/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
3636
let tcx = ecx.tcx();
3737

3838
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
39-
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
39+
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
4040
if iter::zip(goal.predicate.trait_ref.substs, impl_trait_ref.skip_binder().substs)
4141
.any(|(goal, imp)| !drcx.generic_args_may_unify(goal, imp))
4242
{

‎compiler/rustc_trait_selection/src/traits/coherence.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn overlapping_impls(
7575
// Before doing expensive operations like entering an inference context, do
7676
// a quick check via fast_reject to tell if the impl headers could possibly
7777
// unify.
78-
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
78+
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsCandidateKey };
7979
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
8080
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
8181
let may_overlap = match (impl1_ref, impl2_ref) {

‎compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
18031803
self.tcx.find_map_relevant_impl(
18041804
id,
18051805
proj.projection_ty.self_ty(),
1806-
TreatProjections::DefaultLookup,
1806+
TreatProjections::ForLookup,
18071807
|did| {
18081808
self.tcx
18091809
.associated_items(did)
@@ -2185,7 +2185,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21852185
self.tcx.find_map_relevant_impl(
21862186
trait_def_id,
21872187
trait_ref.skip_binder().self_ty(),
2188-
TreatProjections::DefaultLookup,
2188+
TreatProjections::ForLookup,
21892189
Some,
21902190
)
21912191
};

‎compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -784,7 +784,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
784784
let relevant_impl = self.tcx().find_map_relevant_impl(
785785
self.tcx().require_lang_item(LangItem::Drop, None),
786786
obligation.predicate.skip_binder().trait_ref.self_ty(),
787-
TreatProjections::DefaultLookup,
787+
TreatProjections::ForLookup,
788788
Some,
789789
);
790790

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2558,7 +2558,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
25582558
// We can avoid creating type variables and doing the full
25592559
// substitution if we find that any of the input types, when
25602560
// simplified, do not match.
2561-
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsPlaceholder };
2561+
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
25622562
iter::zip(obligation.predicate.skip_binder().trait_ref.substs, impl_trait_ref.substs)
25632563
.any(|(obl, imp)| !drcx.generic_args_may_unify(obl, imp))
25642564
}

‎compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
5252
if let Some(st) = fast_reject::simplify_type(
5353
tcx,
5454
trait_ref.self_ty(),
55-
TreatParams::AsInfer,
56-
fast_reject::TreatProjections::DefaultCandidate,
55+
TreatParams::AsCandidateKey,
56+
TreatProjections::AsCandidateKey,
5757
) {
5858
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
5959
self.non_blanket_impls.entry(st).or_default().push(impl_def_id)
@@ -72,8 +72,8 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
7272
if let Some(st) = fast_reject::simplify_type(
7373
tcx,
7474
trait_ref.self_ty(),
75-
TreatParams::AsInfer,
76-
TreatProjections::DefaultCandidate,
75+
TreatParams::AsCandidateKey,
76+
TreatProjections::AsCandidateKey,
7777
) {
7878
debug!("remove_existing: impl_def_id={:?} st={:?}", impl_def_id, st);
7979
vec = self.non_blanket_impls.get_mut(&st).unwrap();
@@ -313,8 +313,8 @@ impl<'tcx> GraphExt<'tcx> for Graph {
313313
let simplified = fast_reject::simplify_type(
314314
tcx,
315315
trait_ref.self_ty(),
316-
TreatParams::AsInfer,
317-
TreatProjections::DefaultCandidate,
316+
TreatParams::AsCandidateKey,
317+
TreatProjections::AsCandidateKey,
318318
);
319319

320320
// Descend the specialization tree, where `parent` is the current parent node.

‎src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ fn trait_impls_for<'a>(
735735
trace!("considering explicit impl for trait {:?}", trait_);
736736

737737
// Look at each trait implementation to see if it's an impl for `did`
738-
tcx.find_map_relevant_impl(trait_, ty, TreatProjections::DefaultLookup, |impl_| {
738+
tcx.find_map_relevant_impl(trait_, ty, TreatProjections::ForLookup, |impl_| {
739739
let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl");
740740
// Check if these are the same type.
741741
let impl_type = trait_ref.skip_binder().self_ty();

0 commit comments

Comments
 (0)
Please sign in to comment.