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

Fix #50865: ICE on impl-trait returning functions reaching private items #53545

Merged
merged 7 commits into from
Aug 24, 2018

Conversation

FelixMcFelix
Copy link
Contributor

@FelixMcFelix FelixMcFelix commented Aug 20, 2018

Adds a test case as suggested in #50865, and implements @petrochenkov's suggestion. Fixes #50865.

Impl-trait-returning functions are marked under a new (low) access level, which they propagate rather than AccessLevels::Reachable. AccessLevels::is_reachable returns false for such items (leaving stability analysis unaffected), these items may still be visible to the lints phase however.

Copy link
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

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

lgtm

r? @eddyb

@@ -40,7 +42,8 @@ pub struct AccessLevels<Id = NodeId> {

impl<Id: Hash + Eq> AccessLevels<Id> {
pub fn is_reachable(&self, id: Id) -> bool {
self.map.contains_key(&id)
// self.map.contains_key(&id)
Copy link
Contributor

Choose a reason for hiding this comment

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

do not leave commented out code

@@ -0,0 +1,20 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
Copy link
Contributor

Choose a reason for hiding this comment

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

Update year.

@@ -0,0 +1,24 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
Copy link
Contributor

Choose a reason for hiding this comment

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

Update year.

@@ -147,6 +150,7 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
}

fn visit_item(&mut self, item: &'tcx hir::Item) {
debug!("Walked item {:?}", item);
Copy link
Member

Choose a reason for hiding this comment

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

Usually this would be something like: debug!("visit_item({:?})", item);, so it's easier to see where it comes from.

@@ -171,6 +184,8 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
// Update level of the item itself
let item_level = self.update(item.id, inherited_item_level);

debug!("Its privacy is believed to be: {:?}", item_level);
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps just item_level = {:?} is sufficient?

@rust-highfive

This comment has been minimized.

@FelixMcFelix
Copy link
Contributor Author

Applied suggestions, thanks for the feedback.

@eddyb
Copy link
Member

eddyb commented Aug 21, 2018

r? @petrochenkov

@XAMPPRocky XAMPPRocky added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 21, 2018
src/Cargo.lock Outdated
@@ -2237,6 +2237,7 @@ dependencies = [
name = "rustc_privacy"
version = "0.0.0"
dependencies = [
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you avoid introducing this new dependency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Any debug!("...") calls would then also need to be removed. Is this version of log different from that used by the rest of the rustc_* crates?

Copy link
Contributor

Choose a reason for hiding this comment

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

debug!(...) logging used for a specific debugging session is usually useless for anything else in the future, so I mean yes, it is better removed.

@@ -227,6 +242,9 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> {
hir::ItemKind::ExternCrate(..) => {}
}

let orig_level = self.prev_level;
self.prev_level = item_level;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: let orig_level = mem::replace(&mut self.prev_level, item_level);

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not sure why these lines were moved from there to here actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok. This was moved while I was figuring out how best to propagate the level from the ReachEverythingInTheInterfaceVisitor. Will move back and modify.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this was moved so that EmbargoVisitor::reach would be able to see whether the parent node was ReachableFromImplTrait or at least Reachable, to propagate the correct level.

if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) {
self.update(node_id, Some(AccessLevel::ReachableFromImplTrait));
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move this piece of code from here to // Update levels of nested things below, it belongs there logically.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok.

@petrochenkov petrochenkov 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2018
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Aug 24, 2018

📌 Commit 85a05d1 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 Aug 24, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Aug 24, 2018
…ochenkov

Fix rust-lang#50865: ICE on impl-trait returning functions reaching private items

Adds a test case as suggested in rust-lang#50865, and implements @petrochenkov's suggestion. Fixes rust-lang#50865.

Impl-trait-returning functions are marked under a new (low) access level, which they propagate rather than `AccessLevels::Reachable`. `AccessLevels::is_reachable` returns false for such items (leaving stability analysis unaffected), these items may still be visible to the lints phase however.
bors added a commit that referenced this pull request Aug 24, 2018
Rollup of 16 pull requests

Successful merges:

 - #53311 (Window Mutex: Document that we properly initialize the SRWLock)
 - #53503 (Discourage overuse of mem::forget)
 - #53545 (Fix #50865: ICE on impl-trait returning functions reaching private items)
 - #53559 (add macro check for lint)
 - #53562 (Lament the invincibility of the Turbofish)
 - #53563 (use String::new() instead of String::from(""), "".to_string(), "".to_owned() or "".into())
 - #53592 (docs: minor stylistic changes to str/string docs)
 - #53594 (Update RELEASES.md to include clippy-preview)
 - #53600 (Fix a grammatical mistake in "expected generic arguments" errors)
 - #53614 (update nomicon and book)
 - #53617 (tidy: Stop requiring a license header)
 - #53618 (Add missing fmt examples)
 - #53636 (Prefer `.nth(n)` over `.skip(n).next()`.)
 - #53644 (Use SmallVec for SmallCStr)
 - #53664 (Remove unnecessary closure in rustc_mir/build/mod.rs)
 - #53666 (Added rustc_codegen_llvm to compiler documentation.)
@bors bors merged commit 85a05d1 into rust-lang:master Aug 24, 2018
@FelixMcFelix FelixMcFelix deleted the fix-50865-beta branch August 28, 2018 14:50
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants