1
Fork 0

Use smaller spans when suggesting method call disambiguation

This commit is contained in:
Esteban Kuber 2021-08-09 16:47:09 +00:00
parent eaf6f46359
commit f3021b3561
6 changed files with 22 additions and 20 deletions

View file

@ -1695,8 +1695,8 @@ fn print_disambiguation_help(
source_map: &source_map::SourceMap, source_map: &source_map::SourceMap,
) { ) {
let mut applicability = Applicability::MachineApplicable; let mut applicability = Applicability::MachineApplicable;
let sugg_args = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) { let (span, sugg) = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
format!( let args = format!(
"({}{})", "({}{})",
if rcvr_ty.is_region_ptr() { if rcvr_ty.is_region_ptr() {
if rcvr_ty.is_mutable_ptr() { "&mut " } else { "&" } if rcvr_ty.is_mutable_ptr() { "&mut " } else { "&" }
@ -1710,12 +1710,12 @@ fn print_disambiguation_help(
})) }))
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
) );
(span, format!("{}::{}{}", trait_name, item_name, args))
} else { } else {
String::new() (span.with_hi(item_name.span.lo()), format!("{}::", trait_name))
}; };
let sugg = format!("{}::{}{}", trait_name, item_name, sugg_args); err.span_suggestion_verbose(
err.span_suggestion(
span, span,
&format!( &format!(
"disambiguate the {} for {}", "disambiguate the {} for {}",

View file

@ -17,11 +17,11 @@ LL | const ID: i32 = 3;
help: disambiguate the associated constant for candidate #1 help: disambiguate the associated constant for candidate #1
| |
LL | const X: i32 = Foo::ID; LL | const X: i32 = Foo::ID;
| ^^^^^^^ | ^^^^^
help: disambiguate the associated constant for candidate #2 help: disambiguate the associated constant for candidate #2
| |
LL | const X: i32 = Bar::ID; LL | const X: i32 = Bar::ID;
| ^^^^^^^ | ^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -17,11 +17,11 @@ LL | fn foo() {}
help: disambiguate the associated function for candidate #1 help: disambiguate the associated function for candidate #1
| |
LL | Trait1::foo() LL | Trait1::foo()
| ^^^^^^^^^^^ | ^^^^^^^^
help: disambiguate the associated function for candidate #2 help: disambiguate the associated function for candidate #2
| |
LL | Trait2::foo() LL | Trait2::foo()
| ^^^^^^^^^^^ | ^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -2,10 +2,7 @@ error[E0034]: multiple applicable items in scope
--> $DIR/issue-18446.rs:18:7 --> $DIR/issue-18446.rs:18:7
| |
LL | x.foo(); LL | x.foo();
| --^^^-- | ^^^ multiple `foo` found
| | |
| | multiple `foo` found
| help: disambiguate the associated function for candidate #2: `T::foo(&x)`
| |
note: candidate #1 is defined in an impl for the type `(dyn T + 'a)` note: candidate #1 is defined in an impl for the type `(dyn T + 'a)`
--> $DIR/issue-18446.rs:9:5 --> $DIR/issue-18446.rs:9:5
@ -17,6 +14,10 @@ note: candidate #2 is defined in the trait `T`
| |
LL | fn foo(&self); LL | fn foo(&self);
| ^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^
help: disambiguate the associated function for candidate #2
|
LL | T::foo(&x);
| ^^^^^^^^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -17,11 +17,11 @@ LL | fn foo() {}
help: disambiguate the associated function for candidate #1 help: disambiguate the associated function for candidate #1
| |
LL | A::foo(); LL | A::foo();
| ^^^^^^ | ^^^
help: disambiguate the associated function for candidate #2 help: disambiguate the associated function for candidate #2
| |
LL | B::foo(); LL | B::foo();
| ^^^^^^ | ^^^
error: aborting due to previous error error: aborting due to previous error

View file

@ -61,10 +61,7 @@ error[E0599]: no method named `is_str` found for type parameter `T` in the curre
--> $DIR/issue-7575.rs:70:7 --> $DIR/issue-7575.rs:70:7
| |
LL | t.is_str() LL | t.is_str()
| --^^^^^^-- | ^^^^^^ this is an associated function, not a method
| | |
| | this is an associated function, not a method
| help: disambiguate the associated function for the candidate: `ManyImplTrait::is_str(t)`
| |
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `ManyImplTrait` note: the candidate is defined in the trait `ManyImplTrait`
@ -73,6 +70,10 @@ note: the candidate is defined in the trait `ManyImplTrait`
LL | fn is_str() -> bool { LL | fn is_str() -> bool {
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
= help: items from traits can only be used if the type parameter is bounded by the trait = help: items from traits can only be used if the type parameter is bounded by the trait
help: disambiguate the associated function for the candidate
|
LL | ManyImplTrait::is_str(t)
|
error: aborting due to 3 previous errors error: aborting due to 3 previous errors