- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Closed
Copy link
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsP-mediumMedium priorityMedium priorityT-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.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.
Description
Given the following code:
fn takes_callback(callback: impl Fn(i32)) {
    callback(&0);
}The current output is dependent on whether you have the rust-src component installed. With it installed:
error[E0308]: mismatched types
  --> src/main.rs:2:14
   |
2  |     callback(&0);
   |     -------- ^^ expected `i32`, found `&{integer}`
   |     |
   |     arguments to this function are incorrect
   |
note: associated function defined here
  --> /home/jnelson/.local/lib/rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:77:27
   |
77 |     extern "rust-call" fn call(&self, args: Args)...
   |                           ^^^^
help: consider removing the borrow
   |
2  -     callback(&0);
2  +     callback(0);
without it (e.g. on playground), the same except the note looks very strange because it doesn't actually point anywhere:
note: associated function defined here
help: consider removing the borrow
Ideally the output should look like:
error[E0308]: mismatched types
  --> src/main.rs:2:14
   |
2  |     callback(&0);
   |     -------- ^^ expected `i32`, found `&{integer}`
   |     |
   |     arguments to this function are incorrect
   |
note: function defined here:
  --> src/main.rs:1:x
   |
1 |     fn takes_callback(callback: impl Fn(i32)) {
   |                                ^^^^^^^^^^^^
help: consider removing the borrow
   |
2  -     callback(&0);
2  +     callback(0);
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsP-mediumMedium priorityMedium priorityT-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.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.Performance or correctness regression from stable to nightly.