Skip to content

No syntax for type of boxed trait with a kind bound and a generic parameter  #9265

Closed
@ben0x539

Description

@ben0x539
trait Tr1<T> {}

fn f<T>(_x: ~Tr1<T>) {}

trait Tr2 {}
impl Tr2 for ();

fn g(_x: ~Tr2:Send) {}

// fn h1<T>(_x: ~Tr1:Send<T>) {} // error: wrong number of type arguments: expected 1 but found 0
                                 // (apparently the <T> parameterizes Send)

// fn h2<T>(_x: ~Tr1<T>:Send) {} // error: expected `,` but found `:`

fn main() {}

Seems like both generic parameters and kind bounds are individually okay on paths, but you can't have both right now.

The pretty printer would apparently happily emit the form in h1's declaration, but it's not currently parsed (and possibly ambiguous if there's a context where instead of Send there could be a user-defined trait with a legimitate parameter, not sure if that is possible).

The form in h2 seems somewhat sensible to me if we pretend that type parameters are part of individual path segments now but the kind bounds apply to the type as a whole, but of course the compiler isn't convinced.

Maybe I'm missing something. :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTA-type-systemArea: Type system

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions