diff options
| author | bors <bors@rust-lang.org> | 2019-10-24 03:38:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-10-24 03:38:57 +0000 |
| commit | 55e00631e5bc5b16d40232914e57deeea197a8e4 (patch) | |
| tree | aa2b50a73237dd118df3faef760be2bf3dd7723f /src/libsyntax_pos | |
| parent | 4a8c5b20c7772bc5342b83d4b0696ea216ef75a7 (diff) | |
| parent | 3cd7a1740692ec34825d916550141b299caf458b (diff) | |
| download | rust-55e00631e5bc5b16d40232914e57deeea197a8e4.tar.gz rust-55e00631e5bc5b16d40232914e57deeea197a8e4.zip | |
Auto merge of #65733 - Centril:rollup-0zth66f, r=Centril
Rollup of 12 pull requests
Successful merges:
- #64178 (More Clippy fixes for alloc, core and std)
- #65144 (Add Cow::is_borrowed and Cow::is_owned)
- #65193 (Lockless LintStore)
- #65479 (Add the `matches!( $expr, $pat ) -> bool` macro)
- #65518 (Avoid ICE when checking `Destination` of `break` inside a closure)
- #65583 (rustc_metadata: use a table for super_predicates, fn_sig, impl_trait_ref.)
- #65641 (Derive `Rustc{En,De}codable` for `TokenStream`.)
- #65648 (Eliminate `intersect_opt`.)
- #65657 (Remove `InternedString`)
- #65691 (Update E0659 error code long explanation to 2018 edition)
- #65696 (Fix an issue with const inference variables sticking around under Chalk + NLL)
- #65704 (relax ExactSizeIterator bound on write_bytes)
Failed merges:
r? @ghost
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 120 |
1 files changed, 5 insertions, 115 deletions
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 634f58c5285..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; @@ -767,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)) @@ -814,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 { @@ -904,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 { @@ -923,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() } @@ -1106,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, @@ -1117,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, } @@ -1158,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)) - } -} |
