mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 00:34:06 +00:00
Remove Ident::{gensym, is_gensymed}
`gensym_if_underscore` still exists. The symbol interner can still create arbitray gensyms, this is just not exposed publicly.
This commit is contained in:
parent
2a82aec36a
commit
beb2f5b8ff
@ -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 {
|
||||
|
@ -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 {
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user