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

Do not encode gensymed imports in metadata #59296

Merged
merged 1 commit into from
Mar 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ impl<'a> Resolver<'a> {
}

// Empty groups `a::b::{}` are turned into synthetic `self` imports
// `a::b::c::{self as _}`, so that their prefixes are correctly
// `a::b::c::{self as __dummy}`, so that their prefixes are correctly
// resolved and checked for privacy/stability/etc.
if items.is_empty() && !empty_for_self(&prefix) {
let new_span = prefix[prefix.len() - 1].ident.span;
Expand All @@ -312,7 +312,7 @@ impl<'a> Resolver<'a> {
Ident::new(keywords::SelfLower.name(), new_span)
),
kind: ast::UseTreeKind::Simple(
Some(Ident::new(keywords::Underscore.name().gensymed(), new_span)),
Some(Ident::new(Name::gensym("__dummy"), new_span)),
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't this shift the problem to the possible existence of __dummy somewhere in the namespace?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it's still a gensym, so it doesn't conflict with anything locally + it's not written into metadata since it's no longer an underscore.
(Previously it wasn't written due to the binding.vis != ty::Visibility::Invisible condition, but I removed it to simplify things a bit.)

ast::DUMMY_NODE_ID,
ast::DUMMY_NODE_ID,
),
Expand Down
6 changes: 4 additions & 2 deletions src/librustc_resolve/resolve_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1295,9 +1295,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
None => continue,
};

// Filter away "empty import canaries" and ambiguous imports.
// Filter away ambiguous and gensymed imports. Gensymed imports
// (e.g. implicitly injected `std`) cannot be properly encoded in metadata,
// so they can cause name conflict errors downstream.
let is_good_import = binding.is_import() && !binding.is_ambiguity() &&
binding.vis != ty::Visibility::Invisible;
!(ident.name.is_gensymed() && ident.name != "_");
if is_good_import || binding.is_macro_def() {
let def = binding.def();
if def != Def::Err {
Expand Down
4 changes: 4 additions & 0 deletions src/libsyntax_pos/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,10 @@ impl Symbol {
with_interner(|interner| interner.gensymed(self))
}

pub fn is_gensymed(self) -> bool {
with_interner(|interner| interner.is_gensymed(self))
}

pub fn as_str(self) -> LocalInternedString {
with_interner(|interner| unsafe {
LocalInternedString {
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/imports/auxiliary/gensymed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// edition:2018

mod std {}
7 changes: 7 additions & 0 deletions src/test/ui/imports/gensymed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// compile-pass
// edition:2018
// aux-build:gensymed.rs

extern crate gensymed;

fn main() {}