Skip to content

Grammar: Functions, methods, impl, traits, extern. #430

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 5 commits into from
Oct 3, 2018

Conversation

ehuss
Copy link
Contributor

@ehuss ehuss commented Sep 23, 2018

These all are intertwined with the "function" definition. Updates grammar for:

  • Functions and methods
  • Extern blocks
  • Implementation
  • Traits

@ehuss
Copy link
Contributor Author

ehuss commented Sep 24, 2018

Question: Would it be clearer if Method was split into two (Method | Function) and make Method something that strictly has a self parameter? I'm thinking it would be clearer.
EDIT: Although it could be complicated in the future due to arbitrary_self_types.

Also, I missed the 2015/2018 difference of trait functions taking optional named parameters. I'm thinking of documenting the 2015 behavior with a dagger (or something) that links to the section that describes that it is no longer allowed. Thoughts?

@ehuss ehuss mentioned this pull request Sep 25, 2018
Copy link
Contributor

@matthewjasper matthewjasper left a comment

Choose a reason for hiding this comment

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

This looks great, left a few small comments

> _BlockWithInnerAttributes_ :\
>    `{`\
> &nbsp;&nbsp; &nbsp;&nbsp; [_InnerAttribute_]<sup>\*</sup>\
> &nbsp;&nbsp; &nbsp;&nbsp; [_Statement_]<sup>\*</sup>\
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing an optional expression

@@ -115,6 +135,23 @@ let circle = Box::new(circle) as Box<dyn Circle>;
let nonsense = circle.radius() * circle.area();
```

## Unsafe traits

Traits that begin with the `unsafe` keyword indicate that *implementing* the
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this would be clearer as "Trait items that..."


Traits that begin with the `unsafe` keyword indicate that *implementing* the
trait may be [unsafe]. It is safe to use a correctly implemented unsafe trait.
The [trait implementation] must also include the `unsafe` keyword.
Copy link
Contributor

Choose a reason for hiding this comment

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

"include" should be "start with" or "begin with"

@matthewjasper
Copy link
Contributor

Question: Would it be clearer if Method was split into two (Method | Function) and make Method something that strictly has a self parameter? I'm thinking it would be clearer.
EDIT: Although it could be complicated in the future due to arbitrary_self_types.

I'm not sure how arbitrary self types changes anything here. It would probably be slightly better for methods to only include things with self parameters, since I think it is the more common meaning in Rust.

@ehuss
Copy link
Contributor Author

ehuss commented Oct 1, 2018

Thanks for taking a look. I've done some updates to fix a bunch of things and specify functions and methods separately. I added some detail about pattern limitations for parameters.

ehuss added 5 commits October 1, 2018 19:46
These all are intertwined with the "function" definition. Updates grammar for:
- Functions and methods
- Extern blocks
- Implementation
- Traits
- Review comments.
- Separate Function and Method in impl.
- Move _Method_ grammar to the section discussing methods.
- Be a little more explicit about `self` types.
- Fix block ending with expression for functions.
- Fix extern blocks not supporting patterns.
- Fix trait functions/methods having optional patterns, and the pattern restrictions.
@ehuss ehuss force-pushed the grammar-fn-stuff branch from d0bb7a7 to 028fd75 Compare October 2, 2018 03:02
@ehuss
Copy link
Contributor Author

ehuss commented Oct 2, 2018

I attempted to explain the 2018 edition changes for trait parameter patterns.

@matthewjasper
Copy link
Contributor

Thanks!

@matthewjasper matthewjasper merged commit ac6a74f into rust-lang:master Oct 3, 2018
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.

2 participants