Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down Expand Up @@ -170,16 +172,18 @@ pub fn join_path_syms(path: impl IntoIterator<Item = impl Borrow<Symbol>>) -> 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
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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))
})
}))
}

Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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()
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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))
})
}
}

Expand Down
Loading