Skip to content
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 lint for unused macros #41907

Merged
merged 8 commits into from May 17, 2017

Conversation

Projects
None yet
10 participants
@est31
Copy link
Contributor

est31 commented May 11, 2017

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:

  • fix the NodeId issue described above
  • remove all unused macros from rustc and the libraries or set #[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. -> #41934
  • implement the full extent of #34938, that means the macro match arm checking as well. let's not do this for now
@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented May 11, 2017

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@est31

This comment has been minimized.

Copy link
Contributor Author

est31 commented May 11, 2017

r? @jseyfried because you seem to have done many things with macros in the past, so might know the code best.

@rust-highfive rust-highfive assigned jseyfried and unassigned pnkfelix May 11, 2017

@est31

This comment has been minimized.

Copy link
Contributor Author

est31 commented May 11, 2017

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 ExprKind like UnusedMac or something that then lives on until the linter runs.

@est31

This comment has been minimized.

Copy link
Contributor Author

est31 commented May 12, 2017

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 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

Rollup merge of rust-lang#41934 - est31:remove_unused_macros, r=nagisa
Remove unused macros from the codebase

Thanks to the lint I've implemented in rust-lang#41907 I've found some unused macros inside the rustc codebase.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 12, 2017

Rollup merge of rust-lang#41934 - est31:remove_unused_macros, r=nagisa
Remove unused macros from the codebase

Thanks to the lint I've implemented in rust-lang#41907 I've found some unused macros inside the rustc codebase.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 12, 2017

Rollup merge of rust-lang#41934 - est31:remove_unused_macros, r=nagisa
Remove unused macros from the codebase

Thanks to the lint I've implemented in rust-lang#41907 I've found some unused macros inside the rustc codebase.

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 13, 2017

Rollup merge of rust-lang#41934 - est31:remove_unused_macros, r=nagisa
Remove unused macros from the codebase

Thanks to the lint I've implemented in rust-lang#41907 I've found some unused macros inside the rustc codebase.
@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented May 13, 2017

If @jseyfried doesn't appear, then r=me after #41934 is merged.

est31 added some commits May 11, 2017

est31
Support #[allow] etc logic on a per macro level
This commit extends the current unused macro linter
to support directives like #[allow(unused_macros)]
or #[deny(unused_macros)] directly next to the macro
definition, or in one of the modules the macro is
inside. Before, we only supported such directives
at a per crate level, due to the crate's NodeId
being passed to session.add_lint.

We also had to implement handling of the macro's
NodeId in the lint visitor.
est31

@est31 est31 force-pushed the est31:macro_unused branch from a97a1c5 to b36d23c May 13, 2017

@est31 est31 changed the title Add lint for unused macros [WIP] Add lint for unused macros May 13, 2017

@est31

This comment has been minimized.

Copy link
Contributor Author

est31 commented May 13, 2017

okay, ready for review. r? @jseyfried

@jseyfried
Copy link
Contributor

jseyfried left a comment

Looks good! r=me modulo comments

let id_span = match *self.macro_map[did] {
SyntaxExtension::NormalTT(_, isp, _) => isp,
_ => None
};

This comment has been minimized.

@jseyfried

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.

@jseyfried

jseyfried May 15, 2017

Contributor

Is there a reason we can't just remove the unused macro here?

This comment has been minimized.

@est31

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.

@jseyfried

jseyfried May 15, 2017

Contributor

Makes sense.

exp,
Some((def.id, def.span)),
attr::contains_name(&def.attrs, "allow_internal_unstable")
)

This comment has been minimized.

@jseyfried

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.

@jseyfried

jseyfried May 15, 2017

Contributor

Could you clarify that this is only for crate-local macro_rules!?

This comment has been minimized.

@est31

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.

@jseyfried

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!).

est31
@est31

This comment has been minimized.

Copy link
Contributor Author

est31 commented May 15, 2017

updated. re-r? @jseyfried

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 15, 2017

📌 Commit 25b7f10 has been approved by jseyfried

frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 16, 2017

Rollup merge of rust-lang#41907 - est31:macro_unused, r=jseyfried
Add lint for unused macros

Addresses parts of rust-lang#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:

- [x] fix the NodeId issue described above
- [x] remove all unused macros from rustc and the libraries or set `#[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. -> rust-lang#41934
- [x] ~~implement the full extent of rust-lang#34938, that means the macro match arm checking as well.~~ *let's not do this for now*

bors added a commit that referenced this pull request May 16, 2017

Auto merge of #42022 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests

- Successful merges: #41489, #41771, #41907, #41982, #41994, #41995
- Failed merges:

bors added a commit that referenced this pull request May 16, 2017

Auto merge of #42022 - frewsxcv:rollup, r=frewsxcv
Rollup of 6 pull requests

- Successful merges: #41489, #41771, #41907, #41982, #41994, #41995
- Failed merges:
@est31

This comment has been minimized.

Copy link
Contributor Author

est31 commented May 16, 2017

Had to update due to this failure. re-r? @jseyfried

@jseyfried

This comment has been minimized.

Copy link
Contributor

jseyfried commented May 16, 2017

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 16, 2017

📌 Commit 6dbd706 has been approved by jseyfried

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request May 16, 2017

Rollup merge of rust-lang#41907 - est31:macro_unused, r=jseyfried
Add lint for unused macros

Addresses parts of rust-lang#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:

- [x] fix the NodeId issue described above
- [x] remove all unused macros from rustc and the libraries or set `#[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. -> rust-lang#41934
- [x] ~~implement the full extent of rust-lang#34938, that means the macro match arm checking as well.~~ *let's not do this for now*

bors added a commit that referenced this pull request May 16, 2017

Auto merge of #42032 - Mark-Simulacrum:rollup, r=Mark-Simulacrum
Rollup of 8 pull requests

- Successful merges: #41489, #41907, #41932, #41982, #41994, #41995, #42001, #42005
- Failed merges:
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 16, 2017

⌛️ Testing commit 6dbd706 with merge 9ccc84d...

bors added a commit that referenced this pull request May 16, 2017

Auto merge of #41907 - est31:macro_unused, r=jseyfried
Add lint for unused macros

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:

- [x] fix the NodeId issue described above
- [x] remove all unused macros from rustc and the libraries or set `#[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. -> #41934
- [x] ~~implement the full extent of #34938, that means the macro match arm checking as well.~~ *let's not do this for now*
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 16, 2017

💔 Test failed - status-travis

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented May 16, 2017


[01:15:04] ---- concurrent_installs stdout ----

[01:15:04] 	thread 'concurrent_installs' panicked at '

[01:15:04] Expected: execs

[01:15:04]     but: exited with exit code: 101

[01:15:04] --- stdout

[01:15:04] 

[01:15:04] --- stderr

[01:15:04]     Updating registry `file:///checkout/obj/build/x86_64-unknown-linux-gnu/stage2-tools/x86_64-unknown-linux-gnu/cit/t0/registry`

[01:15:04]     Blocking waiting for file lock on the registry index

[01:15:04] error: could not find `foo` in `registry https://github.com/rust-lang/crates.io-index`

[01:15:04] ', /cargo/registry/src/github.com-1ecc6299db9ec823/hamcrest-0.1.1/src/core.rs:31

[01:15:04] note: Run with `RUST_BACKTRACE=1` for a backtrace.

[01:15:04] 

[01:15:04] 

[01:15:04] failures:

[01:15:04]     concurrent_installs

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

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented May 16, 2017

FWIW that was fixed by rust-lang/cargo#4051 and we'll get the update in #42039

@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 16, 2017

⌛️ Testing commit 6dbd706 with merge 86319e4...

bors added a commit that referenced this pull request May 16, 2017

Auto merge of #41907 - est31:macro_unused, r=jseyfried
Add lint for unused macros

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:

- [x] fix the NodeId issue described above
- [x] remove all unused macros from rustc and the libraries or set `#[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. -> #41934
- [x] ~~implement the full extent of #34938, that means the macro match arm checking as well.~~ *let's not do this for now*
@bors

This comment has been minimized.

Copy link
Contributor

bors commented May 17, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: jseyfried
Pushing 86319e4 to master...

@bors bors merged commit 6dbd706 into rust-lang:master May 17, 2017

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Jun 2, 2017

Rollup merge of rust-lang#42334 - est31:master, r=jseyfried
Extend the unused macro lint to macros 2.0

Extends the unused macro lint (added in PR rust-lang#41907) to macros 2.0 (added in PR rust-lang#40847).

r? @jseyfried

bors added a commit that referenced this pull request Jun 3, 2017

Auto merge of #42334 - est31:master, r=jseyfried
Extend the unused macro lint to macros 2.0

Extends the unused macro lint (added in PR #41907) to macros 2.0 (added in PR #40847).

r? @jseyfried

@brson brson added the relnotes label Jun 6, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.