Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't point to Fn::call when the arguments passed to a closure are incorrect #98308

Closed
jyn514 opened this issue Jun 20, 2022 · 2 comments · Fixed by #99131
Closed

Don't point to Fn::call when the arguments passed to a closure are incorrect #98308

jyn514 opened this issue Jun 20, 2022 · 2 comments · Fixed by #99131
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jyn514
Copy link
Member

jyn514 commented Jun 20, 2022

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);
@jyn514 jyn514 added A-diagnostics Area: Messages for errors, warnings, and lints regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 20, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jun 20, 2022
@jyn514
Copy link
Member Author

jyn514 commented Jun 20, 2022

regression from 1549576 maybe? cc @jackh726

err.span_note(spans, &format!("{} defined here", def_kind.descr(def_id)));

@compiler-errors compiler-errors self-assigned this Jun 20, 2022
@inquisitivecrystal inquisitivecrystal added P-medium Medium priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jun 23, 2022
@inquisitivecrystal
Copy link
Contributor

Tagging as P-medium, as discussed by the prioritization working group.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints P-medium Medium priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants