Skip to content

Add lifetime bounds on Items and MutItems. #16993

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

Merged
merged 4 commits into from
Oct 3, 2014

Conversation

dschatzberg
Copy link
Contributor

This also required a fix for Vec's MoveItems. This resolves issue #16941

let ptr = self.ptr;
let cap = self.cap;
let begin = self.ptr as *const T;
let end = (self.ptr as uint + self.len()) as *const T;
Copy link
Member

Choose a reason for hiding this comment

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

It may be somewhat important for this to stay as pointers for non-zero sized types, since casting to integers loses optimisation information, e.g.

let end = if mem::size_of::<T>() == 0 {
     (p as uint + self.len()) as *const T
} else {
     p.offset(self.len() as int)
};

I would be very interested in seeing this not reencode the iteration, but I guess this may not be possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the response. I've gone ahead and made the change. My first pass at fixing this issue involved making an UnsafeItems struct which could be used to implement Items, MutItems, and Vec's MoveItems. But on second thought it seemed a bit unnecessary to create a new public struct which had very few uses.

If this is desirable, I'd be happy to implement it that way.

@aturon
Copy link
Member

aturon commented Oct 1, 2014

@huonw is this good to go?

@huonw
Copy link
Member

huonw commented Oct 1, 2014

Can you add a test for move_items specifically, including testing with both zero-sized and non-zero-sized types?

Thanks! (Sorry it's taken so long.)

@dschatzberg
Copy link
Contributor Author

Looking at this now. I assume you want me to rebase to master which causes a few more things to break.

@dschatzberg
Copy link
Contributor Author

I've updated the pull request to work off the latest commits. In the interim - this fix also affected the new btree implementation

alexcrichton added a commit to alexcrichton/rust that referenced this pull request Oct 2, 2014
@bors bors merged commit 49e593c into rust-lang:master Oct 3, 2014
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.

5 participants