summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_span
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:59:24 +0000
commit023939b627b7dc93b01471f7d41fb8553ddb4ffa (patch)
tree60fc59477c605c72b0a1051409062ddecc43f877 /compiler/rustc_span
parentAdding debian version 1.72.1+dfsg1-1. (diff)
downloadrustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.tar.xz
rustc-023939b627b7dc93b01471f7d41fb8553ddb4ffa.zip
Merging upstream version 1.73.0+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.rs95
-rw-r--r--compiler/rustc_span/src/edit_distance.rs7
-rw-r--r--compiler/rustc_span/src/edition.rs6
-rw-r--r--compiler/rustc_span/src/lib.rs59
-rw-r--r--compiler/rustc_span/src/source_map.rs15
-rw-r--r--compiler/rustc_span/src/symbol.rs30
6 files changed, 184 insertions, 28 deletions
diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs
index f65a6aa4f..595babc26 100644
--- a/compiler/rustc_span/src/def_id.rs
+++ b/compiler/rustc_span/src/def_id.rs
@@ -28,10 +28,16 @@ impl CrateNum {
CrateNum::from_usize(x)
}
+ // FIXME(typed_def_id): Replace this with `as_mod_def_id`.
#[inline]
pub fn as_def_id(self) -> DefId {
DefId { krate: self, index: CRATE_DEF_INDEX }
}
+
+ #[inline]
+ pub fn as_mod_def_id(self) -> ModDefId {
+ ModDefId::new_unchecked(DefId { krate: self, index: CRATE_DEF_INDEX })
+ }
}
impl fmt::Display for CrateNum {
@@ -485,3 +491,92 @@ impl<CTX: HashStableContext> ToStableHashKey<CTX> for CrateNum {
self.as_def_id().to_stable_hash_key(hcx)
}
}
+
+macro_rules! typed_def_id {
+ ($Name:ident, $LocalName:ident) => {
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
+ pub struct $Name(DefId);
+
+ impl $Name {
+ pub const fn new_unchecked(def_id: DefId) -> Self {
+ Self(def_id)
+ }
+
+ pub fn to_def_id(self) -> DefId {
+ self.into()
+ }
+
+ pub fn is_local(self) -> bool {
+ self.0.is_local()
+ }
+
+ pub fn as_local(self) -> Option<$LocalName> {
+ self.0.as_local().map($LocalName::new_unchecked)
+ }
+ }
+
+ impl From<$LocalName> for $Name {
+ fn from(local: $LocalName) -> Self {
+ Self(local.0.to_def_id())
+ }
+ }
+
+ impl From<$Name> for DefId {
+ fn from(typed: $Name) -> Self {
+ typed.0
+ }
+ }
+
+ #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
+ pub struct $LocalName(LocalDefId);
+
+ impl !Ord for $LocalName {}
+ impl !PartialOrd for $LocalName {}
+
+ impl $LocalName {
+ pub const fn new_unchecked(def_id: LocalDefId) -> Self {
+ Self(def_id)
+ }
+
+ pub fn to_def_id(self) -> DefId {
+ self.0.into()
+ }
+
+ pub fn to_local_def_id(self) -> LocalDefId {
+ self.0
+ }
+ }
+
+ impl From<$LocalName> for LocalDefId {
+ fn from(typed: $LocalName) -> Self {
+ typed.0
+ }
+ }
+
+ impl From<$LocalName> for DefId {
+ fn from(typed: $LocalName) -> Self {
+ typed.0.into()
+ }
+ }
+ };
+}
+
+// N.B.: when adding new typed `DefId`s update the corresponding trait impls in
+// `rustc_middle::dep_graph::def_node` for `DepNodeParams`.
+typed_def_id! { ModDefId, LocalModDefId }
+
+impl LocalModDefId {
+ pub const CRATE_DEF_ID: Self = Self::new_unchecked(CRATE_DEF_ID);
+}
+
+impl ModDefId {
+ pub fn is_top_level_module(self) -> bool {
+ self.0.is_top_level_module()
+ }
+}
+
+impl LocalModDefId {
+ pub fn is_top_level_module(self) -> bool {
+ self.0.is_top_level_module()
+ }
+}
diff --git a/compiler/rustc_span/src/edit_distance.rs b/compiler/rustc_span/src/edit_distance.rs
index 259f42386..96a118e59 100644
--- a/compiler/rustc_span/src/edit_distance.rs
+++ b/compiler/rustc_span/src/edit_distance.rs
@@ -238,8 +238,9 @@ fn find_best_match_for_name_impl(
}
fn find_match_by_sorted_words(iter_names: &[Symbol], lookup: &str) -> Option<Symbol> {
+ let lookup_sorted_by_words = sort_by_words(lookup);
iter_names.iter().fold(None, |result, candidate| {
- if sort_by_words(candidate.as_str()) == sort_by_words(lookup) {
+ if sort_by_words(candidate.as_str()) == lookup_sorted_by_words {
Some(*candidate)
} else {
result
@@ -247,9 +248,9 @@ fn find_match_by_sorted_words(iter_names: &[Symbol], lookup: &str) -> Option<Sym
})
}
-fn sort_by_words(name: &str) -> String {
+fn sort_by_words(name: &str) -> Vec<&str> {
let mut split_words: Vec<&str> = name.split('_').collect();
// We are sorting primitive &strs and can use unstable sort here.
split_words.sort_unstable();
- split_words.join("_")
+ split_words
}
diff --git a/compiler/rustc_span/src/edition.rs b/compiler/rustc_span/src/edition.rs
index f16db69aa..608b8c24b 100644
--- a/compiler/rustc_span/src/edition.rs
+++ b/compiler/rustc_span/src/edition.rs
@@ -82,17 +82,17 @@ impl Edition {
}
/// Are we allowed to use features from the Rust 2018 edition?
- pub fn rust_2018(self) -> bool {
+ pub fn at_least_rust_2018(self) -> bool {
self >= Edition::Edition2018
}
/// Are we allowed to use features from the Rust 2021 edition?
- pub fn rust_2021(self) -> bool {
+ pub fn at_least_rust_2021(self) -> bool {
self >= Edition::Edition2021
}
/// Are we allowed to use features from the Rust 2024 edition?
- pub fn rust_2024(self) -> bool {
+ pub fn at_least_rust_2024(self) -> bool {
self >= Edition::Edition2024
}
}
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index 3bb9c4920..c24b8d9ec 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -23,6 +23,7 @@
#![feature(round_char_boundary)]
#![deny(rustc::untranslatable_diagnostic)]
#![deny(rustc::diagnostic_outside_of_impl)]
+#![cfg_attr(not(bootstrap), allow(internal_features))]
#[macro_use]
extern crate rustc_macros;
@@ -605,7 +606,7 @@ impl Span {
// FIXME: If this span comes from a `derive` macro but it points at code the user wrote,
// the callsite span and the span will be pointing at different places. It also means that
// we can safely provide suggestions on this span.
- || (matches!(self.ctxt().outer_expn_data().kind, ExpnKind::Macro(MacroKind::Derive, _))
+ || (self.in_derive_expansion()
&& self.parent_callsite().map(|p| (p.lo(), p.hi())) != Some((self.lo(), self.hi())))
}
@@ -685,6 +686,12 @@ impl Span {
}
/// Walk down the expansion ancestors to find a span that's contained within `outer`.
+ ///
+ /// The span returned by this method may have a different [`SyntaxContext`] as `outer`.
+ /// If you need to extend the span, use [`find_ancestor_inside_same_ctxt`] instead,
+ /// because joining spans with different syntax contexts can create unexpected results.
+ ///
+ /// [`find_ancestor_inside_same_ctxt`]: Self::find_ancestor_inside_same_ctxt
pub fn find_ancestor_inside(mut self, outer: Span) -> Option<Span> {
while !outer.contains(self) {
self = self.parent_callsite()?;
@@ -692,11 +699,34 @@ 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).
+ /// Walk down the expansion ancestors to find a span with the same [`SyntaxContext`] as
+ /// `other`.
+ ///
+ /// Like [`find_ancestor_inside_same_ctxt`], but specifically for when spans might not
+ /// overlap. Take care when using this, and prefer [`find_ancestor_inside`] or
+ /// [`find_ancestor_inside_same_ctxt`] when you know that the spans are nested (modulo
+ /// macro expansion).
+ ///
+ /// [`find_ancestor_inside`]: Self::find_ancestor_inside
+ /// [`find_ancestor_inside_same_ctxt`]: Self::find_ancestor_inside_same_ctxt
pub fn find_ancestor_in_same_ctxt(mut self, other: Span) -> Option<Span> {
- while !Span::eq_ctxt(self, other) {
+ while !self.eq_ctxt(other) {
+ self = self.parent_callsite()?;
+ }
+ Some(self)
+ }
+
+ /// Walk down the expansion ancestors to find a span that's contained within `outer` and
+ /// has the same [`SyntaxContext`] as `outer`.
+ ///
+ /// This method is the combination of [`find_ancestor_inside`] and
+ /// [`find_ancestor_in_same_ctxt`] and should be preferred when extending the returned span.
+ /// If you do not need to modify the span, use [`find_ancestor_inside`] instead.
+ ///
+ /// [`find_ancestor_inside`]: Self::find_ancestor_inside
+ /// [`find_ancestor_in_same_ctxt`]: Self::find_ancestor_in_same_ctxt
+ pub fn find_ancestor_inside_same_ctxt(mut self, outer: Span) -> Option<Span> {
+ while !outer.contains(self) || !self.eq_ctxt(outer) {
self = self.parent_callsite()?;
}
Some(self)
@@ -707,24 +737,28 @@ impl Span {
self.ctxt().edition()
}
+ /// Is this edition 2015?
#[inline]
pub fn is_rust_2015(self) -> bool {
self.edition().is_rust_2015()
}
+ /// Are we allowed to use features from the Rust 2018 edition?
#[inline]
- pub fn rust_2018(self) -> bool {
- self.edition().rust_2018()
+ pub fn at_least_rust_2018(self) -> bool {
+ self.edition().at_least_rust_2018()
}
+ /// Are we allowed to use features from the Rust 2021 edition?
#[inline]
- pub fn rust_2021(self) -> bool {
- self.edition().rust_2021()
+ pub fn at_least_rust_2021(self) -> bool {
+ self.edition().at_least_rust_2021()
}
+ /// Are we allowed to use features from the Rust 2024 edition?
#[inline]
- pub fn rust_2024(self) -> bool {
- self.edition().rust_2024()
+ pub fn at_least_rust_2024(self) -> bool {
+ self.edition().at_least_rust_2024()
}
/// Returns the source callee.
@@ -2159,7 +2193,8 @@ where
// If this is not an empty or invalid span, we want to hash the last
// position that belongs to it, as opposed to hashing the first
// position past it.
- let Some((file, line_lo, col_lo, line_hi, col_hi)) = ctx.span_data_to_lines_and_cols(&span) else {
+ let Some((file, line_lo, col_lo, line_hi, col_hi)) = ctx.span_data_to_lines_and_cols(&span)
+ else {
Hash::hash(&TAG_INVALID_SPAN, hasher);
return;
};
diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs
index 86716da17..983b2ab04 100644
--- a/compiler/rustc_span/src/source_map.rs
+++ b/compiler/rustc_span/src/source_map.rs
@@ -973,24 +973,21 @@ impl SourceMap {
Span::new(BytePos(start_of_next_point), end_of_next_point, sp.ctxt(), None)
}
- /// Returns a new span to check next none-whitespace character or some specified expected character
- /// If `expect` is none, the first span of non-whitespace character is returned.
- /// If `expect` presented, the first span of the character `expect` is returned
- /// Otherwise, the span reached to limit is returned.
- pub fn span_look_ahead(&self, span: Span, expect: Option<&str>, limit: Option<usize>) -> Span {
+ /// Check whether span is followed by some specified expected string in limit scope
+ pub fn span_look_ahead(&self, span: Span, expect: &str, limit: Option<usize>) -> Option<Span> {
let mut sp = span;
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.is_some_and(|es| snippet == es) {
- break;
+ if snippet == expect {
+ return Some(sp);
}
- if expect.is_none() && snippet.chars().any(|c| !c.is_whitespace()) {
+ if snippet.chars().any(|c| !c.is_whitespace()) {
break;
}
}
}
- sp
+ None
}
/// Finds the width of the character, either before or after the end of provided span,
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 5c6d43e50..28a2dfebc 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -326,6 +326,7 @@ symbols! {
abi_efiapi,
abi_msp430_interrupt,
abi_ptx,
+ abi_riscv_interrupt,
abi_sysv64,
abi_thiscall,
abi_unadjusted,
@@ -372,6 +373,7 @@ symbols! {
arm_target_feature,
array,
arrays,
+ as_mut_ptr,
as_ptr,
as_ref,
as_str,
@@ -399,6 +401,7 @@ symbols! {
async_await,
async_closure,
async_fn_in_trait,
+ async_fn_track_caller,
atomic,
atomic_mod,
atomics,
@@ -442,6 +445,7 @@ symbols! {
bridge,
bswap,
builtin_syntax,
+ c,
c_str,
c_str_literals,
c_unwind,
@@ -465,6 +469,7 @@ symbols! {
cfg_hide,
cfg_overflow_checks,
cfg_panic,
+ cfg_relocation_model,
cfg_sanitize,
cfg_target_abi,
cfg_target_compact,
@@ -496,6 +501,7 @@ symbols! {
cold,
collapse_debuginfo,
column,
+ compare_bytes,
compare_exchange,
compare_exchange_weak,
compile_error,
@@ -539,6 +545,7 @@ symbols! {
const_panic_fmt,
const_param_ty,
const_precise_live_drops,
+ const_ptr_cast,
const_raw_ptr_deref,
const_raw_ptr_to_usize_cast,
const_refs_to_cell,
@@ -570,6 +577,7 @@ symbols! {
crate_type,
crate_visibility_modifier,
crt_dash_static: "crt-static",
+ csky_target_feature,
cstring_type,
ctlz,
ctlz_nonzero,
@@ -619,6 +627,7 @@ symbols! {
destruct,
destructuring_assignment,
diagnostic,
+ diagnostic_namespace,
direct,
discriminant_kind,
discriminant_type,
@@ -654,6 +663,7 @@ symbols! {
dyn_metadata,
dyn_star,
dyn_trait,
+ dynamic_no_pic: "dynamic-no-pic",
e,
edition_panic,
effects,
@@ -781,6 +791,7 @@ symbols! {
generic_associated_types,
generic_associated_types_extended,
generic_const_exprs,
+ generic_const_items,
generic_param_attrs,
get_context,
global_allocator,
@@ -858,6 +869,7 @@ symbols! {
item,
item_like_imports,
iter,
+ iter_mut,
iter_repeat,
iterator_collect_fn,
kcfi,
@@ -1106,6 +1118,8 @@ symbols! {
path,
pattern_parentheses,
phantom_data,
+ pic,
+ pie,
pin,
platform_intrinsics,
plugin,
@@ -1151,9 +1165,14 @@ symbols! {
profiler_builtins,
profiler_runtime,
ptr,
+ ptr_cast,
+ ptr_cast_const,
ptr_cast_mut,
+ ptr_const_is_null,
+ ptr_from_mut,
ptr_from_ref,
ptr_guaranteed_cmp,
+ ptr_is_null,
ptr_mask,
ptr_null,
ptr_null_mut,
@@ -1209,6 +1228,7 @@ symbols! {
register_tool,
relaxed_adts,
relaxed_struct_unsize,
+ relocation_model,
rem,
rem_assign,
repr,
@@ -1229,6 +1249,8 @@ symbols! {
rintf64,
riscv_target_feature,
rlib,
+ ropi,
+ ropi_rwpi: "ropi-rwpi",
rotate_left,
rotate_right,
roundevenf32,
@@ -1263,6 +1285,7 @@ symbols! {
rustc_clean,
rustc_coherence_is_core,
rustc_coinductive,
+ rustc_confusables,
rustc_const_stable,
rustc_const_unstable,
rustc_conversion_suggestion,
@@ -1278,7 +1301,7 @@ symbols! {
rustc_dummy,
rustc_dump_env_program_clauses,
rustc_dump_program_clauses,
- rustc_dump_user_substs,
+ rustc_dump_user_args,
rustc_dump_vtable,
rustc_effective_visibility,
rustc_error,
@@ -1339,6 +1362,7 @@ symbols! {
rustdoc_missing_doc_code_examples,
rustfmt,
rvalue_static_promotion,
+ rwpi,
s,
safety,
sanitize,
@@ -1364,9 +1388,13 @@ symbols! {
simd_arith_offset,
simd_as,
simd_bitmask,
+ simd_bitreverse,
+ simd_bswap,
simd_cast,
simd_cast_ptr,
simd_ceil,
+ simd_ctlz,
+ simd_cttz,
simd_div,
simd_eq,
simd_expose_addr,