-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
have simpler diagnostic when passing arg to closure and missing borrow #64915
Comments
The following function needs to be changed to inspect and compare the expected and found argument and return types and modify 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 rust/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 |
I would be happy to work on implementing this, as it seems like a wonderful opportunity to get into the span code. |
Feel free to reach out! |
@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? |
@Quantumplation I believe they are just incorrectly swapped. |
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. |
@workingjubilee ah! feel free to claim it from me then! Also happy to collaborate, if you want to find me on Discord! |
Shiver me timbers, it's piracy on the Rust Sea!!! @rustbot claim |
Triage: I'm going to release assignment due to inactivity. |
Working on it. |
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 |
@rustbot claim |
…stic_when_passing_arg_to_closure_and_missing_borrow, r=estebank Simpler diagnostic when passing arg to closure and missing borrow fixes rust-lang#64915 I followed roughly the instructions and the older PR rust-lang#76362. The number of references for the expected and the found types will be compared and depending on which has more the diagnostic will be emitted. I'm not quite sure if my approach with the many `span_bug!`s is good, it could lead to some ICEs. Would it be better if those errors are ignored? As far as I know the following code works similarly but in a different context. Is this probably reusable since it looks like it would emit better diagnostics? https://github.com/rust-lang/rust/blob/a688a0305fad9219505a8f2576446510601bafe8/compiler/rustc_hir_analysis/src/check/demand.rs#L713-L1061 When running the tests locally, a codegen test failed. Is there something I can/ should do about that? If you have some improvements/ corrections please say so and I will happily include them. r? `@estebank` (as you added the mentoring instructions to the issue)
playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9f1e00046f513d4d9da8790042e52ca9
Code:
The error I got was
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.
The text was updated successfully, but these errors were encountered: