Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdd lint for unused macros #41907
Conversation
rust-highfive
assigned
pnkfelix
May 11, 2017
This comment has been minimized.
This comment has been minimized.
|
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
r? @jseyfried because you seem to have done many things with macros in the past, so might know the code best. |
rust-highfive
assigned
jseyfried
and unassigned
pnkfelix
May 11, 2017
This comment has been minimized.
This comment has been minimized.
|
Hmmm, I suspect that the lint checker requires something to be present under the NodeId we give it, so we can't just bail out by creating some random one, but I guess we'll need to create our own special |
alexcrichton
added
the
S-waiting-on-review
label
May 11, 2017
This comment has been minimized.
This comment has been minimized.
|
Okay, apparently macro definitions do survive inside the AST (but not in the hir), only have to add handling for them in the lint code. Update incoming. I've also found some occurences of unused macros inside the codebase, |
est31
force-pushed the
est31:macro_unused
branch
5 times, most recently
from
0c72cd2
to
a97a1c5
May 12, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
May 12, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
May 12, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
May 12, 2017
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
May 13, 2017
This comment has been minimized.
This comment has been minimized.
|
If @jseyfried doesn't appear, then r=me after #41934 is merged. |
added some commits
May 11, 2017
est31
force-pushed the
est31:macro_unused
branch
from
a97a1c5
to
b36d23c
May 13, 2017
est31
changed the title
Add lint for unused macros [WIP]
Add lint for unused macros
May 13, 2017
This comment has been minimized.
This comment has been minimized.
|
okay, ready for review. r? @jseyfried |
jseyfried
reviewed
May 15, 2017
|
Looks good! r=me modulo comments |
| let id_span = match *self.macro_map[did] { | ||
| SyntaxExtension::NormalTT(_, isp, _) => isp, | ||
| _ => None | ||
| }; |
This comment has been minimized.
This comment has been minimized.
jseyfried
May 15, 2017
Contributor
nit: this is usually formatted
let id_span = match *self.macro_map[did] {
SyntaxExtension::NormalTT(_, isp, _) => isp,
_ => None
};| @@ -12,6 +12,7 @@ use super::Wrapping; | |||
|
|
|||
| use ops::*; | |||
|
|
|||
| #[allow(unused_macros)] | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
est31
May 15, 2017
Author
Contributor
There is a FIXME below to get the remaining impls uncommented, including invocations of the macro.
This comment has been minimized.
This comment has been minimized.
| exp, | ||
| Some((def.id, def.span)), | ||
| attr::contains_name(&def.attrs, "allow_internal_unstable") | ||
| ) |
This comment has been minimized.
This comment has been minimized.
jseyfried
May 15, 2017
Contributor
nit: nonstandard formatting -- should be three lines with "visual indenting" or indented one block with four/five lines.
| // List of macros that we need to warn about as being unused. | ||
| // The bool is true if the macro is unused, and false if its used. | ||
| // Setting a bool to false should be much faster than removing a single | ||
| // element from a FxHashSet. |
This comment has been minimized.
This comment has been minimized.
jseyfried
May 15, 2017
Contributor
Could you clarify that this is only for crate-local macro_rules!?
This comment has been minimized.
This comment has been minimized.
est31
May 15, 2017
Author
Contributor
Okay, but hopefully the upcoming macros 2.0 macros could be included as well.
| // The bool is true if the macro is unused, and false if its used. | ||
| // Setting a bool to false should be much faster than removing a single | ||
| // element from a FxHashSet. | ||
| unused_macros: FxHashMap<DefId, bool>, |
This comment has been minimized.
This comment has been minimized.
jseyfried
May 15, 2017
Contributor
I still think this should be an FxHashSet<DefId> -- I believe the perf difference is negligible here (removing a value from a hash set is already many orders of magnitude faster than the rest the processing we do per used crate-local macro_rules!).
This comment has been minimized.
This comment has been minimized.
|
updated. re-r? @jseyfried |
This comment has been minimized.
This comment has been minimized.
|
|
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this pull request
May 16, 2017
bors
added a commit
that referenced
this pull request
May 16, 2017
bors
added a commit
that referenced
this pull request
May 16, 2017
This comment has been minimized.
This comment has been minimized.
|
Had to update due to this failure. re-r? @jseyfried |
This comment has been minimized.
This comment has been minimized.
|
@bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this pull request
May 16, 2017
bors
added a commit
that referenced
this pull request
May 16, 2017
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
May 16, 2017
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
I think this was recently fixed, but the update to the cargo submodule hasn't been pulled in yet (if the PR was even merged) @bors retry |
This comment has been minimized.
This comment has been minimized.
|
FWIW that was fixed by rust-lang/cargo#4051 and we'll get the update in #42039 |
arielb1
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
May 16, 2017
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
May 16, 2017
This comment has been minimized.
This comment has been minimized.
|
|
est31 commentedMay 11, 2017
•
edited
Addresses parts of #34938, to add a lint for unused macros.
We now output warnings by default when we encounter a macro that we didn't use for expansion.
Issues to be resolved before this PR is ready for merge:
#[allow(unused_macros)]next to them if they should be kept for some reason. This is needed for successful boostrap and bors to accept the PR. -> #41934implement the full extent of #34938, that means the macro match arm checking as well.let's not do this for now