summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:31 +0000
commit2ff14448863ac1a1dd9533461708e29aae170c2d (patch)
tree85b9fea2bbfe3f06473cfa381eed11f273b57c5c /compiler/rustc_span/src
parentAdding debian version 1.64.0+dfsg1-1. (diff)
downloadrustc-2ff14448863ac1a1dd9533461708e29aae170c2d.tar.xz
rustc-2ff14448863ac1a1dd9533461708e29aae170c2d.zip
Adding debian version 1.65.0+dfsg1-2.debian/1.65.0+dfsg1-2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/def_id.rs15
-rw-r--r--compiler/rustc_span/src/hygiene.rs29
-rw-r--r--compiler/rustc_span/src/lib.rs37
-rw-r--r--compiler/rustc_span/src/source_map.rs107
-rw-r--r--compiler/rustc_span/src/source_map/tests.rs2
-rw-r--r--compiler/rustc_span/src/symbol.rs51
6 files changed, 112 insertions, 129 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index a1533fe46..37b8371a8 100644
--- a/compiler/rustc_span/src/def_id.rs
+++ b/compiler/rustc_span/src/def_id.rs
@@ -305,6 +305,12 @@ impl DefId {
}
}
+impl From<LocalDefId> for DefId {
+ fn from(local: LocalDefId) -> DefId {
+ local.to_def_id()
+ }
+}
+
impl<E: Encoder> Encodable<E> for DefId {
default fn encode(&self, s: &mut E) {
self.krate.encode(s);
@@ -331,7 +337,7 @@ impl fmt::Debug for DefId {
}
}
-rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefId);
+rustc_data_structures::define_id_collections!(DefIdMap, DefIdSet, DefIdMapEntry, DefId);
/// A `LocalDefId` is equivalent to a `DefId` with `krate == LOCAL_CRATE`. Since
/// we encode this information in the type, we can ensure at compile time that
@@ -393,7 +399,12 @@ impl<D: Decoder> Decodable<D> for LocalDefId {
}
}
-rustc_data_structures::define_id_collections!(LocalDefIdMap, LocalDefIdSet, LocalDefId);
+rustc_data_structures::define_id_collections!(
+ LocalDefIdMap,
+ LocalDefIdSet,
+ LocalDefIdMapEntry,
+ LocalDefId
+);
impl<CTX: HashStableContext> HashStable<CTX> for DefId {
#[inline]
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs
index e169d3c7c..191186af6 100644
--- a/compiler/rustc_span/src/hygiene.rs
+++ b/compiler/rustc_span/src/hygiene.rs
@@ -41,7 +41,6 @@ use rustc_macros::HashStable_Generic;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use std::fmt;
use std::hash::Hash;
-use tracing::*;
/// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks".
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
@@ -945,12 +944,6 @@ pub struct ExpnData {
/// internally without forcing the whole crate to opt-in
/// to them.
pub allow_internal_unstable: Option<Lrc<[Symbol]>>,
- /// Whether the macro is allowed to use `unsafe` internally
- /// even if the user crate has `#![forbid(unsafe_code)]`.
- pub allow_internal_unsafe: bool,
- /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`)
- /// for a given macro.
- pub local_inner_macros: bool,
/// Edition of the crate in which the macro is defined.
pub edition: Edition,
/// The `DefId` of the macro being invoked,
@@ -958,6 +951,13 @@ pub struct ExpnData {
pub macro_def_id: Option<DefId>,
/// The normal module (`mod`) in which the expanded macro was defined.
pub parent_module: Option<DefId>,
+ /// Suppresses the `unsafe_code` lint for code produced by this macro.
+ pub allow_internal_unsafe: bool,
+ /// Enables the macro helper hack (`ident!(...)` -> `$crate::ident!(...)`) for this macro.
+ pub local_inner_macros: bool,
+ /// Should debuginfo for the macro be collapsed to the outermost expansion site (in other
+ /// words, was the macro definition annotated with `#[collapse_debuginfo]`)?
+ pub collapse_debuginfo: bool,
}
impl !PartialEq for ExpnData {}
@@ -970,11 +970,12 @@ impl ExpnData {
call_site: Span,
def_site: Span,
allow_internal_unstable: Option<Lrc<[Symbol]>>,
- allow_internal_unsafe: bool,
- local_inner_macros: bool,
edition: Edition,
macro_def_id: Option<DefId>,
parent_module: Option<DefId>,
+ allow_internal_unsafe: bool,
+ local_inner_macros: bool,
+ collapse_debuginfo: bool,
) -> ExpnData {
ExpnData {
kind,
@@ -982,12 +983,13 @@ impl ExpnData {
call_site,
def_site,
allow_internal_unstable,
- allow_internal_unsafe,
- local_inner_macros,
edition,
macro_def_id,
parent_module,
disambiguator: 0,
+ allow_internal_unsafe,
+ local_inner_macros,
+ collapse_debuginfo,
}
}
@@ -1005,12 +1007,13 @@ impl ExpnData {
call_site,
def_site: DUMMY_SP,
allow_internal_unstable: None,
- allow_internal_unsafe: false,
- local_inner_macros: false,
edition,
macro_def_id,
parent_module,
disambiguator: 0,
+ allow_internal_unsafe: false,
+ local_inner_macros: false,
+ collapse_debuginfo: false,
}
}
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index cf3069281..da31b3462 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -15,11 +15,13 @@
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![feature(array_windows)]
-#![feature(let_else)]
+#![cfg_attr(bootstrap, feature(let_else))]
#![feature(if_let_guard)]
#![feature(negative_impls)]
#![feature(min_specialization)]
#![feature(rustc_attrs)]
+#![deny(rustc::untranslatable_diagnostic)]
+#![deny(rustc::diagnostic_outside_of_impl)]
#[macro_use]
extern crate rustc_macros;
@@ -74,8 +76,6 @@ use md5::Md5;
use sha1::Sha1;
use sha2::Sha256;
-use tracing::debug;
-
#[cfg(test)]
mod tests;
@@ -558,12 +558,25 @@ impl Span {
self.data_untracked().is_dummy()
}
- /// Returns `true` if this span comes from a macro or desugaring.
+ /// Returns `true` if this span comes from any kind of macro, desugaring or inlining.
#[inline]
pub fn from_expansion(self) -> bool {
self.ctxt() != SyntaxContext::root()
}
+ /// Returns `true` if `span` originates in a macro's expansion where debuginfo should be
+ /// collapsed.
+ pub fn in_macro_expansion_with_collapse_debuginfo(self) -> bool {
+ let outer_expn = self.ctxt().outer_expn_data();
+ 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, _))
@@ -662,6 +675,16 @@ impl Span {
Some(self)
}
+ /// Like `find_ancestor_inside`, but specifically for when spans might not
+ /// overlaps. Take care when using this, and prefer `find_ancestor_inside`
+ /// when you know that the spans are nested (modulo macro expansion).
+ pub fn find_ancestor_in_same_ctxt(mut self, other: Span) -> Option<Span> {
+ while !Span::eq_ctxt(self, other) {
+ self = self.parent_callsite()?;
+ }
+ Some(self)
+ }
+
/// Edition of the crate from which this span came.
pub fn edition(self) -> edition::Edition {
self.ctxt().edition()
@@ -1094,10 +1117,8 @@ pub enum ExternalSource {
Unneeded,
Foreign {
kind: ExternalSourceKind,
- /// This SourceFile's byte-offset within the source_map of its original crate.
- original_start_pos: BytePos,
- /// The end of this SourceFile within the source_map of its original crate.
- original_end_pos: BytePos,
+ /// Index of the file inside metadata.
+ metadata_index: u32,
},
}
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 28381157d..4d94c92d3 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -23,7 +23,6 @@ use std::{convert::TryFrom, unreachable};
use std::fs;
use std::io;
-use tracing::debug;
#[cfg(test)]
mod tests;
@@ -336,7 +335,7 @@ impl SourceMap {
mut file_local_non_narrow_chars: Vec<NonNarrowChar>,
mut file_local_normalized_pos: Vec<NormalizedPos>,
original_start_pos: BytePos,
- original_end_pos: BytePos,
+ metadata_index: u32,
) -> Lrc<SourceFile> {
let start_pos = self
.allocate_address_space(source_len)
@@ -381,8 +380,7 @@ impl SourceMap {
src_hash,
external_src: Lock::new(ExternalSource::Foreign {
kind: ExternalSourceKind::AbsentOk,
- original_start_pos,
- original_end_pos,
+ metadata_index,
}),
start_pos,
end_pos,
@@ -473,7 +471,7 @@ impl SourceMap {
let hi = self.lookup_char_pos(sp.hi());
let offset = self.lookup_char_pos(relative_to.lo());
- if lo.file.name != offset.file.name {
+ if lo.file.name != offset.file.name || !relative_to.contains(sp) {
return self.span_to_embeddable_string(sp);
}
@@ -722,7 +720,7 @@ impl SourceMap {
})
}
- /// Extends the given `Span` to just after the next occurrence of `c`.
+ /// Extends the given `Span` to just before the next occurrence of `c`.
pub fn span_extend_to_next_char(&self, sp: Span, c: char, accept_newlines: bool) -> Span {
if let Ok(next_source) = self.span_to_next_source(sp) {
let next_source = next_source.split(c).next().unwrap_or("");
@@ -983,93 +981,6 @@ impl SourceMap {
self.files().iter().fold(0, |a, f| a + f.count_lines())
}
- pub fn generate_fn_name_span(&self, span: Span) -> Option<Span> {
- let prev_span = self.span_extend_to_prev_str(span, "fn", true, true)?;
- if let Ok(snippet) = self.span_to_snippet(prev_span) {
- debug!(
- "generate_fn_name_span: span={:?}, prev_span={:?}, snippet={:?}",
- span, prev_span, snippet
- );
-
- if snippet.is_empty() {
- return None;
- };
-
- let len = snippet
- .find(|c: char| !c.is_alphanumeric() && c != '_')
- .expect("no label after fn");
- Some(prev_span.with_hi(BytePos(prev_span.lo().0 + len as u32)))
- } else {
- None
- }
- }
-
- /// Takes the span of a type parameter in a function signature and try to generate a span for
- /// the function name (with generics) and a new snippet for this span with the pointed type
- /// parameter as a new local type parameter.
- ///
- /// For instance:
- /// ```rust,ignore (pseudo-Rust)
- /// // Given span
- /// fn my_function(param: T)
- /// // ^ Original span
- ///
- /// // Result
- /// fn my_function(param: T)
- /// // ^^^^^^^^^^^ Generated span with snippet `my_function<T>`
- /// ```
- ///
- /// Attention: The method used is very fragile since it essentially duplicates the work of the
- /// parser. If you need to use this function or something similar, please consider updating the
- /// `SourceMap` functions and this function to something more robust.
- pub fn generate_local_type_param_snippet(&self, span: Span) -> Option<(Span, String)> {
- // Try to extend the span to the previous "fn" keyword to retrieve the function
- // signature.
- if let Some(sugg_span) = self.span_extend_to_prev_str(span, "fn", false, true) {
- if let Ok(snippet) = self.span_to_snippet(sugg_span) {
- // Consume the function name.
- let mut offset = snippet
- .find(|c: char| !c.is_alphanumeric() && c != '_')
- .expect("no label after fn");
-
- // Consume the generics part of the function signature.
- let mut bracket_counter = 0;
- let mut last_char = None;
- for c in snippet[offset..].chars() {
- match c {
- '<' => bracket_counter += 1,
- '>' => bracket_counter -= 1,
- '(' => {
- if bracket_counter == 0 {
- break;
- }
- }
- _ => {}
- }
- offset += c.len_utf8();
- last_char = Some(c);
- }
-
- // Adjust the suggestion span to encompass the function name with its generics.
- let sugg_span = sugg_span.with_hi(BytePos(sugg_span.lo().0 + offset as u32));
-
- // Prepare the new suggested snippet to append the type parameter that triggered
- // the error in the generics of the function signature.
- let mut new_snippet = if last_char == Some('>') {
- format!("{}, ", &snippet[..(offset - '>'.len_utf8())])
- } else {
- format!("{}<", &snippet[..offset])
- };
- new_snippet
- .push_str(&self.span_to_snippet(span).unwrap_or_else(|_| "T".to_string()));
- new_snippet.push('>');
-
- return Some((sugg_span, new_snippet));
- }
- }
-
- None
- }
pub fn ensure_source_file_source_present(&self, source_file: Lrc<SourceFile>) -> bool {
source_file.add_external_src(|| {
match source_file.name {
@@ -1148,13 +1059,13 @@ impl FilePathMapping {
return remap_path_prefix(&self.mapping, path);
- #[instrument(level = "debug", skip(mapping))]
+ #[instrument(level = "debug", skip(mapping), ret)]
fn remap_path_prefix(mapping: &[(PathBuf, PathBuf)], path: PathBuf) -> (PathBuf, bool) {
// NOTE: We are iterating over the mapping entries from last to first
// because entries specified later on the command line should
// take precedence.
for &(ref from, ref to) in mapping.iter().rev() {
- debug!("Trying to apply {:?} => {:?}", from, to);
+ debug!("Trying to apply {from:?} => {to:?}");
if let Ok(rest) = path.strip_prefix(from) {
let remapped = if rest.as_os_str().is_empty() {
@@ -1168,15 +1079,15 @@ impl FilePathMapping {
} else {
to.join(rest)
};
- debug!("Match - remapped {:?} => {:?}", path, remapped);
+ debug!("Match - remapped");
return (remapped, true);
} else {
- debug!("No match - prefix {:?} does not match {:?}", from, path);
+ debug!("No match - prefix {from:?} does not match");
}
}
- debug!("Path {:?} was not remapped", path);
+ debug!("not remapped");
(path, false)
}
}
diff --git a/compiler/rustc_span/src/source_map/tests.rs b/compiler/rustc_span/src/source_map/tests.rs
index be827cea8..3058ec45a 100644
--- a/compiler/rustc_span/src/source_map/tests.rs
+++ b/compiler/rustc_span/src/source_map/tests.rs
@@ -251,7 +251,7 @@ fn t10() {
non_narrow_chars,
normalized_pos,
start_pos,
- end_pos,
+ 0,
);
assert!(
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 791160ff6..ae4d1a463 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -157,6 +157,7 @@ symbols! {
BTreeSet,
BinaryHeap,
Borrow,
+ BorrowMut,
Break,
C,
CStr,
@@ -213,6 +214,7 @@ symbols! {
IntoIterator,
IoRead,
IoWrite,
+ IpAddr,
IrTyKind,
Is,
ItemContext,
@@ -222,6 +224,7 @@ symbols! {
LinkedList,
LintPass,
Mutex,
+ MutexGuard,
N,
NonZeroI128,
NonZeroI16,
@@ -270,6 +273,8 @@ symbols! {
Rust,
RustcDecodable,
RustcEncodable,
+ RwLockReadGuard,
+ RwLockWriteGuard,
Send,
SeqCst,
SessionDiagnostic,
@@ -280,6 +285,7 @@ symbols! {
StructuralPartialEq,
SubdiagnosticMessage,
Sync,
+ T,
Target,
ToOwned,
ToString,
@@ -334,6 +340,7 @@ symbols! {
alias,
align,
align_offset,
+ alignment,
alignstack,
all,
alloc,
@@ -481,6 +488,7 @@ symbols! {
cmse_nonsecure_entry,
coerce_unsized,
cold,
+ collapse_debuginfo,
column,
column_macro,
compare_and_swap,
@@ -504,7 +512,6 @@ symbols! {
const_deallocate,
const_eval_limit,
const_eval_select,
- const_eval_select_ct,
const_evaluatable_checked,
const_extern_fn,
const_fn,
@@ -644,6 +651,7 @@ symbols! {
dropck_parametricity,
dylib,
dyn_metadata,
+ dyn_star,
dyn_trait,
e,
edition_macro_pats,
@@ -656,7 +664,6 @@ symbols! {
emit_struct,
emit_struct_field,
enable,
- enclosing_scope,
encode,
end,
env,
@@ -759,7 +766,7 @@ symbols! {
gen_future,
gen_kill,
generator,
- generator_return,
+ generator_clone,
generator_state,
generators,
generic_arg_infer,
@@ -802,6 +809,7 @@ symbols! {
impl_trait_in_bindings,
implied_by,
import,
+ import_name_type,
import_shadowing,
imported_main,
in_band_lifetimes,
@@ -817,6 +825,7 @@ symbols! {
infer_outlives_requirements,
infer_static_outlives_requirements,
inherent_associated_types,
+ inherit,
inlateout,
inline,
inline_const,
@@ -859,6 +868,7 @@ symbols! {
lib,
libc,
lifetime,
+ lifetimes,
likely,
line,
line_macro,
@@ -1056,6 +1066,7 @@ symbols! {
panic_unwind,
panicking,
param_attrs,
+ parent_label,
partial_cmp,
partial_ord,
passes,
@@ -1110,14 +1121,15 @@ symbols! {
profiler_builtins,
profiler_runtime,
ptr,
- ptr_guaranteed_eq,
- ptr_guaranteed_ne,
+ ptr_guaranteed_cmp,
+ ptr_mask,
ptr_null,
ptr_null_mut,
ptr_offset_from,
ptr_offset_from_unsigned,
pub_macro_rules,
pub_restricted,
+ public,
pure,
pushpop_unsafe,
qreg,
@@ -1170,8 +1182,10 @@ symbols! {
repr_packed,
repr_simd,
repr_transparent,
+ require,
residual,
result,
+ return_position_impl_trait_in_trait,
rhs,
rintf32,
rintf64,
@@ -1200,6 +1214,7 @@ symbols! {
rust_eh_unregister_frames,
rust_oom,
rustc,
+ rustc_access_level,
rustc_allocator,
rustc_allocator_nounwind,
rustc_allocator_zeroed,
@@ -1217,6 +1232,7 @@ symbols! {
rustc_conversion_suggestion,
rustc_deallocator,
rustc_def_path,
+ rustc_default_body_unstable,
rustc_diagnostic_item,
rustc_diagnostic_macros,
rustc_dirty,
@@ -1279,9 +1295,11 @@ symbols! {
rustc_variance,
rustdoc,
rustdoc_internals,
+ rustdoc_missing_doc_code_examples,
rustfmt,
rvalue_static_promotion,
s,
+ safety,
sanitize,
sanitizer_runtime,
saturating_add,
@@ -1295,6 +1313,8 @@ symbols! {
should_panic,
shr,
shr_assign,
+ sig_dfl,
+ sig_ign,
simd,
simd_add,
simd_and,
@@ -1302,9 +1322,11 @@ symbols! {
simd_as,
simd_bitmask,
simd_cast,
+ simd_cast_ptr,
simd_ceil,
simd_div,
simd_eq,
+ simd_expose_addr,
simd_extract,
simd_fabs,
simd_fcos,
@@ -1320,6 +1342,7 @@ symbols! {
simd_fmin,
simd_fpow,
simd_fpowi,
+ simd_from_exposed_addr,
simd_fsin,
simd_fsqrt,
simd_gather,
@@ -1464,6 +1487,7 @@ symbols! {
trait_alias,
trait_upcasting,
transmute,
+ transmute_opts,
transmute_trait,
transparent,
transparent_enums,
@@ -1480,6 +1504,7 @@ symbols! {
tuple,
tuple_from_req,
tuple_indexing,
+ tuple_trait,
two_phase,
ty,
type_alias_enum_variants,
@@ -1513,6 +1538,7 @@ symbols! {
unit,
universal_impl_trait,
unix,
+ unix_sigpipe,
unlikely,
unmarked_api,
unpin,
@@ -1558,6 +1584,7 @@ symbols! {
va_list,
va_start,
val,
+ validity,
values,
var,
variant_count,
@@ -1801,6 +1828,11 @@ impl Symbol {
Symbol(SymbolIndex::from_u32(n))
}
+ /// for use in Decoder only
+ pub fn new_from_decoded(n: u32) -> Self {
+ Self::new(n)
+ }
+
/// Maps a string to its interned representation.
pub fn intern(string: &str) -> Self {
with_session_globals(|session_globals| session_globals.symbol_interner.intern(string))
@@ -1850,14 +1882,14 @@ impl fmt::Display for Symbol {
}
impl<S: Encoder> Encodable<S> for Symbol {
- fn encode(&self, s: &mut S) {
+ default fn encode(&self, s: &mut S) {
s.emit_str(self.as_str());
}
}
impl<D: Decoder> Decodable<D> for Symbol {
#[inline]
- fn decode(d: &mut D) -> Symbol {
+ default fn decode(d: &mut D) -> Symbol {
Symbol::intern(&d.read_str())
}
}
@@ -2025,6 +2057,11 @@ impl Symbol {
pub fn can_be_raw(self) -> bool {
self != kw::Empty && self != kw::Underscore && !self.is_path_segment_keyword()
}
+
+ /// Is this symbol was interned in compiler's `symbols!` macro
+ pub fn is_preinterned(self) -> bool {
+ self.as_u32() < PREINTERNED_SYMBOLS_COUNT
+ }
}
impl Ident {