diff options
| author | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-11-23 16:12:51 +0000 |
|---|---|---|
| committer | Maybe Waffle <waffle.lapkin@gmail.com> | 2022-11-23 16:12:51 +0000 |
| commit | 20f3de5ab1151e68e727b5e1c22bcafca738bb7e (patch) | |
| tree | c9c2acc13a39f76bebb41125baa2c80e6c21a650 /compiler/rustc_lint | |
| parent | 0d4a5c725a3f0cbc2f2597be7e9dec9ba27409ff (diff) | |
| download | rust-20f3de5ab1151e68e727b5e1c22bcafca738bb7e.tar.gz rust-20f3de5ab1151e68e727b5e1c22bcafca738bb7e.zip | |
Use nicer spans for `deref_into_dyn_supertrait`
Diffstat (limited to 'compiler/rustc_lint')
| -rw-r--r-- | compiler/rustc_lint/src/deref_into_dyn_supertrait.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs b/compiler/rustc_lint/src/deref_into_dyn_supertrait.rs index 74081f2da6f..1d29a234a3c 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 + }, ) } } |
