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.
This commit is contained in:
parent
b34c79f8f1
commit
c4acac6443
3 changed files with 38 additions and 44 deletions
|
@ -57,7 +57,6 @@ macro_rules! with_api {
|
|||
fn track_env_var(var: &str, value: Option<&str>);
|
||||
fn track_path(path: &str);
|
||||
fn literal_from_str(s: &str) -> Result<Literal<$S::Span, $S::Symbol>, ()>;
|
||||
fn literal_subspan(lit: Literal<$S::Span, $S::Symbol>, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
|
||||
},
|
||||
TokenStream {
|
||||
fn drop($self: $S::TokenStream);
|
||||
|
@ -114,6 +113,7 @@ macro_rules! with_api {
|
|||
fn before($self: $S::Span) -> $S::Span;
|
||||
fn after($self: $S::Span) -> $S::Span;
|
||||
fn join($self: $S::Span, other: $S::Span) -> Option<$S::Span>;
|
||||
fn subspan($self: $S::Span, start: Bound<usize>, end: Bound<usize>) -> Option<$S::Span>;
|
||||
fn resolved_at($self: $S::Span, at: $S::Span) -> $S::Span;
|
||||
fn source_text($self: $S::Span) -> Option<String>;
|
||||
fn save_span($self: $S::Span) -> usize;
|
||||
|
|
|
@ -1379,12 +1379,7 @@ impl Literal {
|
|||
// was 'c' or whether it was '\u{63}'.
|
||||
#[unstable(feature = "proc_macro_span", issue = "54725")]
|
||||
pub fn subspan<R: RangeBounds<usize>>(&self, range: R) -> Option<Span> {
|
||||
bridge::client::FreeFunctions::literal_subspan(
|
||||
self.0.clone(),
|
||||
range.start_bound().cloned(),
|
||||
range.end_bound().cloned(),
|
||||
)
|
||||
.map(Span)
|
||||
self.0.span.subspan(range.start_bound().cloned(), range.end_bound().cloned()).map(Span)
|
||||
}
|
||||
|
||||
fn with_symbol_and_suffix<R>(&self, f: impl FnOnce(&str, &str) -> R) -> R {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue