Skip to content

Commit 306a7ea

Browse files
committed
AliasTy::new instead of tcx method
1 parent 6d7160c commit 306a7ea

File tree

15 files changed

+46
-39
lines changed

15 files changed

+46
-39
lines changed

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
448448

449449
debug!(?args_trait_ref_and_assoc_item);
450450

451-
tcx.mk_alias_ty(assoc_item.def_id, args_trait_ref_and_assoc_item)
451+
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
452452
})
453453
};
454454

compiler/rustc_hir_analysis/src/astconv/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
437437
);
438438

439439
let quiet_projection_ty =
440-
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
440+
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
441441

442442
let term = pred.skip_binder().term;
443443

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
916916
// Type aliases defined in crates that have the
917917
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
918918
// then actually instantiate the where bounds of.
919-
let alias_ty = tcx.mk_alias_ty(did, args);
919+
let alias_ty = ty::AliasTy::new(tcx, did, args);
920920
Ty::new_alias(tcx, ty::Weak, alias_ty)
921921
} else {
922922
tcx.at(span).type_of(did).instantiate(tcx, args)
@@ -1718,7 +1718,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
17181718
.chain(args.into_iter().skip(parent_args.len())),
17191719
);
17201720

1721-
let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, args));
1721+
let ty = Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new(tcx, assoc_item, args));
17221722

17231723
return Ok(Some((ty, assoc_item)));
17241724
}

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2286,7 +2286,7 @@ pub(super) fn check_type_bounds<'tcx>(
22862286
_ => predicates.push(
22872287
ty::Binder::bind_with_vars(
22882288
ty::ProjectionPredicate {
2289-
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args),
2289+
projection_ty: ty::AliasTy::new(tcx, trait_ty.def_id, rebased_args),
22902290
term: normalize_impl_ty.into(),
22912291
},
22922292
bound_vars,

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
674674
);
675675

676676
let quiet_projection_ty =
677-
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
677+
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
678678

679679
let term = pred.skip_binder().term;
680680

compiler/rustc_middle/src/ty/context.rs

-10
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,6 @@ impl<'tcx> TyCtxt<'tcx> {
16871687
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(_def_id))
16881688
{
16891689
// If this is an inherent projection.
1690-
16911690
generics.params.len() + 1
16921691
} else {
16931692
generics.count()
@@ -1897,15 +1896,6 @@ impl<'tcx> TyCtxt<'tcx> {
18971896
self.mk_args_from_iter(iter::once(self_ty.into()).chain(rest))
18981897
}
18991898

1900-
pub fn mk_alias_ty(
1901-
self,
1902-
def_id: DefId,
1903-
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
1904-
) -> ty::AliasTy<'tcx> {
1905-
let args = self.check_and_mk_args(def_id, args);
1906-
ty::AliasTy { def_id, args, _use_mk_alias_ty_instead: () }
1907-
}
1908-
19091899
pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
19101900
where
19111901
I: Iterator<Item = T>,

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ impl<'tcx> Term<'tcx> {
10231023
_ => None,
10241024
},
10251025
TermKind::Const(ct) => match ct.kind() {
1026-
ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def, uv.args)),
1026+
ConstKind::Unevaluated(uv) => Some(AliasTy::new(tcx, uv.def, uv.args)),
10271027
_ => None,
10281028
},
10291029
}

compiler/rustc_middle/src/ty/relate.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
288288
}
289289
def => bug!("unknown alias DefKind: {def:?}"),
290290
};
291-
Ok(relation.tcx().mk_alias_ty(a.def_id, args))
291+
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
292292
}
293293
}
294294
}

compiler/rustc_middle/src/ty/sty.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -1213,11 +1213,20 @@ pub struct AliasTy<'tcx> {
12131213
pub def_id: DefId,
12141214

12151215
/// This field exists to prevent the creation of `AliasTy` without using
1216-
/// [TyCtxt::mk_alias_ty].
1217-
pub(super) _use_mk_alias_ty_instead: (),
1216+
/// [AliasTy::new].
1217+
_use_alias_ty_new_instead: (),
12181218
}
12191219

12201220
impl<'tcx> AliasTy<'tcx> {
1221+
pub fn new(
1222+
tcx: TyCtxt<'tcx>,
1223+
def_id: DefId,
1224+
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
1225+
) -> ty::AliasTy<'tcx> {
1226+
let args = tcx.check_and_mk_args(def_id, args);
1227+
ty::AliasTy { def_id, args, _use_alias_ty_new_instead: () }
1228+
}
1229+
12211230
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
12221231
match tcx.def_kind(self.def_id) {
12231232
DefKind::AssocTy
@@ -1245,7 +1254,7 @@ impl<'tcx> AliasTy<'tcx> {
12451254
}
12461255

12471256
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
1248-
tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
1257+
AliasTy::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
12491258
}
12501259
}
12511260

@@ -1667,8 +1676,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
16671676
debug_assert!(!self_ty.has_escaping_bound_vars());
16681677

