diff options
| author | Oli Scherer <github333195615777966@oli-obk.de> | 2025-06-04 11:32:29 +0000 |
|---|---|---|
| committer | Oli Scherer <github333195615777966@oli-obk.de> | 2025-06-30 08:45:43 +0000 |
| commit | 28f023c75194fdd61b12b64a33e7e0ba877eb3c9 (patch) | |
| tree | d6cfc5c2f1a16000edde2a97a35c81bf5b1dd10a /compiler/rustc_hir_analysis/src/check/wfcheck.rs | |
| parent | ee8fa4eb169949600da993a0bfcb2d5fe85e6043 (diff) | |
| download | rust-28f023c75194fdd61b12b64a33e7e0ba877eb3c9.tar.gz rust-28f023c75194fdd61b12b64a33e7e0ba877eb3c9.zip | |
Use predicate spans instead of whole item spans
Diffstat (limited to 'compiler/rustc_hir_analysis/src/check/wfcheck.rs')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/wfcheck.rs | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 90368f7b26c..c096eb465e7 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -25,7 +25,7 @@ use rustc_middle::ty::{ }; use rustc_middle::{bug, span_bug}; use rustc_session::parse::feature_err; -use rustc_span::{DUMMY_SP, Ident, Span, sym}; +use rustc_span::{DUMMY_SP, Span, sym}; use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::regions::{InferCtxtRegionExt, OutlivesEnvironmentBuildExt}; use rustc_trait_selection::traits::misc::{ @@ -290,8 +290,8 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<() } res } - hir::ItemKind::Fn { ident, sig, .. } => check_item_fn(tcx, def_id, ident, sig.decl), - hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span, item.span), + hir::ItemKind::Fn { sig, .. } => check_item_fn(tcx, def_id, sig.decl), + hir::ItemKind::Const(_, _, ty, _) => check_const_item(tcx, def_id, ty.span), hir::ItemKind::Struct(..) => check_type_defn(tcx, item, false), hir::ItemKind::Union(..) => check_type_defn(tcx, item, true), hir::ItemKind::Enum(..) => check_type_defn(tcx, item, true), @@ -307,7 +307,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<() Some(WellFormedLoc::Ty(def_id)), item_ty.into(), ); - check_where_clauses(wfcx, item.span, def_id); + check_where_clauses(wfcx, def_id); Ok(()) }) } @@ -327,7 +327,7 @@ fn check_foreign_item<'tcx>( ); match item.kind { - hir::ForeignItemKind::Fn(sig, ..) => check_item_fn(tcx, def_id, item.ident, sig.decl), + hir::ForeignItemKind::Fn(sig, ..) => check_item_fn(tcx, def_id, sig.decl), hir::ForeignItemKind::Static(..) | hir::ForeignItemKind::Type => Ok(()), } } @@ -1017,13 +1017,7 @@ fn check_associated_item( ty::AssocKind::Fn { .. } => { let sig = tcx.fn_sig(item.def_id).instantiate_identity(); let hir_sig = sig_if_method.expect("bad signature for method"); - check_fn_or_method( - wfcx, - item.ident(tcx).span, - sig, - hir_sig.decl, - item.def_id.expect_local(), - ); + check_fn_or_method(wfcx, sig, hir_sig.decl, item.def_id.expect_local()); check_method_receiver(wfcx, hir_sig, item, self_ty) } ty::AssocKind::Type { .. } => { @@ -1152,7 +1146,7 @@ fn check_type_defn<'tcx>( } } - check_where_clauses(wfcx, item.span, item.owner_id.def_id); + check_where_clauses(wfcx, item.owner_id.def_id); Ok(()) }) } @@ -1183,7 +1177,7 @@ fn check_trait(tcx: TyCtxt<'_>, item: &hir::Item<'_>) -> Result<(), ErrorGuarant } let res = enter_wf_checking_ctxt(tcx, def_id, |wfcx| { - check_where_clauses(wfcx, item.span, def_id); + check_where_clauses(wfcx, def_id); Ok(()) }); @@ -1219,12 +1213,11 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt fn check_item_fn( tcx: TyCtxt<'_>, def_id: LocalDefId, - ident: Ident, decl: &hir::FnDecl<'_>, ) -> Result<(), ErrorGuaranteed> { enter_wf_checking_ctxt(tcx, def_id, |wfcx| { let sig = tcx.fn_sig(def_id).instantiate_identity(); - check_fn_or_method(wfcx, ident.span, sig, decl, def_id); + check_fn_or_method(wfcx, sig, decl, def_id); Ok(()) }) } @@ -1287,7 +1280,6 @@ fn check_const_item( tcx: TyCtxt<'_>, def_id: LocalDefId, ty_span: Span, - item_span: Span, ) -> Result<(), ErrorGuaranteed> { enter_wf_checking_ctxt(tcx, def_id, |wfcx| { let ty = tcx.type_of(def_id).instantiate_identity(); @@ -1305,7 +1297,7 @@ fn check_const_item( tcx.require_lang_item(LangItem::Sized, ty_span), ); - check_where_clauses(wfcx, item_span, def_id); + check_where_clauses(wfcx, def_id); Ok(()) }) @@ -1402,14 +1394,14 @@ fn check_impl<'tcx>( } } - check_where_clauses(wfcx, item.span, item.owner_id.def_id); + check_where_clauses(wfcx, item.owner_id.def_id); Ok(()) }) } /// Checks where-clauses and inline bounds that are declared on `def_id`. #[instrument(level = "debug", skip(wfcx))] -fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id: LocalDefId) { +pub(super) fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, def_id: LocalDefId) { let infcx = wfcx.infcx; let tcx = wfcx.tcx(); @@ -1564,21 +1556,18 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id let predicates = predicates.instantiate_identity(tcx); - let predicates = wfcx.normalize(span, None, predicates); - - debug!(?predicates.predicates); assert_eq!(predicates.predicates.len(), predicates.spans.len()); let wf_obligations = predicates.into_iter().flat_map(|(p, sp)| { + let p = wfcx.normalize(sp, None, p); traits::wf::clause_obligations(infcx, wfcx.param_env, wfcx.body_def_id, p, sp) }); let obligations: Vec<_> = wf_obligations.chain(default_obligations).collect(); wfcx.register_obligations(obligations); } -#[instrument(level = "debug", skip(wfcx, span, hir_decl))] +#[instrument(level = "debug", skip(wfcx, hir_decl))] fn check_fn_or_method<'tcx>( wfcx: &WfCheckingCtxt<'_, 'tcx>, - span: Span, sig: ty::PolyFnSig<'tcx>, hir_decl: &hir::FnDecl<'_>, def_id: LocalDefId, @@ -1616,7 +1605,7 @@ fn check_fn_or_method<'tcx>( ); } - check_where_clauses(wfcx, span, def_id); + check_where_clauses(wfcx, def_id); if sig.abi == ExternAbi::RustCall { let span = tcx.def_span(def_id); |
