added error handle for error code > 9999

This commit is contained in:
Kivooeo 2025-05-06 15:06:45 +05:00
parent 651e9cf327
commit 3c1c0726ad
11 changed files with 75 additions and 0 deletions

View File

@ -463,6 +463,7 @@ fn handle_explain(early_dcx: &EarlyDiagCtxt, registry: Registry, code: &str, col
// Allow "E0123" or "0123" form.
let upper_cased_code = code.to_ascii_uppercase();
if let Ok(code) = upper_cased_code.strip_prefix('E').unwrap_or(&upper_cased_code).parse::<u32>()
&& code <= ErrCode::MAX_AS_U32
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code))
{
let mut is_in_code_block = false;

View File

@ -0,0 +1,3 @@
// It's a valid error with no added explanation
//@ compile-flags: --explain E9999
//~? ERROR: E9999 is not a valid error code

View File

@ -0,0 +1,2 @@
error: E9999 is not a valid error code

View File

@ -0,0 +1,2 @@
//@ compile-flags: --explain error_code
//~? ERROR: error_code is not a valid error code

View File

@ -0,0 +1,2 @@
error: error_code is not a valid error code

View File

@ -0,0 +1,2 @@
//@ compile-flags: --explain 425
//@ check-pass

View File

@ -0,0 +1,57 @@
An unresolved name was used.
Erroneous code examples:
```
something_that_doesnt_exist::foo;
// error: unresolved name `something_that_doesnt_exist::foo`
// or:
trait Foo {
fn bar() {
Self; // error: unresolved name `Self`
}
}
// or:
let x = unknown_variable; // error: unresolved name `unknown_variable`
```
Please verify that the name wasn't misspelled and ensure that the
identifier being referred to is valid for the given situation. Example:
```
enum something_that_does_exist {
Foo,
}
```
Or:
```
mod something_that_does_exist {
pub static foo : i32 = 0i32;
}
something_that_does_exist::foo; // ok!
```
Or:
```
let unknown_variable = 12u32;
let x = unknown_variable; // ok!
```
If the item is not defined in the current module, it must be imported using a
`use` statement, like so:
```
use foo::bar;
bar();
```
If the item you are importing is not defined in some super-module of the
current module, then it must also be declared as public (e.g., `pub fn`).

View File

@ -0,0 +1,4 @@
// Check that we don't crash on error codes exceeding our internal limit.
// issue: <https://github.com/rust-lang/rust/issues/140647>
//@ compile-flags: --explain E10000
//~? ERROR: E10000 is not a valid error code

View File

@ -0,0 +1,2 @@
error: E10000 is not a valid error code