Skip to content

Commit 0b5795f

Browse files
committed
proc_macro: Move subspan to be a method on Span in the bridge
This method is still only used for Literal::subspan, however the implementation only depends on the Span component, so it is simpler and more efficient for now to pass down only the information that is needed. In the future, if more information about the Literal is required in the implementation (e.g. to validate that spans line up as expected with source text), that extra information can be added back with extra arguments.
1 parent efd7542 commit 0b5795f

File tree

2 files changed

+2
-7
lines changed

2 files changed

+2
-7
lines changed

proc_macro/src/bridge/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ macro_rules! with_api {
5757
fn track_env_var(var: &str, value: Option<&str>);
5858
fn track_path(path: &str);
5959
fn literal_from_str(s: &str) -> Result<Literal<$S::Span, $S::Symbol>, ()>;
60-
fn literal_subspan(lit: Literal<$S::Span, $S::Symbol>, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
6160
},
6261
TokenStream {
6362
fn drop($self: $S::TokenStream);
@@ -114,6 +113,7 @@ macro_rules! with_api {
114113
fn before($self: $S::Span) -> $S::Span;
115114
fn after($self: $S::Span) -> $S::Span;
116115
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
116+
fn subspan($self: $S::Span, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
117117
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
118118
fn source_text($self: $S::Span) -> Option<String>;
119119
fn save_span($self: $S::Span) -> usize;

proc_macro/src/lib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,12 +1379,7 @@ impl Literal {
13791379
// was 'c' or whether it was '\u{63}'.
13801380
#[unstable(feature = "proc_macro_span", issue = "54725")]
13811381
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
1382-
bridge::client::FreeFunctions::literal_subspan(
1383-
self.0.clone(),
1384-
range.start_bound().cloned(),
1385-
range.end_bound().cloned(),
1386-
)
1387-
.map(Span)
1382+
self.0.span.subspan(range.start_bound().cloned(), range.end_bound().cloned()).map(Span)
13881383
}
13891384

13901385
fn with_symbol_and_suffix<R>(&self, f: impl FnOnce(&str, &str) -> R) -> R {

0 commit comments

Comments
 (0)