Fix suggestion span for typo in associated type name

This commit is contained in:
Esteban Küber 2019-12-19 11:23:57 -08:00
parent 245f62eb8a
commit 93fb219579
8 changed files with 22 additions and 18 deletions

View file

@ -1995,6 +1995,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
) where
I: Iterator<Item = ty::PolyTraitRef<'tcx>>,
{
// The fallback span is needed because `assoc_name` might be an `Fn()`'s `Output` without a
// valid span, so we point at the whole path segment instead.
let span = if assoc_name.span != DUMMY_SP { assoc_name.span } else { span };
let mut err = struct_span_err!(
self.tcx().sess,
span,
@ -2012,11 +2015,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
)
.collect();
if let Some(suggested_name) =
find_best_match_for_name(all_candidate_names.iter(), &assoc_name.as_str(), None)
{
if let (Some(suggested_name), true) = (
find_best_match_for_name(all_candidate_names.iter(), &assoc_name.as_str(), None),
assoc_name.span != DUMMY_SP,
) {
err.span_suggestion(
span,
assoc_name.span,
"there is an associated type with a similar name",
suggested_name.to_string(),
Applicability::MaybeIncorrect,

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `A` not found for `T`
--> $DIR/associated-types-path-1.rs:10:23
--> $DIR/associated-types-path-1.rs:10:26
|
LL | pub fn f1<T>(a: T, x: T::A) {}
| ^^^^ associated type `A` not found
| ^ associated type `A` not found
error[E0221]: ambiguous associated type `A` in bounds of `T`
--> $DIR/associated-types-path-1.rs:11:34

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `F` not found for `Trait`
--> $DIR/E0220.rs:5:16
--> $DIR/E0220.rs:5:22
|
LL | type Foo = dyn Trait<F=i32>;
| ^^^^^^^^^^^^ associated type `F` not found
| ^ associated type `F` not found
error[E0191]: the value of the associated type `Bar` (from trait `Trait`) must be specified
--> $DIR/E0220.rs:5:16

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `anything_here_kills_it` not found for `Self`
--> $DIR/issue-23595-2.rs:6:16
--> $DIR/issue-23595-2.rs:6:22
|
LL | type B = C<Self::anything_here_kills_it>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `anything_here_kills_it` not found
| ^^^^^^^^^^^^^^^^^^^^^^ associated type `anything_here_kills_it` not found
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `Row` not found for `M`
--> $DIR/issue-39211.rs:11:17
--> $DIR/issue-39211.rs:11:20
|
LL | let a = [3; M::Row::DIM];
| ^^^^^^^^^^^ associated type `Row` not found
| ^^^ associated type `Row` not found
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `Res` not found for `Self`
--> $DIR/issue-59029-1.rs:5:46
--> $DIR/issue-59029-1.rs:5:52
|
LL | trait MkSvc<Target, Req> = Svc<Target> where Self::Res: Svc<Req>;
| ^^^^^^^^^ associated type `Res` not found
| ^^^ associated type `Res` not found
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `Trget` not found for `std::ops::Deref`
--> $DIR/type-binding.rs:6:14
--> $DIR/type-binding.rs:6:20
|
LL | fn homura<T: Deref<Trget = i32>>(_: T) {}
| ^^^^^^^^^^^ help: there is an associated type with a similar name: `Target`
| ^^^^^ help: there is an associated type with a similar name: `Target`
error: aborting due to previous error

View file

@ -1,8 +1,8 @@
error[E0220]: associated type `Assoc` not found for `V`
--> $DIR/not_well_formed.rs:10:26
--> $DIR/not_well_formed.rs:10:29
|
LL | type Foo<V> = impl Trait<V::Assoc>;
| ^^^^^^^^ associated type `Assoc` not found
| ^^^^^ associated type `Assoc` not found
error: aborting due to previous error