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_ext | |
| 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_ext')
| -rw-r--r-- | src/libsyntax_ext/Cargo.toml | 1 | ||||
| -rw-r--r-- | src/libsyntax_ext/asm.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/deriving/default.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax_ext/error_codes.rs | 120 | ||||
| -rw-r--r-- | src/libsyntax_ext/lib.rs | 2 |
5 files changed, 5 insertions, 122 deletions
diff --git a/src/libsyntax_ext/Cargo.toml b/src/libsyntax_ext/Cargo.toml index 5ae8b3a3e0c..2ebdac8ef7c 100644 --- a/src/libsyntax_ext/Cargo.toml +++ b/src/libsyntax_ext/Cargo.toml @@ -20,3 +20,4 @@ smallvec = { version = "1.0", features = ["union", "may_dangle"] } syntax = { path = "../libsyntax" } syntax_expand = { path = "../libsyntax_expand" } syntax_pos = { path = "../libsyntax_pos" } +rustc_error_codes = { path = "../librustc_error_codes" } diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 539d777105d..5fab101957a 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -16,6 +16,8 @@ use syntax_pos::Span; use syntax::tokenstream::{self, TokenStream}; use syntax::{span_err, struct_span_err}; +use rustc_error_codes::*; + enum State { Asm, Outputs, diff --git a/src/libsyntax_ext/deriving/default.rs b/src/libsyntax_ext/deriving/default.rs index cfc0f3cd6cb..ab57f395f6a 100644 --- a/src/libsyntax_ext/deriving/default.rs +++ b/src/libsyntax_ext/deriving/default.rs @@ -9,6 +9,8 @@ use syntax::symbol::{kw, sym}; use syntax::span_err; use syntax_pos::Span; +use rustc_error_codes::*; + pub fn expand_deriving_default(cx: &mut ExtCtxt<'_>, span: Span, mitem: &MetaItem, diff --git a/src/libsyntax_ext/error_codes.rs b/src/libsyntax_ext/error_codes.rs deleted file mode 100644 index 2bc990574f7..00000000000 --- a/src/libsyntax_ext/error_codes.rs +++ /dev/null @@ -1,120 +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. -syntax::register_diagnostics! { -E0660: r##" -The argument to the `asm` macro is not well-formed. - -Erroneous code example: - -```compile_fail,E0660 -asm!("nop" "nop"); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0661: r##" -An invalid syntax was passed to the second argument of an `asm` macro line. - -Erroneous code example: - -```compile_fail,E0661 -let a; -asm!("nop" : "r"(a)); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0662: r##" -An invalid input operand constraint was passed to the `asm` macro (third line). - -Erroneous code example: - -```compile_fail,E0662 -asm!("xor %eax, %eax" - : - : "=test"("a") - ); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0663: r##" -An invalid input operand constraint was passed to the `asm` macro (third line). - -Erroneous code example: - -```compile_fail,E0663 -asm!("xor %eax, %eax" - : - : "+test"("a") - ); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0664: r##" -A clobber was surrounded by braces in the `asm` macro. - -Erroneous code example: - -```compile_fail,E0664 -asm!("mov $$0x200, %eax" - : - : - : "{eax}" - ); -``` - -Considering that this would be a long explanation, we instead recommend you to -take a look at the unstable book: -https://doc.rust-lang.org/unstable-book/language-features/asm.html -"##, - -E0665: r##" -The `Default` trait was derived on an enum. - -Erroneous code example: - -```compile_fail,E0665 -#[derive(Default)] -enum Food { - Sweet, - Salty, -} -``` - -The `Default` cannot be derived on an enum for the simple reason that the -compiler doesn't know which value to pick by default whereas it can for a -struct as long as all its fields implement the `Default` trait as well. - -If you still want to implement `Default` on your enum, you'll have to do it "by -hand": - -``` -enum Food { - Sweet, - Salty, -} - -impl Default for Food { - fn default() -> Food { - Food::Sweet - } -} -``` -"##, -} diff --git a/src/libsyntax_ext/lib.rs b/src/libsyntax_ext/lib.rs index 5516f276422..07fdec05046 100644 --- a/src/libsyntax_ext/lib.rs +++ b/src/libsyntax_ext/lib.rs @@ -19,8 +19,6 @@ use syntax::symbol::sym; use syntax_expand::base::{Resolver, SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn}; use syntax_expand::proc_macro::BangProcMacro; -mod error_codes; - mod asm; mod assert; mod cfg; |
