-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Add suggestion to diagnostic when user has array but trait wants slice. #91314
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
r? @estebank This seems up your alley :) |
r? rust-lang/diagnostics |
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.
Apologies for the delay in having this reviewed, this looks good to me, I've left one suggestion that you can change if you'd like, but otherwise we can see this merged.
@@ -0,0 +1,28 @@ | |||
// Issue #90528: provide helpful suggestions when a trait bound is unsatisfied |
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.
nit: you could probably collapse these tests down into fewer files - perhaps cases where a suggestion is made and where a suggestion isn't made - and then you can add // run-rustfix
to the test to confirm the suggestion works.
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.
Sure. What should I do about the scenarios where the suggestion is wrong (see anywhere I put bad suggestion
)?
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.
We could split these out into another test, as long as the suggestion is MaybeIncorrect
then it's fine that it's sometimes wrong, it'll just need to be in a different test if we want // run-rustfix
to work on the cases that do have correct suggestions.
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.
I'm still new to rustfix. Will it apply MaybeIncorrect changes if the test is annotated with // run-rustfix
? As written, my code does not know when its suggestion is MachineApplicable and when it is MaybeIncorrect, so I just always give MaybeIncorrect.
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.
I actually can't remember, if it isn't doing it when you're trying this locally then we can just approve this - apologies for the runaround.
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.
I think that in tests MaybeIncorrect
ones do get applied. If they don't what we normally do is separate all the cases that can be fixed into its own file and another for the rest.
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.
@estebank looks like you're right: https://rustc-dev-guide.rust-lang.org/tests/adding.html#other-header-commands
rustfix-only-machine-applicable
is equivalent torun-rustfix
except it will only applyMachineApplicable
suggestions.run-rustfix
will apply all suggestions.
I went to go and apply the CR feedback today, but after rebasing with upstream, it seems my changes no longer work (i.e., no suggestions are being produced). Some very rudimentary debugging has revealed that the
Shall I go bisecting to figure out where things went wrong? Or does anybody have an idea as to what changed between Nov 28 and today that could be causing this? |
Bisect points to dcd716f. Prior to that commit, rustc will suggest the traitref of Given: trait Read {}
impl Read for &[u8] {}
fn wants_read(_: impl Read) {}
fn main() {
wants_read([0u8]);
} Compiled on dcd716f~1 (83b32f2):
Compiled on dcd716f:
I'll open another issue |
Ah crap I accidentally clicked the re-request review button, sorry @estebank |
This comment was marked as resolved.
This comment was marked as resolved.
Someone (maybe me, eventually) should check the state of the diagnostics now that #93298 is in. Just to confirm that this PR is even necessary. |
@BGR360 Heads up, I rebased this really quick and I think the suggestion may be showing up correctly now. You might be able to get this landed now, unless I'm mistaken. If you do rebase this PR, maybe you want to make this into a multipart-suggestion that suggests prepending |
Finally looking at this again.
@compiler-errors why would that be preferable in your opinion? |
@BGR360 it's just conventional to avoid |
To clarify the rationale:
|
Feel free to ping me once you've rebased. |
Unblocking as #92113 is resolved |
@BGR360 are you still interested in working on this? I could potentially bring this over the finish line by addressing the final reviews if you no longer are able to. |
@jackh726 All yours if you want it! Thanks :) |
…rrors Add suggestion to diagnostic when user has array but trait wants slice. (rebased) Rebase of rust-lang#91314, except for change to multipart suggestion Resolves rust-lang#90528 r? `@compiler-errors` since you requested the multipart suggestion
…rrors Add suggestion to diagnostic when user has array but trait wants slice. (rebased) Rebase of rust-lang#91314, except for change to multipart suggestion Resolves rust-lang#90528 r? ``@compiler-errors`` since you requested the multipart suggestion
Resolves #90528.
Before:
After:
Alternatively, I could make it look like this:
The latter more closely mirrors other suggestions like "consider changing this borrow's mutability," but the former kinda looks better. I'm open to other ideas as well.
The code ended up being a little more complicated than I had hoped. Had to account for different mutabilities and variables vs. literals. See the tests.
Since I found it impractical to provide a machine applicable suggestion, is it maybe not worth bothering with the complicated mutability logic?
cc @binajmen