Skip to content

Trait inheritance doesn't work with the Copy trait #5452

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
erickt opened this issue Mar 20, 2013 · 2 comments
Closed

Trait inheritance doesn't work with the Copy trait #5452

erickt opened this issue Mar 20, 2013 · 2 comments

Comments

@erickt
Copy link
Contributor

erickt commented Mar 20, 2013

While trait inheritance works with user defined traits, it doesn't appear to work with special traits like Copy. This code compiles fine:

trait Foo       { fn f(&self); }
trait Bar: Foo  { fn g(&self); }
trait Baz: Copy { fn h(&self); }

struct A;

impl Foo for A { fn f(&self) { } }
impl Bar for A { fn g(&self) { } }
impl Baz for A { fn h(&self) { } }

fn f<T: Bar>(t: &T) {
    t.f();
    t.g();
}

fn g<T: Baz+Copy>(t: T) -> T {
    t.h();
    copy t
}

/*
fn h<T: Baz>(t: T) -> T {
    t.h();
    copy t
}
*/

fn main() { }

However, if you uncomment function h, it errors with:

foo.rs:23:9: 23:10 error: copying a value of non-copyable type `'a`
foo.rs:23     copy t
                   ^
foo.rs:23:9: 23:10 note: explicit copy requires a copyable argument
foo.rs:23     copy t
                   ^
error: aborting due to previous error
@erickt
Copy link
Contributor Author

erickt commented Mar 20, 2013

This was based off of an issue @lifthrasiir mentioned in IRC.

@catamorphism
Copy link
Contributor

Yes, this functionality isn't implemented yet. Sorry! Follow #3984 to see progress.

oli-obk pushed a commit to oli-obk/rust that referenced this issue May 2, 2020
…thiaskrgr

Refactor: Use rustc's `match_def_path`

This replaces our match_def_path implementation with the rustc one.

Note that we can't just use it in all call sites because of the
`&[&str]` / `&[Symbol]` difference in Clippy/rustc.

changelog: none
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

No branches or pull requests

2 participants