Skip to content

Commit ce263b7

Browse files
authored
Rollup merge of #104422 - compiler-errors:fix-suggest_associated_call_syntax, r=BoxyUwU
Fix suggest associated call syntax Fixes #104412
2 parents 5e753ca + 540e12f commit ce263b7

File tree

6 files changed

+239
-145
lines changed

6 files changed

+239
-145
lines changed

compiler/rustc_hir_typeck/src/method/suggest.rs

+171-145
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fn main() {
2+
1_u32.MAX();
3+
//~^ ERROR no method named `MAX` found for type `u32` in the current scope
4+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0599]: no method named `MAX` found for type `u32` in the current scope
2+
--> $DIR/dont-suggest-ufcs-for-const.rs:2:11
3+
|
4+
LL | 1_u32.MAX();
5+
| ------^^^--
6+
| | |
7+
| | this is an associated function, not a method
8+
| help: use associated function syntax instead: `u32::MAX()`
9+
|
10+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
11+
= note: the candidate is defined in an impl for the type `u32`
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0599`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-rustfix
2+
3+
#![allow(unused)]
4+
5+
struct Foo<T>(T);
6+
7+
impl<T> Foo<T> {
8+
fn test() -> i32 { 1 }
9+
}
10+
11+
fn main() {
12+
let x = Box::new(Foo(1i32));
13+
Foo::<i32>::test();
14+
//~^ ERROR no method named `test` found for struct `Box<Foo<i32>>` in the current scope
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-rustfix
2+
3+
#![allow(unused)]
4+
5+
struct Foo<T>(T);
6+
7+
impl<T> Foo<T> {
8+
fn test() -> i32 { 1 }
9+
}
10+
11+
fn main() {
12+
let x = Box::new(Foo(1i32));
13+
x.test();
14+
//~^ ERROR no method named `test` found for struct `Box<Foo<i32>>` in the current scope
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
error[E0599]: no method named `test` found for struct `Box<Foo<i32>>` in the current scope
2+
--> $DIR/suggest-assoc-fn-call-deref.rs:13:7
3+
|
4+
LL | x.test();
5+
| --^^^^--
6+
| | |
7+
| | this is an associated function, not a method
8+
| help: use associated function syntax instead: `Foo::<i32>::test()`
9+
|
10+
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
11+
note: the candidate is defined in an impl for the type `Foo<T>`
12+
--> $DIR/suggest-assoc-fn-call-deref.rs:8:5
13+
|
14+
LL | fn test() -> i32 { 1 }
15+
| ^^^^^^^^^^^^^^^^
16+
17+
error: aborting due to previous error
18+
19+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)