Skip to content

Commit 080332b

Browse files
authored
Rollup merge of rust-lang#59296 - petrochenkov:stdup, r=estebank
Do not encode gensymed imports in metadata (Unless they are underscore `_` imports which are re-gensymed on crate loading, see rust-lang#56392.) We cannot encode gensymed imports properly in metadata and if we encode them improperly, we can get erroneous name conflicts downstream. Gensymed imports are produced by the compiler, so we control their set, and can be sure that none of them needs being encoded for use from other crates. A workaround that fixes rust-lang#59243.
2 parents 3ff78d4 + 30d5dc9 commit 080332b

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/librustc_resolve/build_reduced_graph.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a> Resolver<'a> {
303303
}
304304

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

src/librustc_resolve/resolve_imports.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1295,9 +1295,11 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
12951295
None => continue,
12961296
};
12971297

1298-
// Filter away "empty import canaries" and ambiguous imports.
1298+
// Filter away ambiguous and gensymed imports. Gensymed imports
1299+
// (e.g. implicitly injected `std`) cannot be properly encoded in metadata,
1300+
// so they can cause name conflict errors downstream.
12991301
let is_good_import = binding.is_import() && !binding.is_ambiguity() &&
1300-
binding.vis != ty::Visibility::Invisible;
1302+
!(ident.name.is_gensymed() && ident.name != "_");
13011303
if is_good_import || binding.is_macro_def() {
13021304
let def = binding.def();
13031305
if def != Def::Err {

src/libsyntax_pos/symbol.rs

+4
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ impl Symbol {
179179
with_interner(|interner| interner.gensymed(self))
180180
}
181181

182+
pub fn is_gensymed(self) -> bool {
183+
with_interner(|interner| interner.is_gensymed(self))
184+
}
185+
182186
pub fn as_str(self) -> LocalInternedString {
183187
with_interner(|interner| unsafe {
184188
LocalInternedString {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// edition:2018
2+
3+
mod std {}

src/test/ui/imports/gensymed.rs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-pass
2+
// edition:2018
3+
// aux-build:gensymed.rs
4+
5+
extern crate gensymed;
6+
7+
fn main() {}

0 commit comments

Comments
 (0)