-
-
Notifications
You must be signed in to change notification settings - Fork 15.6k
implement const Iterator for Range #156216
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,48 @@ | ||
| error[E0015]: cannot use `for` loop on `std::ops::Range<i32>` in constants | ||
| error[E0658]: cannot use `for` loop on `std::ops::Range<i32>` in constants | ||
| --> $DIR/const-for-feature-gate.rs:4:14 | ||
| | | ||
| LL | for _ in 0..5 {} | ||
| | ^^^^ | ||
| | | ||
| = note: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
| = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information | ||
| = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
|
|
||
| error[E0015]: cannot use `for` loop on `std::ops::Range<i32>` in constants | ||
| error: `IntoIterator` is not yet stable as a const trait | ||
| --> $DIR/const-for-feature-gate.rs:4:14 | ||
| | | ||
| LL | for _ in 0..5 {} | ||
| | ^^^^ | ||
| | | ||
| help: add `#![feature(const_iter)]` to the crate attributes to enable | ||
| | | ||
| LL + #![feature(const_iter)] | ||
| | | ||
|
|
||
| error[E0658]: cannot use `for` loop on `std::ops::Range<i32>` in constants | ||
| --> $DIR/const-for-feature-gate.rs:4:14 | ||
| | | ||
| LL | for _ in 0..5 {} | ||
| | ^^^^ | ||
| | | ||
| = note: calls in constants are limited to constant functions, tuple structs and tuple variants | ||
| = note: see issue #143874 <https://github.com/rust-lang/rust/issues/143874> for more information | ||
| = help: add `#![feature(const_trait_impl)]` to the crate attributes to enable | ||
| = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
|
||
| error: aborting due to 2 previous errors | ||
| error: `Iterator` is not yet stable as a const trait | ||
| --> $DIR/const-for-feature-gate.rs:4:14 | ||
| | | ||
| LL | for _ in 0..5 {} | ||
| | ^^^^ | ||
| | | ||
| help: add `#![feature(const_iter)]` to the crate attributes to enable | ||
| | | ||
| LL + #![feature(const_iter)] | ||
| | | ||
|
|
||
| error: aborting due to 4 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0015`. | ||
| For more information about this error, try `rustc --explain E0658`. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,8 @@ | ||
| #![feature(const_for)] | ||
| //@ check-pass | ||
| #![feature(const_trait_impl,const_iter,const_for)] | ||
|
|
||
| const _: () = { | ||
| for _ in 0..5 {} | ||
| //~^ ERROR cannot use `for` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also appears to test specifically for |
||
| //~| ERROR cannot use `for` | ||
| }; | ||
|
|
||
| fn main() {} | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| //@ check-pass | ||
| #![feature(const_iter,const_trait_impl)] | ||
|
|
||
| const _: () = loop { break (); }; | ||
|
|
||
| static FOO: i32 = loop { break 4; }; | ||
|
|
@@ -51,14 +54,10 @@ const _: i32 = { | |
| let mut x = 0; | ||
|
|
||
| for i in 0..4 { | ||
| //~^ ERROR: cannot use `for` | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to clearly test loops in const context |
||
| //~| ERROR: cannot use `for` | ||
| x += i; | ||
| } | ||
|
|
||
| for i in 0..4 { | ||
| //~^ ERROR: cannot use `for` | ||
| //~| ERROR: cannot use `for` | ||
| x += i; | ||
| } | ||
|
|
||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
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.
So unfortunately, due to this, I think we're going to have to block this on the discussion in #148200.
Added T-types label as well and will update the Zulip thread. Hopefully we do resolve that discussion soon, though.
View changes since the review
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.
Makes sense. I don't think there is any sensible resolution in which this code is problematic (particularly because we want some version of this PR to work), but better to have working solution first
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.
Yeah, to be clear we want to be able to do stuff like this, but there's been some discussion over making sure it works properly.