Skip to content

Commit 16f490f

Browse files
authored
Rollup merge of #93898 - GuillaumeGomez:error-code-check, r=Mark-Simulacrum
tidy: Extend error code check We discovered in #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```
2 parents 475b45f + 087fb23 commit 16f490f

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ E0184: include_str!("./error_codes/E0184.md"),
9797
E0185: include_str!("./error_codes/E0185.md"),
9898
E0186: include_str!("./error_codes/E0186.md"),
9999
E0191: include_str!("./error_codes/E0191.md"),
100+
E0192: include_str!("./error_codes/E0192.md"),
100101
E0193: include_str!("./error_codes/E0193.md"),
101102
E0195: include_str!("./error_codes/E0195.md"),
102103
E0197: include_str!("./error_codes/E0197.md"),
@@ -522,7 +523,6 @@ E0787: include_str!("./error_codes/E0787.md"),
522523
// E0188, // can not cast an immutable reference to a mutable pointer
523524
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
524525
// E0190, // deprecated: can only cast a &-pointer to an &-object
525-
// E0192, // negative impl only applicable to auto traits
526526
// E0194, // merged into E0403
527527
// E0196, // cannot determine a type for this closure
528528
E0208,

compiler/rustc_error_codes/src/error_codes/E0192.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
A negative impl was added on a trait implementation.
24

35
Erroneous code example:
46

5-
```compile_fail,E0192
7+
```compile_fail
68
trait Trait {
79
type Bar;
810
}
911
1012
struct Foo;
1113
12-
impl !Trait for Foo { } //~ ERROR E0192
14+
impl !Trait for Foo { } //~ ERROR
1315
1416
fn main() {}
1517
```

src/tools/tidy/src/error_codes_check.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Checks that all error codes have at least one test to prevent having error
22
//! codes that are silently not thrown by the compiler anymore.
33
4-
use std::collections::HashMap;
4+
use std::collections::{HashMap, HashSet};
55
use std::ffi::OsStr;
66
use std::fs::read_to_string;
77
use std::path::Path;
@@ -205,6 +205,7 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
205205
let mut found_explanations = 0;
206206
let mut found_tests = 0;
207207
let mut error_codes: HashMap<String, ErrorCodeStatus> = HashMap::new();
208+
let mut explanations: HashSet<String> = HashSet::new();
208209
// We want error codes which match the following cases:
209210
//
210211
// * foo(a, E0111, a)
@@ -218,17 +219,27 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
218219
for path in paths {
219220
super::walk(path, &mut |path| super::filter_dirs(path), &mut |entry, contents| {
220221
let file_name = entry.file_name();
222+
let entry_path = entry.path();
223+
221224
if file_name == "error_codes.rs" {
222225
extract_error_codes(contents, &mut error_codes, entry.path(), &mut errors);
223226
found_explanations += 1;
224-
} else if entry.path().extension() == Some(OsStr::new("stderr")) {
227+
} else if entry_path.extension() == Some(OsStr::new("stderr")) {
225228
extract_error_codes_from_tests(contents, &mut error_codes);
226229
found_tests += 1;
227-
} else if entry.path().extension() == Some(OsStr::new("rs")) {
230+
} else if entry_path.extension() == Some(OsStr::new("rs")) {
228231
let path = entry.path().to_string_lossy();
229232
if PATHS_TO_IGNORE_FOR_EXTRACTION.iter().all(|c| !path.contains(c)) {
230233
extract_error_codes_from_source(contents, &mut error_codes, &regex);
231234
}
235+
} else if entry_path
236+
.parent()
237+
.and_then(|p| p.file_name())
238+
.map(|p| p == "error_codes")
239+
.unwrap_or(false)
240+
&& entry_path.extension() == Some(OsStr::new("md"))
241+
{
242+
explanations.insert(file_name.to_str().unwrap().replace(".md", ""));
232243
}
233244
});
234245
}
@@ -240,6 +251,10 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
240251
eprintln!("No error code was found in compilation errors!");
241252
*bad = true;
242253
}
254+
if explanations.is_empty() {
255+
eprintln!("No error code explanation was found!");
256+
*bad = true;
257+
}
243258
if errors.is_empty() {
244259
println!("Found {} error codes", error_codes.len());
245260

@@ -282,11 +297,21 @@ pub fn check(paths: &[&Path], bad: &mut bool) {
282297
}
283298
}
284299
}
300+
if errors.is_empty() {
301+
for explanation in explanations {
302+
if !error_codes.contains_key(&explanation) {
303+
errors.push(format!(
304+
"{} error code explanation should be listed in `error_codes.rs`",
305+
explanation
306+
));
307+
}
308+
}
309+
}
285310
errors.sort();
286311
for err in &errors {
287312
eprintln!("{}", err);
288313
}
289-
println!("Found {} error codes with no tests", errors.len());
314+
println!("Found {} error(s) in error codes", errors.len());
290315
if !errors.is_empty() {
291316
*bad = true;
292317
}

0 commit comments

Comments
 (0)