about summary refs log tree commit diff
path: root/src/libsyntax_pos
diff options
context:
space:
mode:
authorStefan Lankes <slankes@eonerc.rwth-aachen.de>2019-10-25 09:09:55 +0200
committerStefan Lankes <slankes@eonerc.rwth-aachen.de>2019-10-25 09:09:55 +0200
commitd349e32fc70da197918256c29a0858fe7e1a6588 (patch)
tree17f268176d32a172c84e84c30303a4794f4513b0 /src/libsyntax_pos
parentddcd157d03a067419d7f5b4375cfaff5a474856a (diff)
parentd54111afc061ef398cd8ce28984f9e8d70001b24 (diff)
downloadrust-d349e32fc70da197918256c29a0858fe7e1a6588.tar.gz
rust-d349e32fc70da197918256c29a0858fe7e1a6588.zip
Merge branch 'master' into rusty-hermit, resolve conflicts
Diffstat (limited to 'src/libsyntax_pos')
-rw-r--r--src/libsyntax_pos/symbol.rs121
1 files changed, 6 insertions, 115 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index fa9567fb62c..377d2f877b3 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -9,7 +9,7 @@ use rustc_macros::symbols;
 use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
 use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable};
 
-use std::cmp::{PartialEq, Ordering, PartialOrd, Ord};
+use std::cmp::{PartialEq, PartialOrd, Ord};
 use std::fmt;
 use std::hash::{Hash, Hasher};
 use std::str;
@@ -459,6 +459,7 @@ symbols! {
         no_std,
         not,
         note,
+        object_safe_for_dispatch,
         Ok,
         omit_gdb_pretty_printer_section,
         on,
@@ -766,11 +767,6 @@ impl Ident {
         Ident::with_dummy_span(kw::Invalid)
     }
 
-    /// Maps an interned string to an identifier with an empty syntax context.
-    pub fn from_interned_str(string: InternedString) -> Ident {
-        Ident::with_dummy_span(string.as_symbol())
-    }
-
     /// Maps a string to an identifier with a dummy span.
     pub fn from_str(string: &str) -> Ident {
         Ident::with_dummy_span(Symbol::intern(string))
@@ -813,11 +809,6 @@ impl Ident {
     pub fn as_str(self) -> LocalInternedString {
         self.name.as_str()
     }
-
-    /// Convert the name to an `InternedString`.
-    pub fn as_interned_str(self) -> InternedString {
-        self.name.as_interned_str()
-    }
 }
 
 impl PartialEq for Ident {
@@ -903,15 +894,6 @@ impl Symbol {
         })
     }
 
-    /// Access two symbols' chars. This is a slowish operation because it
-    /// requires locking the symbol interner, but it is faster than calling
-    /// `with()` twice.
-    fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: Symbol, f: F) -> R {
-        with_interner(|interner| {
-            f(interner.get(self), interner.get(other))
-        })
-    }
-
     /// Convert to a `LocalInternedString`. This is a slowish operation because
     /// it requires locking the symbol interner.
     pub fn as_str(self) -> LocalInternedString {
@@ -922,11 +904,6 @@ impl Symbol {
         })
     }
 
-    /// Convert to an `InternedString`.
-    pub fn as_interned_str(self) -> InternedString {
-        InternedString { symbol: self }
-    }
-
     pub fn as_u32(self) -> u32 {
         self.0.as_u32()
     }
@@ -1105,9 +1082,9 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
     GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock()))
 }
 
-/// An alternative to `Symbol` and `InternedString`, useful when the chars
-/// within the symbol need to be accessed. It deliberately has limited
-/// functionality and should only be used for temporary values.
+/// An alternative to `Symbol`, useful when the chars within the symbol need to
+/// be accessed. It deliberately has limited functionality and should only be
+/// used for temporary values.
 ///
 /// Because the interner outlives any thread which uses this type, we can
 /// safely treat `string` which points to interner data, as an immortal string,
@@ -1116,7 +1093,7 @@ fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T {
 // FIXME: ensure that the interner outlives any thread which uses
 // `LocalInternedString`, by creating a new thread right after constructing the
 // interner.
-#[derive(Eq, PartialOrd, Ord)]
+#[derive(Clone, Eq, PartialOrd, Ord)]
 pub struct LocalInternedString {
     string: &'static str,
 }
@@ -1157,89 +1134,3 @@ impl fmt::Display for LocalInternedString {
         fmt::Display::fmt(self.string, f)
     }
 }
-
-/// An alternative to `Symbol` that is focused on string contents.
-///
-/// Its implementations of `Hash`, `PartialOrd` and `Ord` work with the
-/// string chars rather than the symbol integer. This is useful when hash
-/// stability is required across compile sessions, or a guaranteed sort
-/// ordering is required.
-#[derive(Clone, Copy, PartialEq, Eq)]
-pub struct InternedString {
-    symbol: Symbol,
-}
-
-impl InternedString {
-    /// Maps a string to its interned representation.
-    pub fn intern(string: &str) -> Self {
-        InternedString {
-            symbol: Symbol::intern(string)
-        }
-    }
-
-    pub fn with<F: FnOnce(&str) -> R, R>(self, f: F) -> R {
-        self.symbol.with(f)
-    }
-
-    fn with2<F: FnOnce(&str, &str) -> R, R>(self, other: &InternedString, f: F) -> R {
-        self.symbol.with2(other.symbol, f)
-    }
-
-    pub fn as_symbol(self) -> Symbol {
-        self.symbol
-    }
-
-    /// Convert to a `LocalInternedString`. This is a slowish operation because it
-    /// requires locking the symbol interner.
-    pub fn as_str(self) -> LocalInternedString {
-        self.symbol.as_str()
-    }
-}
-
-impl Hash for InternedString {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        self.with(|str| str.hash(state))
-    }
-}
-
-impl PartialOrd<InternedString> for InternedString {
-    fn partial_cmp(&self, other: &InternedString) -> Option<Ordering> {
-        if self.symbol == other.symbol {
-            return Some(Ordering::Equal);
-        }
-        self.with2(other, |self_str, other_str| self_str.partial_cmp(other_str))
-    }
-}
-
-impl Ord for InternedString {
-    fn cmp(&self, other: &InternedString) -> Ordering {
-        if self.symbol == other.symbol {
-            return Ordering::Equal;
-        }
-        self.with2(other, |self_str, other_str| self_str.cmp(other_str))
-    }
-}
-
-impl fmt::Debug for InternedString {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        self.with(|str| fmt::Debug::fmt(&str, f))
-    }
-}
-
-impl fmt::Display for InternedString {
-    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-        self.with(|str| fmt::Display::fmt(&str, f))
-    }
-}
-
-impl Decodable for InternedString {
-    fn decode<D: Decoder>(d: &mut D) -> Result<InternedString, D::Error> {
-        Ok(InternedString::intern(&d.read_str()?))
-    }
-}
-
-impl Encodable for InternedString {
-    fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
-        self.with(|string| s.emit_str(string))
-    }
-}