11

More informative error message for E0015 by fee1-dead · Pull Request #90532 · ru...

 3 years ago
source link: https://github.com/rust-lang/rust/pull/90532
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Copy link

Member

Author

fee1-dead commented on Dec 9, 2021

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

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK