Skip to content

Added byte position range for proc_macro::Span #109002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Renamed to byte_range and changed Range generics [skip ci]
  • Loading branch information
michaelvanstraten committed Mar 11, 2023
commit c67ae04acae514ba9a3ce04fde12d1bb23cf5ca1
4 changes: 2 additions & 2 deletions compiler/rustc_expand/src/proc_macro_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,8 +634,8 @@ impl server::Span for Rustc<'_, '_> {
span.source_callsite()
}

fn position(&mut self, span: Self::Span) -> Range<u32> {
Range { start: span.lo().0, end: span.hi().0 }
fn byte_range(&mut self, span: Self::Span) -> Range<usize> {
Range { start: span.lo().0 as usize, end: span.hi().0 as usize }
}

fn start(&mut self, span: Self::Span) -> LineColumn {
Expand Down
3 changes: 1 addition & 2 deletions library/proc_macro/src/bridge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ macro_rules! with_api {
fn source_file($self: $S::Span) -> $S::SourceFile;
fn parent($self: $S::Span) -> Option<$S::Span>;
fn source($self: $S::Span) -> $S::Span;
fn position($self: $S::Span) -> Range<u32>;
fn byte_range($self: $S::Span) -> Range<usize>;
fn start($self: $S::Span) -> LineColumn;
fn end($self: $S::Span) -> LineColumn;
fn before($self: $S::Span) -> $S::Span;
Expand Down Expand Up @@ -295,7 +295,6 @@ mark_noop! {
&'_ str,
String,
u8,
u32,
usize,
Delimiter,
LitKind,
Expand Down
4 changes: 2 additions & 2 deletions library/proc_macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,8 +490,8 @@ impl Span {

/// Returns the span's byte position range in the source file.
#[unstable(feature = "proc_macro_span", issue = "54725")]
pub fn position(&self) -> Range<u32> {
self.0.position()
pub fn byte_range(&self) -> Range<usize> {
self.0.byte_range()
}

/// Gets the starting line/column in the source file for this span.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ impl server::Span for RustAnalyzer {
// FIXME handle span
span
}
fn position(&mut self, _span: Self::Span) -> Range<u32> {
fn byte_range(&mut self, _span: Self::Span) -> Range<usize> {
// FIXME handle span
Range { start: 0, end: 0 }
}
Expand Down