diff options
Diffstat (limited to 'compiler/rustc_span/src')
| -rw-r--r-- | compiler/rustc_span/src/analyze_source_file.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/def_id.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/hygiene.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_span/src/lib.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_span/src/source_map.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_span/src/span_encoding.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_span/src/symbol.rs | 117 |
7 files changed, 128 insertions, 22 deletions
diff --git a/compiler/rustc_span/src/analyze_source_file.rs b/compiler/rustc_span/src/analyze_source_file.rs index ba7e0cec5bd..28ce883daee 100644 --- a/compiler/rustc_span/src/analyze_source_file.rs +++ b/compiler/rustc_span/src/analyze_source_file.rs @@ -8,7 +8,7 @@ mod tests; /// /// This function will use an SSE2 enhanced implementation if hardware support /// is detected at runtime. -pub fn analyze_source_file(src: &str) -> (Vec<RelativeBytePos>, Vec<MultiByteChar>) { +pub(crate) fn analyze_source_file(src: &str) -> (Vec<RelativeBytePos>, Vec<MultiByteChar>) { let mut lines = vec![RelativeBytePos::from_u32(0)]; let mut multi_byte_chars = vec![]; diff --git a/compiler/rustc_span/src/def_id.rs b/compiler/rustc_span/src/def_id.rs index a45b676acae..f61ce37131e 100644 --- a/compiler/rustc_span/src/def_id.rs +++ b/compiler/rustc_span/src/def_id.rs @@ -1,12 +1,12 @@ use std::fmt; use std::hash::{BuildHasherDefault, Hash, Hasher}; +use rustc_data_structures::AtomicRef; use rustc_data_structures::fingerprint::Fingerprint; use rustc_data_structures::stable_hasher::{ Hash64, HashStable, StableHasher, StableOrd, ToStableHashKey, }; use rustc_data_structures::unhash::Unhasher; -use rustc_data_structures::AtomicRef; use rustc_index::Idx; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_serialize::{Decodable, Encodable}; diff --git a/compiler/rustc_span/src/hygiene.rs b/compiler/rustc_span/src/hygiene.rs index 5e1b1b44bc2..c57d516fcae 100644 --- a/compiler/rustc_span/src/hygiene.rs +++ b/compiler/rustc_span/src/hygiene.rs @@ -39,10 +39,10 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use tracing::{debug, trace}; -use crate::def_id::{CrateNum, DefId, StableCrateId, CRATE_DEF_ID, LOCAL_CRATE}; +use crate::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, StableCrateId}; use crate::edition::Edition; -use crate::symbol::{kw, sym, Symbol}; -use crate::{with_session_globals, HashStableContext, Span, SpanDecoder, SpanEncoder, DUMMY_SP}; +use crate::symbol::{Symbol, kw, sym}; +use crate::{DUMMY_SP, HashStableContext, Span, SpanDecoder, SpanEncoder, with_session_globals}; /// A `SyntaxContext` represents a chain of pairs `(ExpnId, Transparency)` named "marks". #[derive(Clone, Copy, PartialEq, Eq, Hash)] @@ -1358,7 +1358,7 @@ pub fn decode_syntax_context<D: Decoder, F: FnOnce(&mut D, u32) -> SyntaxContext let mut inner = context.inner.lock(); if let Some(ctxt) = inner.remapped_ctxts.get(raw_id as usize).copied().flatten() { - // This has already beeen decoded. + // This has already been decoded. return ctxt; } diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 7b020f11cdd..9dbdab84a81 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -30,6 +30,7 @@ #![feature(round_char_boundary)] #![feature(rustc_attrs)] #![feature(rustdoc_internals)] +#![warn(unreachable_pub)] // tidy-alphabetical-end // The code produced by the `Encodable`/`Decodable` derive macros refer to @@ -38,7 +39,7 @@ extern crate self as rustc_span; use derive_where::derive_where; -use rustc_data_structures::{outline, AtomicRef}; +use rustc_data_structures::{AtomicRef, outline}; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_serialize::opaque::{FileEncoder, MemDecoder}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -59,13 +60,13 @@ pub use hygiene::{ }; use rustc_data_structures::stable_hasher::HashingControls; pub mod def_id; -use def_id::{CrateNum, DefId, DefIndex, DefPathHash, LocalDefId, StableCrateId, LOCAL_CRATE}; +use def_id::{CrateNum, DefId, DefIndex, DefPathHash, LOCAL_CRATE, LocalDefId, StableCrateId}; pub mod edit_distance; mod span_encoding; -pub use span_encoding::{Span, DUMMY_SP}; +pub use span_encoding::{DUMMY_SP, Span}; pub mod symbol; -pub use symbol::{sym, Symbol}; +pub use symbol::{Symbol, sym}; mod analyze_source_file; pub mod fatal_error; @@ -82,7 +83,7 @@ use std::{fmt, iter}; use md5::{Digest, Md5}; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::stable_hasher::{Hash128, Hash64, HashStable, StableHasher}; +use rustc_data_structures::stable_hasher::{Hash64, Hash128, HashStable, StableHasher}; use rustc_data_structures::sync::{FreezeLock, FreezeWriteGuard, Lock, Lrc}; use sha1::Sha1; use sha2::Sha256; @@ -271,7 +272,7 @@ impl RealFileName { } } - /// Return the path remmapped or not depending on the [`FileNameDisplayPreference`]. + /// Return the path remapped or not depending on the [`FileNameDisplayPreference`]. /// /// For the purpose of this function, local and short preference are equal. pub fn to_path(&self, display_pref: FileNameDisplayPreference) -> &Path { @@ -1683,7 +1684,7 @@ impl fmt::Debug for SourceFile { /// is because SourceFiles for the local crate are allocated very early in the /// compilation process when the `StableCrateId` is not yet known. If, due to /// some refactoring of the compiler, the `StableCrateId` of the local crate -/// were to become available, it would be better to uniformely make this a +/// were to become available, it would be better to uniformly make this a /// hash of `(filename, stable_crate_id)`. /// /// When `SourceFile`s are exported in crate metadata, the `StableSourceFileId` diff --git a/compiler/rustc_span/src/source_map.rs b/compiler/rustc_span/src/source_map.rs index f914e8dc1ba..98447147d3e 100644 --- a/compiler/rustc_span/src/source_map.rs +++ b/compiler/rustc_span/src/source_map.rs @@ -779,7 +779,7 @@ impl SourceMap { return Ok(false); } } - return Ok(true); + Ok(true) }) .is_ok_and(|is_accessible| is_accessible) } diff --git a/compiler/rustc_span/src/span_encoding.rs b/compiler/rustc_span/src/span_encoding.rs index 8988becb171..db8170fa6ae 100644 --- a/compiler/rustc_span/src/span_encoding.rs +++ b/compiler/rustc_span/src/span_encoding.rs @@ -5,7 +5,7 @@ use rustc_serialize::int_overflow::DebugStrictAdd; use crate::def_id::{DefIndex, LocalDefId}; use crate::hygiene::SyntaxContext; -use crate::{BytePos, SpanData, SPAN_TRACK}; +use crate::{BytePos, SPAN_TRACK, SpanData}; /// A compressed span. /// @@ -424,7 +424,7 @@ impl Span { } #[derive(Default)] -pub struct SpanInterner { +pub(crate) struct SpanInterner { spans: FxIndexSet<SpanData>, } diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index aba56732725..8f226b26bef 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -11,16 +11,17 @@ use rustc_data_structures::stable_hasher::{ HashStable, StableCompare, StableHasher, ToStableHashKey, }; use rustc_data_structures::sync::Lock; -use rustc_macros::{symbols, Decodable, Encodable, HashStable_Generic}; +use rustc_macros::{Decodable, Encodable, HashStable_Generic, symbols}; -use crate::{with_session_globals, Edition, Span, DUMMY_SP}; +use crate::{DUMMY_SP, Edition, Span, with_session_globals}; #[cfg(test)] mod tests; // The proc macro code for this is in `compiler/rustc_macros/src/symbols.rs`. symbols! { - // If you modify this list, adjust `is_special` and `is_used_keyword`/`is_unused_keyword`. + // If you modify this list, adjust `is_special`, `is_used_keyword`/`is_unused_keyword` + // and `AllKeywords`. // But this should rarely be necessary if the keywords are kept in alphabetic order. Keywords { // Special reserved identifiers used internally for elided lifetimes, @@ -308,6 +309,7 @@ symbols! { RwLockReadGuard, RwLockWriteGuard, Saturating, + SeekFrom, Send, SeqCst, Sized, @@ -341,6 +343,7 @@ symbols! { Upvars, Vec, VecDeque, + Waker, Wrapper, Wrapping, Yield, @@ -407,6 +410,7 @@ symbols! { append_const_msg, arbitrary_enum_discriminant, arbitrary_self_types, + arbitrary_self_types_pointers, args, arith_offset, arm, @@ -486,6 +490,7 @@ symbols! { begin_panic, bench, bin, + binaryheap_iter, bind_by_move_pattern_guards, bindings_after_at, bitand, @@ -498,6 +503,7 @@ symbols! { black_box, block, bool, + bool_then, borrowck_graphviz_format, borrowck_graphviz_postflow, box_new, @@ -509,6 +515,9 @@ symbols! { breakpoint, bridge, bswap, + btreemap_contains_key, + btreemap_insert, + btreeset_iter, builtin_syntax, c, c_str, @@ -536,6 +545,7 @@ symbols! { cfg_attr_multi, cfg_doctest, cfg_eval, + cfg_fmt_debug, cfg_hide, cfg_overflow_checks, cfg_panic, @@ -596,7 +606,6 @@ symbols! { conservative_impl_trait, console, const_allocate, - const_arg_path, const_async_blocks, const_closures, const_compare_raw_pointers, @@ -676,6 +685,7 @@ symbols! { crt_dash_static: "crt-static", csky_target_feature, cstr_type, + cstring_as_c_str, cstring_type, ctlz, ctlz_nonzero, @@ -831,6 +841,7 @@ symbols! { f16_nan, f16c_target_feature, f32, + f32_epsilon, f32_legacy_const_digits, f32_legacy_const_epsilon, f32_legacy_const_infinity, @@ -847,6 +858,7 @@ symbols! { f32_legacy_const_radix, f32_nan, f64, + f64_epsilon, f64_legacy_const_digits, f64_legacy_const_epsilon, f64_legacy_const_infinity, @@ -884,6 +896,7 @@ symbols! { field, field_init_shorthand, file, + file_options, float, float_to_int_unchecked, floorf128, @@ -895,6 +908,7 @@ symbols! { fmaf32, fmaf64, fmt, + fmt_debug, fmul_algebraic, fmul_fast, fn_align, @@ -938,6 +952,7 @@ symbols! { fs_create_dir, fsub_algebraic, fsub_fast, + full, fundamental, fused_iterator, future, @@ -967,6 +982,17 @@ symbols! { half_open_range_patterns, half_open_range_patterns_in_slices, hash, + hashmap_contains_key, + hashmap_drain_ty, + hashmap_insert, + hashmap_iter_mut_ty, + hashmap_iter_ty, + hashmap_keys_ty, + hashmap_values_mut_ty, + hashmap_values_ty, + hashset_drain_ty, + hashset_iter, + hashset_iter_ty, hexagon_target_feature, hidden, homogeneous_aggregate, @@ -1012,6 +1038,7 @@ symbols! { ident, if_let, if_let_guard, + if_let_rescope, if_while_or_patterns, ignore, impl_header_lifetime_elision, @@ -1044,6 +1071,7 @@ symbols! { inline_const, inline_const_pat, inout, + instant_now, instruction_set, integer_: "integer", // underscore to avoid clashing with the function `sym::integer` below integral, @@ -1072,6 +1100,9 @@ symbols! { item, item_like_imports, iter, + iter_cloned, + iter_copied, + iter_filter, iter_mut, iter_repeat, iterator, @@ -1250,6 +1281,7 @@ symbols! { mut_preserve_binding_mode_2024, mut_ref, naked, + naked_asm, naked_functions, name, names, @@ -1281,6 +1313,7 @@ symbols! { new_binary, new_const, new_debug, + new_debug_noop, new_display, new_lower_exp, new_lower_hex, @@ -1339,6 +1372,7 @@ symbols! { on, on_unimplemented, opaque, + open_options_new, ops, opt_out_copy, optimize, @@ -1346,10 +1380,14 @@ symbols! { optin_builtin_traits, option, option_env, + option_expect, + option_unwrap, options, or, or_patterns, ord_cmp_method, + os_str_to_os_string, + os_string_as_os_str, other, out, overflow_checks, @@ -1403,14 +1441,19 @@ symbols! { pat_param, patchable_function_entry, path, + path_main_separator, + path_to_pathbuf, + pathbuf_as_path, pattern_complexity, pattern_parentheses, pattern_type, pattern_types, + permissions_from_mode, phantom_data, pic, pie, pin, + pin_ergonomics, platform_intrinsics, plugin, plugin_registrar, @@ -1558,6 +1601,7 @@ symbols! { residual, result, result_ffi_guarantees, + result_ok_method, resume, return_position_impl_trait_in_trait, return_type_notation, @@ -1649,6 +1693,7 @@ symbols! { rustc_lint_opt_deny_field_access, rustc_lint_opt_ty, rustc_lint_query_instability, + rustc_lint_untracked_query_information, rustc_macro_transparency, rustc_main, rustc_mir, @@ -1715,6 +1760,7 @@ symbols! { semitransparent, sha512_sm_x86, shadow_call_stack, + shallow, shl, shl_assign, shorter_tail_lifetimes, @@ -1808,6 +1854,8 @@ symbols! { slice, slice_from_raw_parts, slice_from_raw_parts_mut, + slice_into_vec, + slice_iter, slice_len_fn, slice_patterns, slicing_syntax, @@ -1840,20 +1888,29 @@ symbols! { stop_after_dataflow, store, str, + str_chars, + str_ends_with, str_from_utf8, str_from_utf8_mut, str_from_utf8_unchecked, str_from_utf8_unchecked_mut, + str_len, str_split_whitespace, + str_starts_with, str_trim, str_trim_end, str_trim_start, strict_provenance, + string_as_mut_str, + string_as_str, string_deref_patterns, + string_from_utf8, + string_insert_str, + string_new, + string_push_str, stringify, struct_field_attributes, struct_inherit, - struct_target_features, struct_variant, structural_match, structural_peq, @@ -2001,6 +2058,7 @@ symbols! { unmarked_api, unnamed_fields, unpin, + unqualified_local_imports, unreachable, unreachable_2015, unreachable_2015_macro, @@ -2055,7 +2113,15 @@ symbols! { var, variant_count, vec, + vec_as_mut_slice, + vec_as_slice, + vec_from_elem, + vec_is_empty, vec_macro, + vec_new, + vec_pop, + vec_with_capacity, + vecdeque_iter, version, vfp2, vis, @@ -2458,10 +2524,10 @@ pub mod kw { /// For example `sym::rustfmt` or `sym::u8`. pub mod sym { // Used from a macro in `librustc_feature/accepted.rs` + use super::Symbol; pub use super::kw::MacroRules as macro_rules; #[doc(inline)] pub use super::sym_generated::*; - use super::Symbol; /// Get the symbol for an integer. /// @@ -2573,3 +2639,42 @@ impl Ident { self.name.can_be_raw() && self.is_reserved() } } + +/// An iterator over all the keywords in Rust. +#[derive(Copy, Clone)] +pub struct AllKeywords { + curr_idx: u32, + end_idx: u32, +} + +impl AllKeywords { + /// Initialize a new iterator over all the keywords. + /// + /// *Note:* Please update this if a new keyword is added beyond the current + /// range. + pub fn new() -> Self { + AllKeywords { curr_idx: kw::Empty.as_u32(), end_idx: kw::Yeet.as_u32() } + } + + /// Collect all the keywords in a given edition into a vector. + pub fn collect_used(&self, edition: impl Copy + FnOnce() -> Edition) -> Vec<Symbol> { + self.filter(|&keyword| { + keyword.is_used_keyword_always() || keyword.is_used_keyword_conditional(edition) + }) + .collect() + } +} + +impl Iterator for AllKeywords { + type Item = Symbol; + + fn next(&mut self) -> Option<Self::Item> { + if self.curr_idx <= self.end_idx { + let keyword = Symbol::new(self.curr_idx); + self.curr_idx += 1; + Some(keyword) + } else { + None + } + } +} |
