Repository navigation
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: 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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Description
On current beta, at least, I see:
error: attempted access of field `test_results` on type `TestResult`, but no field with that name was
found
--> src/main.rs:196:25
|
196 | tests_passed += normal_test.test_results.iter().filter(|t| t.status == "ok").count();
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: did you mean `results`?
--> src/main.rs:196:37
|
196 | tests_passed += normal_test.test_results.iter().filter(|t| t.status == "ok").count();
| ^^^^^^^^^^^^
But I feel like I'd rather see:
error: attempted access of field `test_results` on type `TestResult`, but no field with that name was
found
--> src/main.rs:196:25
|
196 | tests_passed += normal_test.test_results.iter().filter(|t| t.status == "ok").count();
| ^^^^^^^^^^^^
= help: did you mean `results`?
Come to think of it, we could shorten the main message and move the suggestion into the label, as I think you've done elsewhere:
error: no field `test_results` on type `TestResult`
--> src/main.rs:196:25
|
196 | tests_passed += normal_test.test_results.iter().filter(|t| t.status == "ok").count();
| ^^^^^^^^^^^^ did you mean `results`?
|
Standalone example:
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: 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.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
durka commentedon Aug 31, 2016
Another possibility is to actually replace it
But if it's only a guess, that might not be a good idea.
nikomatsakis commentedon Aug 31, 2016
@durka my inclination is that the extra 5 lines of output aren't valuable enough in this case, it's not likely it's tricky to figure out how to apply the change
sophiajt commentedon Aug 31, 2016
Or maybe even...
nikomatsakis commentedon Sep 1, 2016
@jonathandturner how is that different from my 3rd example? (Except for using a longer "error' message)
sophiajt commentedon Sep 1, 2016
@nikomatsakis - lol are you sure you didn't add it after I commented?
Just kidding, I just didn't see it the first time through.
sophiajt commentedon Sep 1, 2016
My vote is your # 3 ;)
nikomatsakis commentedon Sep 2, 2016
I'm happy to mentor the change. It seems like it would be fairly self-contained. The error is reported by this code in
src/librustc_typeck/check/mod.rs-- just search for "attempted access of field" and you ought to find it.The idea would be to
{}in type{}"expr.spaninself.type_error_struct(expr.spantofield.span, so that we highlight just the field name itselfsuggest_field_namesfunction so that instead of callingerr.span_helpit callserr.span_labelI think that will basically do it!
nikomatsakis commentedon Sep 2, 2016
One wrinkle I am not sure about: the changes that I suggested above will, iirc, cause a
^^^with no suggestion to appear in the case that we don't have a suggested field name to offer. I feel like we wanted to move away from those, which might suggest that we ought to offer a generic label like "this field here" or something? <-- @jonathandturner ?sophiajt commentedon Sep 2, 2016
Yes, a default label would be great when we don't know the name. Maybe something like "^^^^ unknown field" when we don't know of a good suggestion
aravind-pg commentedon Sep 2, 2016
I'd love to try my hand at this. The instructions posted seem sufficient for now, but I'll come back if I have any questions.
KiChjang commentedon Sep 17, 2016
@aravind-pg Are you still working on this?
aravind-pg commentedon Sep 19, 2016
Sorry, I just haven't found time for this unfortunately. You can go ahead and un-assign me.
improve snippet for "did you mean `x`"
Rollup merge of rust-lang#36798 - gavinb:fix/36164, r=GuillaumeGomez