Auto merge of #101990 - clubby789:dont-machine-apply-placeholder-method, r=compiler-errors
Fix auto-application of associated generic functions with placeholders Fixes #101920
This commit is contained in:
commit
5eef9b2c50
12 changed files with 286 additions and 35 deletions
|
|
@ -2,10 +2,10 @@ error[E0599]: no method named `boom` found for reference `&Obj` in the current s
|
|||
--> $DIR/issue-3707.rs:10:14
|
||||
|
|
||||
LL | self.boom();
|
||||
| -----^^^^
|
||||
| -----^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `Obj::boom`
|
||||
| help: use associated function syntax instead: `Obj::boom()`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `Obj`
|
||||
|
|
|
|||
|
|
@ -22,5 +22,5 @@ fn main() {
|
|||
let item = std::mem::MaybeUninit::new(Struct { p: 42_u32 });
|
||||
item.method();
|
||||
//~^ ERROR no method named `method` found for union `MaybeUninit` in the current scope [E0599]
|
||||
//~| HELP if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
|
||||
//~| HELP if this `MaybeUninit<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ error[E0599]: no method named `method` found for union `MaybeUninit` in the curr
|
|||
LL | item.method();
|
||||
| ^^^^^^ method not found in `MaybeUninit<Struct<u32>>`
|
||||
|
|
||||
= help: if this `MaybeUninit::<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
|
||||
= help: if this `MaybeUninit<Struct<u32>>` has been initialized, use one of the `assume_init` methods to access the inner value
|
||||
note: the method `method` exists on the type `Struct<u32>`
|
||||
--> $DIR/inner_type2.rs:6:5
|
||||
|
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ LL | fn func() {}
|
|||
help: use associated function syntax instead
|
||||
|
|
||||
LL | i32::func();
|
||||
| ~~~~~~~~~
|
||||
| ~~~~~~~~~~~
|
||||
help: disambiguate the associated function for the candidate
|
||||
|
|
||||
LL | <i32 as Trait>::func(x);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,11 @@
|
|||
struct GenericAssocMethod<T>(T);
|
||||
|
||||
impl<T> GenericAssocMethod<T> {
|
||||
fn default_hello() {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = GenericAssocMethod(33);
|
||||
x.default_hello();
|
||||
//~^ ERROR no method named `default_hello` found
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
error[E0599]: no method named `default_hello` found for struct `GenericAssocMethod<{integer}>` in the current scope
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish-placeholder.rs:9:7
|
||||
|
|
||||
LL | struct GenericAssocMethod<T>(T);
|
||||
| ---------------------------- method `default_hello` not found for this struct
|
||||
...
|
||||
LL | x.default_hello();
|
||||
| --^^^^^^^^^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<_>::default_hello()`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish-placeholder.rs:4:5
|
||||
|
|
||||
LL | fn default_hello() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
|
|
@ -2,10 +2,10 @@ error[E0599]: no method named `hello` found for struct `RefMut<'_, HasAssocMetho
|
|||
--> $DIR/suggest-assoc-fn-call-with-turbofish-through-deref.rs:11:11
|
||||
|
|
||||
LL | state.hello();
|
||||
| ------^^^^^
|
||||
| ------^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `HasAssocMethod::hello`
|
||||
| help: use associated function syntax instead: `HasAssocMethod::hello()`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `HasAssocMethod`
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
// run-rustfix
|
||||
|
||||
struct GenericAssocMethod<T>(T);
|
||||
|
||||
impl<T> GenericAssocMethod<T> {
|
||||
fn default_hello() {}
|
||||
fn self_ty_hello(_: Self) {}
|
||||
fn self_ty_ref_hello(_: &Self) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// Test for inferred types
|
||||
let x = GenericAssocMethod(33);
|
||||
GenericAssocMethod::<_>::self_ty_ref_hello(&x);
|
||||
//~^ ERROR no method named `self_ty_ref_hello` found
|
||||
GenericAssocMethod::<_>::self_ty_hello(x);
|
||||
//~^ ERROR no method named `self_ty_hello` found
|
||||
// Test for known types
|
||||
let y = GenericAssocMethod(33i32);
|
||||
GenericAssocMethod::<i32>::default_hello();
|
||||
//~^ ERROR no method named `default_hello` found
|
||||
GenericAssocMethod::<i32>::self_ty_ref_hello(&y);
|
||||
//~^ ERROR no method named `self_ty_ref_hello` found
|
||||
GenericAssocMethod::<i32>::self_ty_hello(y);
|
||||
//~^ ERROR no method named `self_ty_hello` found
|
||||
}
|
||||
|
|
@ -1,11 +1,26 @@
|
|||
// run-rustfix
|
||||
|
||||
struct GenericAssocMethod<T>(T);
|
||||
|
||||
impl<T> GenericAssocMethod<T> {
|
||||
fn default_hello() {}
|
||||
fn self_ty_hello(_: Self) {}
|
||||
fn self_ty_ref_hello(_: &Self) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = GenericAssocMethod(33i32);
|
||||
x.default_hello();
|
||||
// Test for inferred types
|
||||
let x = GenericAssocMethod(33);
|
||||
x.self_ty_ref_hello();
|
||||
//~^ ERROR no method named `self_ty_ref_hello` found
|
||||
x.self_ty_hello();
|
||||
//~^ ERROR no method named `self_ty_hello` found
|
||||
// Test for known types
|
||||
let y = GenericAssocMethod(33i32);
|
||||
y.default_hello();
|
||||
//~^ ERROR no method named `default_hello` found
|
||||
y.self_ty_ref_hello();
|
||||
//~^ ERROR no method named `self_ty_ref_hello` found
|
||||
y.self_ty_hello();
|
||||
//~^ ERROR no method named `self_ty_hello` found
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,22 +1,98 @@
|
|||
error[E0599]: no method named `self_ty_ref_hello` found for struct `GenericAssocMethod<{integer}>` in the current scope
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:14:7
|
||||
|
|
||||
LL | struct GenericAssocMethod<T>(T);
|
||||
| ---------------------------- method `self_ty_ref_hello` not found for this struct
|
||||
...
|
||||
LL | x.self_ty_ref_hello();
|
||||
| --^^^^^^^^^^^^^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<_>::self_ty_ref_hello(&x)`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:8:5
|
||||
|
|
||||
LL | fn self_ty_ref_hello(_: &Self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0599]: no method named `self_ty_hello` found for struct `GenericAssocMethod<{integer}>` in the current scope
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:16:7
|
||||
|
|
||||
LL | struct GenericAssocMethod<T>(T);
|
||||
| ---------------------------- method `self_ty_hello` not found for this struct
|
||||
...
|
||||
LL | x.self_ty_hello();
|
||||
| --^^^^^^^^^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<_>::self_ty_hello(x)`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:7:5
|
||||
|
|
||||
LL | fn self_ty_hello(_: Self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0599]: no method named `default_hello` found for struct `GenericAssocMethod<i32>` in the current scope
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:9:7
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:20:7
|
||||
|
|
||||
LL | struct GenericAssocMethod<T>(T);
|
||||
| ---------------------------- method `default_hello` not found for this struct
|
||||
...
|
||||
LL | x.default_hello();
|
||||
| --^^^^^^^^^^^^^
|
||||
LL | y.default_hello();
|
||||
| --^^^^^^^^^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::default_hello`
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::default_hello()`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:4:5
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:6:5
|
||||
|
|
||||
LL | fn default_hello() {}
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
error[E0599]: no method named `self_ty_ref_hello` found for struct `GenericAssocMethod<i32>` in the current scope
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:22:7
|
||||
|
|
||||
LL | struct GenericAssocMethod<T>(T);
|
||||
| ---------------------------- method `self_ty_ref_hello` not found for this struct
|
||||
...
|
||||
LL | y.self_ty_ref_hello();
|
||||
| --^^^^^^^^^^^^^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::self_ty_ref_hello(&y)`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:8:5
|
||||
|
|
||||
LL | fn self_ty_ref_hello(_: &Self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0599]: no method named `self_ty_hello` found for struct `GenericAssocMethod<i32>` in the current scope
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:24:7
|
||||
|
|
||||
LL | struct GenericAssocMethod<T>(T);
|
||||
| ---------------------------- method `self_ty_hello` not found for this struct
|
||||
...
|
||||
LL | y.self_ty_hello();
|
||||
| --^^^^^^^^^^^^^--
|
||||
| | |
|
||||
| | this is an associated function, not a method
|
||||
| help: use associated function syntax instead: `GenericAssocMethod::<i32>::self_ty_hello(y)`
|
||||
|
|
||||
= note: found the following associated functions; to be used as methods, functions must have a `self` parameter
|
||||
note: the candidate is defined in an impl for the type `GenericAssocMethod<T>`
|
||||
--> $DIR/suggest-assoc-fn-call-with-turbofish.rs:7:5
|
||||
|
|
||||
LL | fn self_ty_hello(_: Self) {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue