diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-08-28 12:41:29 +0300 |
|---|---|---|
| committer | Matthew Jasper <mjjasper1@gmail.com> | 2019-09-05 15:07:17 +0100 |
| commit | c8cf9f5a025bb475804b5a90f54aca310b952526 (patch) | |
| tree | 1c456dab13065396aa1ee1ac79a9574143b82663 /src/libsyntax_pos/lib.rs | |
| parent | 0b86782058c27ba694ec81ebe7108dceb0968a2b (diff) | |
| download | rust-c8cf9f5a025bb475804b5a90f54aca310b952526.tar.gz rust-c8cf9f5a025bb475804b5a90f54aca310b952526.zip | |
Add `with_{def_site,call_site,legacy}_ctxt,` methods to `Span`
Use these to create call-site spans for AST passes when needed.
Diffstat (limited to 'src/libsyntax_pos/lib.rs')
| -rw-r--r-- | src/libsyntax_pos/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index d800109cf85..9a296f17aaf 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -514,6 +514,25 @@ impl Span { span.ctxt) } + /// Equivalent of `Span::def_site` from the proc macro API, + /// except that the location is taken from the `self` span. + pub fn with_def_site_ctxt(self, expn_id: ExpnId) -> Span { + self.with_ctxt_from_mark(expn_id, Transparency::Opaque) + } + + /// Equivalent of `Span::call_site` from the proc macro API, + /// except that the location is taken from the `self` span. + pub fn with_call_site_ctxt(&self, expn_id: ExpnId) -> Span { + self.with_ctxt_from_mark(expn_id, Transparency::Transparent) + } + + /// Span with a context reproducing `macro_rules` hygiene (hygienic locals, unhygienic items). + /// FIXME: This should be eventually replaced either with `with_def_site_ctxt` (preferably), + /// or with `with_call_site_ctxt` (where necessary). + pub fn with_legacy_ctxt(&self, expn_id: ExpnId) -> Span { + self.with_ctxt_from_mark(expn_id, Transparency::SemiTransparent) + } + /// Produces a span with the same location as `self` and context produced by a macro with the /// given ID and transparency, assuming that macro was defined directly and not produced by /// some other macro (which is the case for built-in and procedural macros). |
