@@ -329,6 +329,7 @@ impl Ident {
329
329
sess.symbol_gallery.insert(sym, span);
330
330
Ident { sym, is_raw, span }
331
331
}
332
+
332
333
fn dollar_crate(span: Span) -> Ident {
333
334
// `$crate` is accepted as an ident only if it comes from the compiler.
334
335
Ident { sym: kw::DollarCrate, is_raw: false, span }
@@ -403,6 +404,7 @@ impl server::TokenStream for Rustc<'_, '_> {
403
404
fn is_empty(&mut self, stream: &Self::TokenStream) -> bool {
404
405
stream.is_empty()
405
406
}
407
+
406
408
fn from_str(&mut self, src: &str) -> Self::TokenStream {
407
409
parse_stream_from_source_str(
408
410
FileName::proc_macro_source_code(src),
@@ -411,9 +413,11 @@ impl server::TokenStream for Rustc<'_, '_> {
411
413
Some(self.call_site),
412
414
)
413
415
}
416
+
414
417
fn to_string(&mut self, stream: &Self::TokenStream) -> String {
415
418
pprust::tts_to_string(stream)
416
419
}
420
+
417
421
fn expand_expr(&mut self, stream: &Self::TokenStream) -> Result<Self::TokenStream, ()> {
418
422
// Parse the expression from our tokenstream.
419
423
let expr: PResult<'_, _> = try {
@@ -464,12 +468,14 @@ impl server::TokenStream for Rustc<'_, '_> {
464
468
_ => Err(()),
465
469
}
466
470
}
471
+
467
472
fn from_token_tree(
468
473
&mut self,
469
474
tree: TokenTree<Self::Group, Self::Punct, Self::Ident, Self::Literal>,
470
475
) -> Self::TokenStream {
471
476
tree.to_internal()
472
477
}
478
+
473
479
fn concat_trees(
474
480
&mut self,
475
481
base: Option<Self::TokenStream>,
@@ -484,6 +490,7 @@ impl server::TokenStream for Rustc<'_, '_> {
484
490
}
485
491
builder.build()
486
492
}
493
+
487
494
fn concat_streams(
488
495
&mut self,
489
496
base: Option<Self::TokenStream>,
@@ -498,6 +505,7 @@ impl server::TokenStream for Rustc<'_, '_> {
498
505
}
499
506
builder.build()
500
507
}
508
+
501
509
fn into_trees(
502
510
&mut self,
503
511
stream: Self::TokenStream,
@@ -543,21 +551,27 @@ impl server::Group for Rustc<'_, '_> {
543
551
flatten: false,
544
552
}
545
553
}
554
+
546
555
fn delimiter(&mut self, group: &Self::Group) -> Delimiter {
547
556
group.delimiter
548
557
}
558
+
549
559
fn stream(&mut self, group: &Self::Group) -> Self::TokenStream {
550
560
group.stream.clone()
551
561
}
562
+
552
563
fn span(&mut self, group: &Self::Group) -> Self::Span {
553
564
group.span.entire()
554
565
}
566
+
555
567
fn span_open(&mut self, group: &Self::Group) -> Self::Span {
556
568
group.span.open
557
569
}
570
+
558
571
fn span_close(&mut self, group: &Self::Group) -> Self::Span {
559
572
group.span.close
560
573
}
574
+
561
575
fn set_span(&mut self, group: &mut Self::Group, span: Self::Span) {
562
576
group.span = DelimSpan::from_single(span);
563
577
}
@@ -567,15 +581,19 @@ impl server::Punct for Rustc<'_, '_> {
567
581
fn new(&mut self, ch: char, spacing: Spacing) -> Self::Punct {
568
582
Punct::new(ch, spacing == Spacing::Joint, server::Span::call_site(self))
569
583
}
584
+
570
585
fn as_char(&mut self, punct: Self::Punct) -> char {
571
586
punct.ch
572
587
}
588
+
573
589
fn spacing(&mut self, punct: Self::Punct) -> Spacing {
574
590
if punct.joint { Spacing::Joint } else { Spacing::Alone }
575
591
}
592
+
576
593
fn span(&mut self, punct: Self::Punct) -> Self::Span {
577
594
punct.span
578
595
}
596
+
579
597
fn with_span(&mut self, punct: Self::Punct, span: Self::Span) -> Self::Punct {
580
598
Punct { span, ..punct }
581
599
}
@@ -585,9 +603,11 @@ impl server::Ident for Rustc<'_, '_> {
585
603
fn new(&mut self, string: &str, span: Self::Span, is_raw: bool) -> Self::Ident {
586
604
Ident::new(self.sess(), Symbol::intern(string), is_raw, span)
587
605
}
606
+
588
607
fn span(&mut self, ident: Self::Ident) -> Self::Span {
589
608
ident.span
590
609
}
610
+
591
611
fn with_span(&mut self, ident: Self::Ident, span: Self::Span) -> Self::Ident {
592
612
Ident { span, ..ident }
593
613
}
@@ -639,45 +659,57 @@ impl server::Literal for Rustc<'_, '_> {
639
659
640
660
Ok(Literal { lit, span: self.call_site })
641
661
}
662
+
642
663
fn to_string(&mut self, literal: &Self::Literal) -> String {
643
664
literal.lit.to_string()
644
665
}
666
+
645
667
fn debug_kind(&mut self, literal: &Self::Literal) -> String {
646
668
format!("{:?}", literal.lit.kind)
647
669
}
670
+
648
671
fn symbol(&mut self, literal: &Self::Literal) -> String {
649
672
literal.lit.symbol.to_string()
650
673
}
674
+
651
675
fn suffix(&mut self, literal: &Self::Literal) -> Option<String> {
652
676
literal.lit.suffix.as_ref().map(Symbol::to_string)
653
677
}
678
+
654
679
fn integer(&mut self, n: &str) -> Self::Literal {
655
680
self.lit(token::Integer, Symbol::intern(n), None)
656
681
}
682
+
657
683
fn typed_integer(&mut self, n: &str, kind: &str) -> Self::Literal {
658
684
self.lit(token::Integer, Symbol::intern(n), Some(Symbol::intern(kind)))
659
685
}
686
+
660
687
fn float(&mut self, n: &str) -> Self::Literal {
661
688
self.lit(token::Float, Symbol::intern(n), None)
662
689
}
690
+
663
691
fn f32(&mut self, n: &str) -> Self::Literal {
664
692
self.lit(token::Float, Symbol::intern(n), Some(sym::f32))
665
693
}
694
+
666
695
fn f64(&mut self, n: &str) -> Self::Literal {
667
696
self.lit(token::Float, Symbol::intern(n), Some(sym::f64))
668
697
}
698
+
669
699
fn string(&mut self, string: &str) -> Self::Literal {
670
700
let quoted = format!("{:?}", string);
671
701
assert!(quoted.starts_with('"') && quoted.ends_with('"'));
672
702
let symbol = "ed[1..quoted.len() - 1];
673
703
self.lit(token::Str, Symbol::intern(symbol), None)
674
704
}
705
+
675
706
fn character(&mut self, ch: char) -> Self::Literal {
676
707
let quoted = format!("{:?}", ch);
677
708
assert!(quoted.starts_with('\'') && quoted.ends_with('\''));
678
709
let symbol = "ed[1..quoted.len() - 1];
679
710
self.lit(token::Char, Symbol::intern(symbol), None)
680
711
}
712
+
681
713
fn byte_string(&mut self, bytes: &[u8]) -> Self::Literal {
682
714
let string = bytes
683
715
.iter()
@@ -687,12 +719,15 @@ impl server::Literal for Rustc<'_, '_> {
687
719
.collect::<String>();
688
720
self.lit(token::ByteStr, Symbol::intern(&string), None)
689
721
}
722
+
690
723
fn span(&mut self, literal: &Self::Literal) -> Self::Span {
691
724
literal.span
692
725
}
726
+
693
727
fn set_span(&mut self, literal: &mut Self::Literal, span: Self::Span) {
694
728
literal.span = span;
695
729
}
730
+
696
731
fn subspan(
697
732
&mut self,
698
733
literal: &Self::Literal,
@@ -735,6 +770,7 @@ impl server::SourceFile for Rustc<'_, '_> {
735
770
fn eq(&mut self, file1: &Self::SourceFile, file2: &Self::SourceFile) -> bool {
736
771
Lrc::ptr_eq(file1, file2)
737
772
}
773
+
738
774
fn path(&mut self, file: &Self::SourceFile) -> String {
739
775
match file.name {
740
776
FileName::Real(ref name) => name
@@ -746,6 +782,7 @@ impl server::SourceFile for Rustc<'_, '_> {
746
782
_ => file.name.prefer_local().to_string(),
747
783
}
748
784
}
785
+
749
786
fn is_real(&mut self, file: &Self::SourceFile) -> bool {
750
787
file.is_real_file()
751
788
}
@@ -755,6 +792,7 @@ impl server::MultiSpan for Rustc<'_, '_> {
755
792
fn new(&mut self) -> Self::MultiSpan {
756
793
vec![]
757
794
}
795
+
758
796
fn push(&mut self, spans: &mut Self::MultiSpan, span: Self::Span) {
759
797
spans.push(span)
760
798
}
@@ -766,6 +804,7 @@ impl server::Diagnostic for Rustc<'_, '_> {
766
804
diag.set_span(MultiSpan::from_spans(spans));
767
805
diag
768
806
}
807
+
769
808
fn sub(
770
809
&mut self,
771
810
diag: &mut Self::Diagnostic,
@@ -775,6 +814,7 @@ impl server::Diagnostic for Rustc<'_, '_> {
775
814
) {
776
815
diag.sub(level.to_internal(), msg, MultiSpan::from_spans(spans), None);
777
816
}
817
+
778
818
fn emit(&mut self, mut diag: Self::Diagnostic) {
779
819
self.sess().span_diagnostic.emit_diagnostic(&mut diag);
780
820
}
@@ -788,38 +828,49 @@ impl server::Span for Rustc<'_, '_> {
788
828
format!("{:?} bytes({}..{})", span.ctxt(), span.lo().0, span.hi().0)
789
829
}
790
830
}
831
+
791
832
fn def_site(&mut self) -> Self::Span {
792
833
self.def_site
793
834
}
835
+
794
836
fn call_site(&mut self) -> Self::Span {
795
837
self.call_site
796
838
}
839
+
797
840
fn mixed_site(&mut self) -> Self::Span {
798
841
self.mixed_site
799
842
}
843
+
800
844
fn source_file(&mut self, span: Self::Span) -> Self::SourceFile {
801
845
self.sess().source_map().lookup_char_pos(span.lo()).file
802
846
}
847
+
803
848
fn parent(&mut self, span: Self::Span) -> Option<Self::Span> {
804
849
span.parent_callsite()
805
850
}
851
+
806
852
fn source(&mut self, span: Self::Span) -> Self::Span {
807
853
span.source_callsite()
808
854
}
855
+
809
856
fn start(&mut self, span: Self::Span) -> LineColumn {
810
857
let loc = self.sess().source_map().lookup_char_pos(span.lo());
811
858
LineColumn { line: loc.line, column: loc.col.to_usize() }
812
859
}
860
+
813
861
fn end(&mut self, span: Self::Span) -> LineColumn {
814
862
let loc = self.sess().source_map().lookup_char_pos(span.hi());
815
863
LineColumn { line: loc.line, column: loc.col.to_usize() }
816
864
}
865
+
817
866
fn before(&mut self, span: Self::Span) -> Self::Span {
818
867
span.shrink_to_lo()
819
868
}
869
+
820
870
fn after(&mut self, span: Self::Span) -> Self::Span {
821
871
span.shrink_to_hi()
822
872
}
873
+
823
874
fn join(&mut self, first: Self::Span, second: Self::Span) -> Option<Self::Span> {
824
875
let self_loc = self.sess().source_map().lookup_char_pos(first.lo());
825
876
let other_loc = self.sess().source_map().lookup_char_pos(second.lo());
@@ -830,9 +881,11 @@ impl server::Span for Rustc<'_, '_> {
830
881
831
882
Some(first.to(second))
832
883
}
884
+
833
885
fn resolved_at(&mut self, span: Self::Span, at: Self::Span) -> Self::Span {
834
886
span.with_ctxt(at.ctxt())
835
887
}
888
+
836
889
fn source_text(&mut self, span: Self::Span) -> Option<String> {
837
890
self.sess().source_map().span_to_snippet(span).ok()
838
891
}
@@ -863,6 +916,7 @@ impl server::Span for Rustc<'_, '_> {
863
916
fn save_span(&mut self, span: Self::Span) -> usize {
864
917
self.sess().save_proc_macro_span(span)
865
918
}
919
+
866
920
fn recover_proc_macro_span(&mut self, id: usize) -> Self::Span {
867
921
let (resolver, krate, def_site) = (&*self.ecx.resolver, self.krate, self.def_site);
868
922
*self.rebased_spans.entry(id).or_insert_with(|| {
0 commit comments