mirror of
https://github.com/rust-lang/rust.git
synced 2025-10-02 10:18:25 +00:00
added error handle for error code > 9999
This commit is contained in:
parent
651e9cf327
commit
3c1c0726ad
@ -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;
|
||||
|
3
tests/ui/explain/error-with-no-explanation.rs
Normal file
3
tests/ui/explain/error-with-no-explanation.rs
Normal 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
|
2
tests/ui/explain/error-with-no-explanation.stderr
Normal file
2
tests/ui/explain/error-with-no-explanation.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: E9999 is not a valid error code
|
||||
|
2
tests/ui/explain/invalid-error-code.rs
Normal file
2
tests/ui/explain/invalid-error-code.rs
Normal file
@ -0,0 +1,2 @@
|
||||
//@ compile-flags: --explain error_code
|
||||
//~? ERROR: error_code is not a valid error code
|
2
tests/ui/explain/invalid-error-code.stderr
Normal file
2
tests/ui/explain/invalid-error-code.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: error_code is not a valid error code
|
||||
|
2
tests/ui/explain/no-E-prefix.rs
Normal file
2
tests/ui/explain/no-E-prefix.rs
Normal file
@ -0,0 +1,2 @@
|
||||
//@ compile-flags: --explain 425
|
||||
//@ check-pass
|
57
tests/ui/explain/no-E-prefix.stdout
Normal file
57
tests/ui/explain/no-E-prefix.stdout
Normal 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`).
|
4
tests/ui/explain/overflow-error-code.rs
Normal file
4
tests/ui/explain/overflow-error-code.rs
Normal 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
|
2
tests/ui/explain/overflow-error-code.stderr
Normal file
2
tests/ui/explain/overflow-error-code.stderr
Normal file
@ -0,0 +1,2 @@
|
||||
error: E10000 is not a valid error code
|
||||
|
Loading…
x
Reference in New Issue
Block a user