Closed
Description
STR
#[deriving(Clone)]
//~^ error: trait `Clone` already appears in the list of bounds [E0127]
struct Foo<'a, T: 'a + Clone> {
foo: &'a [T],
}
fn main() {}
Output
If you look at the --pretty=expanded
version, you'll see T
is bounded twice by the Clone
trait
#![feature(phase)]
#![no_std]
#![feature(globs)]
#[phase(plugin, link)]
extern crate "std" as std;
#[prelude_import]
use std::prelude::*;
//~^ error: trait `Clone` already appears in the list of bounds [E0127]
struct Foo<'a, T: 'a + Clone> {
foo: &'a [T],
}
#[automatically_derived]
impl <'a, T: ::std::clone::Clone + 'a + Clone> ::std::clone::Clone for
Foo<'a, T> {
#[inline]
fn clone(&self) -> Foo<'a, T> {
match *self {
Foo { foo: ref __self_0_0 } =>
Foo{foo: ::std::clone::Clone::clone(&(*__self_0_0)),},
}
}
}
Version
rustc 0.13.0-dev (82fc1aa87 2014-11-27 10:11:19 +0000)
The obvious fix seems to make the deriving
syntax extension filter out the duplicated Clone
just by looking at the trait name. The problem is that ::std::clone::Clone
may not be the same trait as Clone
, but AFAIK the syntax extension can't know that, since that (path) information is collected after macro expansion.
Work-around
One workaround to this issue is using the fact that the deriving
syntax extension doesn't look at where
bounds (see #19358), the following code compiles:
#[deriving(Clone)]
struct Foo<'a, T: 'a> where T: Clone {
foo: &'a [T],
}
fn main() {}
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
alexcrichton commentedon Aug 13, 2015
This now works, so I think it was fixed in the meantime? Yay!