Skip to content

Cannot upcast to supertrait which has generic arg that needs normalization #114113

Closed
@compiler-errors

Description

@compiler-errors

I tried this code:

#![feature(trait_upcasting)]

trait Mirror {
    type Assoc;
}
impl<T> Mirror for T {
    type Assoc = T;
}

trait Bar<T> {}
trait Foo<T>: Bar<<T as Mirror>::Assoc> {}

fn upcast<T>(x: &dyn Foo<T>) -> &dyn Bar<T> { x }

fn main() {}

I expected to see it compile.

Instead, this happened:

error[E0308]: mismatched types
  --> <source>:13:47
   |
13 | fn upcast<T>(x: &dyn Foo<T>) -> &dyn Bar<T> { x }
   |                                 -----------   ^ expected trait `Bar`, found trait `Foo`
   |                                 |
   |                                 expected `&dyn Bar<T>` because of return type
   |
   = note: expected reference `&dyn Bar<T>`
              found reference `&dyn Foo<T>`

That's because we're missing a normalize_with_depth_to call in trait upcasting confirmation.

Metadata

Metadata

Labels

C-bugCategory: This is a bug.F-trait_upcasting`#![feature(trait_upcasting)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.fixed-by-next-solverFixed by the next-generation trait solver, `-Znext-solver`.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions