Closed
Description
The function_item_references
lint suggests a wrong function item cast.
I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=d46c30ab809202ea2b88891e529da4f9
fn main() {
use std::mem::size_of;
type Left = [u8; 16];
println!("{:p}", &size_of::<Left>);
// println!("{:p}", size_of as fn() -> _);
}
The compiler suggests this:
warning: taking a reference to a function item does not give a function pointer
--> src/main.rs:4:22
|
4 | println!("{:p}", &size_of::<Left>);
| ^^^^^^^^^^^^^^^^ help: cast `size_of` to obtain a function pointer: `size_of as fn() -> _`
|
= note: `#[warn(function_item_references)]` on by default
However, following the suggestion causes a compiler error:
error[E0282]: type annotations needed
--> src/main.rs:5:22
|
5 | println!("{:p}", size_of as fn() -> _);
| ^^^^^^^ cannot infer type for type parameter `T` declared on the function `size_of`
I would expect the compiler suggests size_of::<Left> as fn() -> _
instead.
Meta
rustc --version --verbose
: (2020-10-29 6bdae9e) from playground
cc #76269