diff options
| author | Matthew Jasper <mjjasper1@gmail.com> | 2023-05-05 15:52:53 +0100 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2023-05-05 22:19:56 +0100 |
| commit | f46eabb9e56fab132ec8171d0e0239f42c986e52 (patch) | |
| tree | 4650dd85c8015bef2e3dd4db160fdb1de24cfb6a /compiler/rustc_hir_analysis/src/impl_wf_check | |
| parent | fafe9e71d5c949c41a5a562e44cc40d72c5f7244 (diff) | |
| download | rust-f46eabb9e56fab132ec8171d0e0239f42c986e52.tar.gz rust-f46eabb9e56fab132ec8171d0e0239f42c986e52.zip | |
Report nicer lifetime errors for specialization
Add an obligation cause for these error so that the error points to the implementations that caused the error.
Diffstat (limited to 'compiler/rustc_hir_analysis/src/impl_wf_check')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs index 4f0df5c5677..e84da2519ae 100644 --- a/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs @@ -80,7 +80,7 @@ use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt}; use rustc_span::Span; use rustc_trait_selection::traits::error_reporting::TypeErrCtxtExt; use rustc_trait_selection::traits::outlives_bounds::InferCtxtExt as _; -use rustc_trait_selection::traits::{self, translate_substs, wf, ObligationCtxt}; +use rustc_trait_selection::traits::{self, translate_substs_with_cause, wf, ObligationCtxt}; pub(super) fn check_min_specialization(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) { if let Some(node) = parent_specialization_node(tcx, impl_def_id) { @@ -180,8 +180,21 @@ fn get_impl_substs( ocx.assumed_wf_types(param_env, tcx.def_span(impl1_def_id), impl1_def_id); let impl1_substs = InternalSubsts::identity_for_item(tcx, impl1_def_id); - let impl2_substs = - translate_substs(infcx, param_env, impl1_def_id.to_def_id(), impl1_substs, impl2_node); + let impl1_span = tcx.def_span(impl1_def_id); + let impl2_substs = translate_substs_with_cause( + infcx, + param_env, + impl1_def_id.to_def_id(), + impl1_substs, + impl2_node, + |_, span| { + traits::ObligationCause::new( + impl1_span, + impl1_def_id, + traits::ObligationCauseCode::BindingObligation(impl2_node.def_id(), span), + ) + }, + ); let errors = ocx.select_all_or_error(); if !errors.is_empty() { |
