Skip to content

Commit 8c70e52

Browse files
committed
Auto merge of rust-lang#113377 - BoxyUwU:move_ty_ctors_to_ty, r=compiler-errors
Move `TyCtxt::mk_x` to `Ty::new_x` where applicable Part of rust-lang/compiler-team#616 turns out there's a lot of places we construct `Ty` this is a ridiculously huge PR :S r? `@oli-obk`
2 parents 8aca068 + cbe4682 commit 8c70e52

11 files changed

+18
-17
lines changed

clippy_lints/src/bool_assert_comparison.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn is_impl_not_trait_with_bool_out<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -
6161
)
6262
})
6363
.map_or(false, |assoc_item| {
64-
let proj = cx.tcx.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(ty, []));
64+
let proj = Ty::new_projection(cx.tcx,assoc_item.def_id, cx.tcx.mk_substs_trait(ty, []));
6565
let nty = cx.tcx.normalize_erasing_regions(cx.param_env, proj);
6666

6767
nty.is_bool()

clippy_lints/src/loops/explicit_iter_loop.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn is_ref_iterable<'tcx>(
149149
let self_ty = if mutbl.is_mut() {
150150
self_ty
151151
} else {
152-
cx.tcx.mk_ref(region, TypeAndMut { ty, mutbl })
152+
Ty::new_ref(cx.tcx,region, TypeAndMut { ty, mutbl })
153153
};
154154
if implements_trait(cx, self_ty, trait_id, &[])
155155
&& let Some(ty) =
@@ -164,7 +164,7 @@ fn is_ref_iterable<'tcx>(
164164
&& !self_ty.is_ref()
165165
{
166166
// Attempt to borrow
167-
let self_ty = cx.tcx.mk_ref(cx.tcx.lifetimes.re_erased, TypeAndMut {
167+
let self_ty = Ty::new_ref(cx.tcx,cx.tcx.lifetimes.re_erased, TypeAndMut {
168168
ty: self_ty,
169169
mutbl,
170170
});

clippy_lints/src/methods/needless_collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn iterates_same_ty<'tcx>(cx: &LateContext<'tcx>, iter_ty: Ty<'tcx>, collect_ty:
215215
&& let Some(into_iter_item_proj) = make_projection(cx.tcx, into_iter_trait, item, [collect_ty])
216216
&& let Ok(into_iter_item_ty) = cx.tcx.try_normalize_erasing_regions(
217217
cx.param_env,
218-
cx.tcx.mk_projection(into_iter_item_proj.def_id, into_iter_item_proj.substs)
218+
Ty::new_projection(cx.tcx,into_iter_item_proj.def_id, into_iter_item_proj.substs)
219219
)
220220
{
221221
iter_item_ty == into_iter_item_ty
@@ -238,7 +238,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) -
238238
.associated_items(iter_trait)
239239
.find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait)
240240
&& let substs = cx.tcx.mk_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))])
241-
&& let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs)
241+
&& let proj_ty = Ty::new_projection(cx.tcx,iter_item.def_id, substs)
242242
&& let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty)
243243
{
244244
item_ty == EarlyBinder::bind(search_ty).subst(cx.tcx, cx.typeck_results().node_substs(call_id))

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ fn check_other_call_arg<'tcx>(
270270
if let Some((n_refs, receiver_ty)) = if n_refs > 0 || is_copy(cx, receiver_ty) {
271271
Some((n_refs, receiver_ty))
272272
} else if trait_predicate.def_id() != deref_trait_id {
273-
Some((1, cx.tcx.mk_ref(
273+
Some((1, Ty::new_ref(cx.tcx,
274274
cx.tcx.lifetimes.re_erased,
275275
ty::TypeAndMut {
276276
ty: receiver_ty,

clippy_lints/src/needless_pass_by_value.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_hir_typeck::expr_use_visitor as euv;
1717
use rustc_infer::infer::TyCtxtInferExt;
1818
use rustc_lint::{LateContext, LateLintPass};
1919
use rustc_middle::mir::FakeReadCause;
20-
use rustc_middle::ty::{self, TypeVisitableExt};
20+
use rustc_middle::ty::{self, TypeVisitableExt, Ty};
2121
use rustc_session::{declare_lint_pass, declare_tool_lint};
2222
use rustc_span::def_id::LocalDefId;
2323
use rustc_span::symbol::kw;
@@ -168,7 +168,7 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
168168
(
169169
preds.iter().any(|t| cx.tcx.is_diagnostic_item(sym::Borrow, t.def_id())),
170170
!preds.is_empty() && {
171-
let ty_empty_region = cx.tcx.mk_imm_ref(cx.tcx.lifetimes.re_erased, ty);
171+
let ty_empty_region = Ty::new_imm_ref(cx.tcx,cx.tcx.lifetimes.re_erased, ty);
172172
preds.iter().all(|t| {
173173
let ty_params = t.trait_ref.substs.iter().skip(1).collect::<Vec<_>>();
174174
implements_trait(cx, ty_empty_region, t.def_id(), &ty_params)

clippy_lints/src/ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ impl<'tcx> DerefTy<'tcx> {
389389
fn ty(&self, cx: &LateContext<'tcx>) -> Ty<'tcx> {
390390
match *self {
391391
Self::Str => cx.tcx.types.str_,
392-
Self::Path => cx.tcx.mk_adt(
392+
Self::Path => Ty::new_adt(cx.tcx,
393393
cx.tcx.adt_def(cx.tcx.get_diagnostic_item(sym::Path).unwrap()),
394394
List::empty(),
395395
),
396-
Self::Slice(_, ty) => cx.tcx.mk_slice(ty),
396+
Self::Slice(_, ty) => Ty::new_slice(cx.tcx,ty),
397397
}
398398
}
399399

clippy_lints/src/redundant_slicing.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_ast::util::parser::PREC_PREFIX;
77
use rustc_errors::Applicability;
88
use rustc_hir::{BorrowKind, Expr, ExprKind, LangItem, Mutability};
99
use rustc_lint::{LateContext, LateLintPass, Lint};
10+
use rustc_middle::ty::Ty;
1011
use rustc_middle::ty::adjustment::{Adjust, AutoBorrow, AutoBorrowMutability};
1112
use rustc_middle::ty::subst::GenericArg;
1213
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -134,7 +135,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing {
134135
} else if let Some(target_id) = cx.tcx.lang_items().deref_target() {
135136
if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions(
136137
cx.param_env,
137-
cx.tcx.mk_projection(target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])),
138+
Ty::new_projection(cx.tcx,target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])),
138139
) {
139140
if deref_ty == expr_ty {
140141
let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0;

clippy_lints/src/transmute/transmute_ptr_to_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(super) fn check<'tcx>(
2424
"transmute from a pointer to a pointer",
2525
|diag| {
2626
if let Some(arg) = sugg::Sugg::hir_opt(cx, arg) {
27-
let sugg = arg.as_ty(cx.tcx.mk_ptr(*to_ty));
27+
let sugg = arg.as_ty(Ty::new_ptr(cx.tcx,*to_ty));
2828
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);
2929
}
3030
},

clippy_lints/src/transmute/transmute_ref_to_ref.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub(super) fn check<'tcx>(
6464
};
6565
let ty_to_and_mut = ty::TypeAndMut { ty: *ty_to, mutbl: *to_mutbl };
6666
let sugg_paren = arg
67-
.as_ty(cx.tcx.mk_ptr(ty_from_and_mut))
68-
.as_ty(cx.tcx.mk_ptr(ty_to_and_mut));
67+
.as_ty(Ty::new_ptr(cx.tcx,ty_from_and_mut))
68+
.as_ty(Ty::new_ptr(cx.tcx,ty_to_and_mut));
6969
let sugg = if *to_mutbl == Mutability::Mut {
7070
sugg_paren.mut_addr_deref()
7171
} else {

clippy_lints/src/transmute/useless_transmute.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub(super) fn check<'tcx>(
4343
let sugg = if *ptr_ty == rty_and_mut {
4444
arg.as_ty(to_ty)
4545
} else {
46-
arg.as_ty(cx.tcx.mk_ptr(rty_and_mut)).as_ty(to_ty)
46+
arg.as_ty(Ty::new_ptr(cx.tcx,rty_and_mut)).as_ty(to_ty)
4747
};
4848

4949
diag.span_suggestion(e.span, "try", sugg, Applicability::Unspecified);

clippy_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ pub fn make_normalized_projection<'tcx>(
11241124
);
11251125
return None;
11261126
}
1127-
match tcx.try_normalize_erasing_regions(param_env, tcx.mk_projection(ty.def_id, ty.substs)) {
1127+
match tcx.try_normalize_erasing_regions(param_env, Ty::new_projection(tcx,ty.def_id, ty.substs)) {
11281128
Ok(ty) => Some(ty),
11291129
Err(e) => {
11301130
debug_assert!(false, "failed to normalize type `{ty}`: {e:#?}");
@@ -1207,7 +1207,7 @@ pub fn make_normalized_projection_with_regions<'tcx>(
12071207
.infer_ctxt()
12081208
.build()
12091209
.at(&cause, param_env)
1210-
.query_normalize(tcx.mk_projection(ty.def_id, ty.substs))
1210+
.query_normalize(Ty::new_projection(tcx,ty.def_id, ty.substs))
12111211
{
12121212
Ok(ty) => Some(ty.value),
12131213
Err(e) => {

0 commit comments

Comments
 (0)