Skip to content
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

Add core::ops::Range*::contains() as per rust-lang/rust#32311 #32396

Merged
merged 1 commit into from
Mar 25, 2016

Conversation

nodakai
Copy link
Contributor

@nodakai nodakai commented Mar 21, 2016

No description provided.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@nodakai
Copy link
Contributor Author

nodakai commented Mar 21, 2016

I wish to have

impl<Idx: PartialOrd<Idx>> RangeFull {
  fn contains(&self, _: Idx) -> bool { true }
}

so that

(..).contains(42) // true
(..).contains("forty-two".to_string()) // true

but it seems like it's not allowed:

error: the type parameter `Idx` is not constrained by the impl trait, self type, or predicates [E0207]

@alexcrichton
Copy link
Member

Travis failures look non-spurious:

---- ops::RangeInclusive_0 stdout ----
        <anon>:5:16: 5:19 error: unresolved name `arr` [E0425]
<anon>:5     assert_eq!(arr[ ...2], [0,1,2  ]);
                        ^~~
<anon>:5:5: 5:39 note: in this expansion of assert_eq! (defined in <std macros>)
<std macros>:5:8: 5:18 error: the type of this value must be known in this context
<std macros>:5 if ! ( * left_val == * right_val ) {
                      ^~~~~~~~~~
<anon>:5:5: 5:39 note: in this expansion of assert_eq! (defined in <std macros>)
<std macros>:5:22: 5:33 error: the type of this value must be known in this context
<std macros>:5 if ! ( * left_val == * right_val ) {
                                    ^~~~~~~~~~~
<anon>:5:5: 5:39 note: in this expansion of assert_eq! (defined in <std macros>)
error: aborting due to previous error(s)
thread 'ops::RangeInclusive_0' panicked at 'Box<Any>', src/librustc/session/mod.rs:153
note: Run with `RUST_BACKTRACE=1` for a backtrace.

---- ops::RangeToInclusive_0 stdout ----
        <anon>:4:5: 4:13 error: unresolved name `Examples` [E0425]
<anon>:4     Examples
             ^~~~~~~~
error: aborting due to previous error(s)
thread 'ops::RangeToInclusive_0' panicked at 'Box<Any>', src/librustc/session/mod.rs:153

---- ops::RangeToInclusive_1 stdout ----
        <anon>:5:21: 5:25 error: inclusive range syntax is experimental (see issue #28237)
<anon>:5     assert_eq!(arr[ ...2], [0,1,2  ]);  // RangeToInclusive
                             ^~~~
<anon>:5:5: 5:39 note: in this expansion of assert_eq! (defined in <std macros>)
<anon>:5:21: 5:25 help: add #![feature(inclusive_range_syntax)] to the crate attributes to enable
<anon>:6:20: 6:25 error: inclusive range syntax is experimental (see issue #28237)
<anon>:6     assert_eq!(arr[1...2], [  1,2  ]);
                            ^~~~~
<anon>:6:5: 6:39 note: in this expansion of assert_eq! (defined in <std macros>)
<anon>:6:20: 6:25 help: add #![feature(inclusive_range_syntax)] to the crate attributes to enable
error: aborting due to previous error(s)
thread 'ops::RangeToInclusive_1' panicked at 'Box<Any>', src/librustc/session/mod.rs:153


failures:
    ops::RangeInclusive_0
    ops::RangeToInclusive_0
    ops::RangeToInclusive_1

Also cc @steveklabnik, quite extensive docs! Not sure if they're idiomatic though?

/// ```
/// #![feature(inclusive_range,inclusive_range_syntax,iter_arith)]
/// fn main() {
/// assert_eq!(arr[ ...2], [0,1,2 ]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy/paste error?

@nodakai
Copy link
Contributor Author

nodakai commented Mar 22, 2016

@nodakai nodakai reopened this Mar 22, 2016
@@ -1458,7 +1475,26 @@ impl fmt::Debug for RangeFull {
}
}

/// A (half-open) range which is bounded at both ends.
/// A (half-open) range which is bounded at both ends: { x | start <= x < end }.
/// Use `stard..end` (two dots) for its shorthand.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Signed-off-by: NODA, Kai <nodakai@gmail.com>
@nodakai
Copy link
Contributor Author

nodakai commented Mar 24, 2016

Fixed typo
Changed #[unstable] to impl-wide; not much difference when each impl has a single method.

@durka
Copy link
Contributor

durka commented Mar 24, 2016

Wait does #[unstable] on an impl actually do anything?

@petrochenkov
Copy link
Contributor

@durka

Wait does #[unstable] on an impl actually do anything?

It passes the unstability to all the child items.

@durka
Copy link
Contributor

durka commented Mar 24, 2016

OK, I remembered something about trait impls being insta-stable. But inherent impls are different I guess.

@nodakai
Copy link
Contributor Author

nodakai commented Mar 24, 2016

@alexcrichton
Copy link
Member

@bors: r+ a21c5f2

@bors
Copy link
Contributor

bors commented Mar 25, 2016

⌛ Testing commit a21c5f2 with merge 37e3ac0...

@alexcrichton
Copy link
Member

@bors: retry force

@bors
Copy link
Contributor

bors commented Mar 25, 2016

⌛ Testing commit a21c5f2 with merge 40deb27...

bors added a commit that referenced this pull request Mar 25, 2016
Add core::ops::Range*::contains() as per #32311
@bors bors merged commit a21c5f2 into rust-lang:master Mar 25, 2016
@nodakai nodakai deleted the range-contains branch March 25, 2016 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants