diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-10-22 06:20:51 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-11-02 09:00:27 +1100 |
| commit | 1b154a31cd09c2e251590b82de26927bdc34009a (patch) | |
| tree | 71d7c319ab51cbce8e1e04595cb900b36f66723b /src/libsyntax_pos | |
| parent | 87cbf0a547aaf9e8a7fc708851ecf4bc2adab5fd (diff) | |
| download | rust-1b154a31cd09c2e251590b82de26927bdc34009a.tar.gz rust-1b154a31cd09c2e251590b82de26927bdc34009a.zip | |
Rename `LocalInternedString` as `SymbolStr`.
It makes the relationship with `Symbol` clearer. The `Str` suffix matches the existing `Symbol::as_str()` method nicely, and is also consistent with it being a wrapper of `&str`.
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 57131ffe18c..8e1eb7366d9 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -806,9 +806,9 @@ impl Ident { Ident::new(self.name, self.span.modern_and_legacy()) } - /// Convert the name to a `LocalInternedString`. This is a slowish - /// operation because it requires locking the symbol interner. - pub fn as_str(self) -> LocalInternedString { + /// Convert the name to a `SymbolStr`. This is a slowish operation because + /// it requires locking the symbol interner. + pub fn as_str(self) -> SymbolStr { self.name.as_str() } } @@ -896,11 +896,11 @@ impl Symbol { }) } - /// Convert to a `LocalInternedString`. This is a slowish operation because - /// it requires locking the symbol interner. - pub fn as_str(self) -> LocalInternedString { + /// Convert to a `SymbolStr`. This is a slowish operation because it + /// requires locking the symbol interner. + pub fn as_str(self) -> SymbolStr { with_interner(|interner| unsafe { - LocalInternedString { + SymbolStr { string: std::mem::transmute::<&str, &str>(interner.get(self)) } }) @@ -973,6 +973,7 @@ impl Interner { self.names.insert(string, name); name } + // Get the symbol as a string. `Symbol::as_str()` should be used in // preference to this function. pub fn get(&self, symbol: Symbol) -> &str { @@ -1092,15 +1093,14 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T { /// safely treat `string` which points to interner data, as an immortal string, /// as long as this type never crosses between threads. // -// FIXME: ensure that the interner outlives any thread which uses -// `LocalInternedString`, by creating a new thread right after constructing the -// interner. +// FIXME: ensure that the interner outlives any thread which uses `SymbolStr`, +// by creating a new thread right after constructing the interner. #[derive(Clone, Eq, PartialOrd, Ord)] -pub struct LocalInternedString { +pub struct SymbolStr { string: &'static str, } -impl<U: ?Sized> std::convert::AsRef<U> for LocalInternedString +impl<U: ?Sized> std::convert::AsRef<U> for SymbolStr where str: std::convert::AsRef<U> { @@ -1110,28 +1110,28 @@ where } } -impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString { +impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for SymbolStr { fn eq(&self, other: &T) -> bool { self.string == other.deref() } } -impl !Send for LocalInternedString {} -impl !Sync for LocalInternedString {} +impl !Send for SymbolStr {} +impl !Sync for SymbolStr {} -impl std::ops::Deref for LocalInternedString { +impl std::ops::Deref for SymbolStr { type Target = str; #[inline] fn deref(&self) -> &str { self.string } } -impl fmt::Debug for LocalInternedString { +impl fmt::Debug for SymbolStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Debug::fmt(self.string, f) } } -impl fmt::Display for LocalInternedString { +impl fmt::Display for SymbolStr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Display::fmt(self.string, f) } |
