Skip to content
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

More informative error message for E0015 #90532

Merged
merged 8 commits into from
Feb 13, 2022

Conversation

fee1-dead
Copy link
Member

@fee1-dead fee1-dead commented Nov 3, 2021

Helps with #92380

@rust-highfive
Copy link
Collaborator

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Nov 3, 2021
@fee1-dead
Copy link
Member Author

fee1-dead commented Nov 3, 2021

r? @oli-obk

@rust-highfive rust-highfive assigned oli-obk and unassigned cjgillot Nov 3, 2021
@fee1-dead fee1-dead added A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) A-const-fn labels Nov 3, 2021
@fee1-dead
Copy link
Member Author

cc @rust-lang/wg-const-eval

@oli-obk
Copy link
Contributor

oli-obk commented Nov 18, 2021

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?

@bors
Copy link
Contributor

bors commented Dec 8, 2021

☔ The latest upstream changes (presumably #91656) made this pull request unmergeable. Please resolve the merge conflicts.

@fee1-dead fee1-dead force-pushed the improve-const-fn-err-msg branch from 2028ed1 to e03cb8e Compare December 9, 2021 17:10
@fee1-dead
Copy link
Member Author

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 {
   |                                       ++++++++++++++++++++++++++++

@camelid camelid added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 14, 2021
@fee1-dead fee1-dead force-pushed the improve-const-fn-err-msg branch from e03cb8e to c17fda7 Compare December 29, 2021 08:29
@fee1-dead fee1-dead marked this pull request as ready for review December 29, 2021 09:07
@oli-obk
Copy link
Contributor

oli-obk commented Jan 27, 2022

@bors r+

@bors
Copy link
Contributor

bors commented Jan 27, 2022

📌 Commit ea0f26a has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 27, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 28, 2022
… r=oli-obk

More informative error message for E0015

Helps with rust-lang#92380
@fee1-dead
Copy link
Member Author

@bors r-

failed in a rollup

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 28, 2022
@fee1-dead fee1-dead force-pushed the improve-const-fn-err-msg branch from ea0f26a to 7a01e66 Compare January 28, 2022 11:01
@fee1-dead
Copy link
Member Author

@oli-obk: please review the two new commits. I improved diagnostics even further by reporting the selection error.

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 28, 2022
@oli-obk
Copy link
Contributor

oli-obk commented Jan 28, 2022

Oh that is a great idea and looks great!

@bors r+

@fee1-dead
Copy link
Member Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2022
@bors
Copy link
Contributor

bors commented Feb 12, 2022

☔ The latest upstream changes (presumably #93691) made this pull request unmergeable. Please resolve the merge conflicts.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 12, 2022

r=me after a rebase

@fee1-dead fee1-dead force-pushed the improve-const-fn-err-msg branch from d6f1762 to 88d433e Compare February 12, 2022 08:35
@fee1-dead
Copy link
Member Author

@bors r=oli-obk

@bors
Copy link
Contributor

bors commented Feb 12, 2022

📌 Commit 88d433e has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 12, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 12, 2022
… r=oli-obk

More informative error message for E0015

Helps with rust-lang#92380
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 13, 2022
…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
@bors bors merged commit 953c4dc into rust-lang:master Feb 13, 2022
@rustbot rustbot added this to the 1.60.0 milestone Feb 13, 2022
@fee1-dead fee1-dead deleted the improve-const-fn-err-msg branch February 22, 2022 00:21
bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 3, 2024
…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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-const-eval Area: Constant evaluation, covers all const contexts (static, const fn, ...) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants