Skip to content

Error mentions invalid nested HRTB: &mut for<'a> fn(for<'a> fn(&'a ())) #134410

Open
@theemathas

Description

Code

// Note: F1 and F2 are subtypes of each other. Not sure if relevant.
type F1 = fn(fn(&'static ()));
type F2 = for<'a> fn(fn(&'a ()));

fn foo(a: &mut F1) {
    let _: &mut F2 = a;
}

Current output

Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:6:22
  |
6 |     let _: &mut F2 = a;
  |                      ^ one type is more general than the other
  |
  = note: expected mutable reference `&mut for<'a> fn(for<'a> fn(&'a ()))`
             found mutable reference `&mut fn(fn(&()))`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

Desired output

Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
 --> src/lib.rs:6:22
  |
6 |     let _: &mut F2 = a;
  |                      ^ one type is more general than the other
  |
  = note: expected mutable reference `&mut for<'a> fn(fn(&'a ()))`
             found mutable reference `&mut fn(fn(&()))`

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground` (lib) due to 1 previous error

Rationale and extra context

The error prints &mut for<'a> fn(for<'a> fn(&'a ())), which has nested for<'a> HRTB binders, which is illegal syntax.

Other cases

// Using a *mut instead of &mut produces the correct error

type F1 = fn(fn(&'static ()));
type F2 = for<'a> fn(fn(&'a ()));

fn foo(a: *mut F1) {
    let _: *mut F2 = a;
}

Rust Version

Reproduced issue on the playground with stable rust `1.83.0` and nightly rust `1.85.0-nightly (2024-12-16 6d9f6ae36ae1299d6126)`

Anything else?

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-prettyArea: Pretty printing (including `-Z unpretty`)D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions