Skip to content

Commit

Permalink
Rollup merge of rust-lang#87889 - estebank:method-call-disambiguate, …
Browse files Browse the repository at this point in the history
…r=oli-obk

Use smaller spans when suggesting method call disambiguation

Use smaller spans when suggesting method call disambiguation.
  • Loading branch information
JohnTitor committed Aug 10, 2021
2 parents 22a1647 + f3021b3 commit 3aa861b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 20 deletions.
12 changes: 6 additions & 6 deletions compiler/rustc_typeck/src/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,8 +1695,8 @@ fn print_disambiguation_help(
source_map: &source_map::SourceMap,
) {
let mut applicability = Applicability::MachineApplicable;
let sugg_args = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
format!(
let (span, sugg) = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
let args = format!(
"({}{})",
if rcvr_ty.is_region_ptr() {
if rcvr_ty.is_mutable_ptr() { "&mut " } else { "&" }
Expand All @@ -1710,12 +1710,12 @@ fn print_disambiguation_help(
}))
.collect::<Vec<_>>()
.join(", "),
)
);
(span, format!("{}::{}{}", trait_name, item_name, args))
} 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(
err.span_suggestion_verbose(
span,
&format!(
"disambiguate the {} for {}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ LL | const ID: i32 = 3;
help: disambiguate the associated constant for candidate #1
|
LL | const X: i32 = Foo::ID;
| ^^^^^^^
| ^^^^^
help: disambiguate the associated constant for candidate #2
|
LL | const X: i32 = Bar::ID;
| ^^^^^^^
| ^^^^^

error: aborting due to previous error

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/error-codes/E0034.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ LL | fn foo() {}
help: disambiguate the associated function for candidate #1
|
LL | Trait1::foo()
| ^^^^^^^^^^^
| ^^^^^^^^
help: disambiguate the associated function for candidate #2
|
LL | Trait2::foo()
| ^^^^^^^^^^^
| ^^^^^^^^

error: aborting due to previous error

Expand Down
9 changes: 5 additions & 4 deletions src/test/ui/issues/issue-18446.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ error[E0034]: multiple applicable items in scope
--> $DIR/issue-18446.rs:18:7
|
LL | x.foo();
| --^^^--
| | |
| | multiple `foo` found
| help: disambiguate the associated function for candidate #2: `T::foo(&x)`
| ^^^ multiple `foo` found
|
note: candidate #1 is defined in an impl for the type `(dyn T + 'a)`
--> $DIR/issue-18446.rs:9:5
Expand All @@ -17,6 +14,10 @@ note: candidate #2 is defined in the trait `T`
|
LL | fn foo(&self);
| ^^^^^^^^^^^^^^
help: disambiguate the associated function for candidate #2
|
LL | T::foo(&x);
| ^^^^^^^^^^

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ LL | fn foo() {}
help: disambiguate the associated function for candidate #1
|
LL | A::foo();
| ^^^^^^
| ^^^
help: disambiguate the associated function for candidate #2
|
LL | B::foo();
| ^^^^^^
| ^^^

error: aborting due to previous error

Expand Down
9 changes: 5 additions & 4 deletions src/test/ui/span/issue-7575.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
|
LL | t.is_str()
| --^^^^^^--
| | |
| | this is an associated function, not a method
| help: disambiguate the associated function for the candidate: `ManyImplTrait::is_str(t)`
| ^^^^^^ this is an associated function, not a method
|
= 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`
Expand All @@ -73,6 +70,10 @@ note: the candidate is defined in the trait `ManyImplTrait`
LL | fn is_str() -> bool {
| ^^^^^^^^^^^^^^^^^^^
= 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

Expand Down

0 comments on commit 3aa861b

Please sign in to comment.