Repository navigation
Implement RFC#2: Unused attribute lint - #14373
Merged
Merged
Conversation
Contributor
|
(Needs a rebase already ;P ) |
Member
Author
|
Yeah, #14320 stomped all over everything :( |
Member
Author
|
Rebased |
Contributor
There was a problem hiding this comment.
Maybe this could be
static ATTR_WHITELIST: &'static [&'static str] = [
// rustdoc
"automatically_derived", "doc",
// trans
"address_insignificant",
// ...
];
// ...
for attr in attrs.iter() {
for name in ATTR_WHITELIST.iter() {
if attr.check_name(*name) {
break // can't have two different names at once.
}
}
if !attr:is_used(attr) {
cx.span_lint(...);
}
}
Member
Author
|
@huonw updated |
Contributor
|
r=me with comments, a FIXME & issue for reducing the whitelist of attributes (especially trans ones) (just to reduce the bus-factor), and a rebase. |
Contributor
|
Oh, also, does this make linting noticably slower ( I imagine doing the whitelist loop is a little slow, as is doing a TLD look up for each attribute, but I don't know how slow. |
Member
Author
|
There's no significant difference in the speed of the lint pass. |
Enough attributes are marked to cleanly compile an empty library.
This is a bit overly permissive but should be okay for now.
There's a fair number of attributes that have to be whitelisted since they're either looked for by rustdoc, in trans, or as needed. These can be cleaned up in the future.
bors
added a commit
that referenced
this pull request
May 25, 2014
The compiler now tracks which attributes were actually looked at during the compilation process and warns for those that were unused. Some things of note: * The tracking is done via thread locals, as it made the implementation more straightforward. Note that this shouldn't hamper any future parallelization as each task can have its own thread local state which can be merged for the lint pass. If there are serious objections to this, I can restructure things to explicitly pass the state around. * There are a number of attributes that have to be special-cased and globally whitelisted. This happens for four reasons: * The `doc` and `automatically_derived` attributes are used by rustdoc, but not by the compiler. * The crate-level attributes `license`, `desc` and `comment` aren't currently used by anything. * Stability attributes as well as `must_use` are checked only when the tagged item is used, so we can't guarantee that the compiler's looked at them. * 12 attributes are used only in trans, which happens after the lint pass. #14300 is adding infrastructure to track lint state through trans, which this lint should also be able to use to handle the last case. For the other attributes, the right solution would probably involve a specific pass to mark uses that occur in the correct context. For example, a `doc` attribute attached to a match arm should generate a warning, but will not currently. RFC: 0002-attribute-usage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The compiler now tracks which attributes were actually looked at during the compilation process and warns for those that were unused.
Some things of note:
docandautomatically_derivedattributes are used by rustdoc, but not by the compiler.license,descandcommentaren't currently used by anything.must_useare checked only when the tagged item is used, so we can't guarantee that the compiler's looked at them.enum size lint #14300 is adding infrastructure to track lint state through trans, which this lint should also be able to use to handle the last case. For the other attributes, the right solution would probably involve a specific pass to mark uses that occur in the correct context. For example, a
docattribute attached to a match arm should generate a warning, but will not currently.RFC: 0002-attribute-usage