Skip to content

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

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

Open
theemathas opened this issue Dec 17, 2024 · 1 comment
Open
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-pretty Area: Pretty printing (including `-Z unpretty`) D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@theemathas
Copy link
Contributor

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

@theemathas theemathas added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 17, 2024
@jieyouxu jieyouxu added D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) labels Dec 17, 2024
@fmease
Copy link
Member

fmease commented Dec 17, 2024

cc #111365

@fmease fmease added the A-pretty Area: Pretty printing (including `-Z unpretty`) label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-pretty Area: Pretty printing (including `-Z unpretty`) D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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