-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-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
playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9f1e00046f513d4d9da8790042e52ca9
Code:
struct MyStruct {
age: u32
}
fn run<F: Fn(&MyStruct) -> bool>(func: F, data: &MyStruct) -> bool {
func(&data)
}
fn main() {
let m = MyStruct { age: 4};
let x = run(|x:MyStruct| x.age > 3, &m);
println!("{}", x);
}
The error I got was
Compiling playground v0.0.1 (/playground)
error[E0631]: type mismatch in closure arguments
--> src/main.rs:12:13
|
6 | fn run<F: Fn(&MyStruct) -> bool>(func: F, data: &MyStruct) -> bool {
| --- --------------------- required by this bound in `run`
...
12 | let x = run(|x:MyStruct| x.age > 3, &m);
| ^^^ ---------------------- found signature of `fn(MyStruct) -> _`
| |
| expected signature of `for<'r> fn(&'r MyStruct) -> _`
which is quite convoluted in my opinion.
It turned out I was only missing a borrow:
let x = run(|x:MyStruct| x.age > 3, &m);
=>
let x = run(|x:&MyStruct| x.age > 3, &m);
A simple "hint: add missing borrow: "&MyStruct"" with corresponding span would have been a lot more helpful here in my opinion.
Metadata
Metadata
Assignees
Labels
A-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.T-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.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
estebank commentedon Oct 1, 2019
The following function needs to be changed to inspect and compare the expected and found argument and return types and modify
err
to be more targeted.rust/src/librustc/traits/error_reporting.rs
Lines 1333 to 1382 in 22bc9e1
Sadly at that point you don't have access to the closure expression, but you get it using
self.tcx.hir().get_if_local(found_did.unwrap())
hererust/src/librustc/traits/error_reporting.rs
Lines 878 to 882 in 22bc9e1
With that then you could extract the appropriate span to suggest a code change using
err.span_suggestion
.workingjubilee commentedon Oct 1, 2019
I would be happy to work on implementing this, as it seems like a wonderful opportunity to get into the span code.
estebank commentedon Oct 1, 2019
Feel free to reach out!
Quantumplation commentedon Oct 26, 2019
@rustbot claim
It's been a while since @workingjubilee expressed interest, so I'm going to take a crack at this!
@estebank Trying to understand the function you pointed out, and the variable naming has me all twisted around. Are the variable names for found_str and expected_str swapped, or is there some subtlety I'm missing?
estebank commentedon Oct 26, 2019
@Quantumplation I believe they are just incorrectly swapped.
workingjubilee commentedon Oct 26, 2019
Ah, I didn't realize I should have formally claimed this mechanically.
I had been delayed a bit, but I have been trying to get into things the past few nights.
Quantumplation commentedon Oct 26, 2019
@workingjubilee ah! feel free to claim it from me then! Also happy to collaborate, if you want to find me on Discord!
1 remaining item
JohnTitor commentedon Jul 24, 2020
Triage: I'm going to release assignment due to inactivity.
@workingjubilee If you're still interested in this, feel free to re-claim.
@rustbot release-assignment
krupitskas commentedon Aug 18, 2020
Working on it.
@rustbot claim
krupitskas commentedon Sep 14, 2020
Still can't find a free dedicated time to sit, read docs and finish it. Some hints can be found in closed pull requests.
@rustbot release-assignment
Akida31 commentedon Oct 8, 2022
@rustbot claim
Rollup merge of rust-lang#102813 - Akida31:issue-64915/simpler_diagno…
Auto merge of rust-lang#102813 - Akida31:issue-64915/simpler_diagnost…