Skip to content

Help message: use . instead of :: when accessing a method of an object #101749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
m-spitfire opened this issue Sep 13, 2022 · 1 comment · Fixed by #101975
Closed

Help message: use . instead of :: when accessing a method of an object #101749

m-spitfire opened this issue Sep 13, 2022 · 1 comment · Fixed by #101975
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@m-spitfire
Copy link

m-spitfire commented Sep 13, 2022

Given the following code: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=d70350eea1ed1dc1dc3a75226a71c8ea

struct Rectangle {
    width: i32,
    height: i32,
}
impl Rectangle {
    fn new(width: i32, height: i32) -> Self {
        Self { width, height }
    }
    fn area(&self) -> i32 {
        self.height * self.width
    }
}

fn main() {
    let width = 3;
    let height = 4;
    let rect1 = Rectangle::new(width, height);
    println!("{}", rect1::area());
}

The current output is:

Compiling playground v0.0.1 (/playground)
error[[E0433]](https://doc.rust-lang.org/stable/error-index.html#E0433): failed to resolve: use of undeclared crate or module `rect1`
  --> src/main.rs:18:20
   |
18 |     println!("{}", rect1::area());
   |                    ^^^^^ use of undeclared crate or module `rect1`

For more information about this error, try `rustc --explain E0433`.
error: could not compile `playground` due to previous error

Ideally the output should look like(additionally):

help: use .area() instead of ::area() when accessing method of an object

The output is the same in nightly too.

@m-spitfire m-spitfire added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 13, 2022
@chenyukang
Copy link
Member

@rustbot claim

chenyukang added a commit to chenyukang/rust that referenced this issue Sep 17, 2022
chenyukang added a commit to chenyukang/rust that referenced this issue Oct 28, 2022
chenyukang added a commit to chenyukang/rust that referenced this issue Nov 20, 2022
chenyukang added a commit to chenyukang/rust that referenced this issue Nov 22, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 4, 2022
…errors

Suggest to use . instead of :: when accessing a method of an object

Fixes rust-lang#101749
Fixes rust-lang#101542
@bors bors closed this as completed in fb004e9 Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants