Skip to content

Commit 2539c15

Browse files
authored
Auto merge of #34637 - GuillaumeGomez:syntax_codes, r=jonathandturner
Syntax codes r? @jonathandturner cc @steveklabnik This is a first big shot. I'll do the second one later in the week once this one is merged.
2 parents 3265bd5 + b777f14 commit 2539c15

File tree

4 files changed

+146
-12
lines changed

4 files changed

+146
-12
lines changed

src/libsyntax/attr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ pub fn find_export_name_attr(diag: &Handler, attrs: &[Attribute]) -> Option<Inte
324324
if let s@Some(_) = attr.value_str() {
325325
s
326326
} else {
327-
struct_span_err!(diag, attr.span, E0533,
327+
struct_span_err!(diag, attr.span, E0558,
328328
"export_name attribute has invalid format")
329329
.help("use #[export_name=\"*\"]")
330330
.emit();
@@ -373,7 +373,7 @@ pub fn find_inline_attr(diagnostic: Option<&Handler>, attrs: &[Attribute]) -> In
373373
InlineAttr::None
374374
}
375375
}
376-
_ => ia
376+
_ => ia,
377377
}
378378
})
379379
}

src/libsyntax/diagnostic_list.rs

+141-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
22
// file at the top-level directory of this distribution and at
33
// http://rust-lang.org/COPYRIGHT.
44
//
@@ -15,9 +15,146 @@
1515
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
1616
register_long_diagnostics! {
1717

18-
E0533: r##"
19-
```compile_fail,E0533
20-
#[export_name]
18+
E0534: r##"
19+
The `inline` attribute was malformed.
20+
21+
Erroneous code example:
22+
23+
```compile_fail,E0534
24+
#[inline()] // error: expected one argument
25+
pub fn something() {}
26+
27+
fn main() {}
28+
```
29+
30+
The parenthesized `inline` attribute requires the parameter to be specified:
31+
32+
```ignore
33+
#[inline(always)]
34+
fn something() {}
35+
36+
// or:
37+
38+
#[inline(never)]
39+
fn something() {}
40+
```
41+
42+
Alternatively, a paren-less version of the attribute may be used to hint the
43+
compiler about inlining opportunity:
44+
45+
```
46+
#[inline]
47+
fn something() {}
48+
```
49+
50+
For more information about the inline attribute, read:
51+
https://doc.rust-lang.org/reference.html#inline-attributes
52+
"##,
53+
54+
E0535: r##"
55+
An unknown argument was given to the `inline` attribute.
56+
57+
Erroneous code example:
58+
59+
```compile_fail,E0535
60+
#[inline(unknown)] // error: invalid argument
61+
pub fn something() {}
62+
63+
fn main() {}
64+
```
65+
66+
The `inline` attribute only supports two arguments:
67+
68+
* always
69+
* never
70+
71+
All other arguments given to the `inline` attribute will return this error.
72+
Example:
73+
74+
```
75+
#[inline(never)] // ok!
76+
pub fn something() {}
77+
78+
fn main() {}
79+
```
80+
81+
For more information about the inline attribute, https:
82+
read://doc.rust-lang.org/reference.html#inline-attributes
83+
"##,
84+
85+
E0536: r##"
86+
The `not` cfg-predicate was malformed.
87+
88+
Erroneous code example:
89+
90+
```compile_fail,E0536
91+
#[cfg(not())] // error: expected 1 cfg-pattern
92+
pub fn something() {}
93+
94+
pub fn main() {}
95+
```
96+
97+
The `not` predicate expects one cfg-pattern. Example:
98+
99+
```
100+
#[cfg(not(target_os = "linux"))] // ok!
101+
pub fn something() {}
102+
103+
pub fn main() {}
104+
```
105+
106+
For more information about the cfg attribute, read:
107+
https://doc.rust-lang.org/reference.html#conditional-compilation
108+
"##,
109+
110+
E0537: r##"
111+
An unknown predicate was used inside the `cfg` attribute.
112+
113+
Erroneous code example:
114+
115+
```compile_fail,E0537
116+
#[cfg(unknown())] // error: invalid predicate `unknown`
117+
pub fn something() {}
118+
119+
pub fn main() {}
120+
```
121+
122+
The `cfg` attribute supports only three kinds of predicates:
123+
124+
* any
125+
* all
126+
* not
127+
128+
Example:
129+
130+
```
131+
#[cfg(not(target_os = "linux"))] // ok!
132+
pub fn something() {}
133+
134+
pub fn main() {}
135+
```
136+
137+
For more information about the cfg attribute, read:
138+
https://doc.rust-lang.org/reference.html#conditional-compilation
139+
"##,
140+
141+
E0558: r##"
142+
The `export_name` attribute was malformed.
143+
144+
Erroneous code example:
145+
146+
```compile_fail,E0558
147+
#[export_name] // error: export_name attribute has invalid format
148+
pub fn something() {}
149+
150+
fn main() {}
151+
```
152+
153+
The `export_name` attribute expects a string in order to determine the name of
154+
the exported symbol. Example:
155+
156+
```
157+
#[export_name = "some_function"] // ok!
21158
pub fn something() {}
22159
23160
fn main() {}
@@ -27,10 +164,6 @@ fn main() {}
27164
}
28165

29166
register_diagnostics! {
30-
E0534, // expected one argument
31-
E0535, // invalid argument
32-
E0536, // expected 1 cfg-pattern
33-
E0537, // invalid predicate
34167
E0538, // multiple [same] items
35168
E0539, // incorrect meta item
36169
E0540, // multiple rustc_deprecated attributes

src/tools/tidy/src/errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub fn check(path: &Path, bad: &mut bool) {
2525
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
2626
&mut |file| {
2727
let filename = file.file_name().unwrap().to_string_lossy();
28-
if filename != "diagnostics.rs" {
28+
if filename != "diagnostics.rs" && filename != "diagnostic_list.rs" {
2929
return
3030
}
3131

src/tools/tidy/src/features.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ pub fn check(path: &Path, bad: &mut bool) {
4646
&mut |path| super::filter_dirs(path) || path.ends_with("src/test"),
4747
&mut |file| {
4848
let filename = file.file_name().unwrap().to_string_lossy();
49-
if !filename.ends_with(".rs") || filename == "features.rs" {
49+
if !filename.ends_with(".rs") || filename == "features.rs" ||
50+
filename == "diagnostic_list.rs" {
5051
return
5152
}
5253

0 commit comments

Comments
 (0)