Skip to content

Commit 32e31b2

Browse files
authored
Unrolled build for rust-lang#124379
Rollup merge of rust-lang#124379 - compiler-errors:remove-new-solver-lookup-behavior, r=lcnr Remove special-casing for `SimplifiedType` for next solver It's unnecessary due to the way that we fully normalize the self type before assembly begins. r? lcnr
2 parents 3a36386 + f2518cd commit 32e31b2

File tree

3 files changed

+18
-63
lines changed

3 files changed

+18
-63
lines changed

compiler/rustc_middle/src/ty/fast_reject.rs

+5-33
Original file line numberDiff line numberDiff line change
@@ -58,30 +58,6 @@ pub enum TreatParams {
5858
/// This also treats projections with inference variables as infer vars
5959
/// since they could be further normalized.
6060
ForLookup,
61-
/// Treat parameters as placeholders in the given environment. This is the
62-
/// correct mode for *lookup*, as during candidate selection.
63-
///
64-
/// N.B. during deep rejection, this acts identically to `ForLookup`.
65-
///
66-
/// FIXME(-Znext-solver): Remove this variant and cleanup
67-
/// the code.
68-
NextSolverLookup,
69-
}
70-
71-
/// During fast-rejection, we have the choice of treating projection types
72-
/// as either simplifiable or not, depending on whether we expect the projection
73-
/// to be normalized/rigid.
74-
#[derive(PartialEq, Eq, Debug, Clone, Copy)]
75-
pub enum TreatProjections {
76-
/// In the old solver we don't try to normalize projections
77-
/// when looking up impls and only access them by using the
78-
/// current self type. This means that if the self type is
79-
/// a projection which could later be normalized, we must not
80-
/// treat it as rigid.
81-
ForLookup,
82-
/// We can treat projections in the self type as opaque as
83-
/// we separately look up impls for the normalized self type.
84-
NextSolverLookup,
8561
}
8662

