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

Implement O(1)-time Iterator::nth for Range*, and slim the Step trait #43077

Merged
merged 7 commits into from
Jul 8, 2017

Conversation

SimonSapin
Copy link
Contributor

@SimonSapin SimonSapin commented Jul 5, 2017

Fixes #43064.
Fixes part of #39975.
Fixes items 1 and 3 of #42168.
CC #27741.

I think #42310 and #43012 should not have landed without the nth part of this PR, but oh well.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.


#[inline]
fn add_n(&self, n: usize) -> Option<Self> {
// FIXME: use faillable conversions when they exist
Copy link
Contributor

Choose a reason for hiding this comment

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

Fallible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@kennytm
Copy link
Member

kennytm commented Jul 6, 2017

A test case needs to be updated.

[00:40:46] ---- [compile-fail] compile-fail/range-1.rs stdout ----
[00:40:46] 	
[00:40:46] error: /checkout/src/test/compile-fail/range-1.rs:19: expected error not found: `for<'a> &'a bool: std::ops::Add` is not satisfied

@SimonSapin
Copy link
Contributor Author

Test updated, thanks for pointing this out.

@kennytm
Copy link
Member

kennytm commented Jul 6, 2017

Need to update run-pass/impl-trait/example-calendar.rs too 😂

Error report
[00:52:28] ---- [run-pass] run-pass/impl-trait/example-calendar.rs stdout ----
[00:52:28] 	
[00:52:28] error: compilation failed!
[00:52:28] status: exit code: 101
[00:52:28] command: /checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc /checkout/src/test/run-pass/impl-trait/example-calendar.rs -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass --target=x86_64-unknown-linux-gnu -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/impl-trait/example-calendar.stage2-x86_64-unknown-linux-gnu.run-pass.libaux -C prefer-dynamic -o /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-pass/impl-trait/example-calendar.stage2-x86_64-unknown-linux-gnu -Crpath -O -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers
[00:52:28] stdout:
[00:52:28] ------------------------------------------
[00:52:28] 
[00:52:28] ------------------------------------------
[00:52:28] stderr:
[00:52:28] ------------------------------------------
[00:52:28] error[E0407]: method `step` is not a member of trait `std::iter::Step`
[00:52:28]    --> /checkout/src/test/run-pass/impl-trait/example-calendar.rs:165:5
[00:52:28]     |
[00:52:28] 165 | /     fn step(&self, by: &Self) -> Option<Self> {
[00:52:28] 166 | |         Some(self + by)
[00:52:28] 167 | |     }
[00:52:28]     | |_____^ not a member of trait `std::iter::Step`
[00:52:28] 
[00:52:28] error[E0407]: method `steps_between_by_one` is not a member of trait `std::iter::Step`
[00:52:28]    --> /checkout/src/test/run-pass/impl-trait/example-calendar.rs:173:5
[00:52:28]     |
[00:52:28] 173 | /     fn steps_between_by_one(_: &Self, _: &Self) -> Option<usize> {
[00:52:28] 174 | |         unimplemented!()
[00:52:28] 175 | |     }
[00:52:28]     | |_____^ not a member of trait `std::iter::Step`
[00:52:28] 
[00:52:28] error[E0407]: method `is_negative` is not a member of trait `std::iter::Step`
[00:52:28]    --> /checkout/src/test/run-pass/impl-trait/example-calendar.rs:177:5
[00:52:28]     |
[00:52:28] 177 | /     fn is_negative(&self) -> bool {
[00:52:28] 178 | |         false
[00:52:28] 179 | |     }
[00:52:28]     | |_____^ not a member of trait `std::iter::Step`
[00:52:28] 
[00:52:28] error[E0050]: method `steps_between` has 3 parameters but the declaration in trait `std::iter::Step::steps_between` has 2
[00:52:28]    --> /checkout/src/test/run-pass/impl-trait/example-calendar.rs:169:45
[00:52:28]     |
[00:52:28] 169 |     fn steps_between(_: &Self, _: &Self, _: &Self) -> Option<usize> {
[00:52:28]     |                                             ^^^^^ expected 2 parameters, found 3
[00:52:28]     |
[00:52:28]     = note: `steps_between` from trait: `fn(&Self, &Self) -> std::option::Option<usize>`
[00:52:28] 
[00:52:28] error[E0046]: not all trait items implemented, missing: `add_n`
[00:52:28]    --> /checkout/src/test/run-pass/impl-trait/example-calendar.rs:164:1
[00:52:28]     |
[00:52:28] 164 | / impl std::iter::Step for NaiveDate {
[00:52:28] 165 | |     fn step(&self, by: &Self) -> Option<Self> {
[00:52:28] 166 | |         Some(self + by)
[00:52:28] 167 | |     }
[00:52:28] ...   |
[00:52:28] 195 | |     }
[00:52:28] 196 | | }
[00:52:28]     | |_^ missing `add_n` in implementation
[00:52:28]     |
[00:52:28]     = note: `add_n` from trait: `fn(&Self, usize) -> std::option::Option<Self>`
[00:52:28] 
[00:52:28] error: aborting due to 5 previous errors
[00:52:28] 
[00:52:28] 
[00:52:28] ------------------------------------------
[00:52:28] 
[00:52:28] thread '[run-pass] run-pass/impl-trait/example-calendar.rs' panicked at 'explicit panic', /checkout/src/tools/compiletest/src/runtest.rs:2473:8
[00:52:28] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[00:52:28] 
[00:52:28] 
[00:52:28] failures:
[00:52:28]     [run-pass] run-pass/impl-trait/example-calendar.rs

@SimonSapin
Copy link
Contributor Author

Removed the i128/u128 changes as I suspect they were buggy. I’ll look into that separately in another PR.

@alexcrichton
Copy link
Member

Thanks! Could you be sure to add some tests for the nth overrides here as well?

@alexcrichton alexcrichton added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 6, 2017
@SimonSapin
Copy link
Contributor Author

Done, in a new commit.

@alexcrichton
Copy link
Member

@bors: r+

cc @scottmcm

@bors
Copy link
Contributor

bors commented Jul 7, 2017

📌 Commit 4e28949 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jul 8, 2017

🔒 Merge conflict

@eddyb
Copy link
Member

eddyb commented Jul 8, 2017

@bors r=alexcrichton

@bors
Copy link
Contributor

bors commented Jul 8, 2017

📌 Commit e9a61ee has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jul 8, 2017

⌛ Testing commit e9a61ee with merge 4d4d76c...

bors added a commit that referenced this pull request Jul 8, 2017
Implement O(1)-time Iterator::nth for Range*, and slim the Step trait

Fixes #43064.
Fixes part of #39975.
Fixes items 1 <s>and 3</s> of #42168.
CC #27741.

I think #42310 and #43012 should not have landed without the `nth` part of this PR, but oh well.
@bors
Copy link
Contributor

bors commented Jul 8, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 4d4d76c to master...

@bors bors merged commit e9a61ee into rust-lang:master Jul 8, 2017
@SimonSapin SimonSapin deleted the ranges branch July 8, 2017 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants