-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Remove &[T] from vec_deque::Drain #101299
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
05fffed
to
2ef7b98
Compare
} | ||
|
||
impl<'a, T> Iter<'a, T> { | ||
pub(super) fn new(ring: &'a [MaybeUninit<T>], tail: usize, head: usize) -> Self { | ||
Iter { ring, tail, head } | ||
Iter { | ||
ring: ptr::slice_from_raw_parts(ring.as_ptr().cast(), ring.len()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could also be written as ring as *const [MaybeUninit<T>] as *const [T]
. Not sure if the as
cast is better than a ptr::slice_from_raw_parts
call, but in both cases I feel like there should be a better way to write this.
2ef7b98
to
f698c27
Compare
This comment has been minimized.
This comment has been minimized.
848f7cd
to
366b647
Compare
r? libs |
} | ||
} | ||
|
||
unsafe fn ring(&self) -> &'a [MaybeUninit<T>] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very long-lived reference, is that needed?
In particular, the entire reason this PR is made is that this lifetime is a lie -- when Iter
is used in Drain
and Drain
is dropped, the memory will be deallocated while 'a
is still ongoing. That should probably be documented somewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I can tell, we need to get a &'a T
by some means in order to implement all the iterator methods, so we're stuck with this hazard.
Let's see if I can do something to just Drain
to fix the problem there...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The second commit in this PR now reverts the first one and modifies just the Drain
struct. Do you think that approach is more satisfying?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't checked the details but I do think that reusing Iter
was kind of a hack so this seems cleaner to me indeed.
Let's see what the libs reviewer says.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems fine to me.
366b647
to
54684c4
Compare
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
Thanks. @bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (59e7a30): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
Footnotes |
Fixes #60076
I don't know what the right approach is here. There were a few suggestions in the issue, and they all seem a bit thorny to implement. So I just picked one that was kind of familiar.