-
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
cleanup and dedupe CTFE and Miri error reporting #104317
Conversation
The Miri subtree was changed cc @rust-lang/miri Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
This comment has been minimized.
This comment has been minimized.
5618924
to
2068b3b
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
src/test/ui/consts/const-err-late.rs
Outdated
black_box((S::<i32>::FOO, S::<u32>::FOO)); | ||
//~^ ERROR erroneous constant | ||
//~| ERROR erroneous constant |
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 is basically the reason the sometimes-duplicate error was added. Without it, it becomes unclear what caused the 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.
There is still an error pointing at FOO
. But the problem is the missing instantiation site?
This is a general problem with our const-eval errors -- they don't show where the const was used. Not sure what the best way is to add that information. After all the query is only evaluated once, without knowing the use sites. A separate lint is kind of a hack. Making this part of const_prop_lint is also a hack, this is an entirely separate concern. (Seems fine to keep it there I guess but there should be a comment explaining all this.)
2068b3b
to
bcb08fb
Compare
All right, attempt #2. :D |
| | ||
LL | const CONST: usize = <&Self>::CONST; | ||
| ^^^^^^^^^^^^^^ | ||
|
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 is strange, the build actually succeeds despite this error...
This comment has been minimized.
This comment has been minimized.
bcb08fb
to
e58fdfc
Compare
This comment has been minimized.
This comment has been minimized.
err.report_as_error(tcx, "erroneous constant used"); | ||
None | ||
let res = self.use_ecx(source_info, |this| this.ecx.const_to_op(&c.literal, None)); | ||
if res.is_none() { |
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.
we do need the error to avoid emitting the note in case of TooGeneric and similar "nonfatal const prop failures"
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.
Urgh but that's a terrible abstraction violation. :/
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.
it's what report_as_error
was doing before. So you could add a maybe_report_erroneous_const()
method to the error type and call it where we called report_as_error
before
e58fdfc
to
97068b6
Compare
I think what we really want is a const_eval query where we pass in a span that points to where the constant is used, so that the error message can incorporate that. Unfortunately we cannot do this on the query level, because then evaluating the same constant at different locations would re-evaluate the constant each time since an input changes. So the 2nd best thing I can think of is some function that wraps the query. It first calls the query and then if that errors also emits a span for the usage location. I don't quite understand how we propagate error information out of the query though... looks like all we get there is So maybe |
This comment has been minimized.
This comment has been minimized.
We could do that by having an |
Hm that sounds like it would make the error code more complicated again because it'd have to suppress the error the first time around. I'll leave that to later, feel free to open an issue tracking that -- it's a nice idea! For now I think I am going with the 2nd variant I described above. |
97068b6
to
30e095d
Compare
30e095d
to
e7d9981
Compare
--> $DIR/const-err-late.rs:19:16 | ||
| | ||
LL | black_box((S::<i32>::FOO, S::<u32>::FOO)); | ||
| ^^^^^^^^^^^^^ |
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 don't know why errors are shown multiple times. But in production we deduplicate so users should see this only once.
@bors r+ |
@bors r+ |
📌 Commit e7d9981eb83cdc7b6a2dc33194e016d99e7ef34b has been approved by It is now in the queue for this repository. |
☔ The latest upstream changes (presumably #104054) made this pull request unmergeable. Please resolve the merge conflicts. |
8cb93db
to
5787421
Compare
5787421
to
1115ec6
Compare
@bors r=oli-obk |
@bors rollup=maybe |
…li-obk cleanup and dedupe CTFE and Miri error reporting It looks like most of the time, this error raised from const_prop_lint is just redundant -- it duplicates the error reported when evaluating the const-eval query. This lets us make `ConstEvalErr` private to the const_eval module which I think is a good step. The Miri change mostly replaces a `match` by `if let`, and dedupes the "this error is impossible in Miri" checks. r? `@oli-obk` Fixes rust-lang#75461
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#103750 (Fix some misleading target feature aliases) - rust-lang#104137 (Issue error when -C link-self-contained option is used on unsupported platforms) - rust-lang#104317 (cleanup and dedupe CTFE and Miri error reporting) - rust-lang#104335 (Only do parser recovery on retried macro matching) - rust-lang#104394 (various cleanups to try to reduce the use of spans inside method resolution) - rust-lang#104459 (rustdoc: remove unused JS IIFE from main.js) - rust-lang#104462 (rustdoc: remove pointless CSS `.rightside { padding-right: 2px }`) - rust-lang#104466 (rustdoc: remove no-op CSS `#crate-search-div { display: inline-block }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
write!(f, "encountered constants with type errors, stopping evaluation") | ||
write!( | ||
f, | ||
"an error has already been reported elsewhere (this sould not usually be printed)" |
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.
s/sould/should
…li-obk cleanup and dedupe CTFE and Miri error reporting It looks like most of the time, this error raised from const_prop_lint is just redundant -- it duplicates the error reported when evaluating the const-eval query. This lets us make `ConstEvalErr` private to the const_eval module which I think is a good step. The Miri change mostly replaces a `match` by `if let`, and dedupes the "this error is impossible in Miri" checks. r? ``@oli-obk`` Fixes rust-lang#75461
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#103750 (Fix some misleading target feature aliases) - rust-lang#104137 (Issue error when -C link-self-contained option is used on unsupported platforms) - rust-lang#104317 (cleanup and dedupe CTFE and Miri error reporting) - rust-lang#104335 (Only do parser recovery on retried macro matching) - rust-lang#104394 (various cleanups to try to reduce the use of spans inside method resolution) - rust-lang#104459 (rustdoc: remove unused JS IIFE from main.js) - rust-lang#104462 (rustdoc: remove pointless CSS `.rightside { padding-right: 2px }`) - rust-lang#104466 (rustdoc: remove no-op CSS `#crate-search-div { display: inline-block }`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
It looks like most of the time, this error raised from const_prop_lint is just redundant -- it duplicates the error reported when evaluating the const-eval query. This lets us make
ConstEvalErr
private to the const_eval module which I think is a good step.The Miri change mostly replaces a
match
byif let
, and dedupes the "this error is impossible in Miri" checks.r? @oli-obk
Fixes #75461