From 47582471c61e15f9e409b45e11f2f15e61a88e29 Mon Sep 17 00:00:00 2001 From: David Wood Date: Sat, 7 May 2022 08:14:48 +0100 Subject: [PATCH] typeck: port "no resolve overridden impl substs" Port "could not resolve substs on overridden impl" diagnostic to use the diagnostic derive. Signed-off-by: David Wood --- compiler/rustc_error_messages/locales/en-US/typeck.ftl | 2 ++ compiler/rustc_typeck/src/errors.rs | 7 +++++++ .../rustc_typeck/src/impl_wf_check/min_specialization.rs | 3 ++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_error_messages/locales/en-US/typeck.ftl b/compiler/rustc_error_messages/locales/en-US/typeck.ftl index 4122464a4a2..95b348ec613 100644 --- a/compiler/rustc_error_messages/locales/en-US/typeck.ftl +++ b/compiler/rustc_error_messages/locales/en-US/typeck.ftl @@ -127,3 +127,5 @@ typeck-manual-implementation = manual implementations of `{$trait_name}` are experimental .label = manual implementations of `{$trait_name}` are experimental .help = add `#![feature(unboxed_closures)]` to the crate attributes to enable + +typeck-substs-on-overridden-impl = could not resolve substs on overridden impl diff --git a/compiler/rustc_typeck/src/errors.rs b/compiler/rustc_typeck/src/errors.rs index 1cb112e68ce..cd3813ca4f5 100644 --- a/compiler/rustc_typeck/src/errors.rs +++ b/compiler/rustc_typeck/src/errors.rs @@ -323,3 +323,10 @@ pub struct ManualImplementation { pub span: Span, pub trait_name: String, } + +#[derive(SessionDiagnostic)] +#[error(slug = "typeck-substs-on-overridden-impl")] +pub struct SubstsOnOverriddenImpl { + #[primary_span] + pub span: Span, +} diff --git a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs index 22db15f4d4e..bb97d00be32 100644 --- a/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs +++ b/compiler/rustc_typeck/src/impl_wf_check/min_specialization.rs @@ -66,6 +66,7 @@ //! on traits with methods can. use crate::constrained_generic_params as cgp; +use crate::errors::SubstsOnOverriddenImpl; use rustc_data_structures::fx::FxHashSet; use rustc_hir::def_id::{DefId, LocalDefId}; @@ -165,7 +166,7 @@ fn get_impl_substs<'tcx>( let outlives_env = OutlivesEnvironment::new(ty::ParamEnv::empty()); infcx.resolve_regions_and_report_errors(impl1_def_id, &outlives_env, RegionckMode::default()); let Ok(impl2_substs) = infcx.fully_resolve(impl2_substs) else { - tcx.sess.struct_span_err(span, "could not resolve substs on overridden impl").emit(); + tcx.sess.emit_err(SubstsOnOverriddenImpl { span }); return None; }; Some((impl1_substs, impl2_substs))