-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
constify Iterator, take IV
#151281
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?
constify Iterator, take IV
#151281
Conversation
|
Some changes occurred in compiler/rustc_hir/src/attrs cc @jdonszelmann, @JonathanBrouwer Some changes occurred to the CTFE machinery Some changes occurred in compiler/rustc_passes/src/check_attr.rs cc @jdonszelmann, @JonathanBrouwer Some changes occurred in compiler/rustc_attr_parsing |
This comment has been minimized.
This comment has been minimized.
7bbe4b2 to
c068979
Compare
This comment has been minimized.
This comment has been minimized.
c068979 to
672348d
Compare
| /// ``` | ||
| #[inline] | ||
| #[unstable(feature = "iter_next_chunk", issue = "98326")] | ||
| #[rustc_non_const_trait_method] |
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.
Please also update the dev-guide docs to explain the attribute.
|
|
||
| trace!("attempting to call a trait method"); | ||
| let trait_is_const = tcx.is_const_trait(trait_did); | ||
| let is_const = tcx.constness(callee) == hir::Constness::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.
The code looks odd in combination with the comment just above it. The comment says "we can't look at the callee" and then the code proceeds to look at the callee...
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.
Can't determine the actual callee means we're calling Trait::func instead of <T as Trait>::func, here we're just looking at the constness of the trait method, although maybe I can adjust the comment above
|
☔ The latest upstream changes (presumably #151291) made this pull request unmergeable. Please resolve the merge conflicts. |
| rustc_non_const_trait_method, AttributeType::Normal, template!(Word), | ||
| ErrorFollowing, EncodeCrossCrate::No, | ||
| "`#[rustc_non_const_trait_method]` should only used by the standard library to mark trait methods \ | ||
| as non-const to allow large traits to easier transition to 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.
"traits an easier transition" or "traits to transition more easily"
Like its predecessors (#92433, #102225, #106541), this PR allows one to make
Iteratorimplementationsconst, and thus enables the ability to haveforloops inconstcontexts. I've also included constifyingOption as IntoIterator,option::IntoIter as Iteratoras a minimal dogfooding example.But unlike its predecessors, it uses a new attribute (not unsound anymore!) that prevents any
Iteratorextension methods from being called. This is intentionally made minimal for an initial approval, the fun stuff like.fold,Range as Iteratorcould be done later.cc @rust-lang/wg-const-eval, cc @oli-obk to review the compiler parts
cc #92476