1
Fork 0

Add SyntaxContext::hygienic_eq.

This combines multiple `HygieneData::with` calls into one, by combining
parts of `hygienic_eq` and `adjust_ident`.
This commit is contained in:
Nicholas Nethercote 2019-06-03 09:43:20 +10:00
parent f9209fcd63
commit 6596743d5e
2 changed files with 10 additions and 1 deletions

View file

@ -3089,7 +3089,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
// comparison fails frequently, and we want to avoid the expensive
// `modern()` calls required for the span comparison whenever possible.
use_name.name == def_name.name &&
self.adjust_ident(use_name, def_parent_def_id).span.ctxt() == def_name.modern().span.ctxt()
use_name.span.ctxt().hygienic_eq(def_name.span.ctxt(),
self.expansion_that_defined(def_parent_def_id))
}
fn expansion_that_defined(self, scope: DefId) -> Mark {

View file

@ -543,6 +543,14 @@ impl SyntaxContext {
})
}
pub fn hygienic_eq(self, other: SyntaxContext, mark: Mark) -> bool {
HygieneData::with(|data| {
let mut self_modern = data.modern(self);
data.adjust(&mut self_modern, mark);
self_modern == data.modern(other)
})
}
#[inline]
pub fn modern(self) -> SyntaxContext {
HygieneData::with(|data| data.modern(self))