Skip to content

Commit 533ca58

Browse files
Merge #10378
10378: fix: Implement most proc_macro span handling methods r=jonas-schievink a=jonas-schievink This closes #10368 – some APIs are still missing, but they are either for unstable features or require #9403 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents afa9e31 + 577aedb commit 533ca58

File tree

1 file changed

+24
-25
lines changed

1 file changed

+24
-25
lines changed

crates/proc_macro_srv/src/abis/abi_1_56/rustc_server.rs

+24-25
Original file line numberDiff line numberDiff line change
@@ -424,19 +424,20 @@ impl server::Group for Rustc {
424424
group.delimiter.map(|it| it.id).unwrap_or_else(tt::TokenId::unspecified)
425425
}
426426

427-
fn set_span(&mut self, _group: &mut Self::Group, _span: Self::Span) {
428-
// FIXME handle span
427+
fn set_span(&mut self, group: &mut Self::Group, span: Self::Span) {
428+
if let Some(delim) = &mut group.delimiter {
429+
delim.id = span;
430+
}
429431
}
430432

431-
fn span_open(&mut self, _group: &Self::Group) -> Self::Span {
432-
// FIXME handle span
433-
// MySpan(self.span_interner.intern(&MySpanData(group.span_open())))
434-
tt::TokenId::unspecified()
433+
fn span_open(&mut self, group: &Self::Group) -> Self::Span {
434+
// FIXME we only store one `TokenId` for the delimiters
435+
group.delimiter.map(|it| it.id).unwrap_or_else(tt::TokenId::unspecified)
435436
}
436437

437-
fn span_close(&mut self, _group: &Self::Group) -> Self::Span {
438-
// FIXME handle span
439-
tt::TokenId::unspecified()
438+
fn span_close(&mut self, group: &Self::Group) -> Self::Span {
439+
// FIXME we only store one `TokenId` for the delimiters
440+
group.delimiter.map(|it| it.id).unwrap_or_else(tt::TokenId::unspecified)
440441
}
441442
}
442443

@@ -454,13 +455,11 @@ impl server::Punct for Rustc {
454455
fn spacing(&mut self, punct: Self::Punct) -> bridge::Spacing {
455456
spacing_to_external(punct.spacing)
456457
}
457-
fn span(&mut self, _punct: Self::Punct) -> Self::Span {
458-
// FIXME handle span
459-
tt::TokenId::unspecified()
458+
fn span(&mut self, punct: Self::Punct) -> Self::Span {
459+
punct.id
460460
}
461-
fn with_span(&mut self, punct: Self::Punct, _span: Self::Span) -> Self::Punct {
462-
// FIXME handle span
463-
punct
461+
fn with_span(&mut self, punct: Self::Punct, span: Self::Span) -> Self::Punct {
462+
tt::Punct { id: span, ..punct }
464463
}
465464
}
466465

@@ -474,13 +473,13 @@ impl server::Ident for Rustc {
474473
)
475474
}
476475

477-
fn span(&mut self, _ident: Self::Ident) -> Self::Span {
478-
// FIXME handle span
479-
tt::TokenId::unspecified()
476+
fn span(&mut self, ident: Self::Ident) -> Self::Span {
477+
self.ident_interner.get(ident.0).0.id
480478
}
481-
fn with_span(&mut self, ident: Self::Ident, _span: Self::Span) -> Self::Ident {
482-
// FIXME handle span
483-
ident
479+
fn with_span(&mut self, ident: Self::Ident, span: Self::Span) -> Self::Ident {
480+
let data = self.ident_interner.get(ident.0);
481+
let new = IdentData(tt::Ident { id: span, ..data.0.clone() });
482+
IdentId(self.ident_interner.intern(&new))
484483
}
485484
}
486485

@@ -500,8 +499,8 @@ impl server::Literal for Rustc {
500499
None
501500
}
502501

503-
fn to_string(&mut self, _literal: &Self::Literal) -> String {
504-
_literal.to_string()
502+
fn to_string(&mut self, literal: &Self::Literal) -> String {
503+
literal.to_string()
505504
}
506505

507506
fn integer(&mut self, n: &str) -> Self::Literal {
@@ -581,8 +580,8 @@ impl server::Literal for Rustc {
581580
literal.id
582581
}
583582

584-
fn set_span(&mut self, _literal: &mut Self::Literal, _span: Self::Span) {
585-
// FIXME handle span
583+
fn set_span(&mut self, literal: &mut Self::Literal, span: Self::Span) {
584+
literal.id = span;
586585
}
587586

588587
fn subspan(

0 commit comments

Comments
 (0)