diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-10 12:31:59 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-10 12:31:59 +0100 |
| commit | afd8558d62f28de101c58f4314ea2ba2c1aa60ec (patch) | |
| tree | 3eddcd22a95c61d33310bac83f545ef0e4f3b8f0 /compiler/rustc_trait_selection/src | |
| parent | 63c6a341f599b7d9788f0a8eaca78089153d495e (diff) | |
| parent | 5b99723439d45fdf7f6c12b7e06f86674e5ce262 (diff) | |
| download | rust-afd8558d62f28de101c58f4314ea2ba2c1aa60ec.tar.gz rust-afd8558d62f28de101c58f4314ea2ba2c1aa60ec.zip | |
Rollup merge of #108945 - spastorino:pass-def-id-instead-of-using-hir-id, r=compiler-errors
Make some report and emit errors take DefIds instead of BodyIds Breaking off from #108915 r? `@compiler-errors`
Diffstat (limited to 'compiler/rustc_trait_selection/src')
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs index a844a1494e2..e56f5aa73c3 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs @@ -24,11 +24,9 @@ use rustc_errors::{ }; use rustc_hir as hir; use rustc_hir::def::Namespace; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::Visitor; -use rustc_hir::GenericParam; -use rustc_hir::Item; -use rustc_hir::Node; +use rustc_hir::{GenericParam, Item, Node}; use rustc_infer::infer::error_reporting::TypeErrCtxt; use rustc_infer::infer::{InferOk, TypeTrace}; use rustc_middle::traits::select::OverflowError; @@ -129,7 +127,7 @@ pub trait TypeErrCtxtExt<'tcx> { fn report_fulfillment_errors( &self, errors: &[FulfillmentError<'tcx>], - body_id: Option<hir::BodyId>, + body_def_id: Option<LocalDefId>, ) -> ErrorGuaranteed; fn report_overflow_obligation<T>( @@ -391,7 +389,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn report_fulfillment_errors( &self, errors: &[FulfillmentError<'tcx>], - body_id: Option<hir::BodyId>, + body_def_id: Option<LocalDefId>, ) -> ErrorGuaranteed { #[derive(Debug)] struct ErrorDescriptor<'tcx> { @@ -469,7 +467,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { for from_expansion in [false, true] { for (error, suppressed) in iter::zip(errors, &is_suppressed) { if !suppressed && error.obligation.cause.span.from_expansion() == from_expansion { - self.report_fulfillment_error(error, body_id); + self.report_fulfillment_error(error, body_def_id); } } } @@ -955,8 +953,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { ); } - let body_hir_id = - self.tcx.hir().local_def_id_to_hir_id(obligation.cause.body_id); + let body_def_id = obligation.cause.body_id; // Try to report a help message if is_fn_trait && let Ok((implemented_kind, params)) = self.type_implements_fn_trait( @@ -1037,7 +1034,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if !self.report_similar_impl_candidates( impl_candidates, trait_ref, - body_hir_id, + body_def_id, &mut err, true, ) { @@ -1073,7 +1070,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.report_similar_impl_candidates( impl_candidates, trait_ref, - body_hir_id, + body_def_id, &mut err, true, ); @@ -1497,7 +1494,7 @@ trait InferCtxtPrivExt<'tcx> { fn report_fulfillment_error( &self, error: &FulfillmentError<'tcx>, - body_id: Option<hir::BodyId>, + body_def_id: Option<LocalDefId>, ); fn report_projection_error( @@ -1531,7 +1528,7 @@ trait InferCtxtPrivExt<'tcx> { &self, impl_candidates: Vec<ImplCandidate<'tcx>>, trait_ref: ty::PolyTraitRef<'tcx>, - body_id: hir::HirId, + body_def_id: LocalDefId, err: &mut Diagnostic, other: bool, ) -> bool; @@ -1564,7 +1561,7 @@ trait InferCtxtPrivExt<'tcx> { fn maybe_report_ambiguity( &self, obligation: &PredicateObligation<'tcx>, - body_id: Option<hir::BodyId>, + body_def_id: Option<LocalDefId>, ); fn predicate_can_apply( @@ -1650,7 +1647,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn report_fulfillment_error( &self, error: &FulfillmentError<'tcx>, - body_id: Option<hir::BodyId>, + body_def_id: Option<LocalDefId>, ) { match error.code { FulfillmentErrorCode::CodeSelectionError(ref selection_error) => { @@ -1664,7 +1661,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.report_projection_error(&error.obligation, e); } FulfillmentErrorCode::CodeAmbiguity => { - self.maybe_report_ambiguity(&error.obligation, body_id); + self.maybe_report_ambiguity(&error.obligation, body_def_id); } FulfillmentErrorCode::CodeSubtypeError(ref expected_found, ref err) => { self.report_mismatched_types( @@ -2029,7 +2026,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { &self, impl_candidates: Vec<ImplCandidate<'tcx>>, trait_ref: ty::PolyTraitRef<'tcx>, - body_id: hir::HirId, + body_def_id: LocalDefId, err: &mut Diagnostic, other: bool, ) -> bool { @@ -2120,9 +2117,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { // FIXME(compiler-errors): This could be generalized, both to // be more granular, and probably look past other `#[fundamental]` // types, too. - self.tcx - .visibility(def.did()) - .is_accessible_from(body_id.owner.def_id, self.tcx) + self.tcx.visibility(def.did()).is_accessible_from(body_def_id, self.tcx) } else { true } @@ -2234,7 +2229,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { fn maybe_report_ambiguity( &self, obligation: &PredicateObligation<'tcx>, - body_id: Option<hir::BodyId>, + body_def_id: Option<LocalDefId>, ) { // Unable to successfully determine, probably means // insufficient type information, but could mean @@ -2277,7 +2272,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { if self.tcx.lang_items().sized_trait() == Some(trait_ref.def_id()) { if let None = self.tainted_by_errors() { self.emit_inference_failure_err( - body_id, + body_def_id, span, trait_ref.self_ty().skip_binder().into(), ErrorCode::E0282, @@ -2304,7 +2299,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let subst = data.trait_ref.substs.iter().find(|s| s.has_non_region_infer()); let mut err = if let Some(subst) = subst { - self.emit_inference_failure_err(body_id, span, subst, ErrorCode::E0283, true) + self.emit_inference_failure_err( + body_def_id, + span, + subst, + ErrorCode::E0283, + true, + ) } else { struct_span_err!( self.tcx.sess, @@ -2348,12 +2349,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { predicate.to_opt_poly_trait_pred().unwrap(), ); if impl_candidates.len() < 10 { - let hir = - self.tcx.hir().local_def_id_to_hir_id(obligation.cause.body_id); self.report_similar_impl_candidates( impl_candidates, trait_ref, - body_id.map(|id| id.hir_id).unwrap_or(hir), + body_def_id.unwrap_or(obligation.cause.body_id), &mut err, false, ); @@ -2375,9 +2374,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { self.suggest_fully_qualified_path(&mut err, def_id, span, trait_ref.def_id()); } - if let (Some(body_id), Some(ty::subst::GenericArgKind::Type(_))) = - (body_id, subst.map(|subst| subst.unpack())) + if let (Some(body_def_id), Some(ty::subst::GenericArgKind::Type(_))) = + (body_def_id, subst.map(|subst| subst.unpack())) { + let body_id = self.tcx.hir().body_owned_by(body_def_id); let mut expr_finder = FindExprBySpan::new(span); expr_finder.visit_expr(&self.tcx.hir().body(body_id).value); @@ -2473,7 +2473,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { return; } - self.emit_inference_failure_err(body_id, span, arg, ErrorCode::E0282, false) + self.emit_inference_failure_err(body_def_id, span, arg, ErrorCode::E0282, false) } ty::PredicateKind::Subtype(data) => { @@ -2487,7 +2487,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let SubtypePredicate { a_is_expected: _, a, b } = data; // both must be type variables, or the other would've been instantiated assert!(a.is_ty_var() && b.is_ty_var()); - self.emit_inference_failure_err(body_id, span, a.into(), ErrorCode::E0282, true) + self.emit_inference_failure_err(body_def_id, span, a.into(), ErrorCode::E0282, true) } ty::PredicateKind::Clause(ty::Clause::Projection(data)) => { if predicate.references_error() || self.tainted_by_errors().is_some() { @@ -2501,7 +2501,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { .find(|g| g.has_non_region_infer()); if let Some(subst) = subst { let mut err = self.emit_inference_failure_err( - body_id, + body_def_id, span, subst, ErrorCode::E0284, @@ -2530,7 +2530,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> { let subst = data.walk().find(|g| g.is_non_region_infer()); if let Some(subst) = subst { let err = self.emit_inference_failure_err( - body_id, + body_def_id, span, subst, ErrorCode::E0284, |
