Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

trait alias generic parameter doesn't specify associated type #122118

Closed
Assignees
Labels
C-bugCategory: This is a bug. F-trait_alias`#![feature(trait_alias)]` requires-nightlyThis issue requires a nightly compiler in some way.
@Dino1694

Description

Grow2 is a generic alias of Grow1, but using the alias on the starred(*) line does not work.

I tried this code:

#![feature(trait_alias)]
trait Tree {
 type Fruit;
}
trait Grow1<T: Tree> {
 fn grow(x: T);
}
trait Grow2<T: Tree> = Grow1<T>;
struct AppleTree;
struct Apple;
impl Tree for AppleTree {
 type Fruit = Apple;
}
type GrowAppleTree1 = dyn Grow1<AppleTree>;
// semantically identical to the above line, but doesn't compile
type GrowAppleTree2 = dyn Grow2<AppleTree>; // (*)
fn main() {}

I expected to see this happen:
Compilation success

Instead, this happened:

error[E0191]: the value of the associated type `Fruit` in `Tree` must be specified
 --> ..\..\rust\trait_alias_bug.rs:15:27
 |
3 | type Fruit;
 | ---------- `Fruit` defined here
...
15 | type GrowAppleTree2 = dyn Grow2<AppleTree>;
 | ^^^^^^^^^^^^^^^^ help: specify the associated type: `Grow2<AppleTree, Fruit = Type>`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0191`.

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (b6d2d841b 2024年03月05日)

Metadata

Metadata

Labels

C-bugCategory: This is a bug. F-trait_alias`#![feature(trait_alias)]` requires-nightlyThis issue requires a nightly compiler in some way.

Type

No type

Projects

No projects

Milestone

No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      AltStyle によって変換されたページ (->オリジナル) /