Skip to content

Check for static methods of the same name when calling an non-existent method #11627

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
huonw opened this issue Jan 17, 2014 · 1 comment
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints

Comments

@huonw
Copy link
Member

huonw commented Jan 17, 2014

e.g.

struct Foo;
impl Foo {
    fn function() {}
}

fn main() {
    Foo.function();
}

The error, "Foo does not implement any method in scope named function", could have a note "maybe you meant to call the non-method Foo::function(...)".

@alexcrichton
Copy link
Member

Closed by cb08cb8

foo.rs:7:9: 7:19 error: type `Foo` does not implement any method in scope named `function`
foo.rs:7     Foo.function();
                 ^~~~~~~~~~
foo.rs:7:19: 7:19 note: found defined static methods, maybe a `self` is missing?
foo.rs:3:5: 3:21 note: candidate #1 is `Foo::function`
foo.rs:3     fn function() {}
             ^~~~~~~~~~~~~~~~
error: aborting due to previous error

Thanks @Ryman!

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 1, 2023
[`needless_return_with_question_mark`]: don't lint if never type is used for coercion

Fixes rust-lang#11616

When we have something like
```rs
let _x: String = {
  return Err(())?;
};
```
we shouldn't suggest removing the `return` because the `!`-ness of `return` is used to coerce the enclosing block to some other type. That will lead to a typeck error without a diverging expression like `return`.

changelog: [`needless_return_with_question_mark`]: don't lint if `return`s never typed-ness is used for coercion
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
Projects
None yet
Development

No branches or pull requests

2 participants