-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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 Range[Inclusive]::is_empty (feature range_is_empty) #48111
Comments
This method is really hard to use. In the program:
Rust 1.31 in the playground (which is 2018 Edition) complains:
This arises without any imports in scope, just the prelude. Using
does work, but is longer than |
@jimblandy The ambiguity happens only because you haven't enabled the relevant features. Assuming both #![feature(exact_size_is_empty, range_is_empty)]
use std::iter::ExactSizeIterator;
fn main() {
println!("{:?}", (0..0).is_empty());
} |
I believe that's an artifact of both being unstable, @jimblandy. With either or both feature gates enabled, it compiles fine (with a future warning if only the ESI gate is active): #![feature(range_is_empty)]
#![feature(exact_size_is_empty)]
fn main() {
println!("{:?}", (0..0).is_empty());
} Edit: doh, 20 seconds late 😆 |
Okay, thanks for the explanation. I guess I'm still surprised that the error message is about the ambiguity, not the use of unstable features; is it that rustc can't decide which unstable feature's use to complain about? ^^;; |
Are there any outstanding concerns to be resolved before stabilization or is the issue just waiting for someone to send a pull request? |
I have no idea why a method like this would be unstable, and the reason provided is kind of old, contradicting itself. Also, why is it coded like this? Isn't it better to just have this? |
@raindev I know of no outstanding concerns, though of course such a stabilization PR would need a T-libs FCP. There was a question about whether it should use
@yankana because those two are only equivalent for |
len_zero: skip ranges if feature `range_is_empty` is not enabled If the feature is not enabled, calling `is_empty()` on a range is ambiguous. Moreover, the two possible resolutions are unstable methods, one inherent to the range and the other being part of the `ExactSizeIterator` trait. Since `len_zero` only checks for existing `is_empty()` inherent methods, we only take into account the `range_is_empty` feature. Related: rust-lang/rust#48111 (comment) changelog: len_zero: avoid linting ranges without #![feature(range_is_empty)] Fixes: #3807
len_zero: skip ranges if feature `range_is_empty` is not enabled If the feature is not enabled, calling `is_empty()` on a range is ambiguous. Moreover, the two possible resolutions are unstable methods, one inherent to the range and the other being part of the `ExactSizeIterator` trait. Since `len_zero` only checks for existing `is_empty()` inherent methods, we only take into account the `range_is_empty` feature. Related: rust-lang/rust#48111 (comment) changelog: len_zero: avoid linting ranges without #![feature(range_is_empty)] Fixes: rust-lang#3807
To anyone following this tracking issue, I've made a PR to request stabilization of these methods: #75132 |
These methods are a clear way to check for empty ranges without the restrictions of
ExactSizeIterator
.Merged as unstable on 2018-02-15 in PR at #48087
The text was updated successfully, but these errors were encountered: