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

type_alias_impl_trait fails to correctly resolve bounds. #101572

Closed
MichaelMauderer opened this issue Sep 8, 2022 · 1 comment
Closed

type_alias_impl_trait fails to correctly resolve bounds. #101572

MichaelMauderer opened this issue Sep 8, 2022 · 1 comment
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]`

Comments

@MichaelMauderer
Copy link

Code

I tried this code:

#![feature(type_alias_impl_trait)]

pub type OnFrameClosure<OnFrame> = impl FnMut();

pub fn on_frame_closure<OnFrame>() -> OnFrameClosure<OnFrame>
where
    OnFrame: FnMut(),
{
    move || {
        unimplemented!();
    }
}

This produces the following error:

error[E0277]: expected a `FnMut<()>` closure, found `OnFrame`
  --> src/lib.rs:9:5
   |
9  | /     move || {
10 | |         unimplemented!();
11 | |     }
   | |_____^ expected an `FnMut<()>` closure, found `OnFrame`
   |
   = note: wrap the `OnFrame` in a closure with no arguments: `|| { /* code */ }`
note: required by a bound in `on_frame_closure`
  --> src/lib.rs:7:18
   |
5  | pub fn on_frame_closure<OnFrame>() -> OnFrameClosure<OnFrame>
   |        ---------------- required by a bound in this
6  |     where
7  |         OnFrame: FnMut(),
   |                  ^^^^^^^ required by this bound in `on_frame_closure`
help: consider restricting type parameter `OnFrame`
   |
3  | pub type OnFrameClosure<OnFrame: std::ops::FnMut<()>> = impl FnMut();
   |                                +++++++++++++++++++++

For more information about this error, try `rustc --explain E0277`.
error: could not compile `tyoe_alias_bug_test` due to previous error

Version it worked on

It most recently worked on nightly-2022-05-14.

Version with regression

The first failing version is nightly-2022-05-15.

cargo-bisect-rustc points to a7d6408 regressed commit.

@MichaelMauderer MichaelMauderer added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Sep 8, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 8, 2022
@oli-obk oli-obk added the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label Sep 8, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Sep 8, 2022

This is expected. This was fixed on purpose: #96899

The hidden type must satisfy the bounds of the TAIT with just the bounds on the TAIT. Since the closure requires OnFrame: FnMut() in order to be sound, and the TAIT does not have this bound, you see the error you are getting. The suggestion will work and fix the error.

@oli-obk oli-obk closed this as completed Sep 8, 2022
@apiraino apiraino removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-untriaged Untriaged performance or correctness regression. labels Sep 8, 2022
@oli-obk oli-obk moved this from Todo to Wontfix in type alias impl trait stabilization Sep 9, 2022
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-type_alias_impl_trait `#[feature(type_alias_impl_trait)]`
Projects
Development

No branches or pull requests

4 participants