Skip to content

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

Merged
bors merged 7 commits into
rust-lang:masterfrom
FelixMcFelix:fix-50865-beta
Aug 24, 2018
Merged

Fix #50865: ICE on impl-trait returning functions reaching private items#53545
bors merged 7 commits into
rust-lang:masterfrom
FelixMcFelix:fix-50865-beta

Conversation

@FelixMcFelix

@FelixMcFelixFelixMcFelix commented Aug 20, 2018

Copy link
Copy Markdown
Contributor

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.

@estebankestebank left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

r? @eddyb

Comment threadsrc/librustc/middle/privacy.rs Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Update year.

Comment threadsrc/librustc_privacy/lib.rs Outdated
}

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

Copy link
Copy Markdown
Contributor

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.

Comment threadsrc/librustc_privacy/lib.rs Outdated
// 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
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

Applied suggestions, thanks for the feedback.

@eddyb

Copy link
Copy Markdown
Contributor

r? @petrochenkov

@XAMPPRockyXAMPPRocky 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
Comment threadsrc/Cargo.lock Outdated
name = "rustc_privacy"
version = "0.0.0"
dependencies = [
"log 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
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.

Comment threadsrc/librustc_privacy/lib.rs Outdated
}

let orig_level = self.prev_level;
self.prev_level = item_level;

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

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.

Comment threadsrc/librustc_privacy/lib.rs Outdated
if let Some(node_id) = self.tcx.hir.as_local_node_id(impl_trait_fn) {
self.update(node_id, Some(AccessLevel::ReachableFromImplTrait));
}
}

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Ok.

@petrochenkovpetrochenkov 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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Aug 24, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 85a05d1 has been approved by petrochenkov

@borsbors 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
@kennytmkennytm mentioned this pull request Aug 24, 2018
kennytm added a commit to kennytm/rust that referenced this pull request Aug 24, 2018
…ochenkov
Fixrust-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. Fixesrust-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:masterAug 24, 2018
@FelixMcFelix
FelixMcFelix deleted the fix-50865-beta branch August 28, 2018 14:50
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant 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

@FelixMcFelix@rust-highfive@eddyb@petrochenkov@bors@estebank@varkor@XAMPPRocky