Skip to content

Beef up Copy documentation #21261

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
wants to merge 1 commit into from
Closed

Conversation

steveklabnik
Copy link
Member

@rust-highfive
Copy link
Contributor

r? @pcwalton

(rust_highfive has picked a reviewer for you, use r? to override)

///
/// ```
/// struct MyStruct;
/// impl Copy for MyStruct;
Copy link
Member

Choose a reason for hiding this comment

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

I think this impl will need braces after it

Copy link
Member Author

Choose a reason for hiding this comment

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

The tests do pass...

Copy link
Member

Choose a reason for hiding this comment

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

Weird...

struct Foo;
impl Copy for Foo;
foo.rs:3:18: 3:19 error: expected one of `(`, `+`, `::`, or `{`, found `;`
foo.rs:3 impl Copy for Foo;
                          ^

@alexcrichton
Copy link
Member

r=me with doc fix

///
/// ```
/// struct MyStruct;
/// impl Copy for MyStruct {};
Copy link
Member

Choose a reason for hiding this comment

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

I think this semicolon will still need to be removed :(

@steveklabnik
Copy link
Member Author

I fixed the semicolon. @kmcallister what do you think is the right full explanation for Drop?

@steveklabnik
Copy link
Member Author

Okay, I think this is good now. One more review?

@kmcallister
Copy link
Contributor

Looks great!

/// ## When should my type be `Copy`?
///
/// Generally speaking, if your type _can_ implement `Copy`, it should. There's one important thing
/// to consider though: if you think your type may _not_ be able to implement `Copy` in the future,
Copy link
Contributor

Choose a reason for hiding this comment

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

Might also want to mention that it is sometimes useful to have types with no Drop impl but which shouldn't be Copy because they represent some kind of unique logical token or otherwise require more than just a bitwise copy to semantically copy them.

@huonw
Copy link
Member

huonw commented Jan 17, 2015

I've found success phrasing copy vs. move in terms of using values by-value, and "byte copies" and "semantic copies" and generally trying to divorce the two uses of the word "copy" because this overloading confuses people a lot.

Clone is always a semantic copy, and a by-value use is always a byte copy. There are some types for which a byte copy is also a semantic copy (indicated by implementing Copy) and other types for which it is not; the latter must move to ensure safety. cc http://stackoverflow.com/a/24253573/1256624 (written before opt-in built-ins, but the content is still correct)

bors added a commit that referenced this pull request Jan 17, 2015
Beef up Copy documentation

Reviewed-by: alexcrichton
bors added a commit that referenced this pull request Jan 17, 2015
Beef up Copy documentation

Reviewed-by: alexcrichton
@steveklabnik
Copy link
Member Author

Doing this manually as part of #21300

@steveklabnik steveklabnik deleted the gh21249 branch October 25, 2017 18:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
7 participants