Skip to content

Commit 8e7bbc9

Browse files
committed
Handle leading colons properly
1 parent 6f45f62 commit 8e7bbc9

File tree

3 files changed

+46
-33
lines changed

3 files changed

+46
-33
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,9 @@ fn expand_preparsed_asm(
511511
// If we encounter a non-label, there cannot be any further labels, so stop checking
512512
break;
513513
}
514+
} else {
515+
// Empty string means a leading ':' in this section, which is not a label
516+
break;
514517
}
515518

516519
start_idx = idx + 1;

src/test/ui/asm/named_asm_labels.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
// only-x86_64
2+
13
#![feature(asm, global_asm)]
24

5+
#[no_mangle]
6+
pub static FOO: usize = 42;
7+
38
fn main() {
49
unsafe {
510
// Basic usage
@@ -104,6 +109,11 @@ fn main() {
104109
"
105110
);
106111
//~^^^^ ERROR do not use named labels
112+
113+
// Tests usage of colons in non-label positions
114+
asm!(":lo12:FOO"); // this is apparently valid aarch64
115+
// is there an example that is valid x86 for this test?
116+
asm!(":bbb nop");
107117
}
108118
}
109119

src/test/ui/asm/named_asm_labels.stderr

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: do not use named labels in inline assembly
2-
--> $DIR/named_asm_labels.rs:6:15
2+
--> $DIR/named_asm_labels.rs:11:15
33
|
44
LL | asm!("bar: nop");
55
| ^^^
@@ -9,7 +9,7 @@ LL | asm!("bar: nop");
99
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
1010

1111
error: do not use named labels in inline assembly
12-
--> $DIR/named_asm_labels.rs:9:15
12+
--> $DIR/named_asm_labels.rs:14:15
1313
|
1414
LL | asm!("abcd:");
1515
| ^^^^
@@ -18,7 +18,7 @@ LL | asm!("abcd:");
1818
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
1919

2020
error: do not use named labels in inline assembly
21-
--> $DIR/named_asm_labels.rs:12:15
21+
--> $DIR/named_asm_labels.rs:17:15
2222
|
2323
LL | asm!("foo: bar1: nop");
2424
| ^^^
@@ -27,7 +27,7 @@ LL | asm!("foo: bar1: nop");
2727
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
2828

2929
error: do not use named labels in inline assembly
30-
--> $DIR/named_asm_labels.rs:12:20
30+
--> $DIR/named_asm_labels.rs:17:20
3131
|
3232
LL | asm!("foo: bar1: nop");
3333
| ^^^^
@@ -36,7 +36,7 @@ LL | asm!("foo: bar1: nop");
3636
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
3737

3838
error: do not use named labels in inline assembly
39-
--> $DIR/named_asm_labels.rs:17:15
39+
--> $DIR/named_asm_labels.rs:22:15
4040
|
4141
LL | asm!("foo1: nop", "nop");
4242
| ^^^^
@@ -45,7 +45,7 @@ LL | asm!("foo1: nop", "nop");
4545
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
4646

4747
error: do not use named labels in inline assembly
48-
--> $DIR/named_asm_labels.rs:18:15
48+
--> $DIR/named_asm_labels.rs:23:15
4949
|
5050
LL | asm!("foo2: foo3: nop", "nop");
5151
| ^^^^
@@ -54,7 +54,7 @@ LL | asm!("foo2: foo3: nop", "nop");
5454
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
5555

5656
error: do not use named labels in inline assembly
57-
--> $DIR/named_asm_labels.rs:18:21
57+
--> $DIR/named_asm_labels.rs:23:21
5858
|
5959
LL | asm!("foo2: foo3: nop", "nop");
6060
| ^^^^
@@ -63,7 +63,7 @@ LL | asm!("foo2: foo3: nop", "nop");
6363
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
6464

6565
error: do not use named labels in inline assembly
66-
--> $DIR/named_asm_labels.rs:21:22
66+
--> $DIR/named_asm_labels.rs:26:22
6767
|
6868
LL | asm!("nop", "foo4: nop");
6969
| ^^^^
@@ -72,7 +72,7 @@ LL | asm!("nop", "foo4: nop");
7272
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
7373

7474
error: do not use named labels in inline assembly
75-
--> $DIR/named_asm_labels.rs:22:15
75+
--> $DIR/named_asm_labels.rs:27:15
7676
|
7777
LL | asm!("foo5: nop", "foo6: nop");
7878
| ^^^^
@@ -81,7 +81,7 @@ LL | asm!("foo5: nop", "foo6: nop");
8181
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
8282

8383
error: do not use named labels in inline assembly
84-
--> $DIR/named_asm_labels.rs:22:28
84+
--> $DIR/named_asm_labels.rs:27:28
8585
|
8686
LL | asm!("foo5: nop", "foo6: nop");
8787
| ^^^^
@@ -90,7 +90,7 @@ LL | asm!("foo5: nop", "foo6: nop");
9090
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
9191

9292
error: do not use named labels in inline assembly
93-
--> $DIR/named_asm_labels.rs:27:15
93+
--> $DIR/named_asm_labels.rs:32:15
9494
|
9595
LL | asm!("foo7: nop; foo8: nop");
9696
| ^^^^
@@ -99,7 +99,7 @@ LL | asm!("foo7: nop; foo8: nop");
9999
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
100100

101101
error: do not use named labels in inline assembly
102-
--> $DIR/named_asm_labels.rs:27:26
102+
--> $DIR/named_asm_labels.rs:32:26
103103
|
104104
LL | asm!("foo7: nop; foo8: nop");
105105
| ^^^^
@@ -108,7 +108,7 @@ LL | asm!("foo7: nop; foo8: nop");
108108
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
109109

110110
error: do not use named labels in inline assembly
111-
--> $DIR/named_asm_labels.rs:30:15
111+
--> $DIR/named_asm_labels.rs:35:15
112112
|
113113
LL | asm!("foo9: nop; nop");
114114
| ^^^^
@@ -117,7 +117,7 @@ LL | asm!("foo9: nop; nop");
117117
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
118118

119119
error: do not use named labels in inline assembly
120-
--> $DIR/named_asm_labels.rs:31:20
120+
--> $DIR/named_asm_labels.rs:36:20
121121
|
122122
LL | asm!("nop; foo10: nop");
123123
| ^^^^^
@@ -126,7 +126,7 @@ LL | asm!("nop; foo10: nop");
126126
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
127127

128128
error: do not use named labels in inline assembly
129-
--> $DIR/named_asm_labels.rs:34:15
129+
--> $DIR/named_asm_labels.rs:39:15
130130
|
131131
LL | asm!("bar2: nop\n bar3: nop");
132132
| ^^^^
@@ -135,7 +135,7 @@ LL | asm!("bar2: nop\n bar3: nop");
135135
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
136136

137137
error: do not use named labels in inline assembly
138-
--> $DIR/named_asm_labels.rs:34:27
138+
--> $DIR/named_asm_labels.rs:39:27
139139
|
140140
LL | asm!("bar2: nop\n bar3: nop");
141141
| ^^^^
@@ -144,7 +144,7 @@ LL | asm!("bar2: nop\n bar3: nop");
144144
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
145145

146146
error: do not use named labels in inline assembly
147-
--> $DIR/named_asm_labels.rs:37:15
147+
--> $DIR/named_asm_labels.rs:42:15
148148
|
149149
LL | asm!("bar4: nop\n nop");
150150
| ^^^^
@@ -153,7 +153,7 @@ LL | asm!("bar4: nop\n nop");
153153
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
154154

155155
error: do not use named labels in inline assembly
156-
--> $DIR/named_asm_labels.rs:38:21
156+
--> $DIR/named_asm_labels.rs:43:21
157157
|
158158
LL | asm!("nop\n bar5: nop");
159159
| ^^^^
@@ -162,7 +162,7 @@ LL | asm!("nop\n bar5: nop");
162162
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
163163

164164
error: do not use named labels in inline assembly
165-
--> $DIR/named_asm_labels.rs:39:21
165+
--> $DIR/named_asm_labels.rs:44:21
166166
|
167167
LL | asm!("nop\n bar6: bar7: nop");
168168
| ^^^^
@@ -171,7 +171,7 @@ LL | asm!("nop\n bar6: bar7: nop");
171171
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
172172

173173
error: do not use named labels in inline assembly
174-
--> $DIR/named_asm_labels.rs:39:27
174+
--> $DIR/named_asm_labels.rs:44:27
175175
|
176176
LL | asm!("nop\n bar6: bar7: nop");
177177
| ^^^^
@@ -180,7 +180,7 @@ LL | asm!("nop\n bar6: bar7: nop");
180180
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
181181

182182
error: do not use named labels in inline assembly
183-
--> $DIR/named_asm_labels.rs:46:13
183+
--> $DIR/named_asm_labels.rs:51:13
184184
|
185185
LL | blah2: nop
186186
| ^^^^^
@@ -189,7 +189,7 @@ LL | blah2: nop
189189
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
190190