8763
/// Tries to simplify a type by only returning the outermost injective¹ layer, if one exists.
@@ -139,21 +115,17 @@ pub fn simplify_type<'tcx>(
139115
ty::FnPtr(f) => Some(SimplifiedType::Function(f.skip_binder().inputs().len())),
140116
ty::Placeholder(..) => Some(SimplifiedType::Placeholder),
141117
ty::Param(_) => match treat_params {
142-
TreatParams::ForLookup | TreatParams::NextSolverLookup => {
143-
Some(SimplifiedType::Placeholder)
144-
}
118+
TreatParams::ForLookup => Some(SimplifiedType::Placeholder),
145119
TreatParams::AsCandidateKey => None,
146120
},
147121
ty::Alias(..) => match treat_params {
148122
// When treating `ty::Param` as a placeholder, projections also
149123
// don't unify with anything else as long as they are fully normalized.
150-
//
151-
// We will have to be careful with lazy normalization here.
152-
// FIXME(lazy_normalization): This is probably not right...
124+
// FIXME(-Znext-solver): Can remove this `if` and always simplify to `Placeholder`
125+
// when the new solver is enabled by default.
153126
TreatParams::ForLookup if !ty.has_non_region_infer() => {
154127
Some(SimplifiedType::Placeholder)
155128
}
156-
TreatParams::NextSolverLookup => Some(SimplifiedType::Placeholder),
157129
TreatParams::ForLookup | TreatParams::AsCandidateKey => None,
158130
},
159131
ty::Foreign(def_id) => Some(SimplifiedType::Foreign(def_id)),
@@ -331,7 +303,7 @@ impl DeepRejectCtxt {
331303
// Depending on the value of `treat_obligation_params`, we either
332304
// treat generic parameters like placeholders or like inference variables.
333305
ty::Param(_) => match self.treat_obligation_params {
334-
TreatParams::ForLookup | TreatParams::NextSolverLookup => false,
306+
TreatParams::ForLookup => false,
335307
TreatParams::AsCandidateKey => true,
336308
},
337309

@@ -373,7 +345,7 @@ impl DeepRejectCtxt {
373345
let k = impl_ct.kind();
374346
match obligation_ct.kind() {
375347
ty::ConstKind::Param(_) => match self.treat_obligation_params {
376-
TreatParams::ForLookup | TreatParams::NextSolverLookup => false,
348+
TreatParams::ForLookup => false,
377349
TreatParams::AsCandidateKey => true,
378350
},
379351

compiler/rustc_middle/src/ty/trait_def.rs

+4-23
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::traits::specialization_graph;
2-
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams, TreatProjections};
2+
use crate::ty::fast_reject::{self, SimplifiedType, TreatParams};
33
use crate::ty::{Ident, Ty, TyCtxt};
44
use hir::def_id::LOCAL_CRATE;
55
use rustc_hir as hir;
@@ -135,21 +135,6 @@ impl<'tcx> TyCtxt<'tcx> {
135135
self,
136136
trait_def_id: DefId,
137137
self_ty: Ty<'tcx>,
138-
f: impl FnMut(DefId),
139-
) {
140-
self.for_each_relevant_impl_treating_projections(
141-
trait_def_id,
142-
self_ty,
143-
TreatProjections::ForLookup,
144-
f,
145-
)
146-
}
147-
148-
pub fn for_each_relevant_impl_treating_projections(
149-
self,
150-
trait_def_id: DefId,
151-
self_ty: Ty<'tcx>,
152-
treat_projections: TreatProjections,
153138
mut f: impl FnMut(DefId),
154139
) {
155140
// FIXME: This depends on the set of all impls for the trait. That is
@@ -163,17 +148,13 @@ impl<'tcx> TyCtxt<'tcx> {
163148
f(impl_def_id);
164149
}
165150

166-
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
167-
// `TreatParams::AsCandidateKey` while actually adding them.
168-
let treat_params = match treat_projections {
169-
TreatProjections::NextSolverLookup => TreatParams::NextSolverLookup,
170-
TreatProjections::ForLookup => TreatParams::ForLookup,
171-
};
172151
// This way, when searching for some impl for `T: Trait`, we do not look at any impls
173152
// whose outer level is not a parameter or projection. Especially for things like
174153
// `T: Clone` this is incredibly useful as we would otherwise look at all the impls
175154
// of `Clone` for `Option<T>`, `Vec<T>`, `ConcreteType` and so on.
176-
if let Some(simp) = fast_reject::simplify_type(self, self_ty, treat_params) {
155+
// Note that we're using `TreatParams::ForLookup` to query `non_blanket_impls` while using
156+
// `TreatParams::AsCandidateKey` while actually adding them.
157+
if let Some(simp) = fast_reject::simplify_type(self, self_ty, TreatParams::ForLookup) {
177158
if let Some(impls) = impls.non_blanket_impls.get(&simp) {
178159
for &impl_def_id in impls {
179160
f(impl_def_id);

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::traits::solve::{
1414
CandidateSource, CanonicalResponse, Certainty, Goal, QueryResult,
1515
};
1616
use rustc_middle::traits::{BuiltinImplSource, Reveal};
17-
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, TreatProjections};
17+
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
1818
use rustc_middle::ty::{self, ToPredicate, Ty, TyCtxt};
1919
use rustc_middle::ty::{TraitPredicate, TypeVisitableExt};
2020
use rustc_span::{ErrorGuaranteed, DUMMY_SP};
@@ -1045,6 +1045,12 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
10451045
}
10461046
}
10471047

1048+
// If we still have an alias here, it must be rigid. For opaques, it's always
1049+
// okay to consider auto traits because that'll reveal its hidden type. For
1050+
// non-opaque aliases, we will not assemble any candidates since there's no way
1051+
// to further look into its type.
1052+
ty::Alias(..) => None,
1053+
10481054
// For rigid types, any possible implementation that could apply to
10491055
// the type (even if after unification and processing nested goals
10501056
// it does not hold) will disqualify the built-in auto impl.
@@ -1072,15 +1078,11 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
10721078
| ty::CoroutineWitness(..)
10731079
| ty::Never
10741080
| ty::Tuple(_)
1075-
| ty::Adt(_, _)
1076-
// FIXME: Handling opaques here is kinda sus. Especially because we
1077-
// simplify them to SimplifiedType::Placeholder.
1078-
| ty::Alias(ty::Opaque, _) => {
1081+
| ty::Adt(_, _) => {
10791082
let mut disqualifying_impl = None;
1080-
self.tcx().for_each_relevant_impl_treating_projections(
1083+
self.tcx().for_each_relevant_impl(
10811084
goal.predicate.def_id(),
10821085
goal.predicate.self_ty(),
1083-
TreatProjections::NextSolverLookup,
10841086
|impl_def_id| {
10851087
disqualifying_impl = Some(impl_def_id);
10861088
},

0 commit comments

Comments
 (0)