16691678
ty::ProjectionPredicate {
1670-
projection_ty: tcx
1671-
.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args)),
1679+
projection_ty: AliasTy::new(
1680+
tcx,
1681+
self.def_id,
1682+
[self_ty.into()].into_iter().chain(self.args),
1683+
),
16721684
term: self.term,
16731685
}
16741686
}
@@ -1971,7 +1983,7 @@ impl<'tcx> Ty<'tcx> {
19711983

19721984
#[inline]
19731985
pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
1974-
Ty::new_alias(tcx, ty::Opaque, tcx.mk_alias_ty(def_id, args))
1986+
Ty::new_alias(tcx, ty::Opaque, AliasTy::new(tcx, def_id, args))
19751987
}
19761988

19771989
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
@@ -2135,7 +2147,7 @@ impl<'tcx> Ty<'tcx> {
21352147
item_def_id: DefId,
21362148
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
21372149
) -> Ty<'tcx> {
2138-
Ty::new_alias(tcx, ty::Projection, tcx.mk_alias_ty(item_def_id, args))
2150+
Ty::new_alias(tcx, ty::Projection, AliasTy::new(tcx, item_def_id, args))
21392151
}
21402152

21412153
#[inline]

compiler/rustc_trait_selection/src/solve/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
129129
self.at.cause.clone(),
130130
self.at.param_env,
131131
ty::ProjectionPredicate {
132-
projection_ty: tcx.mk_alias_ty(uv.def, uv.args),
132+
projection_ty: AliasTy::new(tcx, uv.def, uv.args),
133133
term: new_infer_ct.into(),
134134
},
135135
);

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

+11-6
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
352352

353353
let pred = tupled_inputs_and_output
354354
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
355-
projection_ty: tcx
356-
.mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]),
355+
projection_ty: ty::AliasTy::new(
356+
tcx,
357+
goal.predicate.def_id(),
358+
[goal.predicate.self_ty(), inputs],
359+
),
357360
term: output.into(),
358361
})
359362
.to_predicate(tcx);
@@ -472,7 +475,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
472475
ecx,
473476
goal,
474477
ty::ProjectionPredicate {
475-
projection_ty: ecx.tcx().mk_alias_ty(goal.predicate.def_id(), [self_ty]),
478+
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
476479
term,
477480
}
478481
.to_predicate(tcx),
@@ -512,9 +515,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
512515
ecx,
513516
goal,
514517
ty::ProjectionPredicate {
515-
projection_ty: ecx
516-
.tcx()
517-
.mk_alias_ty(goal.predicate.def_id(), [self_ty, generator.resume_ty()]),
518+
projection_ty: ty::AliasTy::new(
519+
ecx.tcx(),
520+
goal.predicate.def_id(),
521+
[self_ty, generator.resume_ty()],
522+
),
518523
term,
519524
}
520525
.to_predicate(tcx),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -3937,7 +3937,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
39373937
// This corresponds to `<ExprTy as Iterator>::Item = _`.
39383938
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
39393939
ty::ClauseKind::Projection(ty::ProjectionPredicate {
3940-
projection_ty: self.tcx.mk_alias_ty(proj.def_id, args),
3940+
projection_ty: ty::AliasTy::new(self.tcx, proj.def_id, args),
39413941
term: ty_var.into(),
39423942
}),
39433943
));

compiler/rustc_trait_selection/src/traits/project.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
20722072
};
20732073

20742074
ty::ProjectionPredicate {
2075-
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
2075+
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
20762076
term: ty.into(),
20772077
}
20782078
});
@@ -2116,7 +2116,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
21162116
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
21172117

21182118
ty::ProjectionPredicate {
2119-
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
2119+
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
21202120
term: return_ty.into(),
21212121
}
21222122
});
@@ -2172,7 +2172,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
21722172
};
21732173

21742174
let predicate =
2175-
ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, args), term };
2175+
ty::ProjectionPredicate { projection_ty: ty::AliasTy::new(tcx, item_def_id, args), term };
21762176

21772177
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
21782178
.with_addl_obligations(obligations)
@@ -2245,7 +2245,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
22452245
flag,
22462246
)
22472247
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
2248-
projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.args),
2248+
projection_ty: ty::AliasTy::new(tcx, fn_once_output_def_id, trait_ref.args),
22492249
term: ret_type.into(),
22502250
});
22512251

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
704704
let ty = traits::normalize_projection_type(
705705
self,
706706
param_env,
707-
tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.args),
707+
ty::AliasTy::new(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
708708
cause.clone(),
709709
0,
710710
// We're *intentionally* throwing these away,

src/tools/clippy/clippy_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ pub fn make_projection<'tcx>(
11331133
#[cfg(debug_assertions)]
11341134
assert_generic_args_match(tcx, assoc_item.def_id, args);
11351135

1136-
Some(tcx.mk_alias_ty(assoc_item.def_id, args))
1136+
Some(ty::AliasTy::new(tcx, assoc_item.def_id, args))
11371137
}
11381138
helper(
11391139
tcx,

0 commit comments

Comments
 (0)