10
10
11
11
use { ast, attr} ;
12
12
use syntax_pos:: { Span , DUMMY_SP } ;
13
+ use early_buffered_lints:: BufferedEarlyLintId ;
13
14
use edition:: Edition ;
14
15
use ext:: base:: { DummyResult , ExtCtxt , MacResult , SyntaxExtension } ;
15
16
use ext:: base:: { NormalTT , TTMacroExpander } ;
@@ -784,14 +785,23 @@ fn check_matcher_core(sess: &ParseSess,
784
785
match is_in_follow ( tok, & frag_spec. as_str ( ) ) {
785
786
IsInFollow :: Invalid ( ..) | IsInFollow :: Yes => { } // handled elsewhere
786
787
IsInFollow :: No ( possible) => {
787
- let tok_sp = tok. span ( ) ;
788
- let next = if * sp == tok_sp {
788
+ let token_span = tok. span ( ) ;
789
+ let next = if * sp == token_span {
789
790
"itself" . to_owned ( )
790
791
} else {
791
792
quoted_tt_to_string ( tok)
792
793
} ;
793
- let mut err = sess. span_diagnostic . struct_span_warn (
794
+ let sugg_span = sess. source_map ( ) . next_point ( delim_sp. close ) ;
795
+ sess. buffer_lint (
796
+ BufferedEarlyLintId :: IncorrectMacroFragmentRepetition {
797
+ span : * sp,
798
+ token_span : tok. span ( ) ,
799
+ sugg_span,
800
+ frag : frag_spec. to_string ( ) ,
801
+ possible : possible. into_iter ( ) . map ( String :: from) . collect ( ) ,
802
+ } ,
794
803
* sp,
804
+ ast:: CRATE_NODE_ID ,
795
805
& format ! (
796
806
"`${name}:{frag}` is followed (through repetition) by \
797
807
{next}, which is not allowed for `{frag}` fragments",
@@ -800,67 +810,6 @@ fn check_matcher_core(sess: &ParseSess,
800
810
next=next,
801
811
) ,
802
812
) ;
803
- if * sp == tok_sp {
804
- err. span_label (
805
- * sp,
806
- "this fragment is followed by itself without a valid \
807
- separator",
808
- ) ;
809
- } else {
810
- err. span_label (
811
- * sp,
812
- "this fragment is followed by the first fragment in this \
813
- repetition without a valid separator",
814
- ) ;
815
- err. span_label (
816
- tok_sp,
817
- "this is the first fragment in the evaluated repetition" ,
818
- ) ;
819
- }
820
- let sugg_span = sess. source_map ( ) . next_point ( delim_sp. close ) ;
821
- let msg = "allowed there are: " ;
822
- let sugg_msg =
823
- "add a valid separator for the repetition to be unambiguous" ;
824
- match & possible[ ..] {
825
- & [ ] => { }
826
- & [ t] => {
827
- err. note ( & format ! (
828
- "only {} is allowed after `{}` fragments" ,
829
- t,
830
- frag_spec,
831
- ) ) ;
832
- if t. starts_with ( '`' ) && t. ends_with ( '`' ) {
833
- err. span_suggestion_with_applicability (
834
- sugg_span,
835
- & format ! ( "{}, for example" , sugg_msg) ,
836
- ( & t[ 1 ..t. len ( ) -1 ] ) . to_owned ( ) ,
837
- Applicability :: MaybeIncorrect ,
838
- ) ;
839
- } else {
840
- err. note ( sugg_msg) ;
841
- }
842
- }
843
- ts => {
844
- err. note ( & format ! (
845
- "{}{} or {}" ,
846
- msg,
847
- ts[ ..ts. len( ) - 1 ] . iter( ) . map( |s| * s)
848
- . collect:: <Vec <_>>( ) . join( ", " ) ,
849
- ts[ ts. len( ) - 1 ] ,
850
- ) ) ;
851
- if ts[ 0 ] . starts_with ( '`' ) && ts[ 0 ] . ends_with ( '`' ) {
852
- err. span_suggestion_with_applicability (
853
- sugg_span,
854
- & format ! ( "{}, for example" , sugg_msg) ,
855
- ( & ts[ 0 ] [ 1 ..ts[ 0 ] . len ( ) -1 ] ) . to_owned ( ) ,
856
- Applicability :: MaybeIncorrect ,
857
- ) ;
858
- } else {
859
- err. note ( sugg_msg) ;
860
- }
861
- }
862
- }
863
- err. emit ( ) ;
864
813
}
865
814
}
866
815
}
0 commit comments