Skip to content

Use of ty macro non-terminal in trait bounds #20272

Open
@stuglaser

Description

@stuglaser
macro_rules! impl_somethingable {
    ($Base: ty, $Block:ty) => {
        impl<'a, T> Somethingable for $Block where T: $Base {
        }
    }
}

impl_somethingable!(ATrait, A);
<anon>:15:52: 15:60 error: each predicate in a `where` clause must have at least one bound in it
<anon>:15         impl<'a, T> Somethingable for $Block where T: $Base {
                                                             ^~~~~~~~
<anon>:15:56: 15:60 error: expected one of `,` or `{`, found `ATrait`
<anon>:15         impl<'a, T> Somethingable for $Block where T: $Base {
                                                                 ^~~~

The solution is to use $ident instead of $ty, but this is non-obvious to the user, especially since it's perfectly ok to have ATrait in that location.

Playpen: http://is.gd/AMUJDw

cc @huonw

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-grammarArea: The grammar of RustC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-langRelevant to the language team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions