Skip to content

#[deriving(..)] doesn't work on structs that specify their bounds using where clauses #19358

Closed
@japaric

Description

@japaric

STR

trait Trait {}

// OK
#[deriving(Show)]
struct Foo<T: Trait> {
    foo: T,
}

#[deriving(Show)]
//~^ error: the trait `Trait` is not implemented for the type `T`
struct Bar<T> where T: Trait {
    bar: T,
}

fn main() {}

Output

If you check the --pretty=expanded output, you'll notice the T: Trait bound is missing in the Bar case.

// OK
struct Foo<T: Trait> {
    foo: T,
}
#[automatically_derived]
impl <T: ::std::fmt::Show + Trait> ::std::fmt::Show for Foo<T> {
    fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        match *self {
            Foo { foo: ref __self_0_0 } =>
            match (&(*__self_0_0),) {
                (__arg0,) => {
                    #[inline]
                    #[allow(dead_code)]
                    static __STATIC_FMTSTR: &'static [&'static str] =
                        &["Foo { foo: ", " }"];
                    let __args_vec =
                        &[::std::fmt::argument(::std::fmt::Show::fmt,
                                               __arg0)];
                    let __args =
                        unsafe {
                            ::std::fmt::Arguments::new(__STATIC_FMTSTR,
                                                       __args_vec)
                        };
                    __arg_0.write_fmt(&__args)
                }
            },
        }
    }
}

//~^ error: the trait `Trait` is not implemented for the type `T`
struct Bar<T> {
    bar: T,
}
#[automatically_derived]
impl <T: ::std::fmt::Show> ::std::fmt::Show for Bar<T> {
    fn fmt(&self, __arg_0: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
        match *self {
            Bar { bar: ref __self_0_0 } =>
            match (&(*__self_0_0),) {
                (__arg0,) => {
                    #[inline]
                    #[allow(dead_code)]
                    static __STATIC_FMTSTR: &'static [&'static str] =
                        &["Bar { bar: ", " }"];
                    let __args_vec =
                        &[::std::fmt::argument(::std::fmt::Show::fmt,
                                               __arg0)];
                    let __args =
                        unsafe {
                            ::std::fmt::Arguments::new(__STATIC_FMTSTR,
                                                       __args_vec)
                        };
                    __arg_0.write_fmt(&__args)
                }
            },
        }
    }
}

fn main() { }

Version

rustc 0.13.0-dev (8fb027e39 2014-11-26 12:02:16 +0000)

The possible solution would be to make the deriving syntax extension also copy the where clause bounds into the expanded impl, just like it already does for the "inline bounds" impl<T: Show + Trait> ....

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions