Error mentions invalid nested HRTB: &mut for<'a> fn(for<'a> fn(&'a ()))
#134410
Open
Description
opened on Dec 17, 2024
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
Metadata
Assignees
Labels
Area: Messages for errors, warnings, and lintsArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)Area: Pretty printing (including `-Z unpretty`)Diagnostics: A diagnostic that is giving misleading or incorrect information.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity