Skip to content

Commit f5a5f0f

Browse files
committed
use verbose for associated functions suggestion
1 parent 5f7653d commit f5a5f0f

11 files changed

+115
-77
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23392339
applicability = Applicability::HasPlaceholders;
23402340
"(...)".to_owned()
23412341
};
2342-
err.span_suggestion(
2342+
err.span_suggestion_verbose(
23432343
sugg_span,
23442344
"use associated function syntax instead",
23452345
format!("{ty_str}::{item_name}{args}"),

tests/ui/issues/issue-4265.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ LL | struct Foo {
1414
| ---------- method `bar` not found for this struct
1515
...
1616
LL | Foo { baz: 0 }.bar();
17-
| ---------------^^^--
18-
| | |
19-
| | this is an associated function, not a method
20-
| help: use associated function syntax instead: `Foo::bar()`
17+
| ^^^ this is an associated function, not a method
2118
|
2219
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
2320
note: the candidate is defined in an impl for the type `Foo`
2421
--> $DIR/issue-4265.rs:6:5
2522
|
2623
LL | fn bar() {
2724
| ^^^^^^^^
25+
help: use associated function syntax instead
26+
|
27+
LL - Foo { baz: 0 }.bar();
28+
LL + Foo::bar();
29+
|
2830

2931
error: aborting due to 2 previous errors
3032

tests/ui/methods/issue-3707.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ error[E0599]: no method named `boom` found for reference `&Obj` in the current s
22
--> $DIR/issue-3707.rs:10:14
33
|
44
LL | self.boom();
5-
| -----^^^^--
6-
| | |
7-
| | this is an associated function, not a method
8-
| help: use associated function syntax instead: `Obj::boom()`
5+
| ^^^^ this is an associated function, not a method
96
|
107
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
118
note: the candidate is defined in an impl for the type `Obj`
129
--> $DIR/issue-3707.rs:6:5
1310
|
1411
LL | pub fn boom() -> bool {
1512
| ^^^^^^^^^^^^^^^^^^^^^
13+
help: use associated function syntax instead
14+
|
15+
LL - self.boom();
16+
LL + Obj::boom();
17+
|
1618

1719
error: aborting due to 1 previous error
1820

tests/ui/suggestions/issue-102354.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ error[E0599]: no method named `func` found for type `i32` in the current scope
22
--> $DIR/issue-102354.rs:9:7
33
|
44
LL | x.func();
5-
| --^^^^--
6-
| | |
7-
| | this is an associated function, not a method
8-
| help: use associated function syntax instead: `i32::func()`
5+
| ^^^^ this is an associated function, not a method
96
|
107
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
118
note: the candidate is defined in the trait `Trait`
129
--> $DIR/issue-102354.rs:2:5
1310
|
1411
LL | fn func() {}
1512
| ^^^^^^^^^
13+
help: use associated function syntax instead
14+
|
15+
LL - x.func();
16+
LL + i32::func();
17+
|
1618

1719
error: aborting due to 1 previous error
1820

tests/ui/suggestions/issue-103646.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@ error[E0599]: no method named `nya` found for type parameter `T` in the current
44
LL | fn uwu<T: Cat>(c: T) {
55
| - method `nya` not found for this type parameter
66
LL | c.nya();
7-
| --^^^--
8-
| | |
9-
| | this is an associated function, not a method
10-
| help: use associated function syntax instead: `T::nya()`
7+
| ^^^ this is an associated function, not a method
118
|
129
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
1310
note: the candidate is defined in the trait `Cat`
1411
--> $DIR/issue-103646.rs:2:5
1512
|
1613
LL | fn nya() {}
1714
| ^^^^^^^^
15+
help: use associated function syntax instead
16+
|
17+
LL - c.nya();
18+
LL + T::nya();
19+
|
1820

1921
error: aborting due to 1 previous error
2022

tests/ui/suggestions/suggest-assoc-fn-call-deref.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ error[E0599]: no method named `test` found for struct `Box<Foo<i32>>` in the cur
22
--> $DIR/suggest-assoc-fn-call-deref.rs:13:7
33
|
44
LL | x.test();
5-
| --^^^^--
6-
| | |
7-
| | this is an associated function, not a method
8-
| help: use associated function syntax instead: `Foo::<i32>::test()`
5+
| ^^^^ this is an associated function, not a method
96
|
107
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
118
note: the candidate is defined in an impl for the type `Foo<T>`
129
--> $DIR/suggest-assoc-fn-call-deref.rs:8:5
1310
|
1411
LL | fn test() -> i32 { 1 }
1512
| ^^^^^^^^^^^^^^^^
13+
help: use associated function syntax instead
14+
|
15+
LL - x.test();
16+
LL + Foo::<i32>::test();
17+
|
1618

1719
error: aborting due to 1 previous error
1820

tests/ui/suggestions/suggest-assoc-fn-call-for-impl-trait.stderr

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ LL | struct A {
55
| -------- method `foo` not found for this struct
66
...
77
LL | _a.foo();
8-
| ---^^^--
9-
| | |
10-
| | this is an associated function, not a method
11-
| help: use associated function syntax instead: `A::foo(_a)`
8+
| ^^^ this is an associated function, not a method
129
|
1310
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
1411
note: the candidate is defined in the trait `M`
1512
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:8:5
1613
|
1714
LL | fn foo(_a: Self);
1815
| ^^^^^^^^^^^^^^^^^
16+
help: use associated function syntax instead
17+
|
18+
LL - _a.foo();
19+
LL + A::foo(_a);
20+
|
1921

2022
error[E0599]: no method named `baz` found for struct `A` in the current scope
2123
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:23:8
@@ -24,17 +26,19 @@ LL | struct A {
2426
| -------- method `baz` not found for this struct
2527
...
2628
LL | _a.baz(0);
27-
| ---^^^---
28-
| | |
29-
| | this is an associated function, not a method
30-
| help: use associated function syntax instead: `A::baz(0)`
29+
| ^^^ this is an associated function, not a method
3130
|
3231
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
3332
note: the candidate is defined in the trait `M`
3433
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:10:5
3534
|
3635
LL | fn baz(_a: i32);
3736
| ^^^^^^^^^^^^^^^^
37+
help: use associated function syntax instead
38+
|
39+
LL - _a.baz(0);
40+
LL + A::baz(0);
41+
|
3842

3943
error[E0599]: no method named `bar` found for struct `A` in the current scope
4044
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:27:8
@@ -43,17 +47,19 @@ LL | struct A {
4347
| -------- method `bar` not found for this struct
4448
...
4549
LL | _b.bar();
46-
| ---^^^--
47-
| | |
48-
| | this is an associated function, not a method
49-
| help: use associated function syntax instead: `A::bar(_b)`
50+
| ^^^ this is an associated function, not a method
5051
|
5152
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
5253
note: the candidate is defined in the trait `M`
5354
--> $DIR/suggest-assoc-fn-call-for-impl-trait.rs:9:5
5455
|
5556
LL | fn bar(_a: Self);
5657
| ^^^^^^^^^^^^^^^^^
58+
help: use associated function syntax instead
59+
|
60+
LL - _b.bar();
61+
LL + A::bar(_b);
62+
|
5763

5864
error: aborting due to 3 previous errors
5965

tests/ui/suggestions/suggest-assoc-fn-call-with-turbofish-placeholder.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ LL | struct GenericAssocMethod<T>(T);
55
| ---------------------------- method `default_hello` not found for this struct
66
...
77
LL | x.default_hello();
8-
| --^^^^^^^^^^^^^--
9-
| | |
10-
| | this is an associated function, not a method
11-
| help: use associated function syntax instead: `GenericAssocMethod::<_>::default_hello()`
8+
| ^^^^^^^^^^^^^ this is an associated function, not a method
129
|
1310
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
1411
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
1512
--> $DIR/suggest-assoc-fn-call-with-turbofish-placeholder.rs:4:5
1613
|
1714
LL | fn default_hello() {}
1815
| ^^^^^^^^^^^^^^^^^^
16+
help: use associated function syntax instead
17+
|
18+
LL - x.default_hello();
19+
LL + GenericAssocMethod::<_>::default_hello();
20+
|
1921

2022
error: aborting due to 1 previous error
2123

tests/ui/suggestions/suggest-assoc-fn-call-with-turbofish-through-deref.stderr

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@ error[E0599]: no method named `hello` found for struct `RefMut<'_, HasAssocMetho
22
--> $DIR/suggest-assoc-fn-call-with-turbofish-through-deref.rs:11:11
33
|
44
LL | state.hello();
5-
| ------^^^^^--
6-
| | |
7-
| | this is an associated function, not a method
8-
| help: use associated function syntax instead: `HasAssocMethod::hello()`
5+
| ^^^^^ this is an associated function, not a method
96
|
107
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
118
note: the candidate is defined in an impl for the type `HasAssocMethod`
129
--> $DIR/suggest-assoc-fn-call-with-turbofish-through-deref.rs:6:5
1310
|
1411
LL | fn hello() {}
1512
| ^^^^^^^^^^
13+
help: use associated function syntax instead
14+
|
15+
LL - state.hello();
16+
LL + HasAssocMethod::hello();
17+
|
1618

1719
error: aborting due to 1 previous error
1820

tests/ui/suggestions/suggest-assoc-fn-call-with-turbofish.stderr

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ LL | struct GenericAssocMethod<T>(T);
55
| ---------------------------- method `self_ty_ref_hello` not found for this struct
66
...
77
LL | x.self_ty_ref_hello();
8-
| --^^^^^^^^^^^^^^^^^--
9-
| | |
10-
| | this is an associated function, not a method
11-
| help: use associated function syntax instead: `GenericAssocMethod::<_>::self_ty_ref_hello(&x)`
8+
| ^^^^^^^^^^^^^^^^^ this is an associated function, not a method
129
|
1310
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
1411
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
1512
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:8:5
1613
|
1714
LL | fn self_ty_ref_hello(_: &Self) {}
1815
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
help: use associated function syntax instead
17+
|
18+
LL - x.self_ty_ref_hello();
19+
LL + GenericAssocMethod::<_>::self_ty_ref_hello(&x);
20+
|
1921

2022
error[E0599]: no method named `self_ty_hello` found for struct `GenericAssocMethod<{integer}>` in the current scope
2123
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:16:7
@@ -24,17 +26,19 @@ LL | struct GenericAssocMethod<T>(T);
2426
| ---------------------------- method `self_ty_hello` not found for this struct
2527
...
2628
LL | x.self_ty_hello();
27-
| --^^^^^^^^^^^^^--
28-
| | |
29-
| | this is an associated function, not a method
30-
| help: use associated function syntax instead: `GenericAssocMethod::<_>::self_ty_hello(x)`
29+
| ^^^^^^^^^^^^^ this is an associated function, not a method
3130
|
3231
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
3332
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
3433
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:7:5
3534
|
3635
LL | fn self_ty_hello(_: Self) {}
3736
| ^^^^^^^^^^^^^^^^^^^^^^^^^
37+
help: use associated function syntax instead
38+
|
39+
LL - x.self_ty_hello();
40+
LL + GenericAssocMethod::<_>::self_ty_hello(x);
41+
|
3842

3943
error[E0599]: no method named `default_hello` found for struct `GenericAssocMethod<i32>` in the current scope
4044
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:20:7
@@ -43,17 +47,19 @@ LL | struct GenericAssocMethod<T>(T);
4347
| ---------------------------- method `default_hello` not found for this struct
4448
...
4549
LL | y.default_hello();
46-
| --^^^^^^^^^^^^^--
47-
| | |
48-
| | this is an associated function, not a method
49-
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::default_hello()`
50+
| ^^^^^^^^^^^^^ this is an associated function, not a method
5051
|
5152
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
5253
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
5354
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:6:5
5455
|
5556
LL | fn default_hello() {}
5657
| ^^^^^^^^^^^^^^^^^^
58+
help: use associated function syntax instead
59+
|
60+
LL - y.default_hello();
61+
LL + GenericAssocMethod::<i32>::default_hello();
62+
|
5763

5864
error[E0599]: no method named `self_ty_ref_hello` found for struct `GenericAssocMethod<i32>` in the current scope
5965
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:22:7
@@ -62,17 +68,19 @@ LL | struct GenericAssocMethod<T>(T);
6268
| ---------------------------- method `self_ty_ref_hello` not found for this struct
6369
...
6470
LL | y.self_ty_ref_hello();
65-
| --^^^^^^^^^^^^^^^^^--
66-
| | |
67-
| | this is an associated function, not a method
68-
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::self_ty_ref_hello(&y)`
71+
| ^^^^^^^^^^^^^^^^^ this is an associated function, not a method
6972
|
7073
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
7174
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
7275
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:8:5
7376
|
7477
LL | fn self_ty_ref_hello(_: &Self) {}
7578
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
79+
help: use associated function syntax instead
80+
|
81+
LL - y.self_ty_ref_hello();
82+
LL + GenericAssocMethod::<i32>::self_ty_ref_hello(&y);
83+
|
7684

7785
error[E0599]: no method named `self_ty_hello` found for struct `GenericAssocMethod<i32>` in the current scope
7886
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:24:7
@@ -81,17 +89,19 @@ LL | struct GenericAssocMethod<T>(T);
8189
| ---------------------------- method `self_ty_hello` not found for this struct
8290
...
8391
LL | y.self_ty_hello();
84-
| --^^^^^^^^^^^^^--
85-
| | |
86-
| | this is an associated function, not a method
87-
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::self_ty_hello(y)`
92+
| ^^^^^^^^^^^^^ this is an associated function, not a method
8893
|
8994
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
9095
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
9196
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:7:5
9297
|
9398
LL | fn self_ty_hello(_: Self) {}
9499
| ^^^^^^^^^^^^^^^^^^^^^^^^^
100+
help: use associated function syntax instead
101+
|
102+
LL - y.self_ty_hello();
103+
LL + GenericAssocMethod::<i32>::self_ty_hello(y);
104+
|
95105

96106
error: aborting due to 5 previous errors
97107

0 commit comments

Comments
 (0)