Skip to content

Commit 93fb219

Browse files
committed
Fix suggestion span for typo in associated type name
1 parent 245f62e commit 93fb219

File tree

8 files changed

+22
-18
lines changed

8 files changed

+22
-18
lines changed

src/librustc_typeck/astconv.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
19951995
) where
19961996
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
19971997
{
1998+
// The fallback span is needed because `assoc_name` might be an `Fn()`'s `Output` without a
1999+
// valid span, so we point at the whole path segment instead.
2000+
let span = if assoc_name.span != DUMMY_SP { assoc_name.span } else { span };
19982001
let mut err = struct_span_err!(
19992002
self.tcx().sess,
20002003
span,
@@ -2012,11 +2015,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20122015
)
20132016
.collect();
20142017

2015-
if let Some(suggested_name) =
2016-
find_best_match_for_name(all_candidate_names.iter(), &assoc_name.as_str(), None)
2017-
{
2018+
if let (Some(suggested_name), true) = (
2019+
find_best_match_for_name(all_candidate_names.iter(), &assoc_name.as_str(), None),
2020+
assoc_name.span != DUMMY_SP,
2021+
) {
20182022
err.span_suggestion(
2019-
span,
2023+
assoc_name.span,
20202024
"there is an associated type with a similar name",
20212025
suggested_name.to_string(),
20222026
Applicability::MaybeIncorrect,

src/test/ui/associated-types/associated-types-path-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `A` not found for `T`
2-
--> $DIR/associated-types-path-1.rs:10:23
2+
--> $DIR/associated-types-path-1.rs:10:26
33
|
44
LL | pub fn f1<T>(a: T, x: T::A) {}
5-
| ^^^^ associated type `A` not found
5+
| ^ associated type `A` not found
66

77
error[E0221]: ambiguous associated type `A` in bounds of `T`
88
--> $DIR/associated-types-path-1.rs:11:34

src/test/ui/error-codes/E0220.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `F` not found for `Trait`
2-
--> $DIR/E0220.rs:5:16
2+
--> $DIR/E0220.rs:5:22
33
|
44
LL | type Foo = dyn Trait<F=i32>;
5-
| ^^^^^^^^^^^^ associated type `F` not found
5+
| ^ associated type `F` not found
66

77
error[E0191]: the value of the associated type `Bar` (from trait `Trait`) must be specified
88
--> $DIR/E0220.rs:5:16

src/test/ui/issues/issue-23595-2.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `anything_here_kills_it` not found for `Self`
2-
--> $DIR/issue-23595-2.rs:6:16
2+
--> $DIR/issue-23595-2.rs:6:22
33
|
44
LL | type B = C<Self::anything_here_kills_it>;
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `anything_here_kills_it` not found
5+
| ^^^^^^^^^^^^^^^^^^^^^^ associated type `anything_here_kills_it` not found
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-39211.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `Row` not found for `M`
2-
--> $DIR/issue-39211.rs:11:17
2+
--> $DIR/issue-39211.rs:11:20
33
|
44
LL | let a = [3; M::Row::DIM];
5-
| ^^^^^^^^^^^ associated type `Row` not found
5+
| ^^^ associated type `Row` not found
66

77
error: aborting due to previous error
88

src/test/ui/issues/issue-59029-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `Res` not found for `Self`
2-
--> $DIR/issue-59029-1.rs:5:46
2+
--> $DIR/issue-59029-1.rs:5:52
33
|
44
LL | trait MkSvc<Target, Req> = Svc<Target> where Self::Res: Svc<Req>;
5-
| ^^^^^^^^^ associated type `Res` not found
5+
| ^^^ associated type `Res` not found
66

77
error: aborting due to previous error
88

src/test/ui/span/type-binding.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `Trget` not found for `std::ops::Deref`
2-
--> $DIR/type-binding.rs:6:14
2+
--> $DIR/type-binding.rs:6:20
33
|
44
LL | fn homura<T: Deref<Trget = i32>>(_: T) {}
5-
| ^^^^^^^^^^^ help: there is an associated type with a similar name: `Target`
5+
| ^^^^^ help: there is an associated type with a similar name: `Target`
66

77
error: aborting due to previous error
88

src/test/ui/type-alias-impl-trait/not_well_formed.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0220]: associated type `Assoc` not found for `V`
2-
--> $DIR/not_well_formed.rs:10:26
2+
--> $DIR/not_well_formed.rs:10:29
33
|
44
LL | type Foo<V> = impl Trait<V::Assoc>;
5-
| ^^^^^^^^ associated type `Assoc` not found
5+
| ^^^^^ associated type `Assoc` not found
66

77
error: aborting due to previous error
88

0 commit comments

Comments
 (0)