-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Make ErrorReported impossible to construct outside rustc_errors
#93222
Conversation
r? @wesleywiser (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
@mark-i-m I think your formatter isn't working correctly. Can you run |
if recursion_limit_hit { | ||
// If we hit a recursion limit, exit early to avoid later passes getting overwhelmed | ||
// with a large AST | ||
Err(ErrorReported) | ||
Err(ErrorReported::new_i_know_what_im_doing()) |
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.
Looks like reduced_recursion_limit
could contain an ErrorReported
.
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.
Coming from where?
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.
From whatever set it, which presumably produced an error in the process.
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.
IIUC, it starts out set and only becomes None
if there is no error... so there may not be another good place to generate an ErrorReported
...
compiler/rustc_driver/src/lib.rs
Outdated
if value.is::<rustc_errors::FatalErrorMarker>() { | ||
ErrorReported | ||
ErrorReported::new_i_know_what_im_doing() |
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.
This should be a downcast, not just .is::<...>()
, and FatalErrorMarker
should contain ErrorReported
.
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.
Unfortunately, this is difficult because FatalError
is defined in rustc_span
compiler/rustc_errors/src/lib.rs
Outdated
@@ -1000,6 +1003,8 @@ impl HandlerInner { | |||
} else { | |||
self.bump_warn_count(); | |||
} | |||
|
|||
ErrorReported::new_i_know_what_im_doing() |
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.
This needs to check diagnostic.is_error()
.
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.
Overall, it feels like the nice thing would be to seal ErrorReported
and have an impl
in the same "sealed" module that ErrorReported
would be in, with a wrapper method for self.emitter.emit_diagnostic(diagnostic);
that checks for the conditions for ErrorReported
and creates it if necessary.
Another wrapper could be added for self.delayed_span_bugs.push(diagnostic);
. Those should be the only cases in which you can guarantee ErrorReported
. Error deduplication can keep a ErrorReported
around for reuse (in general, this should be favored because it's free, being a ZST).
9a12cc5
to
caf4e6a
Compare
if self.err_count() == old_count { | ||
Ok(result) | ||
} else { | ||
Err(ErrorReported::new_i_know_what_im_doing()) |
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.
err_count
can be something like Option<(NonZeroUsize, ErrorReported)>
, making this only slightly harder than simply ==
.
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.
Tried this, but it creates a lot of noise everywhere else that err_count
is used...
📌 Commit bb8d430 has been approved by |
@bors p=100 (testing to see if ci works fine now after the outage earlier) |
⌛ Testing commit bb8d430 with merge 5f69cbe7530c8201946c38966e9e4dc424aa0ed6... |
@bors retry |
⌛ Testing commit bb8d430 with merge d4c27e66acfef0714867a438bad92a8501dc3ac4... |
💔 Test failed - checks-actions |
The job Click to see the possible cause of the failure (guessed by this bot)
|
@bors retry Ran out of space. For some reason, the runner had an unusually small root partition (84G instead of the normal 667G). Investigation is needed, but tree is closed for now. |
⌛ Testing commit bb8d430 with merge c1e4de654ee31e9f368af371fe8bd269c0ec546e... |
💔 Test failed - checks-actions |
@bors retry p=0 Back to the docker cache/cmake problem. |
Rollup of 10 pull requests Successful merges: - rust-lang#91133 (Improve `unsafe` diagnostic) - rust-lang#93222 (Make ErrorReported impossible to construct outside `rustc_errors`) - rust-lang#93745 (Stabilize ADX target feature) - rust-lang#94309 ([generator_interior] Be more precise with scopes of borrowed places) - rust-lang#94698 (Remove redundant code from copy-suggestions) - rust-lang#94731 (Suggest adding `{ .. }` around a const function call with arguments) - rust-lang#94960 (Fix many spelling mistakes) - rust-lang#94982 (Add deprecated_safe feature gate and attribute, cc rust-lang#94978) - rust-lang#94997 (debuginfo: Fix ICE when generating name for type that produces a layout error.) - rust-lang#95000 (Fixed wrong type name in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
There are a few places were we have to construct it, though, and a few
places that are more invasive to change. To do this, we create a
constructor with a long obvious name.
cc #69426 @varkor @eddyb @estebank
I actually didn't see that I was assigned to this issue until now...