-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Use track_errors
instead of hand rolling
#59358
Conversation
src/librustc_mir/const_eval.rs
Outdated
@@ -647,10 +647,14 @@ pub fn const_eval_raw_provider<'a, 'tcx>( | |||
"could not evaluate static initializer"); | |||
// Ensure that if the above error was either `TooGeneric` or `Reported` | |||
// an error must be reported. | |||
if tcx.sess.err_count() == 0 { | |||
tcx.sess.delay_span_bug(err.span, | |||
let errs = tcx.sess.track_errors(|| { |
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.
You should put the err.report_as_error(...)
call above into the closure. We don't need the err_count
call anymore, it's done by track_errors
.
The idea was to ensure that calling report_as_error
actually reports any errors.
You should then be able to yield the values inside the Err
and Ok
variants instead of having to carry the reported_err
variable around
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 get the point, removed err_count
.
src/librustc_mir/const_eval.rs
Outdated
if tcx.sess.err_count() == 0 { | ||
tcx.sess.delay_span_bug(err.span, | ||
let tracked_err = tcx.sess.track_errors(|| { | ||
err.report_as_error(ecx.tcx, |
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.
You should remove the report_as_error
call above. I'm not sure what types tracked_err
has, but the Ok
path should give you the same value that you got previously in reported_err
. What's the value in the Err
part?
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.
Please let me ask you two questions.
- What should I place instead of
report_as_error
? - How I check if
track_err
returnsOk
?
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.
for 2. you are already checking that via the match
below. You can pattern match on the Ok
value via Ok(reported_err)
.
for 1. nothing, you already are calling it inside of the track_errors
call, so you are replacing it with the tcx.sess.track_errors(|| { err.report_as_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.
Okay, thank you! And what should I do in the Err
part?
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'm not sure, that depends on what is returned there. Have a look at the return type and emit an apropriate ErrorHandled
enum variant
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 pushed WIP commit. Test will be failed because types are incompatible in match
.
But I want to know if my work is correct so far. Could you check this?
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.
Yes, this is correct so far.
In the Ok
arm, the return value should be v
I believe. The Err
pattern can probably be Err(ErrorReported)
and the arm value ErrorHandled::Reported
(or whatever the correct variant is).
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 modified as follows:
match reported_err {
Ok(v) => {
tcx.sess.delay_span_bug(err.span,
&format!("static eval failure did not emit an error: {:#?}",
v));
v
},
Err(ErrorReported) => ErrorReported,
}
but ()
is returned in the Ok
arm and rustc::util::common::ErrorReported
is returned in the Err
arm, so the compile is failed. Any solutions?
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/librustc_mir/const_eval.rs
Outdated
tcx.sess.delay_span_bug(err.span, | ||
let reported_err = tcx.sess.track_errors(|| { | ||
err.report_as_error(ecx.tcx, | ||
"could not evaluate static initializer"); |
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 ;
here drops the value you'd get for v
and makes it ()
.
Removing the ;
here should fix your problem
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.
Thank you! I dropped ;
but the compile was failed. However, the error message was changed.
error[E0308]: mismatched types==================================> ] 128/137: rustc_mir
--> src/librustc_mir/const_eval.rs:657:21
|
657 | v
| ^ expected (), found enum `rustc::mir::interpret::ErrorHandled`
|
= note: expected type `()`
found type `rustc::mir::interpret::ErrorHandled`
related code is here:
if tcx.is_static(def_id).is_some() {
// Ensure that if the above error was either `TooGeneric` or `Reported`
// an error must be reported.
let reported_err = tcx.sess.track_errors(|| {
err.report_as_error(ecx.tcx,
"could not evaluate static initializer")
});
match reported_err {
Ok(v) => {
tcx.sess.delay_span_bug(err.span,
&format!("static eval failure did not emit an error: {:#?}",
v));
v
},
Err(ErrorReported) => Err(ErrorHandled::Reported),
}
reported_err
}
I tried to compile by changing value in the Ok
or Err
arm, but still failed, hmm... When ()
are returned in the Ok
and Err
, another error was occured.
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 match isn't returning the values written in it, because you have a trailing expression (reported_err
) afterwards. Removing that will make the match
the trailing expression
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 got it, modified and pushed.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@oli-obk Is there anything I can do? |
@JohnTitor You might need to rebase on master. Now we have 384 commits in this PR. |
@lzutao yes, I'll fix. |
@oli-obk EDIT: I cleaned up commit log successfully, I'm sorry for confusing you. |
4dc0279
to
169c320
Compare
76d457a
to
6c8e3a5
Compare
@bors r+ Thanks for doing this and seeing this through all the changes! |
📌 Commit 0778847 has been approved by |
Use `track_errors` instead of hand rolling Fixes rust-lang#59215 r? @oli-obk
Rollup of 11 pull requests Successful merges: - #58019 (Combine all builtin late lints and make lint checking parallel) - #59358 (Use `track_errors` instead of hand rolling) - #59394 (warn -> deny duplicate match bindings) - #59401 (bootstrap: build crates under libtest with -Z emit-stack-sizes) - #59423 (Visit path in `walk_mac`) - #59468 (musl: build toolchain libs with -fPIC) - #59476 (Use `SmallVec` in `TokenStreamBuilder`.) - #59496 (Remove unnecessary with_globals calls) - #59498 (Use 'write_all' instead of 'write' in example code) - #59503 (Stablize {f32,f64}::copysign().) - #59511 (Fix missed fn rename in #59284) Failed merges: r? @ghost
Rollup of 11 pull requests Successful merges: - #58019 (Combine all builtin late lints and make lint checking parallel) - #59358 (Use `track_errors` instead of hand rolling) - #59394 (warn -> deny duplicate match bindings) - #59401 (bootstrap: build crates under libtest with -Z emit-stack-sizes) - #59423 (Visit path in `walk_mac`) - #59468 (musl: build toolchain libs with -fPIC) - #59476 (Use `SmallVec` in `TokenStreamBuilder`.) - #59496 (Remove unnecessary with_globals calls) - #59498 (Use 'write_all' instead of 'write' in example code) - #59503 (Stablize {f32,f64}::copysign().) - #59511 (Fix missed fn rename in #59284) Failed merges: r? @ghost
Fixes #59215
r? @oli-obk