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 errors:: FatalError ;
15
16
use ext:: base:: { DummyResult , ExtCtxt , MacResult , SyntaxExtension } ;
@@ -812,14 +813,23 @@ fn check_matcher_core(sess: &ParseSess,
812
813
match is_in_follow ( tok, & frag_spec. as_str ( ) ) {
813
814
IsInFollow :: Invalid ( ..) | IsInFollow :: Yes => { } // handled elsewhere
814
815
IsInFollow :: No ( possible) => {
815
- let tok_sp = tok. span ( ) ;
816
- let next = if * sp == tok_sp {
816
+ let token_span = tok. span ( ) ;
817
+ let next = if * sp == token_span {
817
818
"itself" . to_owned ( )
818
819
} else {
819
820
quoted_tt_to_string ( tok)
820
821
} ;
821
- let mut err = sess. span_diagnostic . struct_span_warn (
822
+ let sugg_span = sess. source_map ( ) . next_point ( delim_sp. close ) ;
823
+ sess. buffer_lint (
824
+ BufferedEarlyLintId :: IncorrectMacroFragmentRepetition {
825
+ span : * sp,
826
+ token_span : tok. span ( ) ,
827
+ sugg_span,
828
+ frag : frag_spec. to_string ( ) ,
829
+ possible : possible. into_iter ( ) . map ( String :: from) . collect ( ) ,
830
+ } ,
822
831
* sp,
832
+ ast:: CRATE_NODE_ID ,
823
833
& format ! (
824
834
"`${name}:{frag}` is followed (through repetition) by \
825
835
{next}, which is not allowed for `{frag}` fragments",
@@ -828,67 +838,6 @@ fn check_matcher_core(sess: &ParseSess,
828
838
next=next,
829
839
) ,
830
840
) ;
831
- if * sp == tok_sp {
832
- err. span_label (
833
- * sp,
834
- "this fragment is followed by itself without a valid \
835
- separator",
836
- ) ;
837
- } else {
838
- err. span_label (
839
- * sp,
840
- "this fragment is followed by the first fragment in this \
841
- repetition without a valid separator",
842
- ) ;
843
- err. span_label (
844
- tok_sp,
845
- "this is the first fragment in the evaluated repetition" ,
846
- ) ;
847
- }
848
- let sugg_span = sess. source_map ( ) . next_point ( delim_sp. close ) ;
849
- let msg = "allowed there are: " ;
850
- let sugg_msg =
851
- "add a valid separator for the repetition to be unambiguous" ;
852
- match & possible[ ..] {
853
- & [ ] => { }
854
- & [ t] => {
855
- err. note ( & format ! (
856
- "only {} is allowed after `{}` fragments" ,
857
- t,
858
- frag_spec,
859
- ) ) ;
860
- if t. starts_with ( '`' ) && t. ends_with ( '`' ) {
861
- err. span_suggestion_with_applicability (
862
- sugg_span,
863
- & format ! ( "{}, for example" , sugg_msg) ,
864
- ( & t[ 1 ..t. len ( ) -1 ] ) . to_owned ( ) ,
865
- Applicability :: MaybeIncorrect ,
866
- ) ;
867
- } else {
868
- err. note ( sugg_msg) ;
869
- }
870
- }
871
- ts => {
872
- err. note ( & format ! (
873
- "{}{} or {}" ,
874
- msg,
875
- ts[ ..ts. len( ) - 1 ] . iter( ) . map( |s| * s)
876
- . collect:: <Vec <_>>( ) . join( ", " ) ,
877
- ts[ ts. len( ) - 1 ] ,
878
- ) ) ;
879
- if ts[ 0 ] . starts_with ( '`' ) && ts[ 0 ] . ends_with ( '`' ) {
880
- err. span_suggestion_with_applicability (
881
- sugg_span,
882
- & format ! ( "{}, for example" , sugg_msg) ,
883
- ( & ts[ 0 ] [ 1 ..ts[ 0 ] . len ( ) -1 ] ) . to_owned ( ) ,
884
- Applicability :: MaybeIncorrect ,
885
- ) ;
886
- } else {
887
- err. note ( sugg_msg) ;
888
- }
889
- }
890
- }
891
- err. emit ( ) ;
892
841
}
893
842
}
894
843
}
0 commit comments