Skip to content

Commit 0016356

Browse files
committed
symbols: add is_preinterned fn to check if symbol was preinterned in compiler
1 parent 36e530c commit 0016356

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

compiler/rustc_macros/src/symbols.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
195195
#n,
196196
});
197197
}
198-
let _ = counter; // for future use
199198

200199
let output = quote! {
201200
const SYMBOL_DIGITS_BASE: u32 = #digits_base;
201+
const PREINTERNED_SYMBOLS_COUNT: u32 = #counter;
202202

203203
#[doc(hidden)]
204204
#[allow(non_upper_case_globals)]

compiler/rustc_span/src/symbol.rs

+5
Original file line numberDiff line numberDiff line change
@@ -2027,6 +2027,11 @@ impl Symbol {
20272027
pub fn can_be_raw(self) -> bool {
20282028
self != kw::Empty && self != kw::Underscore && !self.is_path_segment_keyword()
20292029
}
2030+
2031+
/// Is this symbol was interned in compiler's `symbols!` macro
2032+
pub fn is_preinterned(self) -> bool {
2033+
self.as_u32() < PREINTERNED_SYMBOLS_COUNT
2034+
}
20302035
}
20312036

20322037
impl Ident {

0 commit comments

Comments
 (0)