diff options
| author | bors <bors@rust-lang.org> | 2019-11-14 14:11:38 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-11-14 14:11:38 +0000 |
| commit | 82cf3a4486bc882207a09bf0d9e2dea4632781aa (patch) | |
| tree | 36152685fe6c0e03e5a834a396f553263086e27d /src/libsyntax/error_codes.rs | |
| parent | d63b24ffcc48f44ef09e0369e6516d6f2dec3520 (diff) | |
| parent | b5b2a8984e57260bb91d3327490da74f6fa310db (diff) | |
| download | rust-82cf3a4486bc882207a09bf0d9e2dea4632781aa.tar.gz rust-82cf3a4486bc882207a09bf0d9e2dea4632781aa.zip | |
Auto merge of #66314 - GuillaumeGomez:move-error-codes, r=Centril
Move error codes
Works towards #66210.
r? @Centril
Oh btw, for the ones interested, I used this python script to get all error codes content sorted into one final file:
<details>
```python
from os import listdir
from os.path import isdir, isfile, join
def get_error_codes(error_codes, f_path):
with open(f_path) as f:
short_mode = False
lines = f.read().split("\n")
i = 0
while i < len(lines):
line = lines[i]
if not short_mode and line.startswith("E0") and line.endswith(": r##\""):
error = line
error += "\n"
i += 1
while i < len(lines):
line = lines[i]
error += line
if line.endswith("\"##,"):
break
error += "\n"
i += 1
error_codes["long"].append(error)
elif line == ';':
short_mode = True
elif short_mode is True and len(line) > 0 and line != "}":
error_codes["short"].append(line)
while i + 1 < len(lines):
line = lines[i + 1].strip()
if not line.startswith("//"):
break
parts = line.split("//")
if len(parts) < 2:
break
if parts[1].strip().startswith("E0"):
break
error_codes["short"][-1] += "\n"
error_codes["short"][-1] += lines[i + 1]
i += 1
i += 1
def loop_dirs(error_codes, cur_dir):
for entry in listdir(cur_dir):
f = join(cur_dir, entry)
if isfile(f) and entry == "error_codes.rs":
get_error_codes(error_codes, f)
elif isdir(f) and not entry.startswith("librustc_error_codes"):
loop_dirs(error_codes, f)
def get_error_code(err):
x = err.split(",")
if len(x) < 2:
return err
x = x[0]
if x.strip().startswith("//"):
x = x.split("//")[1].strip()
return x.strip()
def write_into_file(error_codes, f_path):
with open(f_path, "w") as f:
f.write("// Error messages for EXXXX errors. Each message should start and end with a\n")
f.write("// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and\n")
f.write("// use `gq` to wrap paragraphs. Use `:set tw=0` to disable.\n\n")
f.write("syntax::register_diagnostics! {\n\n")
error_codes["long"].sort()
for i in error_codes["long"]:
f.write(i)
f.write("\n\n")
f.write(";\n")
error_codes["short"] = sorted(error_codes["short"], key=lambda err: get_error_code(err))
for i in error_codes["short"]:
f.write(i)
f.write("\n")
f.write("}\n")
error_codes = {
"long": [],
"short": []
}
loop_dirs(error_codes, "src")
write_into_file(error_codes, "src/librustc_error_codes/src/error_codes.rs")
```
</details>
And to move the error codes into their own files:
<details>
```python
import os
try:
os.mkdir("src/librustc_error_codes/error_codes")
except OSError:
print("Seems like folder already exist, moving on!")
data = ''
with open("src/librustc_error_codes/error_codes.rs") as f:
x = f.read().split('\n')
i = 0
short_part = False
while i < len(x):
line = x[i]
if short_part is False and line.startswith('E0') and line.endswith(': r##"'):
err_code = line.split(':')[0]
i += 1
content = ''
while i < len(x):
if x[i] == '"##,':
break
content += x[i]
content += '\n'
i += 1
f_path = "src/librustc_error_codes/error_codes/{}.md".format(err_code)
with open(f_path, "w") as ff:
ff.write(content)
data += '{}: include_str!("./error_codes/{}.md"),'.format(err_code, err_code)
elif short_part is False and line == ';':
short_part is True
data += ';\n'
else:
data += line
data += '\n'
i += 1
with open("src/librustc_error_codes/error_codes.rs", "w") as f:
f.write(data)
```
</details>
Diffstat (limited to 'src/libsyntax/error_codes.rs')
| -rw-r--r-- | src/libsyntax/error_codes.rs | 379 |
1 files changed, 0 insertions, 379 deletions
diff --git a/src/libsyntax/error_codes.rs b/src/libsyntax/error_codes.rs deleted file mode 100644 index 0e81de7d4a7..00000000000 --- a/src/libsyntax/error_codes.rs +++ /dev/null @@ -1,379 +0,0 @@ -// Error messages for EXXXX errors. -// Each message should start and end with a new line, and be wrapped to 80 -// characters. In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use -// `:set tw=0` to disable. -register_diagnostics! { - -E0536: r##" -The `not` cfg-predicate was malformed. - -Erroneous code example: - -```compile_fail,E0536 -#[cfg(not())] // error: expected 1 cfg-pattern -pub fn something() {} - -pub fn main() {} -``` - -The `not` predicate expects one cfg-pattern. Example: - -``` -#[cfg(not(target_os = "linux"))] // ok! -pub fn something() {} - -pub fn main() {} -``` - -For more information about the cfg attribute, read: -https://doc.rust-lang.org/reference.html#conditional-compilation -"##, - -E0537: r##" -An unknown predicate was used inside the `cfg` attribute. - -Erroneous code example: - -```compile_fail,E0537 -#[cfg(unknown())] // error: invalid predicate `unknown` -pub fn something() {} - -pub fn main() {} -``` - -The `cfg` attribute supports only three kinds of predicates: - - * any - * all - * not - -Example: - -``` -#[cfg(not(target_os = "linux"))] // ok! -pub fn something() {} - -pub fn main() {} -``` - -For more information about the cfg attribute, read: -https://doc.rust-lang.org/reference.html#conditional-compilation -"##, - -E0538: r##" -Attribute contains same meta item more than once. - -Erroneous code example: - -```compile_fail,E0538 -#[deprecated( - since="1.0.0", - note="First deprecation note.", - note="Second deprecation note." // error: multiple same meta item -)] -fn deprecated_function() {} -``` - -Meta items are the key-value pairs inside of an attribute. Each key may only be -used once in each attribute. - -To fix the problem, remove all but one of the meta items with the same key. - -Example: - -``` -#[deprecated( - since="1.0.0", - note="First deprecation note." -)] -fn deprecated_function() {} -``` -"##, - -E0541: r##" -An unknown meta item was used. - -Erroneous code example: - -```compile_fail,E0541 -#[deprecated( - since="1.0.0", - // error: unknown meta item - reason="Example invalid meta item. Should be 'note'") -] -fn deprecated_function() {} -``` - -Meta items are the key-value pairs inside of an attribute. The keys provided -must be one of the valid keys for the specified attribute. - -To fix the problem, either remove the unknown meta item, or rename it if you -provided the wrong name. - -In the erroneous code example above, the wrong name was provided, so changing -to a correct one it will fix the error. Example: - -``` -#[deprecated( - since="1.0.0", - note="This is a valid meta item for the deprecated attribute." -)] -fn deprecated_function() {} -``` -"##, - -E0550: r##" -More than one `deprecated` attribute has been put on an item. - -Erroneous code example: - -```compile_fail,E0550 -#[deprecated(note = "because why not?")] -#[deprecated(note = "right?")] // error! -fn the_banished() {} -``` - -The `deprecated` attribute can only be present **once** on an item. - -``` -#[deprecated(note = "because why not, right?")] -fn the_banished() {} // ok! -``` -"##, - -E0551: r##" -An invalid meta-item was used inside an attribute. - -Erroneous code example: - -```compile_fail,E0551 -#[deprecated(note)] // error! -fn i_am_deprecated() {} -``` - -Meta items are the key-value pairs inside of an attribute. To fix this issue, -you need to give a value to the `note` key. Example: - -``` -#[deprecated(note = "because")] // ok! -fn i_am_deprecated() {} -``` -"##, - -E0552: r##" -A unrecognized representation attribute was used. - -Erroneous code example: - -```compile_fail,E0552 -#[repr(D)] // error: unrecognized representation hint -struct MyStruct { - my_field: usize -} -``` - -You can use a `repr` attribute to tell the compiler how you want a struct or -enum to be laid out in memory. - -Make sure you're using one of the supported options: - -``` -#[repr(C)] // ok! -struct MyStruct { - my_field: usize -} -``` - -For more information about specifying representations, see the ["Alternative -Representations" section] of the Rustonomicon. - -["Alternative Representations" section]: https://doc.rust-lang.org/nomicon/other-reprs.html -"##, - -E0554: r##" -Feature attributes are only allowed on the nightly release channel. Stable or -beta compilers will not comply. - -Example of erroneous code (on a stable compiler): - -```ignore (depends on release channel) -#![feature(non_ascii_idents)] // error: `#![feature]` may not be used on the - // stable release channel -``` - -If you need the feature, make sure to use a nightly release of the compiler -(but be warned that the feature may be removed or altered in the future). -"##, - -E0556: r##" -The `feature` attribute was badly formed. - -Erroneous code example: - -```compile_fail,E0556 -#![feature(foo_bar_baz, foo(bar), foo = "baz", foo)] // error! -#![feature] // error! -#![feature = "foo"] // error! -``` - -The `feature` attribute only accept a "feature flag" and can only be used on -nightly. Example: - -```ignore (only works in nightly) -#![feature(flag)] -``` -"##, - -E0557: r##" -A feature attribute named a feature that has been removed. - -Erroneous code example: - -```compile_fail,E0557 -#![feature(managed_boxes)] // error: feature has been removed -``` - -Delete the offending feature attribute. -"##, - -E0565: r##" -A literal was used in a built-in attribute that doesn't support literals. - -Erroneous code example: - -```ignore (compile_fail not working here; see Issue #43707) -#[inline("always")] // error: unsupported literal -pub fn something() {} -``` - -Literals in attributes are new and largely unsupported in built-in attributes. -Work to support literals where appropriate is ongoing. Try using an unquoted -name instead: - -``` -#[inline(always)] -pub fn something() {} -``` -"##, - -E0589: r##" -The value of `N` that was specified for `repr(align(N))` was not a power -of two, or was greater than 2^29. - -```compile_fail,E0589 -#[repr(align(15))] // error: invalid `repr(align)` attribute: not a power of two -enum Foo { - Bar(u64), -} -``` -"##, - -E0658: r##" -An unstable feature was used. - -Erroneous code example: - -```compile_fail,E658 -#[repr(u128)] // error: use of unstable library feature 'repr128' -enum Foo { - Bar(u64), -} -``` - -If you're using a stable or a beta version of rustc, you won't be able to use -any unstable features. In order to do so, please switch to a nightly version of -rustc (by using rustup). - -If you're using a nightly version of rustc, just add the corresponding feature -to be able to use it: - -``` -#![feature(repr128)] - -#[repr(u128)] // ok! -enum Foo { - Bar(u64), -} -``` -"##, - -E0633: r##" -The `unwind` attribute was malformed. - -Erroneous code example: - -```ignore (compile_fail not working here; see Issue #43707) -#[unwind()] // error: expected one argument -pub extern fn something() {} - -fn main() {} -``` - -The `#[unwind]` attribute should be used as follows: - -- `#[unwind(aborts)]` -- specifies that if a non-Rust ABI function - should abort the process if it attempts to unwind. This is the safer - and preferred option. - -- `#[unwind(allowed)]` -- specifies that a non-Rust ABI function - should be allowed to unwind. This can easily result in Undefined - Behavior (UB), so be careful. - -NB. The default behavior here is "allowed", but this is unspecified -and likely to change in the future. - -"##, - -E0705: r##" -A `#![feature]` attribute was declared for a feature that is stable in -the current edition, but not in all editions. - -Erroneous code example: - -```ignore (limited to a warning during 2018 edition development) -#![feature(rust_2018_preview)] -#![feature(test_2018_feature)] // error: the feature - // `test_2018_feature` is - // included in the Rust 2018 edition -``` -"##, - -E0725: r##" -A feature attribute named a feature that was disallowed in the compiler -command line flags. - -Erroneous code example: - -```ignore (can't specify compiler flags from doctests) -#![feature(never_type)] // error: the feature `never_type` is not in - // the list of allowed features -``` - -Delete the offending feature attribute, or add it to the list of allowed -features in the `-Z allow_features` flag. -"##, - -; - - E0539, // incorrect meta item - E0540, // multiple rustc_deprecated attributes - E0542, // missing 'since' - E0543, // missing 'reason' - E0544, // multiple stability levels - E0545, // incorrect 'issue' - E0546, // missing 'feature' - E0547, // missing 'issue' -// E0548, // replaced with a generic attribute input check - // rustc_deprecated attribute must be paired with either stable or unstable - // attribute - E0549, - E0553, // multiple rustc_const_unstable attributes -// E0555, // replaced with a generic attribute input check - E0629, // missing 'feature' (rustc_const_unstable) - // rustc_const_unstable attribute must be paired with stable/unstable - // attribute - E0630, - E0693, // incorrect `repr(align)` attribute format -// E0694, // an unknown tool name found in scoped attributes - E0717, // rustc_promotable without stability attribute -} |
