Skip to content

Commit 342f07a

Browse files
committed
Add a test for concat_bytes! with C strings
Also ensure the suggestions are checked, since this will be updated.
1 parent 044514e commit 342f07a

File tree

2 files changed

+83
-29
lines changed

2 files changed

+83
-29
lines changed

tests/ui/macros/concat-bytes-error.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,43 @@
1+
//@ edition: 2021
2+
// 2021 edition for C string literals
3+
14
#![feature(concat_bytes)]
25

36
fn main() {
7+
// Identifiers
48
concat_bytes!(pie); //~ ERROR expected a byte literal
59
concat_bytes!(pie, pie); //~ ERROR expected a byte literal
10+
11+
// String literals
612
concat_bytes!("tnrsi", "tnri"); //~ ERROR cannot concatenate string literals
13+
//~^ SUGGESTION b"tnrsi"
14+
concat_bytes!(r"tnrsi", r"tnri"); //~ ERROR cannot concatenate string literals
15+
//~^ SUGGESTION br"tnrsi"
16+
concat_bytes!(r#"tnrsi"#, r###"tnri"###); //~ ERROR cannot concatenate string literals
17+
//~^ SUGGESTION br#"tnrsi"#
18+
concat_bytes!(c"tnrsi", c"tnri"); //~ ERROR cannot concatenate a C string literal
19+
concat_bytes!(cr"tnrsi", cr"tnri"); //~ ERROR cannot concatenate a C string literal
20+
concat_bytes!(cr#"tnrsi"#, cr###"tnri"###); //~ ERROR cannot concatenate a C string literal
21+
22+
// Other literals
723
concat_bytes!(2.8); //~ ERROR cannot concatenate float literals
824
concat_bytes!(300); //~ ERROR cannot concatenate numeric literals
25+
//~^ SUGGESTION [300]
926
concat_bytes!('a'); //~ ERROR cannot concatenate character literals
27+
//~^ SUGGESTION b'a'
1028
concat_bytes!(true, false); //~ ERROR cannot concatenate boolean literals
1129
concat_bytes!(42, b"va", b'l'); //~ ERROR cannot concatenate numeric literals
30+
//~^ SUGGESTION [42]
1231
concat_bytes!(42, b"va", b'l', [1, 2]); //~ ERROR cannot concatenate numeric literals
32+
//~^ SUGGESTION [42]
33+
34+
// Nested items
1335
concat_bytes!([
1436
"hi", //~ ERROR cannot concatenate string literals
1537
]);
1638
concat_bytes!([
1739
'a', //~ ERROR cannot concatenate character literals
40+
//~^ SUGGESTION b'a'
1841
]);
1942
concat_bytes!([
2043
true, //~ ERROR cannot concatenate boolean literals
@@ -38,6 +61,7 @@ fn main() {
3861
[5, 6, 7], //~ ERROR cannot concatenate doubly nested array
3962
]);
4063
concat_bytes!(5u16); //~ ERROR cannot concatenate numeric literals
64+
//~^ SUGGESTION [5u16]
4165
concat_bytes!([5u16]); //~ ERROR numeric literal is not a `u8`
4266
concat_bytes!([3; ()]); //~ ERROR repeat count is not a positive number
4367
concat_bytes!([3; -2]); //~ ERROR repeat count is not a positive number
Lines changed: 59 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,137 @@
11
error: expected a byte literal
2-
--> $DIR/concat-bytes-error.rs:4:19
2+
--> $DIR/concat-bytes-error.rs:8:19
33
|
44
LL | concat_bytes!(pie);
55
| ^^^
66
|
77
= note: only byte literals (like `b"foo"`, `b's'` and `[3, 4, 5]`) can be passed to `concat_bytes!()`
88

99
error: expected a byte literal
10-
--> $DIR/concat-bytes-error.rs:5:19
10+
--> $DIR/concat-bytes-error.rs:9:19
1111
|
1212
LL | concat_bytes!(pie, pie);
1313
| ^^^ ^^^
1414
|
1515
= note: only byte literals (like `b"foo"`, `b's'` and `[3, 4, 5]`) can be passed to `concat_bytes!()`
1616

1717
error: cannot concatenate string literals
18-
--> $DIR/concat-bytes-error.rs:6:19
18+
--> $DIR/concat-bytes-error.rs:12:19
1919
|
2020
LL | concat_bytes!("tnrsi", "tnri");
2121
| ^^^^^^^ help: try using a byte string: `b"tnrsi"`
2222

23+
error: cannot concatenate string literals
24+
--> $DIR/concat-bytes-error.rs:14:19
25+
|
26+
LL | concat_bytes!(r"tnrsi", r"tnri");
27+
| ^^^^^^^^ help: try using a byte string: `br"tnrsi"`
28+
29+
error: cannot concatenate string literals
30+
--> $DIR/concat-bytes-error.rs:16:19
31+
|
32+
LL | concat_bytes!(r#"tnrsi"#, r###"tnri"###);
33+
| ^^^^^^^^^^ help: try using a byte string: `br#"tnrsi"#`
34+
35+
error: cannot concatenate a C string literal
36+
--> $DIR/concat-bytes-error.rs:18:19
37+
|
38+
LL | concat_bytes!(c"tnrsi", c"tnri");
39+
| ^^^^^^^^
40+
41+
error: cannot concatenate a C string literal
42+
--> $DIR/concat-bytes-error.rs:19:19
43+
|
44+
LL | concat_bytes!(cr"tnrsi", cr"tnri");
45+
| ^^^^^^^^^
46+
47+
error: cannot concatenate a C string literal
48+
--> $DIR/concat-bytes-error.rs:20:19
49+
|
50+
LL | concat_bytes!(cr#"tnrsi"#, cr###"tnri"###);
51+
| ^^^^^^^^^^^
52+
2353
error: cannot concatenate float literals
24-
--> $DIR/concat-bytes-error.rs:7:19
54+
--> $DIR/concat-bytes-error.rs:23:19
2555
|
2656
LL | concat_bytes!(2.8);
2757
| ^^^
2858

2959
error: cannot concatenate numeric literals
30-
--> $DIR/concat-bytes-error.rs:8:19
60+
--> $DIR/concat-bytes-error.rs:24:19
3161
|
3262
LL | concat_bytes!(300);
3363
| ^^^ help: try wrapping the number in an array: `[300]`
3464

3565
error: cannot concatenate character literals
36-
--> $DIR/concat-bytes-error.rs:9:19
66+
--> $DIR/concat-bytes-error.rs:26:19
3767
|
3868
LL | concat_bytes!('a');
3969
| ^^^ help: try using a byte character: `b'a'`
4070

4171
error: cannot concatenate boolean literals
42-
--> $DIR/concat-bytes-error.rs:10:19
72+
--> $DIR/concat-bytes-error.rs:28:19
4373
|
4474
LL | concat_bytes!(true, false);
4575
| ^^^^
4676

4777
error: cannot concatenate numeric literals
48-
--> $DIR/concat-bytes-error.rs:11:19
78+
--> $DIR/concat-bytes-error.rs:29:19
4979
|
5080
LL | concat_bytes!(42, b"va", b'l');
5181
| ^^ help: try wrapping the number in an array: `[42]`
5282

5383
error: cannot concatenate numeric literals
54-
--> $DIR/concat-bytes-error.rs:12:19
84+
--> $DIR/concat-bytes-error.rs:31:19
5585
|
5686
LL | concat_bytes!(42, b"va", b'l', [1, 2]);
5787
| ^^ help: try wrapping the number in an array: `[42]`
5888

5989
error: cannot concatenate string literals
60-
--> $DIR/concat-bytes-error.rs:14:9
90+
--> $DIR/concat-bytes-error.rs:36:9
6191
|
6292
LL | "hi",
6393
| ^^^^
6494

6595
error: cannot concatenate character literals
66-
--> $DIR/concat-bytes-error.rs:17:9
96+
--> $DIR/concat-bytes-error.rs:39:9
6797
|
6898
LL | 'a',
6999
| ^^^ help: try using a byte character: `b'a'`
70100

71101
error: cannot concatenate boolean literals
72-
--> $DIR/concat-bytes-error.rs:20:9
102+
--> $DIR/concat-bytes-error.rs:43:9
73103
|
74104
LL | true,
75105
| ^^^^
76106

77107
error: cannot concatenate boolean literals
78-
--> $DIR/concat-bytes-error.rs:23:9
108+
--> $DIR/concat-bytes-error.rs:46:9
79109
|
80110
LL | false,
81111
| ^^^^^
82112

83113
error: cannot concatenate float literals
84-
--> $DIR/concat-bytes-error.rs:26:9
114+
--> $DIR/concat-bytes-error.rs:49:9
85115
|
86116
LL | 2.6,
87117
| ^^^
88118

89119
error: numeric literal is out of bounds
90-
--> $DIR/concat-bytes-error.rs:29:9
120+
--> $DIR/concat-bytes-error.rs:52:9
91121
|
92122
LL | 265,
93123
| ^^^
94124

95125
error: expected a byte literal
96-
--> $DIR/concat-bytes-error.rs:32:9
126+
--> $DIR/concat-bytes-error.rs:55:9
97127
|
98128
LL | -33,
99129
| ^^^
100130
|
101131
= note: only byte literals (like `b"foo"`, `b's'` and `[3, 4, 5]`) can be passed to `concat_bytes!()`
102132

103133
error: cannot concatenate doubly nested array
104-
--> $DIR/concat-bytes-error.rs:35:9
134+
--> $DIR/concat-bytes-error.rs:58:9
105135
|
106136
LL | b"hi!",
107137
| ^^^^^^
@@ -110,72 +140,72 @@ LL | b"hi!",
110140
= help: try flattening the array
111141

112142
error: cannot concatenate doubly nested array
113-
--> $DIR/concat-bytes-error.rs:38:9
143+
--> $DIR/concat-bytes-error.rs:61:9
114144
|
115145
LL | [5, 6, 7],
116146
| ^^^^^^^^^
117147

118148
error: cannot concatenate numeric literals
119-
--> $DIR/concat-bytes-error.rs:40:19
149+
--> $DIR/concat-bytes-error.rs:63:19
120150
|
121151
LL | concat_bytes!(5u16);
122152
| ^^^^ help: try wrapping the number in an array: `[5u16]`
123153

124154
error: numeric literal is not a `u8`
125-
--> $DIR/concat-bytes-error.rs:41:20
155+
--> $DIR/concat-bytes-error.rs:65:20
126156
|
127157
LL | concat_bytes!([5u16]);
128158
| ^^^^
129159

130160
error: repeat count is not a positive number
131-
--> $DIR/concat-bytes-error.rs:42:23
161+
--> $DIR/concat-bytes-error.rs:66:23
132162
|
133163
LL | concat_bytes!([3; ()]);
134164
| ^^
135165

136166
error: repeat count is not a positive number
137-
--> $DIR/concat-bytes-error.rs:43:23
167+
--> $DIR/concat-bytes-error.rs:67:23
138168
|
139169
LL | concat_bytes!([3; -2]);
140170
| ^^
141171

142172
error: repeat count is not a positive number
143-
--> $DIR/concat-bytes-error.rs:44:25
173+
--> $DIR/concat-bytes-error.rs:68:25
144174
|
145175
LL | concat_bytes!([pie; -2]);
146176
| ^^
147177

148178
error: expected a byte literal
149-
--> $DIR/concat-bytes-error.rs:45:20
179+
--> $DIR/concat-bytes-error.rs:69:20
150180
|
151181
LL | concat_bytes!([pie; 2]);
152182
| ^^^
153183
|
154184
= note: only byte literals (like `b"foo"`, `b's'` and `[3, 4, 5]`) can be passed to `concat_bytes!()`
155185

156186
error: cannot concatenate float literals
157-
--> $DIR/concat-bytes-error.rs:46:20
187+
--> $DIR/concat-bytes-error.rs:70:20
158188
|
159189
LL | concat_bytes!([2.2; 0]);
160190
| ^^^
161191

162192
error: repeat count is not a positive number
163-
--> $DIR/concat-bytes-error.rs:47:25
193+
--> $DIR/concat-bytes-error.rs:71:25
164194
|
165195
LL | concat_bytes!([5.5; ()]);
166196
| ^^
167197

168198
error: cannot concatenate doubly nested array
169-
--> $DIR/concat-bytes-error.rs:48:20
199+
--> $DIR/concat-bytes-error.rs:72:20
170200
|
171201
LL | concat_bytes!([[1, 2, 3]; 3]);
172202
| ^^^^^^^^^
173203

174204
error: cannot concatenate doubly nested array
175-
--> $DIR/concat-bytes-error.rs:49:20
205+
--> $DIR/concat-bytes-error.rs:73:20
176206
|
177207
LL | concat_bytes!([[42; 2]; 3]);
178208
| ^^^^^^^
179209

180-
error: aborting due to 28 previous errors
210+
error: aborting due to 33 previous errors
181211

0 commit comments

Comments
 (0)