diff options
| author | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-06-03 16:10:03 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <nnethercote@mozilla.com> | 2019-06-05 09:09:35 +1000 |
| commit | 4c9ecbf3d1a0fdac1d97c77783685c6281136c0b (patch) | |
| tree | f4f6536f0c6201c6f45dc99593151a6bf0da996b /src/libsyntax_pos | |
| parent | ab9bbf48db3ef8cd83bbcc4dfd40f0308a738cc1 (diff) | |
| download | rust-4c9ecbf3d1a0fdac1d97c77783685c6281136c0b.tar.gz rust-4c9ecbf3d1a0fdac1d97c77783685c6281136c0b.zip | |
Add `modernize_and_adjust` methods.
These combine two `HygieneData::with` calls into one.
Diffstat (limited to 'src/libsyntax_pos')
| -rw-r--r-- | src/libsyntax_pos/hygiene.rs | 8 | ||||
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 8 |
2 files changed, 16 insertions, 0 deletions
diff --git a/src/libsyntax_pos/hygiene.rs b/src/libsyntax_pos/hygiene.rs index 62a2d93a52e..213993996a6 100644 --- a/src/libsyntax_pos/hygiene.rs +++ b/src/libsyntax_pos/hygiene.rs @@ -508,6 +508,14 @@ impl SyntaxContext { HygieneData::with(|data| data.adjust(self, expansion)) } + /// Like `SyntaxContext::adjust`, but also modernizes `self`. + pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> { + HygieneData::with(|data| { + *self = data.modern(*self); + data.adjust(self, expansion) + }) + } + /// Adjust this context for resolution in a scope created by the given expansion /// via a glob import with the given `SyntaxContext`. /// For example: diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 9bab95efd1b..24aa82184ce 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -535,6 +535,14 @@ impl Span { } #[inline] + pub fn modernize_and_adjust(&mut self, expansion: Mark) -> Option<Mark> { + let mut span = self.data(); + let mark = span.ctxt.modernize_and_adjust(expansion); + *self = Span::new(span.lo, span.hi, span.ctxt); + mark + } + + #[inline] pub fn glob_adjust(&mut self, expansion: Mark, glob_span: Span) -> Option<Option<Mark>> { let mut span = self.data(); let mark = span.ctxt.glob_adjust(expansion, glob_span); |
