Skip to content

Commit 7e65067

Browse files
IdentitySubsts::identity_for_item takes Into<DefId>
1 parent 979ef59 commit 7e65067

File tree

14 files changed

+27
-28
lines changed

14 files changed

+27
-28
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ impl<'tcx> InferCtxtExt<'tcx> for InferCtxt<'tcx> {
284284
// hidden type is well formed even without those bounds.
285285
let predicate = ty::Binder::dummy(ty::PredicateKind::WellFormed(definition_ty.into()));
286286

287-
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id.to_def_id());
287+
let id_substs = InternalSubsts::identity_for_item(self.tcx, def_id);
288288

289289
// Require that the hidden type actually fulfills all the bounds of the opaque type, even without
290290
// the bounds that the function supplies.

compiler/rustc_hir_analysis/src/check/check.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ fn check_opaque(tcx: TyCtxt<'_>, id: hir::ItemId) {
211211
return;
212212
}
213213

214-
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id.to_def_id());
214+
let substs = InternalSubsts::identity_for_item(tcx, item.owner_id);
215215
let span = tcx.def_span(item.owner_id.def_id);
216216

217217
if !tcx.features().impl_trait_projections {
@@ -304,7 +304,7 @@ pub(super) fn check_opaque_for_inheriting_lifetimes(
304304
..
305305
}) = item.kind
306306
{
307-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
307+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
308308
let opaque_identity_ty = if in_trait {
309309
tcx.mk_projection(def_id.to_def_id(), substs)
310310
} else {
@@ -535,7 +535,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
535535
}
536536
ty::AssocKind::Type if assoc_item.defaultness(tcx).has_value() => {
537537
let trait_substs =
538-
InternalSubsts::identity_for_item(tcx, id.owner_id.to_def_id());
538+
InternalSubsts::identity_for_item(tcx, id.owner_id);
539539
let _: Result<_, rustc_errors::ErrorGuaranteed> = check_type_bounds(
540540
tcx,
541541
assoc_item,

compiler/rustc_hir_analysis/src/collect/item_bounds.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ fn associated_type_bounds<'tcx>(
2222
) -> &'tcx [(ty::Predicate<'tcx>, Span)] {
2323
let item_ty = tcx.mk_projection(
2424
assoc_item_def_id.to_def_id(),
25-
InternalSubsts::identity_for_item(tcx, assoc_item_def_id.to_def_id()),
25+
InternalSubsts::identity_for_item(tcx, assoc_item_def_id),
2626
);
2727

2828
let icx = ItemCtxt::new(tcx, assoc_item_def_id);
@@ -92,7 +92,7 @@ pub(super) fn explicit_item_bounds(
9292
opaque_ty.bounds,
9393
tcx.mk_projection(
9494
def_id.to_def_id(),
95-
ty::InternalSubsts::identity_for_item(tcx, def_id.to_def_id()),
95+
ty::InternalSubsts::identity_for_item(tcx, def_id),
9696
),
9797
item.span,
9898
);
@@ -114,7 +114,7 @@ pub(super) fn explicit_item_bounds(
114114
span,
115115
..
116116
}) => {
117-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
117+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
118118
let item_ty = if *in_trait && !tcx.lower_impl_trait_in_trait_to_assoc_ty() {
119119
tcx.mk_projection(def_id.to_def_id(), substs)
120120
} else {

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ pub(super) fn explicit_predicates_of<'tcx>(
405405
// Remove bounds on associated types from the predicates, they will be
406406
// returned by `explicit_item_bounds`.
407407
let predicates_and_bounds = tcx.trait_explicit_predicates_and_bounds(def_id);
408-
let trait_identity_substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
408+
let trait_identity_substs = InternalSubsts::identity_for_item(tcx, def_id);
409409

410410
let is_assoc_item_ty = |ty: Ty<'tcx>| {
411411
// For a predicate from a where clause to become a bound on an

compiler/rustc_hir_analysis/src/collect/type_of.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
274274
let output = match tcx.hir().get(hir_id) {
275275
Node::TraitItem(item) => match item.kind {
276276
TraitItemKind::Fn(..) => {
277-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
277+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
278278
tcx.mk_fn_def(def_id.to_def_id(), substs)
279279
}
280280
TraitItemKind::Const(ty, body_id) => body_id
@@ -294,7 +294,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
294294

295295
Node::ImplItem(item) => match item.kind {
296296
ImplItemKind::Fn(..) => {
297-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
297+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
298298
tcx.mk_fn_def(def_id.to_def_id(), substs)
299299
}
300300
ImplItemKind::Const(ty, body_id) => {
@@ -350,12 +350,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
350350
_ => icx.to_ty(*self_ty),
351351
},
352352
ItemKind::Fn(..) => {
353-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
353+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
354354
tcx.mk_fn_def(def_id.to_def_id(), substs)
355355
}
356356
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
357357
let def = tcx.adt_def(def_id);
358-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
358+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
359359
tcx.mk_adt(def, substs)
360360
}
361361
ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::TyAlias, .. }) => {
@@ -395,7 +395,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
395395

396396
Node::ForeignItem(foreign_item) => match foreign_item.kind {
397397
ForeignItemKind::Fn(..) => {
398-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
398+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
399399
tcx.mk_fn_def(def_id.to_def_id(), substs)
400400
}
401401
ForeignItemKind::Static(t, _) => icx.to_ty(t),
@@ -407,7 +407,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
407407
tcx.type_of(tcx.hir().get_parent_item(hir_id)).subst_identity()
408408
}
409409
VariantData::Tuple(..) => {
410-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
410+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
411411
tcx.mk_fn_def(def_id.to_def_id(), substs)
412412
}
413413
},
@@ -440,7 +440,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<Ty
440440
Node::Expr(Expr { kind: ExprKind::ConstBlock(anon_const), .. })
441441
if anon_const.hir_id == hir_id =>
442442
{
443-
let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
443+
let substs = InternalSubsts::identity_for_item(tcx, def_id);
444444
substs.as_inline_const().ty()
445445
}
446446

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn get_impl_substs(
168168
let assumed_wf_types =
169169
ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id);
170170

171-
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id.to_def_id());
171+
let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id);
172172
let impl2_substs =
173173
translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node);
174174

