Skip to content

Commit d9b520f

Browse files
committed
something is still wrong
1 parent 3978f54 commit d9b520f

File tree

11 files changed

+72
-57
lines changed

11 files changed

+72
-57
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2946,6 +2946,12 @@ define_print_and_forward_display! {
29462946
p!(print(self.term))
29472947
}
29482948

2949+
ty::NormalizesTo<'tcx> {
2950+
p!(print(self.alias), " normalizes-to ");
2951+
cx.reset_type_limit();
2952+
p!(print(self.term))
2953+
}
2954+
29492955
ty::Term<'tcx> {
29502956
match self.unpack() {
29512957
ty::TermKind::Ty(ty) => p!(print(ty)),

compiler/rustc_trait_selection/src/solve/assembly/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,15 +352,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
352352
num_steps: usize,
353353
) {
354354
let tcx = self.tcx();
355-
let &ty::Alias(_, projection_ty) = goal.predicate.self_ty().kind() else { return };
355+
let &ty::Alias(_, alias) = goal.predicate.self_ty().kind() else { return };
356356

357357
candidates.extend(self.probe(|_| ProbeKind::NormalizedSelfTyAssembly).enter(|ecx| {
358358
if tcx.recursion_limit().value_within_limit(num_steps) {
359359
let normalized_ty = ecx.next_ty_infer();
360-
let normalizes_to_goal = goal.with(
361-
tcx,
362-
ty::ProjectionPredicate { projection_ty, term: normalized_ty.into() },
363-
);
360+
let normalizes_to_goal =
361+
goal.with(tcx, ty::NormalizesTo { alias, term: normalized_ty.into() });
364362
ecx.add_goal(normalizes_to_goal);
365363
if let Err(NoSolution) = ecx.try_evaluate_added_goals() {
366364
debug!("self type normalization failed");

compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub(super) struct NestedGoals<'tcx> {
103103
/// with a fresh inference variable when we evaluate this goal. That can result
104104
/// in a trait solver cycle. This would currently result in overflow but can be
105105
/// can be unsound with more powerful coinduction in the future.
106-
pub(super) normalizes_to_hack_goal: Option<Goal<'tcx, ty::ProjectionPredicate<'tcx>>>,
106+
pub(super) normalizes_to_hack_goal: Option<Goal<'tcx, ty::NormalizesTo<'tcx>>>,
107107
/// The rest of the goals which have not yet processed or remain ambiguous.
108108
pub(super) goals: Vec<Goal<'tcx, ty::Predicate<'tcx>>>,
109109
}
@@ -423,7 +423,9 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
423423
ty::PredicateKind::ConstEquate(_, _) => {
424424
bug!("ConstEquate should not be emitted when `-Ztrait-solver=next` is active")
425425
}
426-
ty::PredicateKind::NormalizesTo(_) => unimplemented!(),
426+
ty::PredicateKind::NormalizesTo(predicate) => {
427+
self.compute_normalizes_to_goal(Goal { param_env, predicate })
428+
}
427429
ty::PredicateKind::AliasRelate(lhs, rhs, direction) => self
428430
.compute_alias_relate_goal(Goal {
429431
param_env,
@@ -493,10 +495,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
493495
let unconstrained_rhs = self.next_term_infer_of_kind(goal.predicate.term);
494496
let unconstrained_goal = goal.with(
495497
tcx,
496-
ty::ProjectionPredicate {
497-
projection_ty: goal.predicate.projection_ty,
498-
term: unconstrained_rhs,
499-
},
498+
ty::NormalizesTo { alias: goal.predicate.alias, term: unconstrained_rhs },
500499
);
501500

502501
let (_, certainty, instantiate_goals) = self.evaluate_goal(
@@ -518,9 +517,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
518517
// looking at the "has changed" return from evaluate_goal,
519518
// because we expect the `unconstrained_rhs` part of the predicate
520519
// to have changed -- that means we actually normalized successfully!
521-
if goal.predicate.projection_ty
522-
!= self.resolve_vars_if_possible(goal.predicate.projection_ty)
523-
{
520+
if goal.predicate.alias != self.resolve_vars_if_possible(goal.predicate.alias) {
524521
unchanged_certainty = None;
525522
}
526523

@@ -592,7 +589,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
592589
/// and does not occur in any other part of the predicate.
593590
pub(super) fn term_is_fully_unconstrained(
594591
&self,
595-
goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>,
592+
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
596593
) -> bool {
597594
let term_is_infer = match goal.predicate.term.unpack() {
598595
ty::TermKind::Ty(ty) => {
@@ -656,7 +653,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
656653
let mut visitor = ContainsTerm { infcx: self.infcx, term: goal.predicate.term };
657654

658655
term_is_infer
659-
&& goal.predicate.projection_ty.visit_with(&mut visitor).is_continue()
656+
&& goal.predicate.alias.visit_with(&mut visitor).is_continue()
660657
&& goal.param_env.visit_with(&mut visitor).is_continue()
661658
}
662659

compiler/rustc_trait_selection/src/solve/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ mod eval_ctxt;
3535
mod fulfill;
3636
pub mod inspect;
3737
mod normalize;
38+
mod normalizes_to;
3839
mod project_goals;
3940
mod search_graph;
4041
mod trait_goals;
@@ -216,7 +217,7 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> {
216217

217218
impl<'tcx> EvalCtxt<'_, 'tcx> {
218219
#[instrument(level = "debug", skip(self))]
219-
fn set_normalizes_to_hack_goal(&mut self, goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>) {
220+
fn set_normalizes_to_hack_goal(&mut self, goal: Goal<'tcx, ty::NormalizesTo<'tcx>>) {
220221
assert!(
221222
self.nested_goals.normalizes_to_hack_goal.is_none(),
222223
"attempted to set the projection eq hack goal when one already exists"
@@ -310,17 +311,17 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
310311
return None;
311312
}
312313

313-
let ty::Alias(kind, projection_ty) = *ty.kind() else {
314+
let ty::Alias(kind, alias) = *ty.kind() else {
314315
return Some(ty);
315316
};
316317

317318
// We do no always define opaque types eagerly to allow non-defining uses in the defining scope.
318319
if let (DefineOpaqueTypes::No, ty::AliasKind::Opaque) = (define_opaque_types, kind) {
319-
if let Some(def_id) = projection_ty.def_id.as_local() {
320+
if let Some(def_id) = alias.def_id.as_local() {
320321
if self
321322
.unify_existing_opaque_tys(
322323
param_env,
323-
OpaqueTypeKey { def_id, args: projection_ty.args },
324+
OpaqueTypeKey { def_id, args: alias.args },
324325
self.next_ty_infer(),
325326
)
326327
.is_empty()
@@ -335,7 +336,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
335336
let normalizes_to_goal = Goal::new(
336337
this.tcx(),
337338
param_env,
338-
ty::ProjectionPredicate { projection_ty, term: normalized_ty.into() },
339+
ty::NormalizesTo { alias, term: normalized_ty.into() },
339340
);
340341
this.add_goal(normalizes_to_goal);
341342
this.try_evaluate_added_goals()?;

compiler/rustc_trait_selection/src/solve/normalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
7676
tcx,
7777
self.at.cause.clone(),
7878
self.at.param_env,
79-
ty::ProjectionPredicate { projection_ty: alias, term: new_infer_ty.into() },
79+
ty::NormalizesTo { alias, term: new_infer_ty.into() },
8080
);
8181

8282
// Do not emit an error if normalization is known to fail but instead

compiler/rustc_trait_selection/src/solve/project_goals/inherent_projection.rs renamed to compiler/rustc_trait_selection/src/solve/normalizes_to/inherent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use super::EvalCtxt;
1212
impl<'tcx> EvalCtxt<'_, 'tcx> {
1313
pub(super) fn normalize_inherent_associated_type(
1414
&mut self,
15-
goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>,
15+
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
1616
) -> QueryResult<'tcx> {
1717
let tcx = self.tcx();
18-
let inherent = goal.predicate.projection_ty;
18+
let inherent = goal.predicate.alias;
1919
let expected = goal.predicate.term.ty().expect("inherent consts are treated separately");
2020

2121
let impl_def_id = tcx.parent(inherent.def_id);

compiler/rustc_trait_selection/src/solve/project_goals/mod.rs renamed to compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@ use rustc_middle::traits::solve::{
1313
};
1414
use rustc_middle::traits::BuiltinImplSource;
1515
use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams};
16-
use rustc_middle::ty::ProjectionPredicate;
16+
use rustc_middle::ty::NormalizesTo;
1717
use rustc_middle::ty::{self, Ty, TyCtxt};
1818
use rustc_middle::ty::{ToPredicate, TypeVisitableExt};
1919
use rustc_span::{sym, ErrorGuaranteed, DUMMY_SP};
2020

21-
mod inherent_projection;
21+
mod inherent;
2222
mod opaques;
2323
mod weak_types;
2424

2525
impl<'tcx> EvalCtxt<'_, 'tcx> {
2626
#[instrument(level = "debug", skip(self), ret)]
27-
pub(super) fn compute_projection_goal(
27+
pub(super) fn compute_normalizes_to_goal(
2828
&mut self,
29-
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
29+
goal: Goal<'tcx, NormalizesTo<'tcx>>,
3030
) -> QueryResult<'tcx> {
3131
let def_id = goal.predicate.def_id();
3232
match self.tcx().def_kind(def_id) {
@@ -71,16 +71,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
7171
#[instrument(level = "debug", skip(self), ret)]
7272
fn normalize_anon_const(
7373
&mut self,
74-
goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>,
74+
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
7575
) -> QueryResult<'tcx> {
7676
if let Some(normalized_const) = self.try_const_eval_resolve(
7777
goal.param_env,
78-
ty::UnevaluatedConst::new(
79-
goal.predicate.projection_ty.def_id,
80-
goal.predicate.projection_ty.args,
81-
),
78+
ty::UnevaluatedConst::new(goal.predicate.alias.def_id, goal.predicate.alias.args),
8279
self.tcx()
83-
.type_of(goal.predicate.projection_ty.def_id)
80+
.type_of(goal.predicate.alias.def_id)
8481
.no_bound_vars()
8582
.expect("const ty should not rely on other generics"),
8683
) {
@@ -92,13 +89,13 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
9289
}
9390
}
9491

95-
impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
92+
impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
9693
fn self_ty(self) -> Ty<'tcx> {
9794
self.self_ty()
9895
}
9996

10097
fn trait_ref(self, tcx: TyCtxt<'tcx>) -> ty::TraitRef<'tcx> {
101-
self.projection_ty.trait_ref(tcx)
98+
self.alias.trait_ref(tcx)
10299
}
103100

104101
fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
@@ -123,7 +120,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
123120
ecx.instantiate_binder_with_infer(projection_pred);
124121
ecx.eq(
125122
goal.param_env,
126-
goal.predicate.projection_ty,
123+
goal.predicate.alias,
127124
assumption_projection_pred.projection_ty,
128125
)?;
129126
ecx.eq(goal.param_env, goal.predicate.term, assumption_projection_pred.term)
@@ -132,7 +129,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
132129
// Add GAT where clauses from the trait's definition
133130
ecx.add_goals(
134131
tcx.predicates_of(goal.predicate.def_id())
135-
.instantiate_own(tcx, goal.predicate.projection_ty.args)
132+
.instantiate_own(tcx, goal.predicate.alias.args)
136133
.map(|(pred, _)| goal.with(tcx, pred)),
137134
);
138135

@@ -148,12 +145,12 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
148145

149146
fn consider_impl_candidate(
150147
ecx: &mut EvalCtxt<'_, 'tcx>,
151-
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
148+
goal: Goal<'tcx, NormalizesTo<'tcx>>,
152149
impl_def_id: DefId,
153150
) -> Result<Candidate<'tcx>, NoSolution> {
154151
let tcx = ecx.tcx();
155152

156-
let goal_trait_ref = goal.predicate.projection_ty.trait_ref(tcx);
153+
let goal_trait_ref = goal.predicate.alias.trait_ref(tcx);
157154
let impl_trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap();
158155
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
159156
if !drcx.args_may_unify(goal_trait_ref.args, impl_trait_ref.skip_binder().args) {
@@ -177,7 +174,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
177174
// Add GAT where clauses from the trait's definition
178175
ecx.add_goals(
179176
tcx.predicates_of(goal.predicate.def_id())
180-
.instantiate_own(tcx, goal.predicate.projection_ty.args)
177+
.instantiate_own(tcx, goal.predicate.alias.args)
181178
.map(|(pred, _)| goal.with(tcx, pred)),
182179
);
183180

@@ -202,7 +199,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
202199
tcx,
203200
guar,
204201
tcx.type_of(goal.predicate.def_id())
205-
.instantiate(tcx, goal.predicate.projection_ty.args),
202+
.instantiate(tcx, goal.predicate.alias.args),
206203
)
207204
.into(),
208205
ty::AssocKind::Type => Ty::new_error(tcx, guar).into(),
@@ -227,11 +224,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
227224
//
228225
// And then map these args to the args of the defining impl of `Assoc`, going
229226
// from `[u32, u64]` to `[u32, i32, u64]`.
230-
let impl_args_with_gat = goal.predicate.projection_ty.args.rebase_onto(
231-
tcx,
232-
goal_trait_ref.def_id,
233-
impl_args,
234-
);
227+
let impl_args_with_gat =
228+
goal.predicate.alias.args.rebase_onto(tcx, goal_trait_ref.def_id, impl_args);
235229
let args = ecx.translate_args(
236230
goal.param_env,
237231
impl_def_id,

compiler/rustc_trait_selection/src/solve/project_goals/opaques.rs renamed to compiler/rustc_trait_selection/src/solve/normalizes_to/opaques.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ use crate::solve::{EvalCtxt, SolverMode};
1212
impl<'tcx> EvalCtxt<'_, 'tcx> {
1313
pub(super) fn normalize_opaque_type(
1414
&mut self,
15-
goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>,
15+
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
1616
) -> QueryResult<'tcx> {
1717
let tcx = self.tcx();
18-
let opaque_ty = goal.predicate.projection_ty;
18+
let opaque_ty = goal.predicate.alias;
1919
let expected = goal.predicate.term.ty().expect("no such thing as an opaque const");
2020

2121
match (goal.param_env.reveal(), self.solver_mode()) {

compiler/rustc_trait_selection/src/solve/project_goals/weak_types.rs renamed to compiler/rustc_trait_selection/src/solve/normalizes_to/weak_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ use super::EvalCtxt;
1111
impl<'tcx> EvalCtxt<'_, 'tcx> {
1212
pub(super) fn normalize_weak_type(
1313
&mut self,
14-
goal: Goal<'tcx, ty::ProjectionPredicate<'tcx>>,
14+
goal: Goal<'tcx, ty::NormalizesTo<'tcx>>,
1515
) -> QueryResult<'tcx> {
1616
let tcx = self.tcx();
17-
let weak_ty = goal.predicate.projection_ty;
17+
let weak_ty = goal.predicate.alias;
1818
let expected = goal.predicate.term.ty().expect("no such thing as a const alias");
1919

2020
let actual = tcx.type_of(weak_ty.def_id).instantiate(tcx, weak_ty.args);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use super::EvalCtxt;
2+
use rustc_middle::traits::solve::{Certainty, Goal, QueryResult};
3+
use rustc_middle::ty::{self, ProjectionPredicate};
4+
5+
impl<'tcx> EvalCtxt<'_, 'tcx> {
6+
#[instrument(level = "debug", skip(self), ret)]
7+
pub(super) fn compute_projection_goal(
8+
&mut self,
9+
goal: Goal<'tcx, ProjectionPredicate<'tcx>>,
10+
) -> QueryResult<'tcx> {
11+
match goal.predicate.term.unpack() {
12+
ty::TermKind::Ty(term) => {
13+
let alias = goal.predicate.projection_ty.to_ty(self.tcx());
14+
self.eq(goal.param_env, alias, term)?;
15+
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
16+
}
17+
// FIXME(associated_const_equality): actually do something here.
18+
ty::TermKind::Const(_) => {
19+
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
20+
}
21+
}
22+
}
23+
}

compiler/rustc_trait_selection/src/traits/structural_normalize.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ impl<'tcx> StructurallyNormalizeExt<'tcx> for At<'_, 'tcx> {
2525
// FIXME(-Ztrait-solver=next): correctly handle
2626
// overflow here.
2727
for _ in 0..256 {
28-
let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, projection_ty) = *ty.kind()
29-
else {
28+
let ty::Alias(ty::Projection | ty::Inherent | ty::Weak, alias) = *ty.kind() else {
3029
break;
3130
};
3231

@@ -38,10 +37,7 @@ impl<'tcx> StructurallyNormalizeExt<'tcx> for At<'_, 'tcx> {
3837
self.infcx.tcx,
3938
self.cause.clone(),
4039
self.param_env,
41-
ty::Binder::dummy(ty::ProjectionPredicate {
42-
projection_ty,
43-
term: new_infer_ty.into(),
44-
}),
40+
ty::NormalizesTo { alias, term: new_infer_ty.into() },
4541
);
4642
if self.infcx.predicate_may_hold(&obligation) {
4743
fulfill_cx.register_predicate_obligation(self.infcx, obligation);

0 commit comments

Comments
 (0)