diff options
| author | Stefan Lankes <slankes@eonerc.rwth-aachen.de> | 2019-11-13 00:24:37 +0100 |
|---|---|---|
| committer | Stefan Lankes <slankes@eonerc.rwth-aachen.de> | 2019-11-13 00:24:37 +0100 |
| commit | 88717319142e162ae2f48124d94f33d2c21bc2ce (patch) | |
| tree | e50a968f836c55007e9bc8f305d4f0f80aca042c /src/libsyntax_pos | |
| parent | 969b74144641bf1c8ae5aba0581f4b52a4c15bac (diff) | |
| parent | 4f03f4a989d1c8346c19dfb417a77c09b34408b8 (diff) | |
| download | rust-88717319142e162ae2f48124d94f33d2c21bc2ce.tar.gz rust-88717319142e162ae2f48124d94f33d2c21bc2ce.zip | |
Merge remote-tracking branch 'rust-lang/master' into hermit
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/hygiene.rs | 19 | ||||
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax_pos/symbol.rs | 65 |
3 files changed, 51 insertions, 34 deletions
diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index e28d9326757..2a48f8e44aa 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -28,7 +28,7 @@ use crate::GLOBALS; use crate::{Span, DUMMY_SP}; use crate::edition::Edition; -use crate::symbol::{kw, Symbol}; +use crate::symbol::{kw, sym, Symbol}; use rustc_serialize::{Encodable, Decodable, Encoder, Decoder}; use rustc_data_structures::fx::FxHashMap; @@ -119,6 +119,23 @@ impl ExpnId { pub fn outer_expn_is_descendant_of(self, ctxt: SyntaxContext) -> bool { HygieneData::with(|data| data.is_descendant_of(self, data.outer_expn(ctxt))) } + + /// Returns span for the macro which originally caused this expansion to happen. + /// + /// Stops backtracing at include! boundary. + pub fn expansion_cause(mut self) -> Option<Span> { + let mut last_macro = None; + loop { + let expn_data = self.expn_data(); + // Stop going up the backtrace once include! is encountered + if expn_data.is_root() || expn_data.kind.descr() == sym::include { + break; + } + self = expn_data.call_site.ctxt().outer_expn(); + last_macro = Some(expn_data.call_site); + } + last_macro + } } #[derive(Debug)] diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 9034f8c1afd..dc29b189639 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -1512,7 +1512,6 @@ pub type FileLinesResult = Result<FileLines, SpanLinesError>; #[derive(Clone, PartialEq, Eq, Debug)] pub enum SpanLinesError { - IllFormedSpan(Span), DistinctSources(DistinctSources), } diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs index 57131ffe18c..b3e9576f43f 100644 --- a/src/libsyntax_pos/symbol.rs +++ b/src/libsyntax_pos/symbol.rs @@ -148,6 +148,7 @@ symbols! { associated_type_bounds, associated_type_defaults, associated_types, + assume_init, async_await, async_closure, attr, @@ -417,7 +418,10 @@ symbols! { match_beginning_vert, match_default_bindings, may_dangle, - mem, + maybe_uninit_uninit, + maybe_uninit_zeroed, + mem_uninitialized, + mem_zeroed, member_constraints, message, meta, @@ -428,6 +432,7 @@ symbols! { module, module_path, more_struct_aliases, + move_val_init, movbe_target_feature, must_use, naked, @@ -542,6 +547,8 @@ symbols! { recursion_limit, reexport_test_harness_main, reflect, + register_attr, + register_tool, relaxed_adts, repr, repr128, @@ -563,6 +570,7 @@ symbols! { rust_2018_preview, rust_begin_unwind, rustc, + Rust, RustcDecodable, RustcEncodable, rustc_allocator, @@ -709,7 +717,6 @@ symbols! { underscore_imports, underscore_lifetimes, uniform_paths, - uninitialized, universal_impl_trait, unmarked_api, unreachable_code, @@ -734,14 +741,12 @@ symbols! { visible_private_types, volatile, warn, - warn_directory_ownership, wasm_import_module, wasm_target_feature, while_let, windows, windows_subsystem, Yield, - zeroed, } } @@ -806,9 +811,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 +901,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 +978,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 { @@ -1078,7 +1084,6 @@ impl Ident { } } -// If an interner exists, return it. Otherwise, prepare a fresh one. #[inline] fn with_interner<T, F: FnOnce(&mut Interner) -> T>(f: F) -> T { GLOBALS.with(|globals| f(&mut *globals.symbol_interner.lock())) @@ -1092,46 +1097,42 @@ 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 -where - str: std::convert::AsRef<U> -{ - #[inline] - fn as_ref(&self) -> &U { - self.string.as_ref() - } -} - -impl<T: std::ops::Deref<Target = str>> std::cmp::PartialEq<T> for LocalInternedString { +// This impl allows a `SymbolStr` to be directly equated with a `String` or +// `&str`. +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 { +/// This impl means that if `ss` is a `SymbolStr`: +/// - `*ss` is a `str`; +/// - `&*ss` is a `&str`; +/// - `&ss as &str` is a `&str`, which means that `&ss` can be passed to a +/// function expecting a `&str`. +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) } |
