Rollup merge of #93898 - GuillaumeGomez:error-code-check, r=Mark-Simulacrum

tidy: Extend error code check

We discovered in https://github.com/rust-lang/rust/pull/93845 that the error code tidy check didn't check everything: if you remove an error code from the listing even if it has an explanation, then it should error.

It also allowed me to put back `E0192` in that listing as well.

r? ```@Mark-Simulacrum```
This commit is contained in:
Matthias Krüger 2022-02-12 09:26:25 +01:00 committed by GitHub
commit 16f490f354
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 7 deletions

View File

@ -97,6 +97,7 @@ E0184: include_str!("./error_codes/E0184.md"),
E0185: include_str!("./error_codes/E0185.md"), E0185: include_str!("./error_codes/E0185.md"),
E0186: include_str!("./error_codes/E0186.md"), E0186: include_str!("./error_codes/E0186.md"),
E0191: include_str!("./error_codes/E0191.md"), E0191: include_str!("./error_codes/E0191.md"),
E0192: include_str!("./error_codes/E0192.md"),
E0193: include_str!("./error_codes/E0193.md"), E0193: include_str!("./error_codes/E0193.md"),
E0195: include_str!("./error_codes/E0195.md"), E0195: include_str!("./error_codes/E0195.md"),
E0197: include_str!("./error_codes/E0197.md"), E0197: include_str!("./error_codes/E0197.md"),
@ -522,7 +523,6 @@ E0787: include_str!("./error_codes/E0787.md"),
// E0188, // can not cast an immutable reference to a mutable pointer // E0188, // can not cast an immutable reference to a mutable pointer
// E0189, // deprecated: can only cast a boxed pointer to a boxed object // E0189, // deprecated: can only cast a boxed pointer to a boxed object
// E0190, // deprecated: can only cast a &-pointer to an &-object // E0190, // deprecated: can only cast a &-pointer to an &-object
// E0192, // negative impl only applicable to auto traits
// E0194, // merged into E0403 // E0194, // merged into E0403
// E0196, // cannot determine a type for this closure // E0196, // cannot determine a type for this closure
E0208, E0208,

View File

@ -1,15 +1,17 @@
#### Note: this error code is no longer emitted by the compiler.
A negative impl was added on a trait implementation. A negative impl was added on a trait implementation.
Erroneous code example: Erroneous code example:
```compile_fail,E0192 ```compile_fail
trait Trait { trait Trait {
type Bar; type Bar;
} }
struct Foo; struct Foo;
impl !Trait for Foo { } //~ ERROR E0192 impl !Trait for Foo { } //~ ERROR
fn main() {} fn main() {}
``` ```

View File

@ -1,7 +1,7 @@
//! Checks that all error codes have at least one test to prevent having error //! Checks that all error codes have at least one test to prevent having error
//! codes that are silently not thrown by the compiler anymore. //! codes that are silently not thrown by the compiler anymore.
use std::collections::HashMap; use std::collections::{HashMap, HashSet};
use std::ffi::OsStr; use std::ffi::OsStr;
use std::fs::read_to_string; use std::fs::read_to_string;
use std::path::Path; use std::path::Path;
@ -205,6 +205,7 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
let mut found_explanations = 0; let mut found_explanations = 0;
let mut found_tests = 0; let mut found_tests = 0;
let mut error_codes: HashMap<String, ErrorCodeStatus> = HashMap::new(); let mut error_codes: HashMap<String, ErrorCodeStatus> = HashMap::new();
let mut explanations: HashSet<String> = HashSet::new();
// We want error codes which match the following cases: // We want error codes which match the following cases:
// //
// * foo(a, E0111, a) // * foo(a, E0111, a)
@ -218,17 +219,27 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
for path in paths { for path in paths {
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| { super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
let file_name = entry.file_name(); let file_name = entry.file_name();
let entry_path = entry.path();
if file_name == "error_codes.rs" { if file_name == "error_codes.rs" {
extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors); extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors);
found_explanations += 1; found_explanations += 1;
} else if entry.path().extension() == Some(OsStr::new("stderr")) { } else if entry_path.extension() == Some(OsStr::new("stderr")) {
extract_error_codes_from_tests(contents, &mut error_codes); extract_error_codes_from_tests(contents, &mut error_codes);
found_tests += 1; found_tests += 1;
} else if entry.path().extension() == Some(OsStr::new("rs")) { } else if entry_path.extension() == Some(OsStr::new("rs")) {
let path = entry.path().to_string_lossy(); let path = entry.path().to_string_lossy();
if PATHS_TO_IGNORE_FOR_EXTRACTION.iter().all(|c| !path.contains(c)) { if PATHS_TO_IGNORE_FOR_EXTRACTION.iter().all(|c| !path.contains(c)) {
extract_error_codes_from_source(contents, &mut error_codes, &regex); extract_error_codes_from_source(contents, &mut error_codes, &regex);
} }
} else if entry_path
.parent()
.and_then(|p| p.file_name())
.map(|p| p == "error_codes")
.unwrap_or(false)
&& entry_path.extension() == Some(OsStr::new("md"))
{
explanations.insert(file_name.to_str().unwrap().replace(".md", ""));
} }
}); });
} }
@ -240,6 +251,10 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
eprintln!("No error code was found in compilation errors!"); eprintln!("No error code was found in compilation errors!");
*bad = true; *bad = true;
} }
if explanations.is_empty() {
eprintln!("No error code explanation was found!");
*bad = true;
}
if errors.is_empty() { if errors.is_empty() {
println!("Found {} error codes", error_codes.len()); println!("Found {} error codes", error_codes.len());
@ -282,11 +297,21 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
} }
} }
} }
if errors.is_empty() {
for explanation in explanations {
if !error_codes.contains_key(&explanation) {
errors.push(format!(
"{} error code explanation should be listed in `error_codes.rs`",
explanation
));
}
}
}
errors.sort(); errors.sort();
for err in &errors { for err in &errors {
eprintln!("{}", err); eprintln!("{}", err);
} }
println!("Found {} error codes with no tests", errors.len()); println!("Found {} error(s) in error codes", errors.len());
if !errors.is_empty() { if !errors.is_empty() {
*bad = true; *bad = true;
} }