Skip to content
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

Implementations improvements part 1 #146

Merged
merged 5 commits into from
Dec 8, 2017
Merged

Conversation

Havvy
Copy link
Contributor

@Havvy Havvy commented Oct 26, 2017

Trying to not focus on what it means to associate a type, nor deal
too much with generic impls at this point. Those will come in future parts.

Right now everything about associated types are defined in items/traits.md. I didn't touch that here.

Fixes #5. Albeit, I'm not a fan of the wording which I just pulled directly from the RFC.

cc @scottmcm for review.

| &mut T
| Box<T>
| (..., T, ...)
| X<..., T, ...> where X is not bivariant with respect to T
Copy link
Contributor

Choose a reason for hiding this comment

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

Just C, &T, &mut T and Box<T>.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was changed from the RFC then? I was wondering how (..., T, ...) would have worked...

The nominal type is called the *implementing type* and the associable items are
the *associated items* to the implementing type.

Bare implementations associates the associated items to the implementing type.
Copy link
Contributor

Choose a reason for hiding this comment

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

'associate'


sequence of 'impl' keyword, generic type declarations, nominal type, where clause and the associable items. Generic type declarations and where clause can be omitted, if not needed. The associable items are contained within braces.

A bare implementation is defined as the sequence of the `impl` keyword, generic
Copy link
Contributor

Choose a reason for hiding this comment

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

Repeated text.

src/glossary.md Outdated
@@ -8,14 +8,21 @@ the structure of the program when the compiler is compiling it.
### Arity

Arity refers to the number of arguments a function or operation takes.
For example, `(2, 3)` and `(4, 6)` have arity 2, and`(8, 2, 6)` has arity 3.
For example, `f(2, 3)` and `g(4, 6)` have arity 2, while `h(8, 2, 6)` has arity 3.
Copy link
Member

Choose a reason for hiding this comment

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

Having an example that's an operation (not a function) might be good, maybe 4 + 6.

src/glossary.md Outdated

An associated item is an item that is associated with another item. Associated
items are defined in [implementations] and [traits]. Only functions, constants,
and types can be associated.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, are types associated, or are type aliases associated? You can't put an enum Foo {} in an impl to satisfy a type Foo; in the trait, right?

Is it worth distinguishing between associated items are "declared in traits" and "defined in impls"? The declared/defined words are used in trait impls below.

Bare implementations associate the associated items to the implementing type.

The associated item has a path of a path to the implementing type followed by
the associate item's path component.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe note that a bare impl cannot have associated type( aliase)s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 I had told myself to do that a million times, yet I did not do it.

Copy link
Member

Choose a reason for hiding this comment

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

(review note, this is resolved below)

src/glossary.md Outdated
### Nominal Types

Types that can be named directly. Specifically [enums], [structs], [unions],
and [trait objects].
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth saying that "named" is "referred to by a path", or similar?

Perhaps also add Structural Types, and a cross-ref between them for contrast?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Worth doing, but in its own PR.

set of associable items.

The nominal type is called the *implementing type* and the associable items are
the *associated items* to the implementing type.
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, libcore has impl<T> [T] {, where that slice isn't a nominal type. Users cannot define structural types, though, so they can't do something like that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That definitely seems like a special case. Not entirely sure how to document that without messing up the flow for everything else.

Copy link
Member

@steveklabnik steveklabnik left a comment

Choose a reason for hiding this comment

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

This is generally good, but one question about naming!


### Array

An array, sometimes also called a fixed-size array or an inline array, is a value
describing a collection of elements, each selected by an index that can be computed
at run time by the program. It occupies a contiguous region of memory.

### Associated Item

An associated item is an item that is associated with another item. Associated
Copy link
Member

Choose a reason for hiding this comment

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

I'm okay with merging this, but this definition is a bit circular; we should figure out a better way to describe this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll do this as a part of Part 2.


Implementations are defined with the keyword `impl`.

## Bare Implementations
Copy link
Member

Choose a reason for hiding this comment

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

Aren't these called "inherent implementations"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've seen them called both. Inherent is probably a better name though. Will fix tonight.

Bare implementations associate the associated items to the implementing type.

The associated item has a path of a path to the implementing type followed by
the associate item's path component.
Copy link
Member

Choose a reason for hiding this comment

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

(review note, this is resolved below)

@steveklabnik steveklabnik merged commit 13f02d1 into rust-lang:master Dec 8, 2017
@steveklabnik
Copy link
Member

Thanks!

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.

4 participants