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

impl_trait_in_fn_trait_return breaks with ref params #103967

Open
douglas-raillard-arm opened this issue Nov 4, 2022 · 1 comment
Open

impl_trait_in_fn_trait_return breaks with ref params #103967

douglas-raillard-arm opened this issue Nov 4, 2022 · 1 comment
Labels
C-bug Category: This is a bug. F-impl_trait_in_fn_trait_return `#![feature(impl_trait_in_fn_trait_return)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@douglas-raillard-arm
Copy link

I tried the new impl_trait_in_fn_trait_return feature tracked at #99697

#![feature(impl_trait_in_fn_trait_return)]

// Having the closure take any kind of reference as parameter results in a
// compilation error. Turning "&()" into "()" fixes it.

fn allowed_in_ret_type() -> impl Fn(&()) -> impl Into<u32> {
    |_| 0u32
}

// This compiles just fine:
// fn allowed_in_ret_type() -> impl Fn(()) -> impl Into<u32> {
//     |_| 0u32
// }

I expected to see this happen:

The code should compile.

Instead, this happened:

error: concrete type differs from previous defining opaque type use
--> src/main.rs:4:9
    |
4 |     |_| 0u32
    |         ^^^^ expected `impl Into<u32>`, got `u32`
    |
note: previous use here
    --> src/main.rs:4:5
    |
4 |     |_| 0u32
    |     ^^^^^^^^

    error[E0720]: cannot resolve opaque type
    --> src/main.rs:3:45
    |
3 | fn allowed_in_ret_type() -> impl Fn(&()) -> impl Into<u32> {
    |                                             ^^^^^^^^^^^^^^ recursive opaque type
        4 |     |_| 0u32
        |     -------- returning here with type `[closure@src/main.rs:4:5: 4:8]`

        For more information about this error, try `rustc --explain E0720`.

Meta

rustc --version --verbose:

rustc 1.67.0-nightly (edf018221 2022-11-02)
@douglas-raillard-arm douglas-raillard-arm added the C-bug Category: This is a bug. label Nov 4, 2022
@Rageking8
Copy link
Contributor

@rustbot label +T-compiler +F-impl_trait_in_fn_trait_return +requires-nightly

@rustbot rustbot added F-impl_trait_in_fn_trait_return `#![feature(impl_trait_in_fn_trait_return)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 4, 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-impl_trait_in_fn_trait_return `#![feature(impl_trait_in_fn_trait_return)]` requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants