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

Update visibility of intermediate use items. #57922

Merged
merged 1 commit into from
Feb 3, 2019

Conversation

davidtwco
Copy link
Member

@davidtwco davidtwco commented Jan 26, 2019

Fixes #57410 and fixes #53925 and fixes #47816.

Currently, the target of a use statement will be updated with
the visibility of the use statement itself (if the use statement was
visible).

This PR ensures that if the path to the target item is via another
use statement then that intermediate use statement will also have the
visibility updated like the target. This silences incorrect
unreachable_pub lints with inactionable suggestions.

@rust-highfive
Copy link
Collaborator

r? @oli-obk

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 26, 2019
let item = self.tcx.hir().expect_item(item_id.id);
if item.ident != name.ident { continue; }
if let hir::ItemKind::Use(..) = item.node {
self.update(item.id, Some(AccessLevel::Exported));
Copy link
Member Author

Choose a reason for hiding this comment

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

I've only taken this approach to updating the intermediate use statement as I couldn't find a way to go to it directly from the first use statement. If anyone has a better way of getting to this, I'm happy to change it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh man, what a hack.
The import -> import -> import -> real definition link is lost after resolve.
The real solution is to calculate AccessLevel::Public and AccessLevel::Exported levels in resolve, while keeping calculating Reachable/ReachableFromImplTrait during the late privacy stage.
It will obviously require changing some infrastructure as well.

Copy link
Contributor

Choose a reason for hiding this comment

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

This solution won't work with glob imports (they don't have a name) and also doesn't respect namespaces.
It's an ok approximation, I think we can merge it after adding a couple of FIXMEs describing why it's not entirely correct.

Copy link
Member Author

@davidtwco davidtwco Jan 27, 2019

Choose a reason for hiding this comment

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

Would you prefer I attempt to do that in this PR or file a separate issue so that this is followed up on?

Clarified by your later message.

Copy link
Member Author

Choose a reason for hiding this comment

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

I've added a FIXME comment.

@petrochenkov petrochenkov assigned petrochenkov and unassigned oli-obk Jan 26, 2019
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@oli-obk
Copy link
Contributor

oli-obk commented Jan 27, 2019

r? @petrochenkov

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jan 27, 2019

📌 Commit b487a4b1c15bfeb0337b079038498ed1d13e5aa8 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 27, 2019
@bors
Copy link
Contributor

bors commented Jan 28, 2019

⌛ Testing commit b487a4b1c15bfeb0337b079038498ed1d13e5aa8 with merge c02deb70ed6d7166c91f3aa33831d99cc1c090cd...

@bors
Copy link
Contributor

bors commented Jan 28, 2019

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 28, 2019
@Centril
Copy link
Contributor

Centril commented Jan 28, 2019

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2019
@rust-highfive

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 28, 2019

⌛ Testing commit b487a4b1c15bfeb0337b079038498ed1d13e5aa8 with merge 3d4225349c6db6f369352904a004cd9abeef9609...

@Dylan-DPC-zz Dylan-DPC-zz added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 28, 2019
@Dylan-DPC-zz
Copy link

ping from triage @petrochenkov waiting for your review on the latest change.

@davidtwco
Copy link
Member Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented Jan 28, 2019

📌 Commit ad22de4 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 28, 2019
Centril added a commit to Centril/rust that referenced this pull request Jan 28, 2019
Update visibility of intermediate use items.

Fixes rust-lang#57410 and fixes rust-lang#53925 and fixes rust-lang#47816.

Currently, the target of a use statement will be updated with
the visibility of the use statement itself (if the use statement was
visible).

This PR ensures that if the path to the target item is via another
use statement then that intermediate use statement will also have the
visibility updated like the target. This silences incorrect
`unreachable_pub` lints with inactionable suggestions.
@Centril
Copy link
Contributor

Centril commented Jan 28, 2019

Failed in rollup, #57955 (comment) (same reason as before).

@bors r-

Please test locally or with try that this builds.

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 28, 2019
@davidtwco
Copy link
Member Author

Please test locally or with try that this builds.

My bad, I had ran tests locally but didn't consider conditional code for other platforms. I'll r+ again when I'm sure it'll be fine.

Currently, the target of a use statement will be updated with
the visibility of the use statement itself (if the use statement was
visible).

This commit ensures that if the path to the target item is via another
use statement then that intermediate use statement will also have the
visibility updated like the target. This silences incorrect
`unreachable_pub` lints with inactionable suggestions.
@davidtwco
Copy link
Member Author

I've ran all the tests for this on both Windows and Linux, I think there shouldn't be any issues.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 3, 2019

📌 Commit 7102339 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 3, 2019
@bors
Copy link
Contributor

bors commented Feb 3, 2019

⌛ Testing commit 7102339 with merge 42b8c77...

bors added a commit that referenced this pull request Feb 3, 2019
Update visibility of intermediate use items.

Fixes #57410 and fixes #53925 and fixes #47816.

Currently, the target of a use statement will be updated with
the visibility of the use statement itself (if the use statement was
visible).

This PR ensures that if the path to the target item is via another
use statement then that intermediate use statement will also have the
visibility updated like the target. This silences incorrect
`unreachable_pub` lints with inactionable suggestions.
@bors
Copy link
Contributor

bors commented Feb 3, 2019

☀️ Test successful - checks-travis, status-appveyor
Approved by: petrochenkov
Pushing 42b8c77 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
7 participants