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

One of the E0599 note disappears when using specialization #55140

Open
glandium opened this issue Oct 17, 2018 · 0 comments
Open

One of the E0599 note disappears when using specialization #55140

glandium opened this issue Oct 17, 2018 · 0 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-specialization Area: Trait impl specialization C-bug Category: This is a bug. F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@glandium
Copy link
Contributor

Take the following code:

struct A {
    b: bool,
}

struct Foo;

struct B<T, U=Foo>(T, U);

impl<T: Clone> Clone for B<T> {
    fn clone(&self) -> B<T> {
        B(self.0.clone(), Foo)
    }
}

fn main() {
    let i = B(A { b: true }, Foo);
    let _j = i.clone();
}

(derived from src/test/ui/unique-pinned-nocopy.rs)

This fails to compile with:

error[E0599]: no method named `clone` found for type `B<A>` in the current scope
  --> src/main.rs:17:16
   |
7  | struct B<T, U=Foo>(T, U);
   | ------------------------- method `clone` not found for this
...
17 |     let _j = i.clone();
   |                ^^^^^
   |
   = note: the method `clone` exists but the following trait bounds were not satisfied:
           `B<A> : std::clone::Clone`
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `clone`, perhaps you need to implement it:
           candidate #1: `std::clone::Clone`

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=bf41d2dae1e36b2cb0ef6d8cae3529e4

Now, add the following:

#![feature(specialization)]

impl<T: Clone, U: Clone> Clone for B<T, U> {
    default fn clone(&self) -> B<T, U> {
        B(self.0.clone(), self.1.clone())
    }
}

and it now fails with:

error[E0599]: no method named `clone` found for type `B<A>` in the current scope
  --> src/main.rs:25:16
   |
9  | struct B<T, U=Foo>(T, U);
   | ------------------------- method `clone` not found for this
...
25 |     let _j = i.clone();
   |                ^^^^^
   |
   = help: items from traits can only be used if the trait is implemented and in scope
   = note: the following trait defines an item `clone`, perhaps you need to implement it:
           candidate #1: `std::clone::Clone`

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=76f69c7ad78d25413784e9cbfd306583

The following note disappeared, but seems like it should still be emitted:

   = note: the method `clone` exists but the following trait bounds were not satisfied:
           `B<A> : std::clone::Clone`
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-specialization Area: Trait impl specialization labels Jan 19, 2019
@jonas-schievink jonas-schievink added C-bug Category: This is a bug. F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-specialization Area: Trait impl specialization C-bug Category: This is a bug. F-specialization `#![feature(specialization)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants