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

single_component_path_imports: ignore pub(crate) use some_macro; #7120

Merged
merged 1 commit into from
Apr 22, 2021
Merged

single_component_path_imports: ignore pub(crate) use some_macro; #7120

merged 1 commit into from
Apr 22, 2021

Conversation

cherryblossom000
Copy link
Contributor

@cherryblossom000 cherryblossom000 commented Apr 22, 2021

Fixes #7106

Please write a short comment explaining your change (or "none" for internal only changes)

changelog: Ignore exporting a macro within a crate using pub(crate) use some_macro; for [single_component_path_imports]

@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @Manishearth (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Apr 22, 2021
@@ -105,14 +119,22 @@ fn track_uses(
ItemKind::Mod(_, ModKind::Loaded(ref items, ..)) => {
check_mod(cx, &items);
},
ItemKind::MacroDef(MacroDef { macro_rules: true, .. }) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a brief look at the macros 2.0 RFC, and it seems like it will introduce a better way of declaring a macro's visibility:

pub(crate) macro foo { /* ... */ }

That's why I've included macro_rules: true so this only applies to macro_rules! macros, but I'm not too sure about this.

ItemKind::Use(use_tree) => {
let segments = &use_tree.prefix.segments;

let should_report =
|name: &Symbol| !macros.contains(name) || matches!(item.vis.kind, VisibilityKind::Inherited);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I remove the &Symbol type annotation, I get this error:

error[E0597]: `name` does not live long enough
   --> clippy_lints/src/single_component_path_imports.rs:150:50
    |
150 | ...                       if should_report(&name) {
    |                              ------------- ^^^^^ borrowed value does not live long enough
    |                              |
    |                              borrow later used here
...
153 | ...                   }
    |                       - `name` dropped here while still borrowed

@Manishearth
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented Apr 22, 2021

📌 Commit b48699e has been approved by Manishearth

@bors
Copy link
Collaborator

bors commented Apr 22, 2021

⌛ Testing commit b48699e with merge 74f5599...

@bors
Copy link
Collaborator

bors commented Apr 22, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Manishearth
Pushing 74f5599 to master...

@bors bors merged commit 74f5599 into rust-lang:master Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

single_component_path_imports: False positive for exporting macros within crate
4 participants