Skip to content

Commit e8b6c97

Browse files
committed
fix ty::UnevaluatedConst<I>>->AliasTerm<I> conversion
1 parent 59be02e commit e8b6c97

14 files changed

Lines changed: 43 additions & 37 deletions

File tree

compiler/rustc_infer/src/infer/relate/generalize.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl<'tcx> InferCtxt<'tcx> {
184184

185185
relation.register_predicates([ty::PredicateKind::AliasRelate(lhs, rhs, direction)]);
186186
} else {
187-
let Some(source_alias) = source_term.to_alias_term() else {
187+
let Some(source_alias) = source_term.to_alias_term(self.tcx) else {
188188
bug!("generalized `{source_term:?} to infer, not an alias");
189189
};
190190
match source_alias.kind(self.tcx) {
@@ -756,7 +756,8 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for Generalizer<'_, 'tcx> {
756756
// path), as doing this new No path breaks some GCE things. I expect GCE to be
757757
// ripped out soon so this shouldn't matter soon.
758758
StructurallyRelateAliases::No if !self.cx().features().generic_const_exprs() => {
759-
self.generalize_alias_term(uv.into()).map(|v| v.expect_const())
759+
self.generalize_alias_term(ty::AliasTerm::from_unevaluated_const(self.cx(), uv))
760+
.map(|v| v.expect_const())
760761
}
761762
_ => {
762763
let ty::UnevaluatedConst { def, args } = uv;

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -607,14 +607,14 @@ impl<'tcx> Term<'tcx> {
607607
}
608608
}
609609

610-
pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
610+
pub fn to_alias_term(self, tcx: TyCtxt<'tcx>) -> Option<AliasTerm<'tcx>> {
611611
match self.kind() {
612612
TermKind::Ty(ty) => match *ty.kind() {
613613
ty::Alias(alias_ty) => Some(alias_ty.into()),
614614
_ => None,
615615
},
616616
TermKind::Const(ct) => match ct.kind() {
617-
ConstKind::Unevaluated(uv) => Some(uv.into()),
617+
ConstKind::Unevaluated(uv) => Some(AliasTerm::from_unevaluated_const(tcx, uv)),
618618
_ => None,
619619
},
620620
}

compiler/rustc_next_trait_solver/src/solve/alias_relate.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ where
4141
// `{type error}` if the alias still contains infer vars, so we also
4242
// accept alias-relate goals where one of the terms is an error.
4343
debug_assert!(
44-
lhs.to_alias_term().is_some()
45-
|| rhs.to_alias_term().is_some()
44+
lhs.to_alias_term(self.cx()).is_some()
45+
|| rhs.to_alias_term(self.cx()).is_some()
4646
|| lhs.is_error()
4747
|| rhs.is_error()
4848
);
4949

5050
// Structurally normalize the lhs.
51-
let lhs = if let Some(alias) = lhs.to_alias_term() {
51+
let lhs = if let Some(alias) = lhs.to_alias_term(self.cx()) {
5252
let term = self.next_term_infer_of_kind(lhs);
5353
self.add_goal(
5454
GoalSource::TypeRelating,
@@ -60,7 +60,7 @@ where
6060
};
6161

6262
// Structurally normalize the rhs.
63-
let rhs = if let Some(alias) = rhs.to_alias_term() {
63+
let rhs = if let Some(alias) = rhs.to_alias_term(self.cx()) {
6464
let term = self.next_term_infer_of_kind(rhs);
6565
self.add_goal(
6666
GoalSource::TypeRelating,
@@ -87,7 +87,7 @@ where
8787
ty::AliasRelationDirection::Equate => ty::Invariant,
8888
ty::AliasRelationDirection::Subtype => ty::Covariant,
8989
};
90-
match (lhs.to_alias_term(), rhs.to_alias_term()) {
90+
match (lhs.to_alias_term(self.cx()), rhs.to_alias_term(self.cx())) {
9191
(None, None) => {
9292
self.relate(param_env, lhs, variance, rhs)?;
9393
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ where
344344
param_env: I::ParamEnv,
345345
term: I::Term,
346346
) -> Result<I::Term, NoSolution> {
347-
if let Some(_) = term.to_alias_term() {
347+
if let Some(_) = term.to_alias_term(self.cx()) {
348348
let normalized_term = self.next_term_infer_of_kind(term);
349349
let alias_relate_goal = Goal::new(
350350
self.cx(),

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,7 +1586,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15861586
}
15871587
};
15881588

1589-
if let Some(lhs) = lhs.to_alias_term()
1589+
if let Some(lhs) = lhs.to_alias_term(self.tcx)
15901590
&& let ty::AliasTermKind::ProjectionTy { .. }
15911591
| ty::AliasTermKind::ProjectionConst { .. } = lhs.kind(self.tcx)
15921592
&& let Some((better_type_err, expected_term)) =
@@ -1596,7 +1596,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
15961596
Some((lhs, self.resolve_vars_if_possible(expected_term), rhs)),
15971597
better_type_err,
15981598
)
1599-
} else if let Some(rhs) = rhs.to_alias_term()
1599+
} else if let Some(rhs) = rhs.to_alias_term(self.tcx)
16001600
&& let ty::AliasTermKind::ProjectionTy { .. }
16011601
| ty::AliasTermKind::ProjectionConst { .. } = rhs.kind(self.tcx)
16021602
&& let Some((better_type_err, expected_term)) =

compiler/rustc_trait_selection/src/solve/normalize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ where
107107
let tcx = infcx.tcx;
108108
let recursion_limit = tcx.recursion_limit();
109109
if !recursion_limit.value_within_limit(self.depth) {
110-
let term = alias_term.to_alias_term().unwrap();
110+
let term = alias_term.to_alias_term(tcx).unwrap();
111111

112112
self.at.infcx.err_ctxt().report_overflow_error(
113113
OverflowCause::DeeplyNormalize(term),

compiler/rustc_trait_selection/src/traits/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,8 @@ impl<'a, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'tcx> {
699699
// `generic_const_exprs`
700700
.eq(
701701
DefineOpaqueTypes::Yes,
702-
ty::AliasTerm::from(a),
703-
ty::AliasTerm::from(b),
702+
ty::AliasTerm::from_unevaluated_const(tcx, a),
703+
ty::AliasTerm::from_unevaluated_const(tcx, b),
704704
)
705705
{
706706
return ProcessResult::Changed(mk_pending(

compiler/rustc_trait_selection/src/traits/normalize.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,20 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
469469
// feature gate causes a parse error.
470470
let ct = match tcx.def_kind(uv.def) {
471471
DefKind::AssocConst { .. } => match tcx.def_kind(tcx.parent(uv.def)) {
472-
DefKind::Trait => self.normalize_trait_projection(uv.into()).expect_const(),
473-
DefKind::Impl { of_trait: false } => {
474-
self.normalize_inherent_projection(uv.into()).expect_const()
475-
}
472+
DefKind::Trait => self
473+
.normalize_trait_projection(ty::AliasTerm::from_unevaluated_const(tcx, uv))
474+
.expect_const(),
475+
DefKind::Impl { of_trait: false } => self
476+
.normalize_inherent_projection(ty::AliasTerm::from_unevaluated_const(tcx, uv))
477+
.expect_const(),
476478
kind => unreachable!(
477479
"unexpected `DefKind` for const alias' resolution's parent def: {:?}",
478480
kind
479481
),
480482
},
481-
DefKind::Const { .. } => self.normalize_free_alias(uv.into()).expect_const(),
483+
DefKind::Const { .. } => self
484+
.normalize_free_alias(ty::AliasTerm::from_unevaluated_const(tcx, uv))
485+
.expect_const(),
482486
DefKind::AnonConst => {
483487
let ct = ct.super_fold_with(self);
484488
super::with_replaced_escaping_bound_vars(

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'a, 'tcx> {
285285
constant,
286286
|constant| crate::traits::evaluate_const(&self.infcx, constant, self.param_env),
287287
),
288-
_ => self.try_fold_free_or_assoc(ty::AliasTerm::from(uv))?.expect_const(),
288+
_ => self
289+
.try_fold_free_or_assoc(ty::AliasTerm::from_unevaluated_const(self.cx(), uv))?
290+
.expect_const(),
289291
};
290292
debug!(?constant, ?self.param_env);
291293
constant.try_super_fold_with(self)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,8 +891,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
891891
// `generic_const_exprs`
892892
.eq(
893893
DefineOpaqueTypes::Yes,
894-
ty::AliasTerm::from(a),
895-
ty::AliasTerm::from(b),
894+
ty::AliasTerm::from_unevaluated_const(tcx, a),
895+
ty::AliasTerm::from_unevaluated_const(tcx, b),
896896
)
897897
{
898898
return self.evaluate_predicates_recursively(

0 commit comments

Comments
 (0)