-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Add a note when trying to call a non-function #30001
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
Conversation
The note added tells the definition location of the non-function that is being called. Fixes rust-lang#10969
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Let's see what the build bot says about this PR. One test failed on my machine even with the master branch of Rust. test.rs:6:5: 6:10 error: expected function, found `&str`
test.rs:6 foo();
^~~~~
test.rs:5:9: 5:12 note: defined here
test.rs:5 let foo="foo"; However, when the non-function is a function argument, the span is a bit funny, as it points to the function argument, but I think it is still quite informative: test.rs:2:5: 2:8 error: expected function, found `i32`
test.rs:2 i();
^~~
test.rs:1:9: 1:10 note: defined here
test.rs:1 fn func(i: i32) {
^ |
Looks good. Could you add a compile-fail test for this? (tests/compile-fail). Just some code that throws this error, with Run the test with |
Done. Should I rebase the PR to be a single commit only? |
In this case two commits is fine. But in general, feel free to rebase. |
Do tests pass locally? |
if let hir::ExprCall(ref expr, _) = call_expr.node { | ||
let tcx = fcx.tcx(); | ||
if let Some(pr) = tcx.def_map.borrow().get(&expr.id) { | ||
if pr.depth == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on the depth check!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Some of the tests caught that one.
@bors r+ |
📌 Commit 210c435 has been approved by |
Thanks! |
r? @Manishearth