Skip to content

ICE: added error handle for values greater than 9999 in #140700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/rustc_driver_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions tests/ui/explain/error-with-no-explanation.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/ui/explain/error-with-no-explanation.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: E9999 is not a valid error code

2 changes: 2 additions & 0 deletions tests/ui/explain/invalid-error-code.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//@ compile-flags: --explain error_code
//~? ERROR: error_code is not a valid error code
2 changes: 2 additions & 0 deletions tests/ui/explain/invalid-error-code.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: error_code is not a valid error code

2 changes: 2 additions & 0 deletions tests/ui/explain/no-E-prefix.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
//@ compile-flags: --explain 425
//@ check-pass
57 changes: 57 additions & 0 deletions tests/ui/explain/no-E-prefix.stdout
Original file line number Diff line number Diff line change
@@ -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 changes: 4 additions & 0 deletions tests/ui/explain/overflow-error-code.rs
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions tests/ui/explain/overflow-error-code.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
error: E10000 is not a valid error code

Loading