compiler/rustc_hir_analysis/src/variance/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
152152

153153
let mut collector =
154154
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
155-
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id.to_def_id());
155+
let id_substs = ty::InternalSubsts::identity_for_item(tcx, item_def_id);
156156
for pred in tcx.bound_explicit_item_bounds(item_def_id.to_def_id()).transpose_iter() {
157157
let pred = pred.map_bound(|(pred, _)| *pred).subst(tcx, id_substs);
158158
debug!(?pred);

compiler/rustc_infer/src/infer/error_reporting/note.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
306306
// Replace the explicit self type with `Self` for better suggestion rendering
307307
.with_self_ty(self.tcx, self.tcx.mk_ty_param(0, kw::SelfUpper))
308308
.substs;
309-
let trait_item_substs =
310-
ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id.to_def_id())
311-
.rebase_onto(self.tcx, impl_def_id, trait_substs);
309+
let trait_item_substs = ty::InternalSubsts::identity_for_item(self.tcx, impl_item_def_id)
310+
.rebase_onto(self.tcx, impl_def_id, trait_substs);
312311

313312
let Ok(trait_predicates) = self
314313
.tcx

compiler/rustc_middle/src/mir/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2525,7 +2525,7 @@ impl<'tcx> ConstantKind<'tcx> {
25252525
let parent_substs = if let Some(parent_hir_id) = tcx.hir().opt_parent_id(hir_id)
25262526
&& let Some(parent_did) = parent_hir_id.as_owner()
25272527
{
2528-
InternalSubsts::identity_for_item(tcx, parent_did.to_def_id())
2528+
InternalSubsts::identity_for_item(tcx, parent_did)
25292529
} else {
25302530
List::empty()
25312531
};
@@ -2554,7 +2554,7 @@ impl<'tcx> ConstantKind<'tcx> {
25542554
Self::Unevaluated(
25552555
UnevaluatedConst {
25562556
def: def.to_global(),
2557-
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
2557+
substs: InternalSubsts::identity_for_item(tcx, def.did),
25582558
promoted: None,
25592559
},
25602560
ty,

compiler/rustc_middle/src/ty/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'tcx> Const<'tcx> {
8383
None => tcx.mk_const(
8484
ty::UnevaluatedConst {
8585
def: def.to_global(),
86-
substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()),
86+
substs: InternalSubsts::identity_for_item(tcx, def.did),
8787
},
8888
ty,
8989
),

compiler/rustc_middle/src/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ impl<'tcx> OpaqueHiddenType<'tcx> {
13851385
// lifetimes with 'static and remapping only those used in the
13861386
// `impl Trait` return type, resulting in the parameters
13871387
// shifting.
1388-
let id_substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id());
1388+
let id_substs = InternalSubsts::identity_for_item(tcx, def_id);
13891389
debug!(?id_substs);
13901390

13911391
// This zip may have several times the same lifetime in `substs` paired with a different

compiler/rustc_middle/src/ty/subst.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ impl<'tcx> InternalSubsts<'tcx> {
302302
}
303303

304304
/// Creates an `InternalSubsts` that maps each generic parameter to itself.
305-
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> SubstsRef<'tcx> {
306-
Self::for_item(tcx, def_id, |param, _| tcx.mk_param_from_def(param))
305+
pub fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: impl Into<DefId>) -> SubstsRef<'tcx> {
306+
Self::for_item(tcx, def_id.into(), |param, _| tcx.mk_param_from_def(param))
307307
}
308308

309309
/// Creates an `InternalSubsts` for generic parameter definitions,

compiler/rustc_mir_build/src/lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub(crate) fn check<'tcx>(tcx: TyCtxt<'tcx>, body: &Body<'tcx>) {
1818
let trait_substs = match tcx.trait_of_item(def_id.to_def_id()) {
1919
Some(trait_def_id) => {
2020
let trait_substs_count = tcx.generics_of(trait_def_id).count();
21-
&InternalSubsts::identity_for_item(tcx, def_id.to_def_id())[..trait_substs_count]
21+
&InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count]
2222
}
2323
_ => &[],
2424
};

compiler/rustc_ty_utils/src/assoc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ fn associated_type_for_impl_trait_in_trait(
296296
// Copy type_of of the opaque.
297297
trait_assoc_ty.type_of(ty::EarlyBinder(tcx.mk_opaque(
298298
opaque_ty_def_id.to_def_id(),
299-
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id.to_def_id()),
299+
InternalSubsts::identity_for_item(tcx, opaque_ty_def_id),
300300
)));
301301

302302
trait_assoc_ty.is_type_alias_impl_trait(false);

0 commit comments

Comments
 (0)