diff --git a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs index 74081f2da6fee..1d29a234a3c88 100644 --- a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs +++ b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs @@ -3,6 +3,7 @@ use crate::{LateContext, LateLintPass, LintContext}; use rustc_errors::DelayDm; use rustc_hir as hir; use rustc_middle::{traits::util::supertraits, ty}; +use rustc_span::sym; declare_lint! { /// The `deref_into_dyn_supertrait` lint is output whenever there is a use of the @@ -72,13 +73,19 @@ impl<'tcx> LateLintPass<'tcx> for DerefIntoDynSupertrait { { cx.struct_span_lint( DEREF_INTO_DYN_SUPERTRAIT, - item.span, + cx.tcx.def_span(item.owner_id.def_id), DelayDm(|| { format!( - "`{t}` implements `Deref` with supertrait `{target_principal}` as output" + "`{t}` implements `Deref` with supertrait `{target_principal}` as target" ) }), - |lint| lint, + |lint| { + if let Some(target_span) = impl_.items.iter().find_map(|i| (i.ident.name == sym::Target).then_some(i.span)) { + lint.span_label(target_span, "target type is set here"); + } + + lint + }, ) } } diff --git a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs index ae36115be7b56..d624187561ed7 100644 --- a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs +++ b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs @@ -9,7 +9,7 @@ trait A {} trait B: A {} impl<'a> Deref for dyn 'a + B { - //~^ ERROR `(dyn B + 'a)` implements `Deref` with supertrait `A` as output + //~^ ERROR `(dyn B + 'a)` implements `Deref` with supertrait `A` as target //~| WARN this was previously accepted by the compiler but is being phased out; type Target = dyn A; diff --git a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr index 03317d09eb682..4533b1163425c 100644 --- a/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr +++ b/src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr @@ -1,14 +1,11 @@ -error: `(dyn B + 'a)` implements `Deref` with supertrait `A` as output +error: `(dyn B + 'a)` implements `Deref` with supertrait `A` as target --> $DIR/migrate-lint-deny.rs:11:1 | -LL | / impl<'a> Deref for dyn 'a + B { -LL | | -LL | | -LL | | -... | -LL | | } -LL | | } - | |_^ +LL | impl<'a> Deref for dyn 'a + B { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +... +LL | type Target = dyn A; + | -------------------- target type is set here | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #89460