@@ -30,6 +30,9 @@ pub fn expand_syntax_ext(
30
30
let mut string_pos = vec ! [ ] ;
31
31
let mut b_accumulator: Vec < u8 > = vec ! [ ] ;
32
32
let mut b_pos: Vec < Span > = vec ! [ ] ;
33
+ // We don't support mixing things with byte str literals, but do a best effort to fill in a
34
+ // reasonable byte str output to avoid further errors down the line.
35
+ let mut unified_accumulator: Vec < u8 > = vec ! [ ] ;
33
36
let mut missing_literal = vec ! [ ] ;
34
37
for e in es {
35
38
match e. node {
@@ -39,28 +42,34 @@ pub fn expand_syntax_ext(
39
42
| ast:: LitKind :: FloatUnsuffixed ( ref s) => {
40
43
string_accumulator. push_str ( & s. as_str ( ) ) ;
41
44
string_pos. push ( e. span ) ;
45
+ unified_accumulator. extend ( s. to_string ( ) . into_bytes ( ) ) ;
42
46
}
43
47
ast:: LitKind :: Char ( c) => {
44
48
string_accumulator. push ( c) ;
45
49
string_pos. push ( e. span ) ;
50
+ unified_accumulator. extend ( c. to_string ( ) . into_bytes ( ) ) ;
46
51
}
47
52
ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsigned ( _) )
48
53
| ast:: LitKind :: Int ( i, ast:: LitIntType :: Signed ( _) )
49
54
| ast:: LitKind :: Int ( i, ast:: LitIntType :: Unsuffixed ) => {
50
55
string_accumulator. push_str ( & i. to_string ( ) ) ;
51
56
string_pos. push ( e. span ) ;
57
+ unified_accumulator. extend ( i. to_bytes ( ) . iter ( ) ) ;
52
58
}
53
59
ast:: LitKind :: Bool ( b) => {
54
60
string_accumulator. push_str ( & b. to_string ( ) ) ;
55
61
string_pos. push ( e. span ) ;
62
+ unified_accumulator. push ( b as u8 ) ;
56
63
}
57
64
ast:: LitKind :: Byte ( byte) => {
58
65
b_accumulator. push ( byte) ;
59
66
b_pos. push ( e. span ) ;
67
+ unified_accumulator. push ( byte) ;
60
68
}
61
69
ast:: LitKind :: ByteStr ( ref b_str) => {
62
70
b_accumulator. extend ( b_str. iter ( ) ) ;
63
71
b_pos. push ( e. span ) ;
72
+ unified_accumulator. extend ( b_str. iter ( ) ) ;
64
73
}
65
74
} ,
66
75
_ => {
@@ -73,7 +82,8 @@ pub fn expand_syntax_ext(
73
82
err. note ( "only literals (like `\" foo\" `, `42` and `3.14`) can be passed to `concat!()`" ) ;
74
83
err. emit ( ) ;
75
84
}
76
- // Do not allow mixing "" and b""
85
+ let sp = sp. apply_mark ( cx. current_expansion . mark ) ;
86
+ // Do not allow mixing "" and b"", but return the joint b"" to avoid further errors
77
87
if string_accumulator. len ( ) > 0 && b_accumulator. len ( ) > 0 {
78
88
let mut err = cx. struct_span_err (
79
89
b_pos. clone ( ) ,
@@ -95,9 +105,8 @@ pub fn expand_syntax_ext(
95
105
. collect ( ) ,
96
106
) ;
97
107
err. emit ( ) ;
98
- }
99
- let sp = sp. apply_mark ( cx. current_expansion . mark ) ;
100
- if b_accumulator. len ( ) > 0 {
108
+ base:: MacEager :: expr ( cx. expr_byte_str ( sp, unified_accumulator) )
109
+ } else if b_accumulator. len ( ) > 0 {
101
110
base:: MacEager :: expr ( cx. expr_byte_str ( sp, b_accumulator) )
102
111
} else {
103
112
base:: MacEager :: expr ( cx. expr_str ( sp, Symbol :: intern ( & string_accumulator) ) )
0 commit comments