diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-06-28 18:28:46 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-28 18:28:46 +0530 |
| commit | fa56e01b357e67713cc44e1095b05b6103f9337a (patch) | |
| tree | 82c5a0c93d3c896c315f0ed2716911d124bbc13e /compiler/rustc_expand/src | |
| parent | 8882507bc7dbad0cc0548204eb8777e51ac92332 (diff) | |
| parent | 61590752a295d0cd2b69f6cb4d0d68fbfe739eb8 (diff) | |
| download | rust-fa56e01b357e67713cc44e1095b05b6103f9337a.tar.gz rust-fa56e01b357e67713cc44e1095b05b6103f9337a.zip | |
Rollup merge of #111571 - jhpratt:proc-macro-span, r=m-ou-se
Implement proposed API for `proc_macro_span` As proposed in [#54725 (comment)](https://github.com/rust-lang/rust/issues/54725#issuecomment-1546918161). I have omitted the byte-level API as it's already available as [`Span::byte_range`](https://doc.rust-lang.org/nightly/proc_macro/struct.Span.html#method.byte_range). `@rustbot` label +A-proc-macros r? `@m-ou-se`
Diffstat (limited to 'compiler/rustc_expand/src')
| -rw-r--r-- | compiler/rustc_expand/src/proc_macro_server.rs | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 891e84a2f30..ecd2315112a 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -2,7 +2,7 @@ use crate::base::ExtCtxt; use pm::bridge::{ server, DelimSpan, Diagnostic, ExpnGlobals, Group, Ident, LitKind, Literal, Punct, TokenTree, }; -use pm::{Delimiter, Level, LineColumn}; +use pm::{Delimiter, Level}; use rustc_ast as ast; use rustc_ast::token; use rustc_ast::tokenstream::{self, Spacing::*, TokenStream}; @@ -648,23 +648,22 @@ impl server::Span for Rustc<'_, '_> { Range { start: relative_start_pos.0 as usize, end: relative_end_pos.0 as usize } } - - fn start(&mut self, span: Self::Span) -> LineColumn { - let loc = self.sess().source_map().lookup_char_pos(span.lo()); - LineColumn { line: loc.line, column: loc.col.to_usize() } + fn start(&mut self, span: Self::Span) -> Self::Span { + span.shrink_to_lo() } - fn end(&mut self, span: Self::Span) -> LineColumn { - let loc = self.sess().source_map().lookup_char_pos(span.hi()); - LineColumn { line: loc.line, column: loc.col.to_usize() } + fn end(&mut self, span: Self::Span) -> Self::Span { + span.shrink_to_hi() } - fn before(&mut self, span: Self::Span) -> Self::Span { - span.shrink_to_lo() + fn line(&mut self, span: Self::Span) -> usize { + let loc = self.sess().source_map().lookup_char_pos(span.lo()); + loc.line } - fn after(&mut self, span: Self::Span) -> Self::Span { - span.shrink_to_hi() + fn column(&mut self, span: Self::Span) -> usize { + let loc = self.sess().source_map().lookup_char_pos(span.lo()); + loc.col.to_usize() + 1 } fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> { |
