-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Hello world. Here is an example of code;
fn main() {
fn test() { println!("Testing !") }
let hm: HashMap<&str, fn()> = HashMap::from([("test", test)]);
hm.get("test").unwrap()();
}
Here is the output:
error[E0308]: mismatched types
--> src/main.rs:5:32
|
5 | let hm: HashMap<&str, fn()> = HashMap::from([("test", test)]);
| ------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected fn pointer, found fn item
| |
| expected due to this
|
= note: expected struct `HashMap<&str, fn()>`
found struct `HashMap<&str, fn() {test}>`
The issue with this output is that, for a newbie, it is very mysterious, it doesn't help to know what exactly is wrong or at least how to fix it.
The compiler should print a hint like: "try test as fn()
".
Thanks in advance !
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.