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

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

Closed
compiler-errors opened this issue Jul 27, 2023 · 1 comment · Fixed by #114036
Closed

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

compiler-errors opened this issue Jul 27, 2023 · 1 comment · Fixed by #114036
Assignees
Labels
C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@compiler-errors
Copy link
Member

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.

@compiler-errors compiler-errors added C-bug Category: This is a bug. F-trait_upcasting `#![feature(trait_upcasting)]` T-types Relevant to the types team, which will review and decide on the PR/issue. labels Jul 27, 2023
@compiler-errors compiler-errors self-assigned this Jul 27, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 27, 2023
@compiler-errors compiler-errors added fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 27, 2023
@compiler-errors
Copy link
Member Author

compiler-errors commented Jul 27, 2023

For the record, should be fixed by #114036. Also, it's "automatically" already working in the new solver because of deferred projection equality ❤️ (but it should work on the old solver as soon as that PR lands).

@compiler-errors compiler-errors changed the title Cannot upcast to supertrait which has associated type that needs normalization Cannot upcast to supertrait which has generic arg that needs normalization Jul 27, 2023
@bors bors closed this as completed in 4f7bb98 Aug 4, 2023
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_upcasting `#![feature(trait_upcasting)]` fixed-by-next-solver Fixed by the next-generation trait solver, `-Znext-solver`. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
2 participants