Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Dino1694 opened this issue Mar 7, 2024 · 0 comments · Fixed by #122123
Closed

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

Dino1694 opened this issue Mar 7, 2024 · 0 comments · Fixed by #122123
Assignees
Labels
C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@Dino1694
Copy link

Dino1694 commented Mar 7, 2024

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)
@Dino1694 Dino1694 added the C-bug Category: This is a bug. label Mar 7, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 7, 2024
@compiler-errors compiler-errors added F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way. labels Mar 7, 2024
@compiler-errors compiler-errors changed the title trait alias generic parameter doesn't specify associated type (T-compiler C-bug F-trait_alias requires-nightly) trait alias generic parameter doesn't specify associated type Mar 7, 2024
@compiler-errors compiler-errors self-assigned this Mar 7, 2024
@bors bors closed this as completed in bb582c6 Mar 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Mar 7, 2024
Rollup merge of rust-lang#122123 - compiler-errors:object-trait-alias-bounds, r=oli-obk

Don't require specifying unrelated assoc types when trait alias is in `dyn` type

Object types must specify the associated types for all of the principal trait ref's supertraits. However, we weren't doing elaboration properly, so we incorrectly errored with erroneous suggestions to specify associated types that were unrelated to that principal trait ref. To fix this, use proper supertrait elaboration when expanding trait aliases in `conv_object_ty_poly_trait_ref`.

**NOTE**: Please use the ignore-whitespace option when reviewing. This only touches a handful of lines.

r? oli-obk or please feel free to reassign.

Fixes rust-lang#122118
@jieyouxu jieyouxu removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-trait_alias `#![feature(trait_alias)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants