Skip to content

Commit d3fa07c

Browse files
committed
Use LocalDefId directly in more places in wfcheck
1 parent a7c132d commit d3fa07c

File tree

1 file changed

+22
-35
lines changed

1 file changed

+22
-35
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

+22-35
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,23 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
142142
}
143143
}
144144
hir::ItemKind::Fn(ref sig, ..) => {
145-
check_item_fn(tcx, item.hir_id(), item.ident, item.span, sig.decl);
145+
check_item_fn(tcx, item.def_id, item.ident, item.span, sig.decl);
146146
}
147147
hir::ItemKind::Static(ty, ..) => {
148-
check_item_type(tcx, item.hir_id(), ty.span, false);
148+
check_item_type(tcx, item.def_id, ty.span, false);
149149
}
150150
hir::ItemKind::Const(ty, ..) => {
151-
check_item_type(tcx, item.hir_id(), ty.span, false);
151+
check_item_type(tcx, item.def_id, ty.span, false);
152152
}
153153
hir::ItemKind::ForeignMod { items, .. } => {
154154
for it in items.iter() {
155155
let it = tcx.hir().foreign_item(it.id);
156156
match it.kind {
157157
hir::ForeignItemKind::Fn(decl, ..) => {
158-
check_item_fn(tcx, it.hir_id(), it.ident, it.span, decl)
158+
check_item_fn(tcx, it.def_id, it.ident, it.span, decl)
159159
}
160160
hir::ForeignItemKind::Static(ty, ..) => {
161-
check_item_type(tcx, it.hir_id(), ty.span, true)
161+
check_item_type(tcx, it.def_id, ty.span, true)
162162
}
163163
hir::ForeignItemKind::Type => (),
164164
}
@@ -199,7 +199,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
199199
_ => (None, trait_item.span),
200200
};
201201
check_object_unsafe_self_trait_by_name(tcx, trait_item);
202-
check_associated_item(tcx, trait_item.hir_id(), span, method_sig);
202+
check_associated_item(tcx, trait_item.def_id, span, method_sig);
203203

204204
let encl_trait_hir_id = tcx.hir().get_parent_item(hir_id);
205205
let encl_trait = tcx.hir().expect_item(encl_trait_hir_id);
@@ -327,7 +327,7 @@ pub fn check_impl_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
327327
_ => (None, impl_item.span),
328328
};
329329

330-
check_associated_item(tcx, impl_item.hir_id(), span, method_sig);
330+
check_associated_item(tcx, impl_item.def_id, span, method_sig);
331331
}
332332

333333
fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
@@ -437,13 +437,13 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
437437
#[tracing::instrument(level = "debug", skip(tcx, span, sig_if_method))]
438438
fn check_associated_item(
439439
tcx: TyCtxt<'_>,
440-
item_id: hir::HirId,
440+
item_id: LocalDefId,
441441
span: Span,
442442
sig_if_method: Option<&hir::FnSig<'_>>,
443443
) {
444-
let code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id.expect_owner())));
444+
let code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id)));
445445
for_id(tcx, item_id, span).with_fcx(|fcx| {
446-
let item = fcx.tcx.associated_item(fcx.tcx.hir().local_def_id(item_id));
446+
let item = fcx.tcx.associated_item(item_id);
447447

448448
let (mut implied_bounds, self_ty) = match item.container {
449449
ty::TraitContainer(_) => (FxHashSet::default(), fcx.tcx.types.self_param),
@@ -455,11 +455,7 @@ fn check_associated_item(
455455
match item.kind {
456456
ty::AssocKind::Const => {
457457
let ty = fcx.tcx.type_of(item.def_id);
458-
let ty = fcx.normalize_associated_types_in_wf(
459-
span,
460-
ty,
461-
WellFormedLoc::Ty(item_id.expect_owner()),
462-
);
458+
let ty = fcx.normalize_associated_types_in_wf(span, ty, WellFormedLoc::Ty(item_id));
463459
fcx.register_wf_obligation(ty.into(), span, code.clone());
464460
}
465461
ty::AssocKind::Fn => {
@@ -481,11 +477,8 @@ fn check_associated_item(
481477
}
482478
if item.defaultness.has_value() {
483479
let ty = fcx.tcx.type_of(item.def_id);
484-
let ty = fcx.normalize_associated_types_in_wf(
485-
span,
486-
ty,
487-
WellFormedLoc::Ty(item_id.expect_owner()),
488-
);
480+
let ty =
481+
fcx.normalize_associated_types_in_wf(span, ty, WellFormedLoc::Ty(item_id));
489482
fcx.register_wf_obligation(ty.into(), span, code.clone());
490483
}
491484
}
@@ -496,14 +489,13 @@ fn check_associated_item(
496489
}
497490

498491
fn for_item<'tcx>(tcx: TyCtxt<'tcx>, item: &hir::Item<'_>) -> CheckWfFcxBuilder<'tcx> {
499-
for_id(tcx, item.hir_id(), item.span)
492+
for_id(tcx, item.def_id, item.span)
500493
}
501494

502-
fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> {
503-
let def_id = tcx.hir().local_def_id(id);
495+
fn for_id(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> CheckWfFcxBuilder<'_> {
504496
CheckWfFcxBuilder {
505497
inherited: Inherited::build(tcx, def_id),
506-
id,
498+
id: hir::HirId::make_owner(def_id),
507499
span,
508500
param_env: tcx.param_env(def_id),
509501
}
@@ -665,30 +657,25 @@ fn check_associated_type_bounds(fcx: &FnCtxt<'_, '_>, item: &ty::AssocItem, span
665657

666658
fn check_item_fn(
667659
tcx: TyCtxt<'_>,
668-
item_id: hir::HirId,
660+
def_id: LocalDefId,
669661
ident: Ident,
670662
span: Span,
671663
decl: &hir::FnDecl<'_>,
672664
) {
673-
for_id(tcx, item_id, span).with_fcx(|fcx| {
674-
let def_id = tcx.hir().local_def_id(item_id);
665+
for_id(tcx, def_id, span).with_fcx(|fcx| {
675666
let sig = tcx.fn_sig(def_id);
676667
let mut implied_bounds = FxHashSet::default();
677668
check_fn_or_method(fcx, ident.span, sig, decl, def_id.to_def_id(), &mut implied_bounds);
678669
implied_bounds
679670
})
680671
}
681672

682-
fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_foreign_ty: bool) {
673+
fn check_item_type(tcx: TyCtxt<'_>, item_id: LocalDefId, ty_span: Span, allow_foreign_ty: bool) {
683674
debug!("check_item_type: {:?}", item_id);
684675

685676
for_id(tcx, item_id, ty_span).with_fcx(|fcx| {
686-
let ty = tcx.type_of(tcx.hir().local_def_id(item_id));
687-
let item_ty = fcx.normalize_associated_types_in_wf(
688-
ty_span,
689-
ty,
690-
WellFormedLoc::Ty(item_id.expect_owner()),
691-
);
677+
let ty = tcx.type_of(item_id);
678+
let item_ty = fcx.normalize_associated_types_in_wf(ty_span, ty, WellFormedLoc::Ty(item_id));
692679

693680
let mut forbid_unsized = true;
694681
if allow_foreign_ty {
@@ -701,7 +688,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo
701688
fcx.register_wf_obligation(
702689
item_ty.into(),
703690
ty_span,
704-
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id.expect_owner()))),
691+
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id))),
705692
);
706693
if forbid_unsized {
707694
fcx.register_bound(

0 commit comments

Comments
 (0)