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

Allow built-in traits implementation and add support for deriving #13868

Merged
merged 2 commits into from
May 3, 2014

Conversation

flaper87
Copy link
Contributor

This is a first patch towards an opt-in built-in trait world. This patch removes the restriction on built-in traits and allows such traits to be derived.

[RFC#3]

cc #13231

@nikomatsakis r?

@alexcrichton
Copy link
Member

(travis appears to have some legitimate errors)

@flaper87
Copy link
Contributor Author

@alexcrichton r?

"Copy" => "Copy",
"Send" => "Send",
"Share" => "Share",
_ => cx.span_bug(span, "couldn't determine built-in trait name")
Copy link
Member

Choose a reason for hiding this comment

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

This would be better as s => cx.span_bug(span, format!("expected built-in trait name but found {}", s)) to assist with debugging.

Copy link
Member

Choose a reason for hiding this comment

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

Also, it's a little weird to have the words duplicated: why not replace this whole let statement with

let name = mitem.name().get();
// verify we're handling a built-in trait.
match name {
    "Copy" | "Send" | "Share" => {}
    s => cx.span_bug(...)
}

let trait_def = ...;

@huonw
Copy link
Member

huonw commented May 1, 2014

Shouldn't there be a few more tests? e.g. a test with an explicit implementation (not just deriving), and a failing test for an explicit implementation/deriving on a type that has non-Send/Copy/Share contents?

@nikomatsakis
Copy link
Contributor

@huonw the failing tests, at least, will come later. This is just a first step PR. A test for an explicit impl isn't a bad idea, but I figured that we'll have plenty of those later when the real PRs start coming that actually implement the full semantics.

@nikomatsakis
Copy link
Contributor

(though we should definitely fix the potential ICEs you pointed out)

item: @Item,
push: |@Item|) {

let name = match mitem.node {
Copy link
Member

Choose a reason for hiding this comment

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

I do think my suggested code was better than this format; what's the reasoning for this being different to all other #[deriving]s? (Also, this still has the problem of repeating the trait names twice.)

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'm really not sure what you mean with this being different to the other
derivings. The code you suggested used a mitem.name() and there's no such
method in mitem

Unless you meant something else, I'm really not following.

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 really not sure what you mean with this being different to the other derivings

No other derivings have an error when used like #[deriving(Eq(int))] etc. I guess it's not a particular problem to have one here, although really all derivings should be updated to not pass through these silent errors.

The code you suggested used a mitem.name() and there's no such method in mitem

Oh, sorry, you have to bring http://static.rust-lang.org/doc/master/syntax/attr/trait.AttrMetaMethods.html into scope.

It would've been nice to tell me that my suggestion didn't work, rather than just ignoring it. In any case, the other part of the suggestion (reducing the duplication of trait names) can be with or without talking the whole thing.

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 guess it's not a particular problem to have one here, although really all derivings should be updated to not pass through these silent errors.

Agreed... It'd be better to have an error raised from the other derivings too.

Oh, sorry, you have to bring http://static.rust-lang.org/doc/master/syntax/attr/trait.AttrMetaMethods.html into scope.

Oh, this makes sense. Thanks.

It would've been nice to tell me that my suggestion didn't work, rather than just ignoring it. In any case, the other part of the suggestion (reducing the duplication of trait names) can be with or without talking the whole thing.

Please, always assume good faith from people's actions. I didn't ignore your suggestion and I couldn't comment back mentioning the issues I had.

I'll address your comment, thanks for the review :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason why I duplicated the trait names is because with the new treatment of @ pointers and the fact that Path just takes &'a str, it throws a bunch of lifetime errors. I tried to workaround this with no luck. if you've a better recommendation, I'd be very happy to use it.

Either way, I'd really like to move this patch forward, it's blocking the work on opt-in traits now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's probably a bug in the new @-pointers lifetime management. This fails:

let n = mitem.name();
let name = n.get();
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:24:16: 24:18 error: `mi` does not live long enough
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:24     let name = mi.get();
                                                                                                           ^~
note: reference must be valid for the static lifetime...
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:21:45: 55:2 note: ...but borrowed value is only valid for the block at 21:44
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:21                              push: |@Item|) {
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:22 
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:23     let mi = mitem.name();
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:24     let name = mi.get();
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:25     
/home/flaper87/workspace/personal/rust/opt-in-kinds/src/libsyntax/ext/deriving/bounds.rs:26     match name {

@huonw
Copy link
Member

huonw commented May 1, 2014

@nikomatsakis oh, ok; I'm looking forward to it.

@alexcrichton
Copy link
Member

It sounds like there are some small incremental improvements that can be made, but I have r+'d this because this will be a huge language change and I'd like to get it underway as soon as possible.

bors added a commit that referenced this pull request May 3, 2014
This is a first patch towards an opt-in built-in trait world. This patch removes the restriction on built-in traits and allows such traits to be derived.

[RFC#3]

cc #13231

@nikomatsakis r?
@bors bors closed this May 3, 2014
@bors bors merged commit c39271e into rust-lang:master May 3, 2014
arcnmx pushed a commit to arcnmx/rust that referenced this pull request Jan 9, 2023
…Veykril

minor: remove unused known `Name`s

After rust-lang#13866, known `Name`s for safe intrinsics are no longer used and thus should be removed.
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.

5 participants