Skip to content

Commit

Permalink
Use LocalDefId directly in more places in wfcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
jackh726 committed Oct 15, 2021
1 parent a7c132d commit d3fa07c
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions compiler/rustc_typeck/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,23 +142,23 @@ pub fn check_item_well_formed(tcx: TyCtxt<'_>, def_id: LocalDefId) {
}
}
hir::ItemKind::Fn(ref sig, ..) => {
check_item_fn(tcx, item.hir_id(), item.ident, item.span, sig.decl);
check_item_fn(tcx, item.def_id, item.ident, item.span, sig.decl);
}
hir::ItemKind::Static(ty, ..) => {
check_item_type(tcx, item.hir_id(), ty.span, false);
check_item_type(tcx, item.def_id, ty.span, false);
}
hir::ItemKind::Const(ty, ..) => {
check_item_type(tcx, item.hir_id(), ty.span, false);
check_item_type(tcx, item.def_id, ty.span, false);
}
hir::ItemKind::ForeignMod { items, .. } => {
for it in items.iter() {
let it = tcx.hir().foreign_item(it.id);
match it.kind {
hir::ForeignItemKind::Fn(decl, ..) => {
check_item_fn(tcx, it.hir_id(), it.ident, it.span, decl)
check_item_fn(tcx, it.def_id, it.ident, it.span, decl)
}
hir::ForeignItemKind::Static(ty, ..) => {
check_item_type(tcx, it.hir_id(), ty.span, true)
check_item_type(tcx, it.def_id, ty.span, true)
}
hir::ForeignItemKind::Type => (),
}
Expand Down Expand Up @@ -199,7 +199,7 @@ pub fn check_trait_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
_ => (None, trait_item.span),
};
check_object_unsafe_self_trait_by_name(tcx, trait_item);
check_associated_item(tcx, trait_item.hir_id(), span, method_sig);
check_associated_item(tcx, trait_item.def_id, span, method_sig);

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

check_associated_item(tcx, impl_item.hir_id(), span, method_sig);
check_associated_item(tcx, impl_item.def_id, span, method_sig);
}

fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
Expand Down Expand Up @@ -437,13 +437,13 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) {
#[tracing::instrument(level = "debug", skip(tcx, span, sig_if_method))]
fn check_associated_item(
tcx: TyCtxt<'_>,
item_id: hir::HirId,
item_id: LocalDefId,
span: Span,
sig_if_method: Option<&hir::FnSig<'_>>,
) {
let code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id.expect_owner())));
let code = ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id)));
for_id(tcx, item_id, span).with_fcx(|fcx| {
let item = fcx.tcx.associated_item(fcx.tcx.hir().local_def_id(item_id));
let item = fcx.tcx.associated_item(item_id);

let (mut implied_bounds, self_ty) = match item.container {
ty::TraitContainer(_) => (FxHashSet::default(), fcx.tcx.types.self_param),
Expand All @@ -455,11 +455,7 @@ fn check_associated_item(
match item.kind {
ty::AssocKind::Const => {
let ty = fcx.tcx.type_of(item.def_id);
let ty = fcx.normalize_associated_types_in_wf(
span,
ty,
WellFormedLoc::Ty(item_id.expect_owner()),
);
let ty = fcx.normalize_associated_types_in_wf(span, ty, WellFormedLoc::Ty(item_id));
fcx.register_wf_obligation(ty.into(), span, code.clone());
}
ty::AssocKind::Fn => {
Expand All @@ -481,11 +477,8 @@ fn check_associated_item(
}
if item.defaultness.has_value() {
let ty = fcx.tcx.type_of(item.def_id);
let ty = fcx.normalize_associated_types_in_wf(
span,
ty,
WellFormedLoc::Ty(item_id.expect_owner()),
);
let ty =
fcx.normalize_associated_types_in_wf(span, ty, WellFormedLoc::Ty(item_id));
fcx.register_wf_obligation(ty.into(), span, code.clone());
}
}
Expand All @@ -496,14 +489,13 @@ fn check_associated_item(
}

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

fn for_id(tcx: TyCtxt<'_>, id: hir::HirId, span: Span) -> CheckWfFcxBuilder<'_> {
let def_id = tcx.hir().local_def_id(id);
fn for_id(tcx: TyCtxt<'_>, def_id: LocalDefId, span: Span) -> CheckWfFcxBuilder<'_> {
CheckWfFcxBuilder {
inherited: Inherited::build(tcx, def_id),
id,
id: hir::HirId::make_owner(def_id),
span,
param_env: tcx.param_env(def_id),
}
Expand Down Expand Up @@ -665,30 +657,25 @@ fn check_associated_type_bounds(fcx: &FnCtxt<'_, '_>, item: &ty::AssocItem, span

fn check_item_fn(
tcx: TyCtxt<'_>,
item_id: hir::HirId,
def_id: LocalDefId,
ident: Ident,
span: Span,
decl: &hir::FnDecl<'_>,
) {
for_id(tcx, item_id, span).with_fcx(|fcx| {
let def_id = tcx.hir().local_def_id(item_id);
for_id(tcx, def_id, span).with_fcx(|fcx| {
let sig = tcx.fn_sig(def_id);
let mut implied_bounds = FxHashSet::default();
check_fn_or_method(fcx, ident.span, sig, decl, def_id.to_def_id(), &mut implied_bounds);
implied_bounds
})
}

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

for_id(tcx, item_id, ty_span).with_fcx(|fcx| {
let ty = tcx.type_of(tcx.hir().local_def_id(item_id));
let item_ty = fcx.normalize_associated_types_in_wf(
ty_span,
ty,
WellFormedLoc::Ty(item_id.expect_owner()),
);
let ty = tcx.type_of(item_id);
let item_ty = fcx.normalize_associated_types_in_wf(ty_span, ty, WellFormedLoc::Ty(item_id));

let mut forbid_unsized = true;
if allow_foreign_ty {
Expand All @@ -701,7 +688,7 @@ fn check_item_type(tcx: TyCtxt<'_>, item_id: hir::HirId, ty_span: Span, allow_fo
fcx.register_wf_obligation(
item_ty.into(),
ty_span,
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id.expect_owner()))),
ObligationCauseCode::WellFormed(Some(WellFormedLoc::Ty(item_id))),
);
if forbid_unsized {
fcx.register_bound(
Expand Down

0 comments on commit d3fa07c

Please sign in to comment.