-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Enable trimmed paths #7668
Enable trimmed paths #7668
Conversation
r? @Manishearth (rust-highfive has picked a reviewer for you, use r? to override) |
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 like this, we should definitely get some agreement from the team though, and perhaps be more explicit about documenting things reviewers need to be aware of.
It seems like this is not a bug, but a feature of the Rust compiler. 🤔 So we'll have to deal with that somehow.
What I really like about our utils functions is that they're just easy to understand and easy to use, because the arguments are really straight forward. You don't have to deal with a A reason why we can have so easy to use utils is that they are good enough for our purposes most of the time. (Also DRY: we'd see many of the same closures over and over again. We even have an internal lint to avoid this currently)
That is a really bad idea in general. Does this only happen with the I don't want to rely on humans remembering to check for specific queries to avoid ICEs in every review. I definitely like the trimmed paths part of this PR. |
Funny, I feel that I had the opposite experience when I was a beginner. I found all the arguments with two spans and two messages hard to reason about what is what. I was particularly confused about the
Yeah I was hesitant about this part. There is I think |
I agree with this one for simple use cases, which are the majority of our (Slightly related: some functions for building suggestions have notes on them that they are slowish (See: Could we maybe make the flag conditional? If we set it to |
Please be aware that the trimmed path is not the locally available name. It "just" looks to see if the identifier is globally unique and uses just the name if it is. This is a hack and likely not what people expect. |
Good point. I was aware of that, but you got me thinking some more. I guess we can't use
@estebank Are you saying it's a bad idea to port this "feature" to Clippy? |
This should be a welcomed feature. At the very least it should be flag enableable with something like |
Closing in favor of #7798 |
changelog: Uses "trimmed paths" instead of fully qualified paths in output
This flips a magic switch in driver.rs so that we get
Option
instead ofstd::option::Option
fromcx.tcx.def_path_str
, for example. This improves Clippy output all around. There aren't a whole lot of these cases. But I suspect there are a number of cases wheredef_path_str
would be a better choice than the current implementation, and it might have been used more if this feature were already enabled.Unfortunately this comes with a footgun. Any time we fetch a trimmed path (usually through
Ty::to_string
orcx.tcx.def_path_str
), but then don't use it to emit a lint, rustc ICEs. This is especially problematic with our utility functionsspan_lint_*
because these functions don't emit if the lint is allowed.To solve this, I created a new util
span_clippy_lint
that works similarly tospan_lint_and_then
. It uses a Drop guard to add our special Clippy messages at the end.And of course you can use anything in
Diagnostic
likespan_suggestion
orhelp
in a call chain. TBH I like this API a lot more than our current util functions.This still leaves a rough edge for Clippy contributors since we can't ever fetch a trimmed path outside of the "diag" closure, and our tests don't necessarily catch the problem if we do it wrong. So this is something all maintainers would need to be wary of when reviewing.
For now, I just converted some lints to
span_clippy_lint
to avoid ICE where needed. But I think we need to convert all the lints over and delete thespan_lint_*
functions to get rid of the footgun. Opening for feedback. @rust-lang/clippyCloses #6385
Closes #7212
TODO
span_lint_*
withspan_clippy_lint
everywherespan_lint_*
and related internal lints