Skip to content

Commit 30d9502

Browse files
committedMay 15, 2018
Add missing error codes in libsyntax-ext asm
1 parent cb1ce7d commit 30d9502

File tree

8 files changed

+146
-3
lines changed

8 files changed

+146
-3
lines changed
 

‎src/libsyntax_ext/asm.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,11 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
179179
let (constraint, _str_style) = panictry!(p.parse_str());
180180

181181
if constraint.as_str().starts_with("=") {
182-
cx.span_err(p.prev_span, "input operand constraint contains '='");
182+
span_err_if_not_stage0!(cx, p.prev_span, E0662,
183+
"input operand constraint contains '='");
183184
} else if constraint.as_str().starts_with("+") {
184-
cx.span_err(p.prev_span, "input operand constraint contains '+'");
185+
span_err_if_not_stage0!(cx, p.prev_span, E0663,
186+
"input operand constraint contains '+'");
185187
}
186188

187189
panictry!(p.expect(&token::OpenDelim(token::Paren)));
@@ -203,7 +205,8 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt,
203205
if OPTIONS.iter().any(|&opt| s == opt) {
204206
cx.span_warn(p.prev_span, "expected a clobber, found an option");
205207
} else if s.as_str().starts_with("{") || s.as_str().ends_with("}") {
206-
cx.span_err(p.prev_span, "clobber should not be surrounded by braces");
208+
span_err_if_not_stage0!(cx, p.prev_span, E0664,
209+
"clobber should not be surrounded by braces");
207210
}
208211

209212
clobs.push(s);

‎src/libsyntax_ext/diagnostics.rs

+52
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,58 @@ let a;
3838
asm!("nop" : "r"(a));
3939
```
4040
41+
Considering that this would be a long explanation, we instead recommend you to
42+
take a look at the unstable book:
43+
https://doc.rust-lang.org/unstable-book/language-features/asm.html
44+
"##,
45+
46+
E0662: r##"
47+
An invalid input operand constraint was passed to the `asm` macro (third line).
48+
49+
Erroneous code example:
50+
51+
```compile_fail,E0662
52+
asm!("xor %eax, %eax"
53+
:
54+
: "=test"("a")
55+
);
56+
```
57+
58+
Considering that this would be a long explanation, we instead recommend you to
59+
take a look at the unstable book:
60+
https://doc.rust-lang.org/unstable-book/language-features/asm.html
61+
"##,
62+
63+
E0663: r##"
64+
An invalid input operand constraint was passed to the `asm` macro (third line).
65+
66+
Erroneous code example:
67+
68+
```compile_fail,E0663
69+
asm!("xor %eax, %eax"
70+
:
71+
: "+test"("a")
72+
);
73+
```
74+
75+
Considering that this would be a long explanation, we instead recommend you to
76+
take a look at the unstable book:
77+
https://doc.rust-lang.org/unstable-book/language-features/asm.html
78+
"##,
79+
80+
E0664: r##"
81+
A clobber was surrounded by braces in the `asm` macro.
82+
83+
Erroneous code example:
84+
85+
```compile_fail,E0663
86+
asm!("mov $$0x200, %eax"
87+
:
88+
:
89+
: "{eax}"
90+
);
91+
```
92+
4193
Considering that this would be a long explanation, we instead recommend you to
4294
take a look at the unstable book:
4395
https://doc.rust-lang.org/unstable-book/language-features/asm.html

‎src/test/ui/E0662.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-stage1
12+
13+
#![feature(asm)]
14+
15+
fn main() {
16+
asm!("xor %eax, %eax"
17+
:
18+
: "=test"("a") //~ ERROR E0662
19+
);
20+
}

‎src/test/ui/E0662.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0662]: input operand constraint contains '='
2+
--> $DIR/E0662.rs:18:12
3+
|
4+
LL | : "=test"("a") //~ ERROR E0662
5+
| ^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0662`.

‎src/test/ui/E0663.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-stage1
12+
13+
#![feature(asm)]
14+
15+
fn main() {
16+
asm!("xor %eax, %eax"
17+
:
18+
: "+test"("a") //~ ERROR E0663
19+
);
20+
}

‎src/test/ui/E0663.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0663]: input operand constraint contains '+'
2+
--> $DIR/E0663.rs:18:12
3+
|
4+
LL | : "+test"("a") //~ ERROR E0663
5+
| ^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0663`.

‎src/test/ui/E0664.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// ignore-stage1
12+
13+
#![feature(asm)]
14+
15+
fn main() {
16+
asm!("mov $$0x200, %eax"
17+
:
18+
:
19+
: "{eax}" //~ ERROR E0664
20+
);
21+
}

‎src/test/ui/E0664.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0664]: clobber should not be surrounded by braces
2+
--> $DIR/E0664.rs:19:12
3+
|
4+
LL | : "{eax}" //~ ERROR E0664
5+
| ^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0664`.

0 commit comments

Comments
 (0)
Please sign in to comment.