Code
struct SomeStruct;
impl SomeStruct {
fn some_fn(&some_name) {
self
}
}
fn main() {}
Current output
error[E0424]: expected value, found module `self`
--> src/main.rs:5:9
|
4 | fn some_fn(&some_name) {
| ------- this function doesn't have a `self` parameter
5 | self
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
help: add a `self` receiver parameter to make the associated `fn` a method
|
4 | fn some_fn(&&self, some_name) {
| ++++++
For more information about this error, try `rustc --explain E0424`.
Desired output
error[E0424]: expected value, found module `self`
--> src/main.rs:5:9
|
4 | fn some_fn(&some_name) {
| ------- this function doesn't have a `self` parameter
5 | self
| ^^^^ `self` value is a keyword only available in methods with a `self` parameter
|
help: add a `self` receiver parameter to make the associated `fn` a method
|
4 | fn some_fn(self, &some_name) {
| +++++
For more information about this error, try `rustc --explain E0424`.
Rationale and extra context
Maybe the user forgot to add the self parameter in the code. Or maybe they forgot to rename some_name to self while refactoring the code. Either way, for beginners, the compiler suggesting to use &&self instead of self or &self may be confusing.
Rust Version
rustc 1.81.0 (eeb90cd 2024-09-04)
binary: rustc
commit-hash: eeb90cd
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7
Code
Current output
Desired output
Rationale and extra context
Maybe the user forgot to add the
selfparameter in the code. Or maybe they forgot to renamesome_nametoselfwhile refactoring the code. Either way, for beginners, the compiler suggesting to use&&selfinstead ofselfor&selfmay be confusing.Rust Version
rustc 1.81.0 (eeb90cd 2024-09-04)
binary: rustc
commit-hash: eeb90cd
commit-date: 2024-09-04
host: aarch64-apple-darwin
release: 1.81.0
LLVM version: 18.1.7