Skip to content

Commit 00ada0f

Browse files
committed
Revert "Allow global_asm! in statement positions"
This reverts commit 450cdb5.
1 parent a06c1ca commit 00ada0f

6 files changed

Lines changed: 37 additions & 104 deletions

File tree

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_parse_format as parse;
1010
use rustc_session::lint;
1111
use rustc_span::{ErrorGuaranteed, InnerSpan, Span, Symbol, sym};
1212
use rustc_target::asm::InlineAsmArch;
13-
use smallvec::{SmallVec, smallvec};
13+
use smallvec::smallvec;
1414

1515
use crate::errors;
1616
use crate::util::{ExprToSpannedString, expr_to_spanned_string};
@@ -26,24 +26,6 @@ struct ValidatedAsmArgs {
2626
pub options_spans: Vec<Span>,
2727
}
2828

29-
struct MacGlobalAsm {
30-
item: ast::Item,
31-
}
32-
33-
impl MacResult for MacGlobalAsm {
34-
fn make_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::Item>; 1]>> {
35-
Some(smallvec![Box::new(self.item)])
36-
}
37-
38-
fn make_stmts(self: Box<Self>) -> Option<SmallVec<[ast::Stmt; 1]>> {
39-
Some(smallvec![ast::Stmt {
40-
id: ast::DUMMY_NODE_ID,
41-
span: self.item.span,
42-
kind: ast::StmtKind::Item(Box::new(self.item)),
43-
}])
44-
}
45-
}
46-
4729
fn parse_args<'a>(
4830
ecx: &ExtCtxt<'a>,
4931
sp: Span,
@@ -668,20 +650,18 @@ pub(super) fn expand_global_asm<'cx>(
668650
return ExpandResult::Retry(());
669651
};
670652
match mac {
671-
Ok(inline_asm) => Box::new(MacGlobalAsm {
672-
item: ast::Item {
673-
attrs: ast::AttrVec::new(),
674-
id: ast::DUMMY_NODE_ID,
675-
kind: ast::ItemKind::GlobalAsm(Box::new(inline_asm)),
676-
vis: ast::Visibility {
677-
span: sp.shrink_to_lo(),
678-
kind: ast::VisibilityKind::Inherited,
679-
tokens: None,
680-
},
681-
span: sp,
653+
Ok(inline_asm) => MacEager::items(smallvec![Box::new(ast::Item {
654+
attrs: ast::AttrVec::new(),
655+
id: ast::DUMMY_NODE_ID,
656+
kind: ast::ItemKind::GlobalAsm(Box::new(inline_asm)),
657+
vis: ast::Visibility {
658+
span: sp.shrink_to_lo(),
659+
kind: ast::VisibilityKind::Inherited,
682660
tokens: None,
683661
},
684-
}),
662+
span: sp,
663+
tokens: None,
664+
})]),
685665
Err(guar) => DummyResult::any(sp, guar),
686666
}
687667
}

tests/ui/asm/naked-functions.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,14 @@
66
#![feature(asm_unwind, linkage, rustc_attrs, cfg_target_object_format)]
77
#![crate_type = "lib"]
88

9-
use std::arch::{asm, global_asm, naked_asm};
9+
use std::arch::{asm, naked_asm};
1010

1111
#[unsafe(naked)]
1212
pub extern "C" fn inline_asm_macro() {
1313
unsafe { asm!("", options(raw)) };
1414
//~^ERROR the `asm!` macro is not allowed in naked functions
1515
}
1616

