Skip to content

Prefer 'associated function' over 'static method' in msg. #31830

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

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/librustc_typeck/check/method/suggest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
if !static_sources.is_empty() {
err.fileline_note(
span,
"found defined static methods, maybe a `self` is missing?");
"found the following associated functions; to be used as \
methods, functions must have a `self` parameter");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to go with the "methods are associated functions" story, I can update this to be:

...to be used as methods, associated functions must have a self parameter


report_candidates(fcx, &mut err, span, item_name, static_sources);
}
Expand Down
7 changes: 4 additions & 3 deletions src/test/compile-fail/issue-7575.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
// except according to those terms.

// Test the mechanism for warning about possible missing `self` declarations.
// ignore-tidy-linelength

trait CtxtFn {
fn f8(self, usize) -> usize;
Expand Down Expand Up @@ -72,15 +73,15 @@ impl ManyImplTrait for Myisize {}
fn no_param_bound(u: usize, m: Myisize) -> usize {
u.f8(42) + u.f9(342) + m.fff(42)
//~^ ERROR no method named `f9` found for type `usize` in the current scope
//~^^ NOTE found defined static methods, maybe a `self` is missing?
//~^^ NOTE found the following associated functions; to be used as methods, functions must have a `self` parameter
//~^^^ ERROR no method named `fff` found for type `Myisize` in the current scope
//~^^^^ NOTE found defined static methods, maybe a `self` is missing?
//~^^^^ NOTE found the following associated functions; to be used as methods, functions must have a `self` parameter
}

fn param_bound<T: ManyImplTrait>(t: T) -> bool {
t.is_str()
//~^ ERROR no method named `is_str` found for type `T` in the current scope
//~^^ NOTE found defined static methods, maybe a `self` is missing?
//~^^ NOTE found the following associated functions; to be used as methods, functions must have a `self` parameter
}

fn main() {
Expand Down