summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:19 +0000
commita0b8f38ab54ac451646aa00cd5e91b6c76f22a84 (patch)
treefc451898ccaf445814e26b46664d78702178101d /compiler/rustc_span
parentAdding debian version 1.71.1+dfsg1-2. (diff)
downloadrustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.tar.xz
rustc-a0b8f38ab54ac451646aa00cd5e91b6c76f22a84.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_span')
-rw-r--r--compiler/rustc_span/Cargo.toml2
-rw-r--r--compiler/rustc_span/src/hygiene.rs17
-rw-r--r--compiler/rustc_span/src/lib.rs31
-rw-r--r--compiler/rustc_span/src/source_map.rs21
-rw-r--r--compiler/rustc_span/src/symbol.rs18
5 files changed, 61 insertions, 28 deletions
diff --git a/compiler/rustc_span/Cargo.toml b/compiler/rustc_span/Cargo.toml
index a7c7575f3..ee93f74e7 100644
--- a/compiler/rustc_span/Cargo.toml
+++ b/compiler/rustc_span/Cargo.toml
@@ -18,4 +18,4 @@ tracing = "0.1"
sha1 = "0.10.0"
sha2 = "0.10.1"
md5 = { package = "md-5", version = "0.10.0" }
-indexmap = { version = "1.9.3" }
+indexmap = { version = "2.0.0" }
diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs
index b219fde4d..9f2ff4378 100644
--- a/compiler/rustc_span/src/hygiene.rs
+++ b/compiler/rustc_span/src/hygiene.rs
@@ -507,7 +507,7 @@ impl HygieneData {
self.normalize_to_macro_rules(call_site_ctxt)
};
- if call_site_ctxt == SyntaxContext::root() {
+ if call_site_ctxt.is_root() {
return self.apply_mark_internal(ctxt, expn_id, transparency);
}
@@ -671,12 +671,17 @@ impl SyntaxContext {
}
#[inline]
- pub(crate) fn as_u32(self) -> u32 {
+ pub const fn is_root(self) -> bool {
+ self.0 == SyntaxContext::root().as_u32()
+ }
+
+ #[inline]
+ pub(crate) const fn as_u32(self) -> u32 {
self.0
}
#[inline]
- pub(crate) fn from_u32(raw: u32) -> SyntaxContext {
+ pub(crate) const fn from_u32(raw: u32) -> SyntaxContext {
SyntaxContext(raw)
}
@@ -1288,7 +1293,7 @@ pub fn decode_expn_id(
decode_data: impl FnOnce(ExpnId) -> (ExpnData, ExpnHash),
) -> ExpnId {
if index == 0 {
- debug!("decode_expn_id: deserialized root");
+ trace!("decode_expn_id: deserialized root");
return ExpnId::root();
}
@@ -1321,7 +1326,7 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext
) -> SyntaxContext {
let raw_id: u32 = Decodable::decode(d);
if raw_id == 0 {
- debug!("decode_syntax_context: deserialized root");
+ trace!("decode_syntax_context: deserialized root");
// The root is special
return SyntaxContext::root();
}
@@ -1500,7 +1505,7 @@ impl<CTX: HashStableContext> HashStable<CTX> for SyntaxContext {
const TAG_EXPANSION: u8 = 0;
const TAG_NO_EXPANSION: u8 = 1;
- if *self == SyntaxContext::root() {
+ if self.is_root() {
TAG_NO_EXPANSION.hash_stable(ctx, hasher);
} else {
TAG_EXPANSION.hash_stable(ctx, hasher);
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index eae3f0fa0..3bb9c4920 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -65,11 +65,11 @@ use rustc_data_structures::sync::{Lock, Lrc};
use std::borrow::Cow;
use std::cmp::{self, Ordering};
-use std::fmt;
use std::hash::Hash;
use std::ops::{Add, Range, Sub};
use std::path::{Path, PathBuf};
use std::str::FromStr;
+use std::{fmt, iter};
use md5::Digest;
use md5::Md5;
@@ -733,12 +733,15 @@ impl Span {
/// else returns the `ExpnData` for the macro definition
/// corresponding to the source callsite.
pub fn source_callee(self) -> Option<ExpnData> {
- fn source_callee(expn_data: ExpnData) -> ExpnData {
- let next_expn_data = expn_data.call_site.ctxt().outer_expn_data();
- if !next_expn_data.is_root() { source_callee(next_expn_data) } else { expn_data }
- }
let expn_data = self.ctxt().outer_expn_data();
- if !expn_data.is_root() { Some(source_callee(expn_data)) } else { None }
+
+ // Create an iterator of call site expansions
+ iter::successors(Some(expn_data), |expn_data| {
+ Some(expn_data.call_site.ctxt().outer_expn_data())
+ })
+ // Find the last expansion which is not root
+ .take_while(|expn_data| !expn_data.is_root())
+ .last()
}
/// Checks if a span is "internal" to a macro in which `#[unstable]`
@@ -777,7 +780,7 @@ impl Span {
pub fn macro_backtrace(mut self) -> impl Iterator<Item = ExpnData> {
let mut prev_span = DUMMY_SP;
- std::iter::from_fn(move || {
+ iter::from_fn(move || {
loop {
let expn_data = self.ctxt().outer_expn_data();
if expn_data.is_root() {
@@ -826,9 +829,9 @@ impl Span {
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
// have an incomplete span than a completely nonsensical one.
if span_data.ctxt != end_data.ctxt {
- if span_data.ctxt == SyntaxContext::root() {
+ if span_data.ctxt.is_root() {
return end;
- } else if end_data.ctxt == SyntaxContext::root() {
+ } else if end_data.ctxt.is_root() {
return self;
}
// Both spans fall within a macro.
@@ -837,7 +840,7 @@ impl Span {
Span::new(
cmp::min(span_data.lo, end_data.lo),
cmp::max(span_data.hi, end_data.hi),
- if span_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
+ if span_data.ctxt.is_root() { end_data.ctxt } else { span_data.ctxt },
if span_data.parent == end_data.parent { span_data.parent } else { None },
)
}
@@ -855,7 +858,7 @@ impl Span {
Span::new(
span.hi,
end.lo,
- if end.ctxt == SyntaxContext::root() { end.ctxt } else { span.ctxt },
+ if end.ctxt.is_root() { end.ctxt } else { span.ctxt },
if span.parent == end.parent { span.parent } else { None },
)
}
@@ -879,9 +882,9 @@ impl Span {
// Return the macro span on its own to avoid weird diagnostic output. It is preferable to
// have an incomplete span than a completely nonsensical one.
if span_data.ctxt != end_data.ctxt {
- if span_data.ctxt == SyntaxContext::root() {
+ if span_data.ctxt.is_root() {
return end;
- } else if end_data.ctxt == SyntaxContext::root() {
+ } else if end_data.ctxt.is_root() {
return self;
}
// Both spans fall within a macro.
@@ -890,7 +893,7 @@ impl Span {
Span::new(
span_data.lo,
end_data.lo,
- if end_data.ctxt == SyntaxContext::root() { end_data.ctxt } else { span_data.ctxt },
+ if end_data.ctxt.is_root() { end_data.ctxt } else { span_data.ctxt },
if span_data.parent == end_data.parent { span_data.parent } else { None },
)
}
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 1824510a9..86716da17 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -744,6 +744,21 @@ impl SourceMap {
})
}
+ /// Extends the given `Span` to previous character while the previous character matches the predicate
+ pub fn span_extend_prev_while(
+ &self,
+ span: Span,
+ f: impl Fn(char) -> bool,
+ ) -> Result<Span, SpanSnippetError> {
+ self.span_to_source(span, |s, start, _end| {
+ let n = s[..start]
+ .char_indices()
+ .rfind(|&(_, c)| !f(c))
+ .map_or(start, |(i, _)| start - i - 1);
+ Ok(span.with_lo(span.lo() - BytePos(n as u32)))
+ })
+ }
+
/// 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) {
@@ -1057,11 +1072,7 @@ impl SourceMap {
/// This index is guaranteed to be valid for the lifetime of this `SourceMap`,
/// since `source_files` is a `MonotonicVec`
pub fn lookup_source_file_idx(&self, pos: BytePos) -> usize {
- self.files
- .borrow()
- .source_files
- .binary_search_by_key(&pos, |key| key.start_pos)
- .unwrap_or_else(|p| p - 1)
+ self.files.borrow().source_files.partition_point(|x| x.start_pos <= pos) - 1
}
pub fn count_lines(&self) -> usize {
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 874d578fe..5c6d43e50 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -432,7 +432,6 @@ symbols! {
bool,
borrowck_graphviz_format,
borrowck_graphviz_postflow,
- box_free,
box_new,
box_patterns,
box_syntax,
@@ -657,6 +656,7 @@ symbols! {
dyn_trait,
e,
edition_panic,
+ effects,
eh_catch_typeinfo,
eh_personality,
emit,
@@ -687,6 +687,7 @@ symbols! {
expf32,
expf64,
explicit_generic_args_with_impl_trait,
+ explicit_tail_calls,
export_name,
expr,
extended_key_value_attributes,
@@ -701,7 +702,9 @@ symbols! {
f,
f16c_target_feature,
f32,
+ f32_nan,
f64,
+ f64_nan,
fabsf32,
fabsf64,
fadd_fast,
@@ -756,7 +759,6 @@ symbols! {
from_desugaring,
from_fn,
from_iter,
- from_method,
from_output,
from_residual,
from_size_align_unchecked,
@@ -791,6 +793,7 @@ symbols! {
hexagon_target_feature,
hidden,
homogeneous_aggregate,
+ host,
html_favicon_url,
html_logo_url,
html_no_source,
@@ -815,6 +818,7 @@ symbols! {
impl_trait_in_bindings,
impl_trait_in_fn_trait_return,
impl_trait_projections,
+ implement_via_object,
implied_by,
import,
import_name_type,
@@ -868,6 +872,7 @@ symbols! {
large_assignments,
lateout,
lazy_normalization_consts,
+ lazy_type_alias,
le,
len,
let_chains,
@@ -1146,12 +1151,15 @@ symbols! {
profiler_builtins,
profiler_runtime,
ptr,
+ ptr_cast_mut,
+ ptr_from_ref,
ptr_guaranteed_cmp,
ptr_mask,
ptr_null,
ptr_null_mut,
ptr_offset_from,
ptr_offset_from_unsigned,
+ ptr_unique,
pub_macro_rules,
pub_restricted,
public,
@@ -1277,6 +1285,7 @@ symbols! {
rustc_evaluate_where_clauses,
rustc_expected_cgu_reuse,
rustc_has_incoherent_inherent_impls,
+ rustc_host,
rustc_if_this_changed,
rustc_inherit_overflow_checks,
rustc_insignificant_dtor,
@@ -1454,6 +1463,10 @@ symbols! {
stop_after_dataflow,
store,
str,
+ str_from_utf8,
+ str_from_utf8_mut,
+ str_from_utf8_unchecked,
+ str_from_utf8_unchecked_mut,
str_split_whitespace,
str_trim,
str_trim_end,
@@ -1547,6 +1560,7 @@ symbols! {
type_length_limit,
type_macros,
type_name,
+ type_privacy_lints,
u128,
u16,
u32,