17-
#[unsafe(naked)]
18-
pub extern "C" fn global_asm_macro() {
19-
//~^ERROR naked functions must contain a single `naked_asm!` invocation
20-
global_asm!("");
21-
}
22-
2317
#[repr(C)]
2418
pub struct P {
2519
x: u8,
Lines changed: 25 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,71 @@
11
error: the `in` operand cannot be used with `naked_asm!`
2-
--> $DIR/naked-functions.rs:53:29
2+
--> $DIR/naked-functions.rs:47:29
33
|
44
LL | naked_asm!("/* {0} */", in(reg) a)
55
| ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
66

77
error: the `in` operand cannot be used with `naked_asm!`
8-
--> $DIR/naked-functions.rs:74:10
8+
--> $DIR/naked-functions.rs:68:10
99
|
1010
LL | in(reg) a,
1111
| ^^ the `in` operand is not meaningful for global-scoped inline assembly, remove it
1212

1313
error: the `noreturn` option cannot be used with `naked_asm!`
14-
--> $DIR/naked-functions.rs:94:28
14+
--> $DIR/naked-functions.rs:88:28
1515
|
1616
LL | naked_asm!("", options(noreturn));
1717
| ^^^^^^^^ the `noreturn` option is not meaningful for global-scoped inline assembly
1818

1919
error: the `nomem` option cannot be used with `naked_asm!`
20-
--> $DIR/naked-functions.rs:111:28
20+
--> $DIR/naked-functions.rs:105:28
2121
|
2222
LL | naked_asm!("", options(nomem, preserves_flags));
2323
| ^^^^^ the `nomem` option is not meaningful for global-scoped inline assembly
2424

2525
error: the `preserves_flags` option cannot be used with `naked_asm!`
26-
--> $DIR/naked-functions.rs:111:35
26+
--> $DIR/naked-functions.rs:105:35
2727
|
2828
LL | naked_asm!("", options(nomem, preserves_flags));
2929
| ^^^^^^^^^^^^^^^ the `preserves_flags` option is not meaningful for global-scoped inline assembly
3030

3131
error: the `readonly` option cannot be used with `naked_asm!`
32-
--> $DIR/naked-functions.rs:118:28
32+
--> $DIR/naked-functions.rs:112:28
3333
|
3434
LL | naked_asm!("", options(readonly, nostack), options(pure));
3535
| ^^^^^^^^ the `readonly` option is not meaningful for global-scoped inline assembly
3636

3737
error: the `nostack` option cannot be used with `naked_asm!`
38-
--> $DIR/naked-functions.rs:118:38
38+
--> $DIR/naked-functions.rs:112:38
3939
|
4040
LL | naked_asm!("", options(readonly, nostack), options(pure));
4141
| ^^^^^^^ the `nostack` option is not meaningful for global-scoped inline assembly
4242

4343
error: the `pure` option cannot be used with `naked_asm!`
44-
--> $DIR/naked-functions.rs:118:56
44+
--> $DIR/naked-functions.rs:112:56
4545
|
4646
LL | naked_asm!("", options(readonly, nostack), options(pure));
4747
| ^^^^ the `pure` option is not meaningful for global-scoped inline assembly
4848

4949
error: the `may_unwind` option cannot be used with `naked_asm!`
50-
--> $DIR/naked-functions.rs:126:28
50+
--> $DIR/naked-functions.rs:120:28
5151
|
5252
LL | naked_asm!("", options(may_unwind));
5353
| ^^^^^^^^^^ the `may_unwind` option is not meaningful for global-scoped inline assembly
5454

5555
error: this is a user specified error
56-
--> $DIR/naked-functions.rs:157:5
56+
--> $DIR/naked-functions.rs:151:5
5757
|
5858
LL | compile_error!("this is a user specified error")
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6060

6161
error: this is a user specified error
62-
--> $DIR/naked-functions.rs:163:5
62+
--> $DIR/naked-functions.rs:157:5
6363
|
6464
LL | compile_error!("this is a user specified error");
6565
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6666

6767
error: asm template must be a string literal
68-
--> $DIR/naked-functions.rs:170:16
68+
--> $DIR/naked-functions.rs:164:16
6969
|
7070
LL | naked_asm!(invalid_syntax)
7171
| ^^^^^^^^^^^^^^
@@ -76,46 +76,40 @@ error[E0787]: the `asm!` macro is not allowed in naked functions
7676
LL | unsafe { asm!("", options(raw)) };
7777
| ^^^^^^^^^^^^^^^^^^^^^^ consider using the `naked_asm!` macro instead
7878

79-
error[E0787]: naked functions must contain a single `naked_asm!` invocation
80-
--> $DIR/naked-functions.rs:18:1
81-
|
82-
LL | pub extern "C" fn global_asm_macro() {
83-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
84-
8579
error: patterns not allowed in naked function parameters
86-
--> $DIR/naked-functions.rs:31:5
80+
--> $DIR/naked-functions.rs:25:5
8781
|
8882
LL | mut a: u32,
8983
| ^^^^^
9084

9185
error: patterns not allowed in naked function parameters
92-
--> $DIR/naked-functions.rs:33:5
86+
--> $DIR/naked-functions.rs:27:5
9387
|
9488
LL | &b: &i32,
9589
| ^^
9690

9791
error: patterns not allowed in naked function parameters
98-
--> $DIR/naked-functions.rs:35:6
92+
--> $DIR/naked-functions.rs:29:6
9993
|
10094
LL | (None | Some(_)): Option<std::ptr::NonNull<u8>>,
10195
| ^^^^^^^^^^^^^^
10296

10397
error: patterns not allowed in naked function parameters
104-
--> $DIR/naked-functions.rs:37:5
98+
--> $DIR/naked-functions.rs:31:5
10599
|
106100
LL | P { x, y }: P,
107101
| ^^^^^^^^^^
108102

109103
error: referencing function parameters is not allowed in naked functions
110-
--> $DIR/naked-functions.rs:46:5
104+
--> $DIR/naked-functions.rs:40:5
111105
|
112106
LL | a + 1
113107
| ^
114108
|
115109
= help: follow the calling convention in asm block to use parameters
116110

117111
error[E0787]: naked functions must contain a single `naked_asm!` invocation
118-
--> $DIR/naked-functions.rs:44:1
112+
--> $DIR/naked-functions.rs:38:1
119113
|
120114
LL | pub extern "C" fn inc(a: u32) -> u32 {
121115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -124,7 +118,7 @@ LL | a + 1
124118
| ----- not allowed in naked functions
125119

126120
error[E0787]: naked functions must contain a single `naked_asm!` invocation
127-
--> $DIR/naked-functions.rs:58:1
121+
--> $DIR/naked-functions.rs:52:1
128122
|
129123
LL | pub extern "C" fn inc_closure(a: u32) -> u32 {
130124
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -133,7 +127,7 @@ LL | (|| a + 1)()
133127
| ------------ not allowed in naked functions
134128

135129
error[E0787]: naked functions must contain a single `naked_asm!` invocation
136-
--> $DIR/naked-functions.rs:64:1
130+
--> $DIR/naked-functions.rs:58:1
137131
|
138132
LL | pub extern "C" fn unsupported_operands() {
139133
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -150,13 +144,13 @@ LL | let mut e = 0usize;
150144
| ------------------- not allowed in naked functions
151145

152146
error[E0787]: naked functions must contain a single `naked_asm!` invocation
153-
--> $DIR/naked-functions.rs:86:1
147+
--> $DIR/naked-functions.rs:80:1
154148
|
155149
LL | pub extern "C" fn missing_assembly() {
156150
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
157151

158152
error[E0787]: naked functions must contain a single `naked_asm!` invocation
159-
--> $DIR/naked-functions.rs:91:1
153+
--> $DIR/naked-functions.rs:85:1
160154
|
161155
LL | pub extern "C" fn too_many_asm_blocks() {
162156
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -165,22 +159,22 @@ LL | naked_asm!("");
165159
| -------------- multiple `naked_asm!` invocations are not allowed in naked functions
166160

167161
error: referencing function parameters is not allowed in naked functions
168-
--> $DIR/naked-functions.rs:103:11
162+
--> $DIR/naked-functions.rs:97:11
169163
|
170164
LL | *&y
171165
| ^
172166
|
173167
= help: follow the calling convention in asm block to use parameters
174168

175169
error[E0787]: naked functions must contain a single `naked_asm!` invocation
176-
--> $DIR/naked-functions.rs:101:5
170+
--> $DIR/naked-functions.rs:95:5
177171
|
178172
LL | pub extern "C" fn inner(y: usize) -> usize {
179173
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
180174
LL |
181175
LL | *&y
182176
| --- not allowed in naked functions
183177

184-
error: aborting due to 26 previous errors
178+
error: aborting due to 25 previous errors
185179

186180
For more information about this error, try `rustc --explain E0787`.

tests/ui/asm/statement-global-asm-error.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.

tests/ui/asm/statement-global-asm-error.stderr

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/ui/asm/statement-global-asm.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)