Skip to content

Commit 1476d5c

Browse files
Added defined here note for non-local associated types
1 parent 1404dbd commit 1476d5c

File tree

8 files changed

+80
-9
lines changed

8 files changed

+80
-9
lines changed

compiler/rustc_hir_analysis/src/astconv/errors.rs

+11-9
Original file line numberDiff line numberDiff line change
@@ -669,22 +669,24 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
669669
{
670670
is_shadowed = true;
671671

672-
let is_local = tcx.hir().get_if_local(assoc_item.def_id).is_some();
673-
let rename_message = if is_local { ", consider renaming it" } else { "" };
672+
let rename_message =
673+
if assoc_item.def_id.is_local() { ", consider renaming it" } else { "" };
674674
err.span_label(
675675
tcx.def_span(assoc_item.def_id),
676676
format!("`{}{}` shadowed here{}", prefix, item.name, rename_message),
677677
);
678678
}
679679

680-
let rename_message = if is_shadowed { ", consider renaming it" } else { "" };
680+
let rename_message = if is_shadowed && item.def_id.is_local() {
681+
", consider renaming it"
682+
} else {
683+
""
684+
};
681685

682-
if let Some(sp) = tcx.hir().span_if_local(item.def_id) {
683-
err.span_label(
684-
sp,
685-
format!("`{}{}` defined here{}", prefix, item.name, rename_message),
686-
);
687-
}
686+
err.span_label(
687+
tcx.def_span(item.def_id),
688+
format!("`{}{}` defined here{}", prefix, item.name, rename_message),
689+
);
688690
}
689691
if potential_assoc_types.len() == assoc_items.len() {
690692
// When the amount of missing associated types equals the number of

tests/ui/associated-type-bounds/overlaping-bound-suggestion.stderr

+10
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,16 @@ LL | inner: <IntoIterator<Item: IntoIterator<Item: >>::IntoIterator as Item>
66
| | |
77
| | associated types `Item`, `IntoIter` must be specified
88
| associated types `Item`, `IntoIter` must be specified
9+
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
10+
|
11+
= note: `Item` defined here
12+
|
13+
= note: `Item` defined here
14+
::: $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
15+
|
16+
= note: `IntoIter` defined here
17+
|
18+
= note: `IntoIter` defined here
919

1020
error[E0223]: ambiguous associated type
1121
--> $DIR/overlaping-bound-suggestion.rs:7:13

tests/ui/associated-types/associated-type-shadowed-from-non-local-supertrait.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ LL | type Item;
66
...
77
LL | impl<T> Clone for Box<dyn NewIter<Item = T>> {
88
| ^^^^^^^^^^^^^^^^^ associated type `Item` must be specified
9+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
10+
|
11+
= note: `Iterator::Item` defined here
912

1013
error: aborting due to 1 previous error
1114

tests/ui/associated-types/missing-associated-types.stderr

+41
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ LL | type Foo<Rhs> = dyn Add<Rhs> + Sub<Rhs> + X<Rhs> + Y<Rhs>;
2121
| | | associated type `Output` must be specified
2222
| | associated type `Output` must be specified
2323
| associated type `Output` must be specified
24+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
25+
|
26+
= note: `Output` defined here
27+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
28+
|
29+
= note: `Output` defined here
30+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
31+
|
32+
= note: `Output` defined here
2433
|
2534
help: specify the associated types
2635
|
@@ -52,6 +61,20 @@ LL | type Bar<Rhs> = dyn Add<Rhs> + Sub<Rhs> + X<Rhs> + Z<Rhs>;
5261
| | | associated types `Output` (from trait `Div`), `Output` (from trait `Mul`) must be specified
5362
| | associated type `Output` must be specified
5463
| associated type `Output` must be specified
64+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
65+
|
66+
= note: `Output` defined here
67+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
68+
|
69+
= note: `Output` defined here
70+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
71+
|
72+
= note: `Mul::Output` defined here
73+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
74+
|
75+
= note: `Output` defined here
76+
|
77+
= note: `Div::Output` defined here
5578
|
5679
help: consider introducing a new type parameter, adding `where` constraints using the fully-qualified path to the associated types
5780
--> $DIR/missing-associated-types.rs:15:43
@@ -85,6 +108,12 @@ LL | type Baz<Rhs> = dyn Add<Rhs> + Sub<Rhs> + Y<Rhs>;
85108
| | |
86109
| | associated type `Output` must be specified
87110
| associated type `Output` must be specified
111+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
112+
|
113+
= note: `Output` defined here
114+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
115+
|
116+
= note: `Output` defined here
88117
|
89118
help: specify the associated types
90119
|
@@ -109,6 +138,12 @@ LL | type Bat<Rhs> = dyn Add<Rhs> + Sub<Rhs> + Fine<Rhs>;
109138
| ^^^^^^^^ ^^^^^^^^ associated type `Output` must be specified
110139
| |
111140
| associated type `Output` must be specified
141+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
142+
|
143+
= note: `Output` defined here
144+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
145+
|
146+
= note: `Output` defined here
112147
|
113148
help: specify the associated types
114149
|
@@ -120,6 +155,12 @@ error[E0191]: the value of the associated types `Output` in `Div`, `Output` in `
120155
|
121156
LL | type Bal<Rhs> = dyn X<Rhs>;
122157
| ^^^^^^ associated types `Output` (from trait `Div`), `Output` (from trait `Mul`) must be specified
158+
--> $SRC_DIR/core/src/ops/arith.rs:LL:COL
159+
|
160+
= note: `Mul::Output` defined here
161+
::: $SRC_DIR/core/src/ops/arith.rs:LL:COL
162+
|
163+
= note: `Div::Output` defined here
123164
|
124165
= help: consider introducing a new type parameter, adding `where` constraints using the fully-qualified path to the associated types
125166

tests/ui/issues/issue-23024.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ error[E0191]: the value of the associated type `Output` in `FnOnce` must be spec
2323
|
2424
LL | println!("{:?}",(vfnfer[0] as dyn Fn)(3));
2525
| ^^ help: specify the associated type: `Fn<Output = Type>`
26+
--> $SRC_DIR/core/src/ops/function.rs:LL:COL
27+
|
28+
= note: `Output` defined here
2629

2730
error: aborting due to 3 previous errors
2831

tests/ui/issues/issue-28344.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ error[E0191]: the value of the associated type `Output` in `BitXor` must be spec
1717
|
1818
LL | let x: u8 = BitXor::bitor(0 as u8, 0 as u8);
1919
| ^^^^^^ help: specify the associated type: `BitXor<Output = Type>`
20+
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
21+
|
22+
= note: `Output` defined here
2023

2124
error[E0599]: no function or associated item named `bitor` found for trait object `dyn BitXor<_>` in the current scope
2225
--> $DIR/issue-28344.rs:4:25
@@ -45,6 +48,9 @@ error[E0191]: the value of the associated type `Output` in `BitXor` must be spec
4548
|
4649
LL | let g = BitXor::bitor;
4750
| ^^^^^^ help: specify the associated type: `BitXor<Output = Type>`
51+
--> $SRC_DIR/core/src/ops/bit.rs:LL:COL
52+
|
53+
= note: `Output` defined here
4854

4955
error[E0599]: no function or associated item named `bitor` found for trait object `dyn BitXor<_>` in the current scope
5056
--> $DIR/issue-28344.rs:10:21

tests/ui/suggestions/trait-hidden-method.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ error[E0191]: the value of the associated type `Item` in `Iterator` must be spec
33
|
44
LL | Box::new(1..=10) as Box<dyn Iterator>
55
| ^^^^^^^^ help: specify the associated type: `Iterator<Item = Type>`
6+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
7+
|
8+
= note: `Item` defined here
69

710
error[E0271]: expected `Box<dyn Iterator>` to be an iterator that yields `u32`, but it yields `<dyn Iterator as Iterator>::Item`
811
--> $DIR/trait-hidden-method.rs:3:32

tests/ui/traits/alias/object-fail.stderr

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ error[E0191]: the value of the associated type `Item` in `Iterator` must be spec
1414
|
1515
LL | let _: &dyn IteratorAlias = &vec![123].into_iter();
1616
| ^^^^^^^^^^^^^ help: specify the associated type: `IteratorAlias<Item = Type>`
17+
--> $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL
18+
|
19+
= note: `Item` defined here
1720

1821
error: aborting due to 2 previous errors
1922

0 commit comments

Comments
 (0)