@@ -12,51 +12,51 @@ use syntax::ast;
1212use syntax:: ext:: base;
1313use syntax:: ext:: build:: AstBuilder ;
1414use syntax:: symbol:: Symbol ;
15- use syntax_pos;
1615use syntax:: tokenstream;
16+ use syntax_pos;
1717
1818use std:: string:: String ;
1919
20- pub fn expand_syntax_ext ( cx : & mut base:: ExtCtxt ,
21- sp : syntax_pos:: Span ,
22- tts : & [ tokenstream:: TokenTree ] )
23- -> Box < base:: MacResult + ' static > {
20+ pub fn expand_syntax_ext (
21+ cx : & mut base:: ExtCtxt ,
22+ sp : syntax_pos:: Span ,
23+ tts : & [ tokenstream:: TokenTree ] ,
24+ ) -> Box < base:: MacResult + ' static > {
2425 let es = match base:: get_exprs_from_tts ( cx, sp, tts) {
2526 Some ( e) => e,
2627 None => return base:: DummyResult :: expr ( sp) ,
2728 } ;
2829 let mut accumulator = String :: new ( ) ;
2930 for e in es {
3031 match e. node {
31- ast:: ExprKind :: Lit ( ref lit) => {
32- match lit. node {
33- ast:: LitKind :: Str ( ref s, _) |
34- ast:: LitKind :: Float ( ref s, _) |
35- ast:: LitKind :: FloatUnsuffixed ( ref s) => {
36- accumulator. push_str ( & s. as_str ( ) ) ;
37- }
38- ast:: LitKind :: Char ( c) => {
39- accumulator. push ( c) ;
40- }
41- ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsigned ( _) ) |
42- ast:: LitKind :: Int ( i, ast:: LitIntType :: Signed ( _) ) |
43- ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsuffixed ) => {
44- accumulator. push_str ( & format ! ( "{}" , i) ) ;
45- }
46- ast:: LitKind :: Bool ( b) => {
47- accumulator. push_str ( & format ! ( "{}" , b) ) ;
48- }
49- ast:: LitKind :: Byte ( ..) |
50- ast:: LitKind :: ByteStr ( ..) => {
51- cx. span_err ( e. span , "cannot concatenate a byte string literal" ) ;
52- }
32+ ast:: ExprKind :: Lit ( ref lit) => match lit. node {
33+ ast:: LitKind :: Str ( ref s, _)
34+ | ast:: LitKind :: Float ( ref s, _)
35+ | ast:: LitKind :: FloatUnsuffixed ( ref s) => {
36+ accumulator. push_str ( & s. as_str ( ) ) ;
5337 }
54- }
38+ ast:: LitKind :: Char ( c) => {
39+ accumulator. push ( c) ;
40+ }
41+ ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsigned ( _) )
42+ | ast:: LitKind :: Int ( i, ast:: LitIntType :: Signed ( _) )
43+ | ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsuffixed ) => {
44+ accumulator. push_str ( & format ! ( "{}" , i) ) ;
45+ }
46+ ast:: LitKind :: Bool ( b) => {
47+ accumulator. push_str ( & format ! ( "{}" , b) ) ;
48+ }
49+ ast:: LitKind :: Byte ( ..) | ast:: LitKind :: ByteStr ( ..) => {
50+ cx. span_err ( e. span , "cannot concatenate a byte string literal" ) ;
51+ }
52+ } ,
5553 _ => {
5654 let mut err = cx. struct_span_err ( e. span , "expected a literal" ) ;
57- err. span_help (
55+ let snippet = cx. codemap ( ) . span_to_snippet ( e. span ) . unwrap ( ) ;
56+ err. span_suggestion (
5857 e. span ,
5958 "you might be missing a string literal to format with" ,
59+ format ! ( "\" {{}}\" , {}" , snippet) ,
6060 ) ;
6161 err. emit ( ) ;
6262 }
0 commit comments