summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /compiler/rustc_span
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_span')
-rw-r--r--compiler/rustc_span/src/def_id.rs50
-rw-r--r--compiler/rustc_span/src/hygiene.rs22
-rw-r--r--compiler/rustc_span/src/lib.rs119
-rw-r--r--compiler/rustc_span/src/source_map.rs28
-rw-r--r--compiler/rustc_span/src/span_encoding.rs24
-rw-r--r--compiler/rustc_span/src/symbol.rs29
-rw-r--r--compiler/rustc_span/src/tests.rs8
7 files changed, 154 insertions, 126 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index b2c58caff..f65a6aa4f 100644
--- a/compiler/rustc_span/src/def_id.rs
+++ b/compiler/rustc_span/src/def_id.rs
@@ -1,12 +1,11 @@
use crate::{HashStableContext, Symbol};
use rustc_data_structures::fingerprint::Fingerprint;
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey};
+use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher, ToStableHashKey};
use rustc_data_structures::unhash::Unhasher;
use rustc_data_structures::AtomicRef;
-use rustc_index::vec::Idx;
+use rustc_index::Idx;
use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
-use std::borrow::Borrow;
use std::fmt;
use std::hash::{BuildHasherDefault, Hash, Hasher};
@@ -105,20 +104,20 @@ impl DefPathHash {
/// originates from.
#[inline]
pub fn stable_crate_id(&self) -> StableCrateId {
- StableCrateId(self.0.as_value().0)
+ StableCrateId(self.0.split().0)
}
/// Returns the crate-local part of the [DefPathHash].
///
/// Used for tests.
#[inline]
- pub fn local_hash(&self) -> u64 {
- self.0.as_value().1
+ pub fn local_hash(&self) -> Hash64 {
+ self.0.split().1
}
/// Builds a new [DefPathHash] with the given [StableCrateId] and
/// `local_hash`, where `local_hash` must be unique within its crate.
- pub fn new(stable_crate_id: StableCrateId, local_hash: u64) -> DefPathHash {
+ pub fn new(stable_crate_id: StableCrateId, local_hash: Hash64) -> DefPathHash {
DefPathHash(Fingerprint::new(stable_crate_id.0, local_hash))
}
}
@@ -129,13 +128,6 @@ impl Default for DefPathHash {
}
}
-impl Borrow<Fingerprint> for DefPathHash {
- #[inline]
- fn borrow(&self) -> &Fingerprint {
- &self.0
- }
-}
-
/// A [`StableCrateId`] is a 64-bit hash of a crate name, together with all
/// `-Cmetadata` arguments, and some other data. It is to [`CrateNum`] what [`DefPathHash`] is to
/// [`DefId`]. It is stable across compilation sessions.
@@ -147,18 +139,19 @@ impl Borrow<Fingerprint> for DefPathHash {
///
/// For more information on the possibility of hash collisions in rustc,
/// see the discussion in [`DefId`].
-#[derive(Copy, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug)]
-#[derive(HashStable_Generic, Encodable, Decodable)]
-pub struct StableCrateId(pub(crate) u64);
+#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
+#[derive(Hash, HashStable_Generic, Encodable, Decodable)]
+pub struct StableCrateId(pub(crate) Hash64);
impl StableCrateId {
- pub fn to_u64(self) -> u64 {
- self.0
- }
-
/// Computes the stable ID for a crate with the given name and
/// `-Cmetadata` arguments.
- pub fn new(crate_name: Symbol, is_exe: bool, mut metadata: Vec<String>) -> StableCrateId {
+ pub fn new(
+ crate_name: Symbol,
+ is_exe: bool,
+ mut metadata: Vec<String>,
+ cfg_version: &'static str,
+ ) -> StableCrateId {
let mut hasher = StableHasher::new();
// We must hash the string text of the crate name, not the id, as the id is not stable
// across builds.
@@ -192,11 +185,22 @@ impl StableCrateId {
if let Some(val) = std::env::var_os("RUSTC_FORCE_RUSTC_VERSION") {
hasher.write(val.to_string_lossy().into_owned().as_bytes())
} else {
- hasher.write(option_env!("CFG_VERSION").unwrap_or("unknown version").as_bytes());
+ hasher.write(cfg_version.as_bytes())
}
StableCrateId(hasher.finish())
}
+
+ #[inline]
+ pub fn as_u64(self) -> u64 {
+ self.0.as_u64()
+ }
+}
+
+impl fmt::LowerHex for StableCrateId {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ fmt::LowerHex::fmt(&self.0, f)
+ }
}
rustc_index::newtype_index! {
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs
index 08c441403..b219fde4d 100644
--- a/compiler/rustc_span/src/hygiene.rs
+++ b/compiler/rustc_span/src/hygiene.rs
@@ -33,10 +33,10 @@ use crate::def_id::{CrateNum, DefId, StableCrateId, CRATE_DEF_ID, LOCAL_CRATE};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::stable_hasher::HashingControls;
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_data_structures::stable_hasher::{Hash64, HashStable, StableHasher};
use rustc_data_structures::sync::{Lock, Lrc};
use rustc_data_structures::unhash::UnhashMap;
-use rustc_index::vec::IndexVec;
+use rustc_index::IndexVec;
use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::fmt;
@@ -123,15 +123,15 @@ impl ExpnHash {
/// originates from.
#[inline]
pub fn stable_crate_id(self) -> StableCrateId {
- StableCrateId(self.0.as_value().0)
+ StableCrateId(self.0.split().0)
}
/// Returns the crate-local part of the [ExpnHash].
///
/// Used for tests.
#[inline]
- pub fn local_hash(self) -> u64 {
- self.0.as_value().1
+ pub fn local_hash(self) -> Hash64 {
+ self.0.split().1
}
#[inline]
@@ -141,7 +141,7 @@ impl ExpnHash {
/// Builds a new [ExpnHash] with the given [StableCrateId] and
/// `local_hash`, where `local_hash` must be unique within its crate.
- fn new(stable_crate_id: StableCrateId, local_hash: u64) -> ExpnHash {
+ fn new(stable_crate_id: StableCrateId, local_hash: Hash64) -> ExpnHash {
ExpnHash(Fingerprint::new(stable_crate_id.0, local_hash))
}
}
@@ -320,7 +320,6 @@ impl ExpnId {
// Stop going up the backtrace once include! is encountered
if expn_data.is_root()
|| expn_data.kind == ExpnKind::Macro(MacroKind::Bang, sym::include)
- || expn_data.kind == ExpnKind::Inlined
{
break;
}
@@ -350,7 +349,7 @@ pub struct HygieneData {
/// would have collisions without a disambiguator.
/// The keys of this map are always computed with `ExpnData.disambiguator`
/// set to 0.
- expn_data_disambiguators: FxHashMap<u64, u32>,
+ expn_data_disambiguators: FxHashMap<Hash64, u32>,
}
impl HygieneData {
@@ -1040,7 +1039,7 @@ impl ExpnData {
}
#[inline]
- fn hash_expn(&self, ctx: &mut impl HashStableContext) -> u64 {
+ fn hash_expn(&self, ctx: &mut impl HashStableContext) -> Hash64 {
let mut hasher = StableHasher::new();
self.hash_stable(ctx, &mut hasher);
hasher.finish()
@@ -1058,8 +1057,6 @@ pub enum ExpnKind {
AstPass(AstPass),
/// Desugaring done by the compiler during HIR lowering.
Desugaring(DesugaringKind),
- /// MIR inlining
- Inlined,
}
impl ExpnKind {
@@ -1073,7 +1070,6 @@ impl ExpnKind {
},
ExpnKind::AstPass(kind) => kind.descr().to_string(),
ExpnKind::Desugaring(kind) => format!("desugaring of {}", kind.descr()),
- ExpnKind::Inlined => "inlined source".to_string(),
}
}
}
@@ -1151,7 +1147,6 @@ pub enum DesugaringKind {
Await,
ForLoop,
WhileLoop,
- Replace,
}
impl DesugaringKind {
@@ -1167,7 +1162,6 @@ impl DesugaringKind {
DesugaringKind::OpaqueTy => "`impl Trait`",
DesugaringKind::ForLoop => "`for` loop",
DesugaringKind::WhileLoop => "`while` loop",
- DesugaringKind::Replace => "drop and replace",
}
}
}
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 28a8d8fc1..eae3f0fa0 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -60,7 +60,7 @@ pub mod fatal_error;
pub mod profiling;
-use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
+use rustc_data_structures::stable_hasher::{Hash128, Hash64, HashStable, StableHasher};
use rustc_data_structures::sync::{Lock, Lrc};
use std::borrow::Cow;
@@ -70,7 +70,6 @@ use std::hash::Hash;
use std::ops::{Add, Range, Sub};
use std::path::{Path, PathBuf};
use std::str::FromStr;
-use std::sync::Arc;
use md5::Digest;
use md5::Md5;
@@ -283,22 +282,22 @@ impl RealFileName {
pub enum FileName {
Real(RealFileName),
/// Call to `quote!`.
- QuoteExpansion(u64),
+ QuoteExpansion(Hash64),
/// Command line.
- Anon(u64),
+ Anon(Hash64),
/// Hack in `src/librustc_ast/parse.rs`.
// FIXME(jseyfried)
- MacroExpansion(u64),
- ProcMacroSourceCode(u64),
+ MacroExpansion(Hash64),
+ ProcMacroSourceCode(Hash64),
/// Strings provided as `--cfg [cfgspec]` stored in a `crate_cfg`.
- CfgSpec(u64),
+ CfgSpec(Hash64),
/// Strings provided as crate attributes in the CLI.
- CliCrateAttr(u64),
+ CliCrateAttr(Hash64),
/// Custom sources for explicit parser calls from plugins and drivers.
Custom(String),
DocTest(PathBuf, isize),
/// Post-substitution inline assembly from LLVM.
- InlineAsm(u64),
+ InlineAsm(Hash64),
}
impl From<PathBuf> for FileName {
@@ -595,12 +594,6 @@ impl Span {
matches!(outer_expn.kind, ExpnKind::Macro(..)) && outer_expn.collapse_debuginfo
}
- /// Returns `true` if this span comes from MIR inlining.
- pub fn is_inlined(self) -> bool {
- let outer_expn = self.ctxt().outer_expn_data();
- matches!(outer_expn.kind, ExpnKind::Inlined)
- }
-
/// Returns `true` if `span` originates in a derive-macro's expansion.
pub fn in_derive_expansion(self) -> bool {
matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
@@ -755,7 +748,7 @@ impl Span {
self.ctxt()
.outer_expn_data()
.allow_internal_unstable
- .map_or(false, |features| features.iter().any(|&f| f == feature))
+ .is_some_and(|features| features.iter().any(|&f| f == feature))
}
/// Checks if this span arises from a compiler desugaring of kind `kind`.
@@ -1045,17 +1038,26 @@ impl fmt::Debug for Span {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Use the global `SourceMap` to print the span. If that's not
// available, fall back to printing the raw values.
- with_session_globals(|session_globals| {
- if let Some(source_map) = &*session_globals.source_map.borrow() {
- write!(f, "{} ({:?})", source_map.span_to_diagnostic_string(*self), self.ctxt())
- } else {
- f.debug_struct("Span")
- .field("lo", &self.lo())
- .field("hi", &self.hi())
- .field("ctxt", &self.ctxt())
- .finish()
- }
- })
+
+ fn fallback(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ f.debug_struct("Span")
+ .field("lo", &span.lo())
+ .field("hi", &span.hi())
+ .field("ctxt", &span.ctxt())
+ .finish()
+ }
+
+ if SESSION_GLOBALS.is_set() {
+ with_session_globals(|session_globals| {
+ if let Some(source_map) = &*session_globals.source_map.borrow() {
+ write!(f, "{} ({:?})", source_map.span_to_diagnostic_string(*self), self.ctxt())
+ } else {
+ fallback(*self, f)
+ }
+ })
+ } else {
+ fallback(*self, f)
+ }
}
}
@@ -1249,29 +1251,6 @@ impl SourceFileHash {
}
}
-#[derive(HashStable_Generic)]
-#[derive(Copy, PartialEq, PartialOrd, Clone, Ord, Eq, Hash, Debug, Encodable, Decodable)]
-pub enum DebuggerVisualizerType {
- Natvis,
- GdbPrettyPrinter,
-}
-
-/// A single debugger visualizer file.
-#[derive(HashStable_Generic)]
-#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Encodable, Decodable)]
-pub struct DebuggerVisualizerFile {
- /// The complete debugger visualizer source.
- pub src: Arc<[u8]>,
- /// Indicates which visualizer type this targets.
- pub visualizer_type: DebuggerVisualizerType,
-}
-
-impl DebuggerVisualizerFile {
- pub fn new(src: Arc<[u8]>, visualizer_type: DebuggerVisualizerType) -> Self {
- DebuggerVisualizerFile { src, visualizer_type }
- }
-}
-
#[derive(Clone)]
pub enum SourceFileLines {
/// The source file lines, in decoded (random-access) form.
@@ -1344,7 +1323,7 @@ pub struct SourceFile {
/// Locations of characters removed during normalization.
pub normalized_pos: Vec<NormalizedPos>,
/// A hash of the filename, used for speeding up hashing in incremental compilation.
- pub name_hash: u128,
+ pub name_hash: Hash128,
/// Indicates which crate this `SourceFile` was imported from.
pub cnum: CrateNum,
}
@@ -1473,7 +1452,7 @@ impl<D: Decoder> Decodable<D> for SourceFile {
};
let multibyte_chars: Vec<MultiByteChar> = Decodable::decode(d);
let non_narrow_chars: Vec<NonNarrowChar> = Decodable::decode(d);
- let name_hash: u128 = Decodable::decode(d);
+ let name_hash = Decodable::decode(d);
let normalized_pos: Vec<NormalizedPos> = Decodable::decode(d);
let cnum: CrateNum = Decodable::decode(d);
SourceFile {
@@ -1515,7 +1494,7 @@ impl SourceFile {
let name_hash = {
let mut hasher: StableHasher = StableHasher::new();
name.hash(&mut hasher);
- hasher.finish::<u128>()
+ hasher.finish()
};
let end_pos = start_pos.to_usize() + src.len();
assert!(end_pos <= u32::MAX as usize);
@@ -1664,10 +1643,11 @@ impl SourceFile {
if let Some(ref src) = self.src {
Some(Cow::from(get_until_newline(src, begin)))
- } else if let Some(src) = self.external_src.borrow().get_source() {
- Some(Cow::Owned(String::from(get_until_newline(src, begin))))
} else {
- None
+ self.external_src
+ .borrow()
+ .get_source()
+ .map(|src| Cow::Owned(String::from(get_until_newline(src, begin))))
}
}
@@ -1736,6 +1716,28 @@ impl SourceFile {
BytePos::from_u32(pos.0 - self.start_pos.0 + diff)
}
+ /// Calculates a normalized byte position from a byte offset relative to the
+ /// start of the file.
+ ///
+ /// When we get an inline assembler error from LLVM during codegen, we
+ /// import the expanded assembly code as a new `SourceFile`, which can then
+ /// be used for error reporting with spans. However the byte offsets given
+ /// to us by LLVM are relative to the start of the original buffer, not the
+ /// normalized one. Hence we need to convert those offsets to the normalized
+ /// form when constructing spans.
+ pub fn normalized_byte_pos(&self, offset: u32) -> BytePos {
+ let diff = match self
+ .normalized_pos
+ .binary_search_by(|np| (np.pos.0 + np.diff).cmp(&(self.start_pos.0 + offset)))
+ {
+ Ok(i) => self.normalized_pos[i].diff,
+ Err(i) if i == 0 => 0,
+ Err(i) => self.normalized_pos[i - 1].diff,
+ };
+
+ BytePos::from_u32(self.start_pos.0 + offset - diff)
+ }
+
/// Converts an absolute `BytePos` to a `CharPos` relative to the `SourceFile`.
pub fn bytepos_to_file_charpos(&self, bpos: BytePos) -> CharPos {
// The number of extra bytes due to multibyte chars in the `SourceFile`.
@@ -2160,9 +2162,7 @@ where
};
Hash::hash(&TAG_VALID_SPAN, hasher);
- // We truncate the stable ID hash and line and column numbers. The chances
- // of causing a collision this way should be minimal.
- Hash::hash(&(file.name_hash as u64), hasher);
+ Hash::hash(&file.name_hash, hasher);
// Hash both the length and the end location (line/column) of a span. If we
// hash only the length, for example, then two otherwise equal spans with
@@ -2193,6 +2193,7 @@ pub struct ErrorGuaranteed(());
impl ErrorGuaranteed {
/// To be used only if you really know what you are doing... ideally, we would find a way to
/// eliminate all calls to this method.
+ #[deprecated = "`Session::delay_span_bug` should be preferred over this function"]
pub fn unchecked_claim_error_was_emitted() -> Self {
ErrorGuaranteed(())
}
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 56573814e..1824510a9 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -13,8 +13,10 @@ pub use crate::hygiene::{ExpnData, ExpnKind};
pub use crate::*;
use rustc_data_structures::fx::FxHashMap;
-use rustc_data_structures::stable_hasher::StableHasher;
-use rustc_data_structures::sync::{AtomicU32, Lrc, MappedReadGuard, ReadGuard, RwLock};
+use rustc_data_structures::stable_hasher::{Hash128, Hash64, StableHasher};
+use rustc_data_structures::sync::{
+ AtomicU32, IntoDynSyncSend, Lrc, MappedReadGuard, ReadGuard, RwLock,
+};
use std::cmp;
use std::hash::Hash;
use std::path::{self, Path, PathBuf};
@@ -138,7 +140,7 @@ impl FileLoader for RealFileLoader {
pub struct StableSourceFileId {
/// A hash of the source file's [`FileName`]. This is hash so that it's size
/// is more predictable than if we included the actual [`FileName`] value.
- pub file_name_hash: u64,
+ pub file_name_hash: Hash64,
/// The [`CrateNum`] of the crate this source file was originally parsed for.
/// We cannot include this information in the hash because at the time
@@ -176,7 +178,7 @@ pub struct SourceMap {
used_address_space: AtomicU32,
files: RwLock<SourceMapFiles>,
- file_loader: Box<dyn FileLoader + Sync + Send>,
+ file_loader: IntoDynSyncSend<Box<dyn FileLoader + Sync + Send>>,
// This is used to apply the file path remapping as specified via
// `--remap-path-prefix` to all `SourceFile`s allocated within this `SourceMap`.
path_mapping: FilePathMapping,
@@ -202,7 +204,7 @@ impl SourceMap {
SourceMap {
used_address_space: AtomicU32::new(0),
files: Default::default(),
- file_loader,
+ file_loader: IntoDynSyncSend(file_loader),
path_mapping,
hash_kind,
}
@@ -331,7 +333,7 @@ impl SourceMap {
&self,
filename: FileName,
src_hash: SourceFileHash,
- name_hash: u128,
+ name_hash: Hash128,
source_len: usize,
cnum: CrateNum,
file_local_lines: Lock<SourceFileLines>,
@@ -483,7 +485,7 @@ impl SourceMap {
self.span_to_string(sp, FileNameDisplayPreference::Remapped)
}
- /// Format the span location suitable for pretty printing anotations with relative line numbers
+ /// Format the span location suitable for pretty printing annotations with relative line numbers
pub fn span_to_relative_line_string(&self, sp: Span, relative_to: Span) -> String {
if self.files.borrow().source_files.is_empty() || sp.is_dummy() || relative_to.is_dummy() {
return "no-location".to_string();
@@ -637,7 +639,7 @@ impl SourceMap {
self.span_to_source(sp, |src, start_index, end_index| {
Ok(src.get(start_index..end_index).is_some())
})
- .map_or(false, |is_accessible| is_accessible)
+ .is_ok_and(|is_accessible| is_accessible)
}
/// Returns the source snippet as `String` corresponding to the given `Span`.
@@ -777,7 +779,7 @@ impl SourceMap {
/// Given a 'Span', tries to tell if it's wrapped by "<>" or "()"
/// the algorithm searches if the next character is '>' or ')' after skipping white space
- /// then searches the previous charactoer to match '<' or '(' after skipping white space
+ /// then searches the previous character to match '<' or '(' after skipping white space
/// return true if wrapped by '<>' or '()'
pub fn span_wrapped_by_angle_or_parentheses(&self, span: Span) -> bool {
self.span_to_source(span, |src, start_index, end_index| {
@@ -833,7 +835,7 @@ impl SourceMap {
}
return Ok(true);
})
- .map_or(false, |is_accessible| is_accessible)
+ .is_ok_and(|is_accessible| is_accessible)
}
/// Given a `Span`, tries to get a shorter span ending just after the first occurrence of `char`
@@ -906,10 +908,8 @@ impl SourceMap {
let snippet = if let Some(ref src) = local_begin.sf.src {
Some(&src[start_index..])
- } else if let Some(src) = src.get_source() {
- Some(&src[start_index..])
} else {
- None
+ src.get_source().map(|src| &src[start_index..])
};
match snippet {
@@ -967,7 +967,7 @@ impl SourceMap {
for _ in 0..limit.unwrap_or(100_usize) {
sp = self.next_point(sp);
if let Ok(ref snippet) = self.span_to_snippet(sp) {
- if expect.map_or(false, |es| snippet == es) {
+ if expect.is_some_and(|es| snippet == es) {
break;
}
if expect.is_none() && snippet.chars().any(|c| !c.is_whitespace()) {
diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs
index c600298c5..1eea0f63c 100644
--- a/compiler/rustc_span/src/span_encoding.rs
+++ b/compiler/rustc_span/src/span_encoding.rs
@@ -181,19 +181,23 @@ impl Span {
#[inline]
pub fn ctxt(self) -> SyntaxContext {
let ctxt_or_tag = self.ctxt_or_tag as u32;
- if ctxt_or_tag <= MAX_CTXT {
- if self.len_or_tag == LEN_TAG || self.len_or_tag & PARENT_MASK == 0 {
- // Inline format or interned format with inline ctxt.
- SyntaxContext::from_u32(ctxt_or_tag)
+ // Check for interned format.
+ if self.len_or_tag == LEN_TAG {
+ if ctxt_or_tag == CTXT_TAG {
+ // Fully interned format.
+ let index = self.base_or_index;
+ with_span_interner(|interner| interner.spans[index as usize].ctxt)
} else {
- // Inline format or interned format with inline parent.
- // We know that the SyntaxContext is root.
- SyntaxContext::root()
+ // Interned format with inline ctxt.
+ SyntaxContext::from_u32(ctxt_or_tag)
}
+ } else if self.len_or_tag & PARENT_MASK == 0 {
+ // Inline format with inline ctxt.
+ SyntaxContext::from_u32(ctxt_or_tag)
} else {
- // Interned format.
- let index = self.base_or_index;
- with_span_interner(|interner| interner.spans[index as usize].ctxt)
+ // Inline format with inline parent.
+ // We know that the SyntaxContext is root.
+ SyntaxContext::root()
}
}
}
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 6bfae3771..874d578fe 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -95,6 +95,7 @@ symbols! {
// Weak keywords, have special meaning only in specific contexts.
Auto: "auto",
+ Builtin: "builtin",
Catch: "catch",
Default: "default",
MacroRules: "macro_rules",
@@ -129,8 +130,7 @@ symbols! {
Any,
Arc,
Argument,
- ArgumentV1,
- ArgumentV1Methods,
+ ArgumentMethods,
Arguments,
AsMut,
AsRef,
@@ -164,6 +164,7 @@ symbols! {
Capture,
Center,
Clone,
+ ConstParamTy,
Context,
Continue,
Copy,
@@ -204,9 +205,11 @@ symbols! {
HashSet,
Hasher,
Implied,
+ IndexOutput,
Input,
Into,
IntoDiagnostic,
+ IntoFuture,
IntoIterator,
IoRead,
IoWrite,
@@ -439,9 +442,12 @@ symbols! {
breakpoint,
bridge,
bswap,
+ builtin_syntax,
c_str,
+ c_str_literals,
c_unwind,
c_variadic,
+ c_void,
call,
call_mut,
call_once,
@@ -458,6 +464,7 @@ symbols! {
cfg_doctest,
cfg_eval,
cfg_hide,
+ cfg_overflow_checks,
cfg_panic,
cfg_sanitize,
cfg_target_abi,
@@ -469,6 +476,7 @@ symbols! {
cfg_target_vendor,
cfg_version,
cfi,
+ cfi_encoding,
char,
client,
clippy,
@@ -530,6 +538,7 @@ symbols! {
const_mut_refs,
const_panic,
const_panic_fmt,
+ const_param_ty,
const_precise_live_drops,
const_raw_ptr_deref,
const_raw_ptr_to_usize_cast,
@@ -650,6 +659,7 @@ symbols! {
edition_panic,
eh_catch_typeinfo,
eh_personality,
+ emit,
emit_enum,
emit_enum_variant,
emit_enum_variant_arg,
@@ -981,6 +991,7 @@ symbols! {
needs_panic_runtime,
neg,
negate_unsigned,
+ negative_bounds,
negative_impls,
neon,
never,
@@ -1024,6 +1035,7 @@ symbols! {
non_exhaustive_omitted_patterns_lint,
non_lifetime_binders,
non_modrs_mods,
+ none,
nontemporal_store,
noop_method_borrow,
noop_method_clone,
@@ -1036,6 +1048,7 @@ symbols! {
object_safe_for_dispatch,
of,
offset,
+ offset_of,
omit_gdb_pretty_printer_section,
on,
on_unimplemented,
@@ -1054,6 +1067,7 @@ symbols! {
or_patterns,
other,
out,
+ overflow_checks,
overlapping_marker_traits,
owned_box,
packed,
@@ -1199,6 +1213,7 @@ symbols! {
require,
residual,
result,
+ resume,
return_position_impl_trait_in_trait,
return_type_notation,
rhs,
@@ -1318,6 +1333,8 @@ symbols! {
s,
safety,
sanitize,
+ sanitizer_cfi_generalize_pointers,
+ sanitizer_cfi_normalize_integers,
sanitizer_runtime,
saturating_add,
saturating_sub,
@@ -1503,6 +1520,7 @@ symbols! {
transmute_generic_consts,
transmute_opts,
transmute_trait,
+ transmute_unchecked,
transparent,
transparent_enums,
transparent_unions,
@@ -1566,6 +1584,7 @@ symbols! {
unrestricted_attribute_tokens,
unsafe_block_in_unsafe_fn,
unsafe_cell,
+ unsafe_cell_from_mut,
unsafe_no_drop_flag,
unsafe_pin_internals,
unsize,
@@ -1632,6 +1651,7 @@ symbols! {
write_bytes,
write_macro,
write_str,
+ write_via_move,
writeln_macro,
x87_reg,
xer,
@@ -1986,8 +2006,9 @@ impl Interner {
name
}
- // Get the symbol as a string. `Symbol::as_str()` should be used in
- // preference to this function.
+ /// Get the symbol as a string.
+ ///
+ /// [`Symbol::as_str()`] should be used in preference to this function.
fn get(&self, symbol: Symbol) -> &str {
self.0.lock().strings[symbol.0.as_usize()]
}
diff --git a/compiler/rustc_span/src/tests.rs b/compiler/rustc_span/src/tests.rs
index 5b3915c33..a242ad6d1 100644
--- a/compiler/rustc_span/src/tests.rs
+++ b/compiler/rustc_span/src/tests.rs
@@ -3,8 +3,12 @@ use super::*;
#[test]
fn test_lookup_line() {
let source = "abcdefghijklm\nabcdefghij\n...".to_owned();
- let sf =
- SourceFile::new(FileName::Anon(0), source, BytePos(3), SourceFileHashAlgorithm::Sha256);
+ let sf = SourceFile::new(
+ FileName::Anon(Hash64::ZERO),
+ source,
+ BytePos(3),
+ SourceFileHashAlgorithm::Sha256,
+ );
sf.lines(|lines| assert_eq!(lines, &[BytePos(3), BytePos(17), BytePos(28)]));
assert_eq!(sf.lookup_line(BytePos(0)), None);