-
Notifications
You must be signed in to change notification settings - Fork 13.5k
More informative error message for E0015 #90532
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
More informative error message for E0015 #90532
Conversation
r? @cjgillot (rust-highfive has picked a reviewer for you, use r? to override) |
r? @oli-obk |
cc @rust-lang/wg-const-eval |
It is a bit surprising to users to see things that aren't mentioned in the code, can we get a span that knows that it's expanded code? |
☔ The latest upstream changes (presumably #91656) made this pull request unmergeable. Please resolve the merge conflicts. |
2028ed1
to
e03cb8e
Compare
Note: This is still not ready for review, but I added a lot of cases for desugarings which can help the users. Examples for the current change: error[E0015]: cannot call non-const fn `<[closure@$DIR/issue-28113.rs:4:5: 4:19] as Fn<()>>::call` in constants
--> $DIR/issue-28113.rs:4:5
|
LL | || -> u8 { 5 }()
| ^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants error[E0015]: cannot call non-const fn `Foo::{constant#0}::Foo::<17_usize>::value` in constants
--> $DIR/nested-type.rs:15:5
|
LL | Foo::<17>::value()
| ^^^^^^^^^^^^^^^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants error[E0015]: cannot perform deref coercion on `A` in statics
--> $DIR/issue-25901.rs:4:24
|
LL | static S: &'static B = &A;
| ^^
|
= note: attempting to deref into `B`
note: deref defined here
--> $DIR/issue-25901.rs:10:5
|
LL | type Target = B;
| ^^^^^^^^^^^^^^^^
note: impl defined here, but it is not `const`
--> $DIR/issue-25901.rs:9:1
|
LL | impl Deref for A {
| ^^^^^^^^^^^^^^^^
= note: calls in statics are limited to constant functions, tuple structs and tuple variants error[E0015]: cannot convert `std::ops::Range<i32>` into an iterator in constants
--> $DIR/const-for.rs:5:14
|
LL | for _ in 0..5 {}
| ^^^^
|
note: impl defined here, but it is not `const`
--> $SRC_DIR/core/src/iter/traits/collect.rs:LL:COL
|
LL | impl<I: Iterator> IntoIterator for I {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
error[E0015]: cannot call non-const fn `<std::ops::Range<i32> as Iterator>::next` in constants
--> $DIR/const-for.rs:5:14
|
LL | for _ in 0..5 {}
| ^^^^
|
= note: calls in constants are limited to constant functions, tuple structs and tuple variants error[E0015]: cannot call non-const operator in constant functions
--> $DIR/call-generic-method-fail.rs:5:5
|
LL | *t == *t
| ^^^^^^^^
|
= note: calls in constant functions are limited to constant functions, tuple structs and tuple variants
help: consider further restricting this bound
|
LL | pub const fn equals_self<T: PartialEq + ~const std::cmp::PartialEq>(t: &T) -> bool {
| ++++++++++++++++++++++++++++ |
e03cb8e
to
c17fda7
Compare
@bors r+ |
📌 Commit ea0f26a has been approved by |
… r=oli-obk More informative error message for E0015 Helps with rust-lang#92380
@bors r- failed in a rollup |
ea0f26a
to
7a01e66
Compare
Oh that is a great idea and looks great! @bors r+ |
@rustbot ready |
☔ The latest upstream changes (presumably #93691) made this pull request unmergeable. Please resolve the merge conflicts. |
r=me after a rebase |
d6f1762
to
88d433e
Compare
@bors r=oli-obk |
📌 Commit 88d433e has been approved by |
… r=oli-obk More informative error message for E0015 Helps with rust-lang#92380
…askrgr Rollup of 9 pull requests Successful merges: - rust-lang#89926 (make `Instant::{duration_since, elapsed, sub}` saturating and remove workarounds) - rust-lang#90532 (More informative error message for E0015) - rust-lang#93810 (Improve chalk integration) - rust-lang#93851 (More practical examples for `Option::and_then` & `Result::and_then`) - rust-lang#93885 (bootstrap.py: Suggest disabling download-ci-llvm option if url fails to download) - rust-lang#93886 (Stabilise inherent_ascii_escape (FCP in rust-lang#77174)) - rust-lang#93930 (add link to format_args! when mention it in docs) - rust-lang#93936 (Couple of driver cleanups) - rust-lang#93944 (Don't relabel to a team if there is already a team label) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…leywiser Get rid of HIR const checker As far as I can tell, the HIR const checker was implemented in rust-lang#66170 because we were not able to issue useful const error messages in the MIR const checker. This seems to have changed in the last 5 years, probably due to work like rust-lang#90532. I've tweaked the diagnostics slightly and think the error messages have gotten *better* in fact. Thus I think the HIR const checker has reached the end of its usefulness, and we can retire it. cc `@RalfJung`
Helps with #92380