-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for start
, end
and new
methods of RangeInclusive
#49022
Comments
Two important points here:
As I've said before, the optimal choice here would be to only have the range types be |
Stabilize inclusive range (`..=`) Stabilize the followings: * `inclusive_range` — The `std::ops::RangeInclusive` and `std::ops::RangeInclusiveTo` types, except its fields (tracked by #49022 separately). * `inclusive_range_syntax` — The `a..=b` and `..=b` expression syntax * `dotdoteq_in_patterns` — Using `a..=b` in a pattern cc #28237 r? @rust-lang/lang
The libs team discussed this and the consensus was to make all fields private, provide accessor methods, and add a boolean field to implement iteration in a way that hopefully optimizes better. impl<Idx> RangeInclusive<Idx> {
pub fn start(&self) -> &Idx {…}
pub fn end(&self) -> &Idx {…}
} If someone has a use case for moving bounds out, they should request something like @rfcbot fcp merge |
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
What exact this this FCPing? It feels odd that the last two times the class was modified it was via RFC, but this time it's just a "hopefully", not even a PR. |
This is not making again deep changes to the data structure or syntax, only picking one of two already-proposed alternatives. And the more conservative one, since methods can keep working even if the internal structure changes. |
Simply making the fields private will break lowering of
Therefore |
I’d be fine with |
It needs a special case in https://github.com/rust-lang/rust/blob/56714acc5eb0687ed9a7566fdebe5528657fc5b/src/librustc/hir/lowering.rs#L3082 for the |
I'm not sure that a doc(hidden) perma-unstable function is better than doc(hidden) perma-unstable fields. |
Why not stabilize that function? Other range types can be created as struct literals in addition to the dedicated syntax. |
I agree with @SimonSapin, it seems reasonable to have a stable constructor for the type. |
start
and end
fields of RangeInclusivestart
, end
and new
methods of RangeInclusive
While i think those methods are fine, i believe (at least) the constructor should be const fn... |
What advantage does the |
@scottmcm There is no advantage using the method.
The question is only whether we want to eventually stabilize |
@kennytm Fair enough, makes sense if the goal is private fields. A thought, since I don't know what was discussed: could the struct be |
@scottmcm This will allow mutating |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
Introduce RangeInclusive::{new, start, end} methods and make the fields private. cc #49022
This makes it very difficult/impossible when
I hereby request |
Adding |
@SimonSapin done! #50574 |
…SimonSapin add fn `into_inner(self) -> (Idx, Idx)` to RangeInclusive (rust-lang#49022) adds `into_inner(self) -> (Idx, Idx)` to RangeInclusive rust-lang#49022 (comment)
…SimonSapin add fn `into_inner(self) -> (Idx, Idx)` to RangeInclusive (rust-lang#49022) adds `into_inner(self) -> (Idx, Idx)` to RangeInclusive rust-lang#49022 (comment)
Rollup of 18 pull requests Successful merges: - #49423 (Extend tests for RFC1598 (GAT)) - #50010 (Give SliceIndex impls a test suite of girth befitting the implementation (and fix a UTF8 boundary check)) - #50447 (Fix update-references for tests within subdirectories.) - #50514 (Pull in a wasm fix from LLVM upstream) - #50524 (Make DepGraph::previous_work_products immutable) - #50532 (Don't use Lock for heavily accessed CrateMetadata::cnum_map.) - #50538 ( Make CrateNum allocation more thread-safe. ) - #50564 (Inline `Span` methods.) - #50565 (Use SmallVec for DepNodeIndex within dep_graph.) - #50569 (Allow for specifying a linker plugin for cross-language LTO) - #50572 (Clarify in the docs that `mul_add` is not always faster.) - #50574 (add fn `into_inner(self) -> (Idx, Idx)` to RangeInclusive (#49022)) - #50575 (std: Avoid `ptr::copy` if unnecessary in `vec::Drain`) - #50588 (Move "See also" disambiguation links for primitive types to top) - #50590 (Fix tuple struct field spans) - #50591 (Restore RawVec::reserve* documentation) - #50598 (Remove unnecessary mutable borrow and resizing in DepGraph::serialize) - #50606 (Retry when downloading the Docker cache.) Failed merges: - #50161 (added missing implementation hint) - #50558 (Remove all reference to DepGraph::work_products)
…monSapin Stabilise inclusive_range_methods r? @SimonSapin Closes #49022.
Tracking issue for the
start
,end
andnew
methods ofRangeInclusive
.(Originally the tracking issue for rust-lang/rfcs#1980 the
start
andend
fields, but we decided to make the representation private in #49022 (comment))Steps:
Unresolved questions:
Should we want to expose the fields as public (stabilize as is), or simply provide getter methods and don't show the implementation detail (redesign from scratch)?This issue is separated from #28237 since there were vocal oppositions from the community (see #47813) due to performance loss if we commit to the two-field design.
If you want
start
andend
, please use these for now:x.start()
↦x.next().unwrap()
x.end()
↦x.next_back().unwrap()
The text was updated successfully, but these errors were encountered: