Skip to content

Commit

Permalink
symbols: add is_preinterned fn to check if symbol was preinterned i…
Browse files Browse the repository at this point in the history
…n compiler
  • Loading branch information
klensy committed Aug 20, 2022
1 parent 36e530c commit 0016356
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_macros/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ fn symbols_with_errors(input: TokenStream) -> (TokenStream, Vec<syn::Error>) {
#n,
});
}
let _ = counter; // for future use

let output = quote! {
const SYMBOL_DIGITS_BASE: u32 = #digits_base;
const PREINTERNED_SYMBOLS_COUNT: u32 = #counter;

#[doc(hidden)]
#[allow(non_upper_case_globals)]
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,11 @@ impl Symbol {
pub fn can_be_raw(self) -> bool {
self != kw::Empty && self != kw::Underscore && !self.is_path_segment_keyword()
}

/// Is this symbol was interned in compiler's `symbols!` macro
pub fn is_preinterned(self) -> bool {
self.as_u32() < PREINTERNED_SYMBOLS_COUNT
}
}

impl Ident {
Expand Down

0 comments on commit 0016356

Please sign in to comment.