-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
base: master
Are you sure you want to change the base?
Conversation
fmease is on vacation. Please choose another assignee. |
r? @davidtwco rustbot has assigned @davidtwco. Use |
This comment has been minimized.
This comment has been minimized.
I feel like this is very arbitrary. The
to behave the same as
and
to gracefully fail with the same error message. |
@jieyouxu any actual idea why tidy start fails here?
like... should I just add E9999 there..? |
Some changes occurred in diagnostic error codes |
oh no, looks like adding E9999 was a miskate here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any actual idea why tidy start fails here?
I'm pretty sure it's simply due to tidy (src/tools/tidy/src/error_codes.rs:361
) grepping through ~all Rust compiler source files looking for \bE\d{4}\b
and finding the E9999
in your previous error message that you've since removed.
@@ -547,6 +547,7 @@ E0801: 0801, | |||
E0802: 0802, | |||
E0803: 0803, | |||
E0804: 0804, | |||
E9999: 9999, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this shouldn't be necessary now that you've removed the specialized error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah i removed this custom message error for anything greater than 9999 and removed E9999 from error_codes, ran tidy locally and tidy said it's fine, let's see
This comment has been minimized.
This comment has been minimized.
compiler/rustc_errors/src/codes.rs
Outdated
@@ -7,7 +7,6 @@ | |||
use std::fmt; | |||
|
|||
rustc_index::newtype_index! { | |||
#[max = 9999] // Because all error codes have four digits. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we obviously shouldn't crash when the user enters error codes greater than E9999, the original purpose of this internal limit is to prevent rustc devs from introducing five-digit error codes without changing all other relevant parts of the compiler, docs and tools (like tidy) to now pad all four-digit codes with an additional 0
to become five-digit codes, etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i was wondering how can i fix this to make not panicking here, and without changing NewType entirely, so this is only solution that worked fine that i came up with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Running the ICE with debuginfo gives this line:
rust/compiler/rustc_driver_impl/src/lib.rs
Line 466 in 651e9cf
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code)) |
You probably want to manually add an
impl TryFrom<u32> for ErrCode
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesnt it will still panic inside NewType because of max limitations?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i believe that the panic occurs here
assert!(value <= (#max as usize)); |
because ICE was adressing to this line
rustc_index::newtype_index! { |
thread 'main' panicked at /rustc/d6a325d93a84077580c677f89affbe45682606c3\compiler\rustc_errors\src\codes.rs:9:1:
assertion failed: value <= 9999
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so, as far as i concerned, we cannot really prevent this panic when having #[max = 9999] and pass something bigger than it, we should not let this error code (that is bigger than max value) get to this assertations because it'll panic is such cases
but i may missing something for sure, if so please let me know we'll brainstorm it together
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea is to return Err(_)
/None
, i.e. not constructing the newtype if code > 9999 (= not calling from_u32
, so the assert!
is not reached).
Alternativement, adding impl Borrow<u32> for ErrCode
so this fn can directly being called with an u32
(try_find_description<C>(&self, code: C) where ErrCode: Borrow<C>
);
rust/compiler/rustc_errors/src/registry.rs
Lines 18 to 22 in 651e9cf
/// Returns `InvalidErrorCode` if the code requested does not exist in the | |
/// registry. | |
pub fn try_find_description(&self, code: ErrCode) -> Result<&'static str, InvalidErrorCode> { | |
self.long_descriptions.get(&code).copied().ok_or(InvalidErrorCode) | |
} |
Alternatively, just adding && code <= ErrCode::MAX_AS_U32
before this:
rust/compiler/rustc_driver_impl/src/lib.rs
Line 466 in 651e9cf
&& let Ok(description) = registry.try_find_description(ErrCode::from_u32(code)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, currently playing around this ideas, this would take some time because of recompilling, thanks for ideas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ive tried this thing
pub fn try_find_description(&self, code: ErrCode) -> Result<&'static str, InvalidErrorCode> {
if code > ErrCode::from_u32(9999) {
return Err(InvalidErrorCode);
}
self.long_descriptions.get(&code).copied().ok_or(InvalidErrorCode)
}
and its not worked for me
but this one && code <= ErrCode::MAX_AS_U32
runs like perfect, so we can stick with it
You may want to add a regression test based on |
@ShE3py oh, yes i want to add tests for it, didnt knew that there is some for yeah, i guess i cant do this in one file |
removed panic in case where we do
--explain > 9999
and added check for itnow error looks like this instead of ICE
fixes #140647
r? @fmease