Skip to content

Commit 3fd3219

Browse files
More nits
1 parent 73b1ebd commit 3fd3219

File tree

7 files changed

+52
-39
lines changed

7 files changed

+52
-39
lines changed

Diff for: compiler/rustc_middle/src/ty/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,14 @@ impl<'tcx> Term<'tcx> {
630630
}
631631

632632
/// This function returns the inner `AliasTy` for a `ty::Alias` or `ConstKind::Unevaluated`.
633-
pub fn to_alias_term(&self, tcx: TyCtxt<'tcx>) -> Option<AliasTerm<'tcx>> {
633+
pub fn to_alias_term(self) -> Option<AliasTerm<'tcx>> {
634634
match self.unpack() {
635635
TermKind::Ty(ty) => match *ty.kind() {
636636
ty::Alias(_kind, alias_ty) => Some(alias_ty.into()),
637637
_ => None,
638638
},
639639
TermKind::Const(ct) => match ct.kind() {
640-
ConstKind::Unevaluated(uv) => Some(AliasTerm::new(tcx, uv.def, uv.args)),
640+
ConstKind::Unevaluated(uv) => Some(uv.into()),
641641
_ => None,
642642
},
643643
}

Diff for: compiler/rustc_middle/src/ty/print/pretty.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -3211,21 +3211,23 @@ define_print_and_forward_display! {
32113211
}
32123212

32133213
ty::AliasTerm<'tcx> {
3214-
// TODO: Use `AliasTerm::kind`
3215-
if let DefKind::Impl { of_trait: false } = cx.tcx().def_kind(cx.tcx().parent(self.def_id)) {
3216-
p!(pretty_print_inherent_projection(*self))
3217-
} else {
3218-
// If we're printing verbosely, or don't want to invoke queries
3219-
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
3220-
// This is likely what you want if you're debugging the compiler anyways.
3221-
if !(cx.should_print_verbose() || with_reduced_queries())
3222-
&& cx.tcx().is_impl_trait_in_trait(self.def_id)
3223-
{
3224-
return cx.pretty_print_opaque_impl_type(self.def_id, self.args);
3225-
} else {
3226-
p!(print_def_path(self.def_id, self.args));
3214+
match self.kind(cx.tcx()) {
3215+
ty::AliasTermKind::InherentTy => p!(pretty_print_inherent_projection(*self)),
3216+
ty::AliasTermKind::ProjectionTy
3217+
| ty::AliasTermKind::WeakTy
3218+
| ty::AliasTermKind::OpaqueTy
3219+
| ty::AliasTermKind::UnevaluatedConst => {
3220+
// If we're printing verbosely, or don't want to invoke queries
3221+
// (`is_impl_trait_in_trait`), then fall back to printing the def path.
3222+
// This is likely what you want if you're debugging the compiler anyways.
3223+
if !(cx.should_print_verbose() || with_reduced_queries())
3224+
&& cx.tcx().is_impl_trait_in_trait(self.def_id)
3225+
{
3226+
return cx.pretty_print_opaque_impl_type(self.def_id, self.args);
3227+
} else {
3228+
p!(print_def_path(self.def_id, self.args));
3229+
}
32273230
}
3228-
32293231
}
32303232
}
32313233

Diff for: compiler/rustc_middle/src/ty/sty.rs

+24-11
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc_span::symbol::{sym, Symbol};
2222
use rustc_span::{Span, DUMMY_SP};
2323
use rustc_target::abi::{FieldIdx, VariantIdx, FIRST_VARIANT};
2424
use rustc_target::spec::abi::{self, Abi};
25-
use std::assert_matches::debug_assert_matches;
25+
use std::assert_matches::{assert_matches, debug_assert_matches};
2626
use std::borrow::Cow;
2727
use std::iter;
2828
use std::ops::{ControlFlow, Deref, Range};
@@ -1195,24 +1195,31 @@ impl<'tcx> AliasTerm<'tcx> {
11951195
tcx: TyCtxt<'tcx>,
11961196
def_id: DefId,
11971197
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
1198-
) -> ty::AliasTerm<'tcx> {
1198+
) -> AliasTerm<'tcx> {
11991199
let args = tcx.check_and_mk_args(def_id, args);
1200-
ty::AliasTerm { def_id, args, _use_alias_term_new_instead: () }
1200+
AliasTerm { def_id, args, _use_alias_term_new_instead: () }
12011201
}
12021202

1203-
pub fn expect_ty(self, _interner: TyCtxt<'tcx>) -> AliasTy<'tcx> {
1204-
todo!()
1203+
pub fn expect_ty(self, tcx: TyCtxt<'tcx>) -> AliasTy<'tcx> {
1204+
assert_matches!(
1205+
self.kind(tcx),
1206+
ty::AliasTermKind::ProjectionTy
1207+
| ty::AliasTermKind::OpaqueTy
1208+
| ty::AliasTermKind::WeakTy
1209+
| ty::AliasTermKind::InherentTy
1210+
);
1211+
ty::AliasTy { def_id: self.def_id, args: self.args, _use_alias_ty_new_instead: () }
12051212
}
12061213

12071214
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasTermKind {
12081215
match tcx.def_kind(self.def_id) {
1209-
DefKind::AssocTy
1210-
if let DefKind::Impl { of_trait: false } =
1211-
tcx.def_kind(tcx.parent(self.def_id)) =>
1212-
{
1213-
ty::AliasTermKind::InherentTy
1216+
DefKind::AssocTy => {
1217+
if let DefKind::Impl { of_trait: false } = tcx.def_kind(tcx.parent(self.def_id)) {
1218+
ty::AliasTermKind::InherentTy
1219+
} else {
1220+
ty::AliasTermKind::ProjectionTy
1221+
}
12141222
}
1215-
DefKind::AssocTy => ty::AliasTermKind::ProjectionTy,
12161223
DefKind::OpaqueTy => ty::AliasTermKind::OpaqueTy,
12171224
DefKind::TyAlias => ty::AliasTermKind::WeakTy,
12181225
DefKind::AssocConst | DefKind::AnonConst => ty::AliasTermKind::UnevaluatedConst,
@@ -1312,6 +1319,12 @@ impl<'tcx> From<AliasTy<'tcx>> for AliasTerm<'tcx> {
13121319
}
13131320
}
13141321

1322+
impl<'tcx> From<ty::UnevaluatedConst<'tcx>> for AliasTerm<'tcx> {
1323+
fn from(ct: ty::UnevaluatedConst<'tcx>) -> Self {
1324+
AliasTerm { args: ct.args, def_id: ct.def, _use_alias_term_new_instead: () }
1325+
}
1326+
}
1327+
13151328
/// Represents the projection of an associated type.
13161329
///
13171330
/// * For a projection, this would be `<Ty as Trait<...>>::N<...>`.

Diff for: compiler/rustc_trait_selection/src/solve/alias_relate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
2929
let Goal { param_env, predicate: (lhs, rhs, direction) } = goal;
3030

3131
// Structurally normalize the lhs.
32-
let lhs = if let Some(alias) = lhs.to_alias_term(self.tcx()) {
32+
let lhs = if let Some(alias) = lhs.to_alias_term() {
3333
let term = self.next_term_infer_of_kind(lhs);
3434
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
3535
term
@@ -38,7 +38,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
3838
};
3939

4040
// Structurally normalize the rhs.
41-
let rhs = if let Some(alias) = rhs.to_alias_term(self.tcx()) {
41+
let rhs = if let Some(alias) = rhs.to_alias_term() {
4242
let term = self.next_term_infer_of_kind(rhs);
4343
self.add_normalizes_to_goal(goal.with(tcx, ty::NormalizesTo { alias, term }));
4444
term
@@ -56,7 +56,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
5656
ty::AliasRelationDirection::Equate => ty::Variance::Invariant,
5757
ty::AliasRelationDirection::Subtype => ty::Variance::Covariant,
5858
};
59-
match (lhs.to_alias_term(tcx), rhs.to_alias_term(tcx)) {
59+
match (lhs.to_alias_term(), rhs.to_alias_term()) {
6060
(None, None) => {
6161
self.relate(param_env, lhs, variance, rhs)?;
6262
self.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)

Diff for: compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -739,8 +739,11 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ReplaceProjectionWith<'_, 'tcx> {
739739
// FIXME: Technically this equate could be fallible...
740740
self.nested.extend(
741741
self.ecx
742-
// TODO: AliasTerm::expect_ty?
743-
.eq_and_get_goals(self.param_env, alias_ty.into(), proj.projection_term)
742+
.eq_and_get_goals(
743+
self.param_env,
744+
alias_ty,
745+
proj.projection_term.expect_ty(self.ecx.tcx()),
746+
)
744747
.expect("expected to be able to unify goal projection with dyn's projection"),
745748
);
746749
proj.term.ty().unwrap()

Diff for: compiler/rustc_trait_selection/src/solve/normalize.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
108108
let recursion_limit = tcx.recursion_limit();
109109
if !recursion_limit.value_within_limit(self.depth) {
110110
self.at.infcx.err_ctxt().report_overflow_error(
111-
// TODO: uv.into()
112-
OverflowCause::DeeplyNormalize(ty::AliasTerm::new(tcx, uv.def, uv.args)),
111+
OverflowCause::DeeplyNormalize(uv.into()),
113112
self.at.cause.span,
114113
true,
115114
|_| {},
@@ -123,10 +122,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
123122
tcx,
124123
self.at.cause.clone(),
125124
self.at.param_env,
126-
ty::NormalizesTo {
127-
alias: ty::AliasTerm::new(tcx, uv.def, uv.args),
128-
term: new_infer_ct.into(),
129-
},
125+
ty::NormalizesTo { alias: uv.into(), term: new_infer_ct.into() },
130126
);
131127

132128
let result = if infcx.predicate_may_hold(&obligation) {

Diff for: compiler/rustc_trait_selection/src/traits/auto_trait.rs

-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@ impl<'tcx> AutoTraitFinder<'tcx> {
554554

555555
fn is_self_referential_projection(&self, p: ty::PolyProjectionPredicate<'tcx>) -> bool {
556556
if let Some(ty) = p.term().skip_binder().ty() {
557-
// TODO: SUS
558557
matches!(ty.kind(), ty::Alias(ty::Projection, proj) if proj == &p.skip_binder().projection_term.expect_ty(self.tcx))
559558
} else {
560559
false

0 commit comments

Comments
 (0)