-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
r? @eddyb
src/librustc/middle/privacy.rs
Outdated
@@ -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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update year.
src/librustc_privacy/lib.rs
Outdated
@@ -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); |
There was a problem hiding this comment.
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.
src/librustc_privacy/lib.rs
Outdated
@@ -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); |
There was a problem hiding this comment.
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?
This comment has been minimized.
This comment has been minimized.
Applied suggestions, thanks for the feedback. |
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)", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/librustc_privacy/lib.rs
Outdated
@@ -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; |
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)); | ||
} | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok.
@bors r+ |
📌 Commit 85a05d1 has been approved by |
…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.
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.)
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.