191191
error: do not use named labels in inline assembly
192-
--> $DIR/named_asm_labels.rs:47:13
192+
--> $DIR/named_asm_labels.rs:52:13
193193
|
194194
LL | blah3: nop
195195
| ^^^^^
@@ -198,7 +198,7 @@ LL | blah3: nop
198198
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
199199

200200
error: do not use named labels in inline assembly
201-
--> $DIR/named_asm_labels.rs:55:19
201+
--> $DIR/named_asm_labels.rs:60:19
202202
|
203203
LL | nop ; blah4: nop
204204
| ^^^^^
@@ -207,7 +207,7 @@ LL | nop ; blah4: nop
207207
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
208208

209209
error: do not use named labels in inline assembly
210-
--> $DIR/named_asm_labels.rs:69:15
210+
--> $DIR/named_asm_labels.rs:74:15
211211
|
212212
LL | asm!("blah1: 2bar: nop");
213213
| ^^^^^
@@ -216,7 +216,7 @@ LL | asm!("blah1: 2bar: nop");
216216
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
217217

218218
error: do not use named labels in inline assembly
219-
--> $DIR/named_asm_labels.rs:72:15
219+
--> $DIR/named_asm_labels.rs:77:15
220220
|
221221
LL | asm!("def: def: nop");
222222
| ^^^
@@ -225,7 +225,7 @@ LL | asm!("def: def: nop");
225225
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
226226

227227
error: do not use named labels in inline assembly
228-
--> $DIR/named_asm_labels.rs:73:15
228+
--> $DIR/named_asm_labels.rs:78:15
229229
|
230230
LL | asm!("def: nop\ndef: nop");
231231
| ^^^
@@ -234,7 +234,7 @@ LL | asm!("def: nop\ndef: nop");
234234
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
235235

236236
error: do not use named labels in inline assembly
237-
--> $DIR/named_asm_labels.rs:74:15
237+
--> $DIR/named_asm_labels.rs:79:15
238238
|
239239
LL | asm!("def: nop; def: nop");
240240
| ^^^
@@ -243,7 +243,7 @@ LL | asm!("def: nop; def: nop");
243243
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
244244

245245
error: do not use named labels in inline assembly
246-
--> $DIR/named_asm_labels.rs:82:15
246+
--> $DIR/named_asm_labels.rs:87:15
247247
|
248248
LL | asm!("fooo\u{003A} nop");
249249
| ^^^^^^^^^^^^^^^^
@@ -252,7 +252,7 @@ LL | asm!("fooo\u{003A} nop");
252252
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
253253

254254
error: do not use named labels in inline assembly
255-
--> $DIR/named_asm_labels.rs:83:15
255+
--> $DIR/named_asm_labels.rs:88:15
256256
|
257257
LL | asm!("foooo\x3A nop");
258258
| ^^^^^^^^^^^^^
@@ -261,7 +261,7 @@ LL | asm!("foooo\x3A nop");
261261
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
262262

263263
error: do not use named labels in inline assembly
264-
--> $DIR/named_asm_labels.rs:86:15
264+
--> $DIR/named_asm_labels.rs:91:15
265265
|
266266
LL | asm!("fooooo:\u{000A} nop");
267267
| ^^^^^^
@@ -270,7 +270,7 @@ LL | asm!("fooooo:\u{000A} nop");
270270
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
271271

272272
error: do not use named labels in inline assembly
273-
--> $DIR/named_asm_labels.rs:87:15
273+
--> $DIR/named_asm_labels.rs:92:15
274274
|
275275
LL | asm!("foooooo:\x0A nop");
276276
| ^^^^^^^
@@ -279,7 +279,7 @@ LL | asm!("foooooo:\x0A nop");
279279
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
280280

281281
error: do not use named labels in inline assembly
282-
--> $DIR/named_asm_labels.rs:91:14
282+
--> $DIR/named_asm_labels.rs:96:14
283283
|
284284
LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
285285
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -288,7 +288,7 @@ LL | asm!("\x41\x42\x43\x3A\x20\x6E\x6F\x70");
288288
= note: See the asm section of the unstable book <https://doc.rust-lang.org/nightly/unstable-book/library-features/asm.html#labels> for more information
289289

290290
error: do not use named labels in inline assembly
291-
--> $DIR/named_asm_labels.rs:102:13
291+
--> $DIR/named_asm_labels.rs:107:13
292292
|
293293
LL | ab: nop // ab: does foo
294294
| ^^

0 commit comments

Comments
 (0)