diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index d48e9fa861a3d..275caae99a797 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -31,7 +31,9 @@ use rustc_data_structures::tagged_ptr::Tag; use rustc_macros::{Decodable, Encodable, HashStable_Generic, Walkable}; pub use rustc_span::AttrId; use rustc_span::source_map::{Spanned, respan}; -use rustc_span::{ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym}; +use rustc_span::{ + ByteSymbol, DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym, with_session_globals, +}; use thin_vec::{ThinVec, thin_vec}; pub use crate::format::*; @@ -170,16 +172,18 @@ pub fn join_path_syms(path: impl IntoIterator>) -> St let mut s = String::with_capacity(len_hint * 8); let first_sym = *iter.next().unwrap().borrow(); - if first_sym != kw::PathRoot { - s.push_str(first_sym.as_str()); - } - for sym in iter { - let sym = *sym.borrow(); - debug_assert_ne!(sym, kw::PathRoot); - s.push_str("::"); - s.push_str(sym.as_str()); - } - s + with_session_globals(|globals| { + if first_sym != kw::PathRoot { + s.push_str(first_sym.get_str_from_session_globals(globals)); + } + for sym in iter { + let sym = *sym.borrow(); + debug_assert_ne!(sym, kw::PathRoot); + s.push_str("::"); + s.push_str(sym.get_str_from_session_globals(globals)); + } + s + }) } /// Like `join_path_syms`, but for `Ident`s. This function is necessary because diff --git a/compiler/rustc_ast/src/token.rs b/compiler/rustc_ast/src/token.rs index accf4d1816323..10bb8af971665 100644 --- a/compiler/rustc_ast/src/token.rs +++ b/compiler/rustc_ast/src/token.rs @@ -8,7 +8,7 @@ pub use TokenKind::*; use rustc_macros::{Decodable, Encodable, HashStable_Generic}; use rustc_span::edition::Edition; use rustc_span::symbol::IdentPrintMode; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym}; +use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, kw, sym, with_session_globals}; #[allow(clippy::useless_attribute)] // FIXME: following use of `hidden_glob_reexports` incorrectly triggers `useless_attribute` lint. #[allow(hidden_glob_reexports)] use rustc_span::{Ident, Symbol}; @@ -927,8 +927,12 @@ impl Token { self.is_keyword(kw) || (case == Case::Insensitive && self.is_non_raw_ident_where(|id| { - // Do an ASCII case-insensitive match, because all keywords are ASCII. - id.name.as_str().eq_ignore_ascii_case(kw.as_str()) + with_session_globals(|globals| { + // Do an ASCII case-insensitive match, because all keywords are ASCII. + id.name + .get_str_from_session_globals(globals) + .eq_ignore_ascii_case(kw.get_str_from_session_globals(globals)) + }) })) } diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index b4ce30767cb8c..16737a1f0e3d1 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -15,7 +15,9 @@ use rustc_errors::{Applicability, PResult, StashKey, struct_span_code_err}; use rustc_session::lint::builtin::VARARGS_WITHOUT_PATTERN; use rustc_span::edit_distance::edit_distance; use rustc_span::edition::Edition; -use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, source_map, sym}; +use rustc_span::{ + DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, source_map, sym, with_session_globals, +}; use thin_vec::{ThinVec, thin_vec}; use tracing::debug; @@ -2653,9 +2655,9 @@ impl<'a> Parser<'a> { && i.is_reserved() ) || case == Case::Insensitive - && t.is_non_raw_ident_where(|i| quals.iter().any(|exp| { - exp.kw.as_str() == i.name.as_str().to_lowercase() - })) + && with_session_globals(|globals| t.is_non_raw_ident_where(|i| quals.iter().any(|exp| { + exp.kw.get_str_from_session_globals(globals) == i.name.get_str_from_session_globals(globals).to_lowercase() + }))) ) // Rule out `unsafe extern {`. && !self.is_unsafe_foreign_mod() diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index c9aaba6cce3bc..0c3295dc33da5 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -15,7 +15,7 @@ use rustc_data_structures::sync::Lock; use rustc_macros::{Decodable, Encodable, HashStable_Generic, symbols}; use crate::edit_distance::find_best_match_for_name; -use crate::{DUMMY_SP, Edition, Span, with_session_globals}; +use crate::{DUMMY_SP, Edition, SessionGlobals, Span, with_session_globals}; #[cfg(test)] mod tests; @@ -2830,6 +2830,13 @@ impl Symbol { }) } + pub fn get_str_from_session_globals<'sess>( + &self, + session_globals: &'sess SessionGlobals, + ) -> &'sess str { + session_globals.symbol_interner.get_str(*self) + } + pub fn as_u32(self) -> u32 { self.0.as_u32() } @@ -2900,7 +2907,10 @@ impl StableCompare for Symbol { const CAN_USE_UNSTABLE_SORT: bool = true; fn stable_cmp(&self, other: &Self) -> std::cmp::Ordering { - self.as_str().cmp(other.as_str()) + with_session_globals(|session_globals| { + self.get_str_from_session_globals(session_globals) + .cmp(other.get_str_from_session_globals(session_globals)) + }) } }