Skip to content

Commit

Permalink
Remove Ident::{gensym, is_gensymed}
Browse files Browse the repository at this point in the history
`gensym_if_underscore` still exists. The symbol interner can still
create arbitray gensyms, this is just not exposed publicly.
  • Loading branch information
matthewjasper committed Sep 5, 2019
1 parent 2a82aec commit beb2f5b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
8 changes: 2 additions & 6 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -1307,12 +1307,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
None => continue,
};

// 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() &&
// Note that as_str() de-gensyms the Symbol
!(ident.is_gensymed() && ident.name.as_str() != "_");
// Filter away ambiguous imports.
let is_good_import = binding.is_import() && !binding.is_ambiguity();
if is_good_import || binding.is_macro_def() {
let res = binding.res();
if res != Res::Err {
Expand Down
27 changes: 12 additions & 15 deletions src/libsyntax_pos/symbol.rs
Expand Up @@ -798,21 +798,15 @@ impl Ident {
Ident::new(self.name, self.span.modern_and_legacy())
}

/// Transforms an identifier into one with the same name, but gensymed.
pub fn gensym(self) -> Ident {
let name = with_interner(|interner| interner.gensymed(self.name));
Ident::new(name, self.span)
}

/// Transforms an underscore identifier into one with the same name, but
/// gensymed. Leaves non-underscore identifiers unchanged.
pub fn gensym_if_underscore(self) -> Ident {
if self.name == kw::Underscore { self.gensym() } else { self }
}

// WARNING: this function is deprecated and will be removed in the future.
pub fn is_gensymed(self) -> bool {
with_interner(|interner| interner.is_gensymed(self.name))
if self.name == kw::Underscore {
let name = with_interner(|interner| interner.gensymed(self.name));
Ident::new(name, self.span)
} else {
self
}
}

pub fn as_str(self) -> LocalInternedString {
Expand Down Expand Up @@ -865,9 +859,12 @@ impl UseSpecializedDecodable for Ident {}
///
/// Examples:
/// ```
/// assert_eq!(Ident::from_str("x"), Ident::from_str("x"))
/// assert_ne!(Ident::from_str("x").gensym(), Ident::from_str("x"))
/// assert_ne!(Ident::from_str("x").gensym(), Ident::from_str("x").gensym())
/// assert_eq!(Ident::from_str("_"), Ident::from_str("_"))
/// assert_ne!(Ident::from_str("_").gensym_if_underscore(), Ident::from_str("_"))
/// assert_ne!(
/// Ident::from_str("_").gensym_if_underscore(),
/// Ident::from_str("_").gensym_if_underscore(),
/// )
/// ```
/// Internally, a symbol is implemented as an index, and all operations
/// (including hashing, equality, and ordering) operate on that index. The use
Expand Down

0 comments on commit beb2f5b

Please sign in to comment.