Skip to content

Commit 4c9ecbf

Browse files
committed
Add modernize_and_adjust methods.
These combine two `HygieneData::with` calls into one.
1 parent ab9bbf4 commit 4c9ecbf

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

src/librustc/ty/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3101,15 +3101,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
31013101
}
31023102

31033103
pub fn adjust_ident(self, mut ident: Ident, scope: DefId) -> Ident {
3104-
ident = ident.modern();
3105-
ident.span.adjust(self.expansion_that_defined(scope));
3104+
ident.span.modernize_and_adjust(self.expansion_that_defined(scope));
31063105
ident
31073106
}
31083107

31093108
pub fn adjust_ident_and_get_scope(self, mut ident: Ident, scope: DefId, block: hir::HirId)
31103109
-> (Ident, DefId) {
3111-
ident = ident.modern();
3112-
let scope = match ident.span.adjust(self.expansion_that_defined(scope)) {
3110+
let scope = match ident.span.modernize_and_adjust(self.expansion_that_defined(scope)) {
31133111
Some(actual_expansion) =>
31143112
self.hir().definitions().parent_module_of_macro_def(actual_expansion),
31153113
None => self.hir().get_module_parent_by_hir_id(block),

src/librustc_resolve/lib.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2330,14 +2330,12 @@ impl<'a> Resolver<'a> {
23302330
let orig_current_module = self.current_module;
23312331
match module {
23322332
ModuleOrUniformRoot::Module(module) => {
2333-
ident.span = ident.span.modern();
2334-
if let Some(def) = ident.span.adjust(module.expansion) {
2333+
if let Some(def) = ident.span.modernize_and_adjust(module.expansion) {
23352334
self.current_module = self.macro_def_scope(def);
23362335
}
23372336
}
23382337
ModuleOrUniformRoot::ExternPrelude => {
2339-
ident.span = ident.span.modern();
2340-
ident.span.adjust(Mark::root());
2338+
ident.span.modernize_and_adjust(Mark::root());
23412339
}
23422340
ModuleOrUniformRoot::CrateRootAndExternPrelude |
23432341
ModuleOrUniformRoot::CurrentScope => {

src/libsyntax_pos/hygiene.rs

+8
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ impl SyntaxContext {
508508
HygieneData::with(|data| data.adjust(self, expansion))
509509
}
510510

511+
/// Like `SyntaxContext::adjust`, but also modernizes `self`.
512+
pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
513+
HygieneData::with(|data| {
514+
*self = data.modern(*self);
515+
data.adjust(self, expansion)
516+
})
517+
}
518+
511519
/// Adjust this context for resolution in a scope created by the given expansion
512520
/// via a glob import with the given `SyntaxContext`.
513521
/// For example:

src/libsyntax_pos/lib.rs

+8
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,14 @@ impl Span {
534534
mark
535535
}
536536

537+
#[inline]
538+
pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> {
539+
let mut span = self.data();
540+
let mark = span.ctxt.modernize_and_adjust(expansion);
541+
*self = Span::new(span.lo, span.hi, span.ctxt);
542+
mark
543+
}
544+
537545
#[inline]
538546
pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> {
539547
let mut span = self.data();

0 commit comments

Comments
 (0)