Skip to content

Commit 20f3de5

Browse files
committed
Use nicer spans for deref_into_dyn_supertrait
1 parent 0d4a5c7 commit 20f3de5

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

compiler/rustc_lint/src/deref_into_dyn_supertrait.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use crate::{LateContext, LateLintPass, LintContext};
33
use rustc_errors::DelayDm;
44
use rustc_hir as hir;
55
use rustc_middle::{traits::util::supertraits, ty};
6+
use rustc_span::sym;
67

78
declare_lint! {
89
/// 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 {
7273
{
7374
cx.struct_span_lint(
7475
DEREF_INTO_DYN_SUPERTRAIT,
75-
item.span,
76+
cx.tcx.def_span(item.owner_id.def_id),
7677
DelayDm(|| {
7778
format!(
78-
"`{t}` implements `Deref` with supertrait `{target_principal}` as output"
79+
"`{t}` implements `Deref` with supertrait `{target_principal}` as target"
7980
)
8081
}),
81-
|lint| lint,
82+
|lint| {
83+
if let Some(target_span) = impl_.items.iter().find_map(|i| (i.ident.name == sym::Target).then_some(i.span)) {
84+
lint.span_label(target_span, "target type is set here");
85+
}
86+
87+
lint
88+
},
8289
)
8390
}
8491
}

src/test/ui/traits/trait-upcasting/migrate-lint-deny.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ trait A {}
99
trait B: A {}
1010

1111
impl<'a> Deref for dyn 'a + B {
12-
//~^ ERROR `(dyn B + 'a)` implements `Deref` with supertrait `A` as output
12+
//~^ ERROR `(dyn B + 'a)` implements `Deref` with supertrait `A` as target
1313
//~| WARN this was previously accepted by the compiler but is being phased out;
1414

1515
type Target = dyn A;

src/test/ui/traits/trait-upcasting/migrate-lint-deny.stderr

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
error: `(dyn B + 'a)` implements `Deref` with supertrait `A` as output
1+
error: `(dyn B + 'a)` implements `Deref` with supertrait `A` as target
22
--> $DIR/migrate-lint-deny.rs:11:1
33
|
4-
LL | / impl<'a> Deref for dyn 'a + B {
5-
LL | |
6-
LL | |
7-
LL | |
8-
... |
9-
LL | | }
10-
LL | | }
11-
| |_^
4+
LL | impl<'a> Deref for dyn 'a + B {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
...
7+
LL | type Target = dyn A;
8+
| -------------------- target type is set here
129
|
1310
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1411
= note: for more information, see issue #89460 <https://github.com/rust-lang/rust/issues/89460>

0 commit comments

Comments
 (0)