Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

`copy` and `send` ifaces cannot be used as type parameter bounds #2284

Closed
brson opened this Issue · 4 comments

3 participants

Brian Anderson Marijn Haverbeke Tim Chevalier
Brian Anderson
Owner

While ifaces with the name copy and send can be declared and implemented, they are always shadowed by the copy and send kind bounds when used like fn f<T: send>. A small inconsistency.

iface send {
    fn f();
}

fn f<T: send>(t: T) {
    t.f();
}

fn main() {
}
../src/test/run-pass/test.rs:6:4: 6:7 error: attempted access of field f on type 'a, but no public field or method with that name was found
../src/test/run-pass/test.rs:6     t.f();
                                   ^~~
../src/test/run-pass/test.rs:6:4: 6:9 error: the type of this value must be known in this context
../src/test/run-pass/test.rs:6     t.f();
                                   ^~~~~
Marijn Haverbeke

Does disallowing these words as iface names sound like an acceptable solution?

Marijn Haverbeke marijnh was assigned
Tim Chevalier

We won't disallow these words as trait names, now that copy and send are just traits. But, I'll fix the code so it doesn't prioritize copy and send over a user-defined trait shadowing one of these names.

Tim Chevalier catamorphism was assigned
Tim Chevalier

Still a bug as of a477c5a.

Tim Chevalier catamorphism referenced this issue from a commit in catamorphism/rust
Tim Chevalier catamorphism Simplify the AST representation of ty param bounds
Change ast::ty_param_bound so that all ty param bounds are represented
as traits, with no special cases for Copy/Send/Owned/Const.
typeck::collect generates the special cases.

A consequence of this is that code using the #[no_core] attribute
can't use the Copy kind/trait. Probably not a big deal?

As a side effect, any user-defined traits that happen to be called
Copy, etc. in the same module override the built-in Copy trait.
Closes #2284
bbc94e8
Tim Chevalier

Fixed, pending code review by @nikomatsakis .

Tim Chevalier catamorphism closed this issue from a commit
Tim Chevalier catamorphism Simplify the AST representation of ty param bounds
Change ast::ty_param_bound so that all ty param bounds are represented
as traits, with no special cases for Copy/Send/Owned/Const.
typeck::collect generates the special cases.

A consequence of this is that code using the #[no_core] attribute
can't use the Copy kind/trait. Probably not a big deal?

As a side effect, any user-defined traits that happen to be called
Copy, etc. in the same module override the built-in Copy trait.

r=nmatsakis

Closes #2284
46d4bbb
Jay Anderson jayanderson referenced this issue from a commit
Commit has since been removed from the repository and is no longer available.
Tim Chevalier catamorphism was unassigned by brson
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.