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

Conversation

frewsxcv
Copy link
Member

TRPL seems to refer to 'static functions' as 'associated functions'.
This terminology should be used consistently.

@steveklabnik
Copy link
Member

We're actually still trying to figure out the proper terminology here.

/cc @aturon @nikomatsakis

@alexcrichton
Copy link
Member

r? @steveklabnik

@nikomatsakis
Copy link
Contributor

The tricky part is that I see methods as a subset of all associated functions. Perhaps we should phrase it like "found the following associated functions that do not define a self parameter; to be used as methods, functions must have a self (or &self, etc) parameter"

@frewsxcv
Copy link
Member Author

The tricky part is that I see methods as a subset of all associated functions.

Agreed.

Perhaps we should phrase it like "found the following associated functions that do not define a self parameter; to be used as methods, functions must have a self (or &self, etc) parameter"

Although verbose, I like this. I'll wait for other opinions before making any changes.

@aturon
Copy link
Member

aturon commented Feb 23, 2016

Strong 👍 on @nikomatsakis's suggested message and terminology.

@steveklabnik
Copy link
Member

The tricky part is that I see methods as a subset of all associated functions.

Agreed, for sure. 👍 for that wording of the diagnostic.

I'm not sure that "associated functions without self" rolls off the tongue the same way "static method" does, in terms of talking about this in other places. But that's a discussion for other places...

@aturon
Copy link
Member

aturon commented Feb 23, 2016

Hm, maybe a better way to think about it is just that methods are methods, and other fns are associated functions.

The idea with the "associated foo" terminology originally is that the "main" thing the trait is being applied to is the Self type, and items in the trait itself are just items "associated with" that Self type. But I'm not sure if there's any fundamental reason to view things this way, versus (say) taking both Self and its methods as the "core" parts of a trait, and all other items as "associated". It makes a certain amount of sense, given that methods are "inherent" parts of a type and directly hooked into it via the . notation.

@nikomatsakis, thoughts?

@arielb1
Copy link
Contributor

arielb1 commented Feb 23, 2016

@aturon

Trait methods are associated items. They behave like associated constants and types in all relevant ways. They can be accessed using UFCS (= associated item notation). They dispatch through an impl.

Inherent methods are a bit weird, because they behave like associated items in some respects (they are accessible via UFCS + method lookup if not static), but they don't have the trait dispatch thing

Unlike associated types/constants, methods can also be used with method lookup. But that sounds to me like an "extra feature". The range structs can be used in range expressions, but they are still structs.

Certainly static methods behave exactly like methods in every way expect for being accessible through method lookup.

@steveklabnik
Copy link
Member

UFCS (= associated item notation)

Oh my, did we just find a solution to the other Great Naming Bikeshed? :)

@frewsxcv frewsxcv force-pushed the assoc-func branch 2 times, most recently from ff547fa to f41dfec Compare February 24, 2016 03:31
@frewsxcv
Copy link
Member Author

Updated the suggestion text. I shortened @nikomatsakis's suggestion a bit, so make sure to reread it. If people are unhappy, I can just use Niko's full text they suggested.

@@ -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

@frewsxcv
Copy link
Member Author

Anyone here have thoughts?

@aturon
Copy link
Member

aturon commented Mar 7, 2016

@frewsxcv Apologies for the delay. This change to the message looks good to me, and I'm going to go ahead and approve it. Thanks for the PR!

@bors: r+ rollup

@bors
Copy link
Collaborator

bors commented Mar 7, 2016

📌 Commit f41dfec has been approved by aturon

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Mar 8, 2016
Prefer 'associated function' over 'static method' in msg.

TRPL seems to refer to 'static functions' as 'associated functions'.
This terminology should be used consistently.
@steveklabnik
Copy link
Member

@bors: r-

this failed tidy.

@frewsxcv
Copy link
Member Author

frewsxcv commented Mar 8, 2016

this failed tidy.

Latest force push includes wrapped long lines.

@steveklabnik
Copy link
Member

Now we're on to legitimate test failures 😄

TRPL seems to refer to 'static functions' as 'associated functions'.
This terminology should be used consistently.
@frewsxcv
Copy link
Member Author

Should be okay now

@steveklabnik
Copy link
Member

@bors: r+ rollup

😄

@bors
Copy link
Collaborator

bors commented Mar 10, 2016

📌 Commit d9dba76 has been approved by steveklabnik

steveklabnik added a commit to steveklabnik/rust that referenced this pull request Mar 10, 2016
Prefer 'associated function' over 'static method' in msg.

TRPL seems to refer to 'static functions' as 'associated functions'.
This terminology should be used consistently.
steveklabnik added a commit to steveklabnik/rust that referenced this pull request Mar 10, 2016
Prefer 'associated function' over 'static method' in msg.

TRPL seems to refer to 'static functions' as 'associated functions'.
This terminology should be used consistently.
bors added a commit that referenced this pull request Mar 10, 2016
Rollup of 8 pull requests

- Successful merges: #31830, #32091, #32125, #32136, #32147, #32148, #32149, #32150
- Failed merges:
@bors bors merged commit d9dba76 into rust-lang:master Mar 10, 2016
@frewsxcv frewsxcv deleted the assoc-func branch March 10, 2016 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants