Open
Description
#![allow(dead_code)]
fn x(_: &()) {}
trait HR {}
impl HR for fn(&()) {}
fn hr<T: HR>(_: T) {}
trait NotHR {}
impl<'a> NotHR for fn(&'a ()) {}
fn not_hr<T: NotHR>(_: T) {}
fn a<'a>() {
let not_hr_func: fn(&'a ()) = x;
let hr_func: fn(&()) = x;
let hr_func2: for<'b> fn(&'b ()) = x;
hr(not_hr_func);
not_hr(hr_func);
not_hr(hr_func2);
}
fn main() {}
gives
<anon>:17:5: 17:7 error: the trait `HR` is not implemented for the type `fn(&())` [E0277]
<anon>:17 hr(not_hr_func);
^~
<anon>:17:5: 17:7 help: see the detailed explanation for E0277
<anon>:17:5: 17:7 note: required by `hr`
<anon>:18:5: 18:11 error: the trait `NotHR` is not implemented for the type `fn(&())` [E0277]
<anon>:18 not_hr(hr_func);
^~~~~~
<anon>:18:5: 18:11 help: see the detailed explanation for E0277
<anon>:18:5: 18:11 note: required by `not_hr`
<anon>:19:5: 19:11 error: the trait `NotHR` is not implemented for the type `fn(&'b ())` [E0277]
<anon>:19 not_hr(hr_func2);
^~~~~~
<anon>:19:5: 19:11 help: see the detailed explanation for E0277
<anon>:19:5: 19:11 note: required by `not_hr`
error: aborting due to 3 previous errors
playpen: application terminated with error code 101
Summarizing, given the type declaration, we have the printed form:
Declaration | Display |
---|---|
fn(&'a ()) |
fn(&()) |
fn(&()) |
fn(&()) |
for<'b> fn(&'b ()) |
fn(&'b ()) |
So the non-higher-ranked type has its lifetime elided and is printed like a higher-ranked type, and higher-ranked types are sometimes printed without the quantifier but with the lifetime, looking like non-higher-ranked types.