about summary refs log tree commit diff
path: root/compiler/rustc_span/src
diff options
context:
space:
mode:
authorTrevor Gross <tmgross@umich.edu>2025-01-08 10:26:24 +0000
committerTrevor Gross <tmgross@umich.edu>2025-01-08 16:27:31 -0500
commit933c4f5a811f2c73b82c35c5b759c2e6b0f5e2f0 (patch)
tree21e194635b8057b2b4023f43db02512896098ad7 /compiler/rustc_span/src
parent1f81f906893d166d05fb4839f169983f2b564cc7 (diff)
downloadrust-933c4f5a811f2c73b82c35c5b759c2e6b0f5e2f0.tar.gz
rust-933c4f5a811f2c73b82c35c5b759c2e6b0f5e2f0.zip
Add a list of symbols for stable standard library crates
There are a few locations where the crate name is checked against an
enumerated list of `std`, `core`, `alloc`, and `proc_macro`, or some
subset thereof. In most of these cases, all four crates should likely be
treated the same. Change this so the crates are listed in one place, and
that list is used wherever a list of `std` crates is needed.

`test` could be considered relevant in some of these cases, but
generally treating it separate from the others seems preferable while it
is unstable.

There are also a few places that Clippy will be able to use this.
Diffstat (limited to 'compiler/rustc_span/src')
-rw-r--r--compiler/rustc_span/src/lib.rs2
-rw-r--r--compiler/rustc_span/src/symbol.rs4
2 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs
index d5c2a337b4c..51cfbf59471 100644
--- a/compiler/rustc_span/src/lib.rs
+++ b/compiler/rustc_span/src/lib.rs
@@ -67,7 +67,7 @@ mod span_encoding;
 pub use span_encoding::{DUMMY_SP, Span};
 
 pub mod symbol;
-pub use symbol::{Ident, MacroRulesNormalizedIdent, Symbol, kw, sym};
+pub use symbol::{Ident, MacroRulesNormalizedIdent, STDLIB_STABLE_CRATES, Symbol, kw, sym};
 
 mod analyze_source_file;
 pub mod fatal_error;
diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs
index 0dcf38e3493..ef1e2c20978 100644
--- a/compiler/rustc_span/src/symbol.rs
+++ b/compiler/rustc_span/src/symbol.rs
@@ -2240,6 +2240,10 @@ symbols! {
     }
 }
 
+/// Symbols for crates that are part of the stable standard library: `std`, `core`, `alloc`, and
+/// `proc_macro`.
+pub const STDLIB_STABLE_CRATES: &[Symbol] = &[sym::std, sym::core, sym::alloc, sym::proc_macro];
+
 #[derive(Copy, Clone, Eq, HashStable_Generic, Encodable, Decodable)]
 pub struct Ident {
     pub name: Symbol,