Skip to content

Commit 4d4915a

Browse files
authored
Rollup merge of #87889 - estebank:method-call-disambiguate, r=oli-obk
Use smaller spans when suggesting method call disambiguation Use smaller spans when suggesting method call disambiguation.
2 parents 22f864e + f3021b3 commit 4d4915a

File tree

6 files changed

+22
-20
lines changed

6 files changed

+22
-20
lines changed

compiler/rustc_typeck/src/check/method/suggest.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1695,8 +1695,8 @@ fn print_disambiguation_help(
16951695
source_map: &source_map::SourceMap,
16961696
) {
16971697
let mut applicability = Applicability::MachineApplicable;
1698-
let sugg_args = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
1699-
format!(
1698+
let (span, sugg) = if let (ty::AssocKind::Fn, Some(args)) = (kind, args) {
1699+
let args = format!(
17001700
"({}{})",
17011701
if rcvr_ty.is_region_ptr() {
17021702
if rcvr_ty.is_mutable_ptr() { "&mut " } else { "&" }
@@ -1710,12 +1710,12 @@ fn print_disambiguation_help(
17101710
}))
17111711
.collect::<Vec<_>>()
17121712
.join(", "),
1713-
)
1713+
);
1714+
(span, format!("{}::{}{}", trait_name, item_name, args))
17141715
} else {
1715-
String::new()
1716+
(span.with_hi(item_name.span.lo()), format!("{}::", trait_name))
17161717
};
1717-
let sugg = format!("{}::{}{}", trait_name, item_name, sugg_args);
1718-
err.span_suggestion(
1718+
err.span_suggestion_verbose(
17191719
span,
17201720
&format!(
17211721
"disambiguate the {} for {}",

src/test/ui/associated-consts/associated-const-ambiguity-report.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ LL | const ID: i32 = 3;
1717
help: disambiguate the associated constant for candidate #1
1818
|
1919
LL | const X: i32 = Foo::ID;
20-
| ^^^^^^^
20+
| ^^^^^
2121
help: disambiguate the associated constant for candidate #2
2222
|
2323
LL | const X: i32 = Bar::ID;
24-
| ^^^^^^^
24+
| ^^^^^
2525

2626
error: aborting due to previous error
2727

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ LL | fn foo() {}
1717
help: disambiguate the associated function for candidate #1
1818
|
1919
LL | Trait1::foo()
20-
| ^^^^^^^^^^^
20+
| ^^^^^^^^
2121
help: disambiguate the associated function for candidate #2
2222
|
2323
LL | Trait2::foo()
24-
| ^^^^^^^^^^^
24+
| ^^^^^^^^
2525

2626
error: aborting due to previous error
2727

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ error[E0034]: multiple applicable items in scope
22
--> $DIR/issue-18446.rs:18:7
33
|
44
LL | x.foo();
5-
| --^^^--
6-
| | |
7-
| | multiple `foo` found
8-
| help: disambiguate the associated function for candidate #2: `T::foo(&x)`
5+
| ^^^ multiple `foo` found
96
|
107
note: candidate #1 is defined in an impl for the type `(dyn T + 'a)`
118
--> $DIR/issue-18446.rs:9:5
@@ -17,6 +14,10 @@ note: candidate #2 is defined in the trait `T`
1714
|
1815
LL | fn foo(&self);
1916
| ^^^^^^^^^^^^^^
17+
help: disambiguate the associated function for candidate #2
18+
|
19+
LL | T::foo(&x);
20+
| ^^^^^^^^^^
2021

2122
error: aborting due to previous error
2223

src/test/ui/methods/method-ambig-two-traits-from-impls2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ LL | fn foo() {}
1717
help: disambiguate the associated function for candidate #1
1818
|
1919
LL | A::foo();
20-
| ^^^^^^
20+
| ^^^
2121
help: disambiguate the associated function for candidate #2
2222
|
2323
LL | B::foo();
24-
| ^^^^^^
24+
| ^^^
2525

2626
error: aborting due to previous error
2727

src/test/ui/span/issue-7575.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ error[E0599]: no method named `is_str` found for type parameter `T` in the curre
6161
--> $DIR/issue-7575.rs:70:7
6262
|
6363
LL | t.is_str()
64-
| --^^^^^^--
65-
| | |
66-
| | this is an associated function, not a method
67-
| help: disambiguate the associated function for the candidate: `ManyImplTrait::is_str(t)`
64+
| ^^^^^^ this is an associated function, not a method
6865
|
6966
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
7067
note: the candidate is defined in the trait `ManyImplTrait`
@@ -73,6 +70,10 @@ note: the candidate is defined in the trait `ManyImplTrait`
7370
LL | fn is_str() -> bool {
7471
| ^^^^^^^^^^^^^^^^^^^
7572
= help: items from traits can only be used if the type parameter is bounded by the trait
73+
help: disambiguate the associated function for the candidate
74+
|
75+
LL | ManyImplTrait::is_str(t)
76+
|
7677

7778
error: aborting due to 3 previous errors
7879

0 commit comments

Comments
 (0)