-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Split up files with // ignore-tidy-filelength
#75701
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
Closed
alex-griffiths
wants to merge
13
commits into
rust-lang:master
from
alex-griffiths:file-length-cleanup
Closed
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f9c24f
Extrated drain into it's own module.
alex-griffiths b2c02be
Remove tidy file length comment
alex-griffiths c8b09e8
Pull Utf8Error and CharIndices structs into their own modules
alex-griffiths 4a87f4b
Pulled BindingError into it's own module. Fixed references to it.
alex-griffiths 64bca9d
Moved Utf8Error doc comments into the Utf8Error module.
alex-griffiths 04d3d93
Added filelength comment to suppress warning because file is still > …
alex-griffiths cd2770e
Added trailing new lines as well as ran x.py fmt
alex-griffiths acc26d5
Remove needless line
alex-griffiths f564cb6
Removing changes in librustc_resolve as per @petrochenkov's comment
alex-griffiths f7285b0
Added brief module docs for Utf8Errors and CharIndicies. Allowing the…
alex-griffiths 1d3aef4
Fixed incorrect module docs
alex-griffiths 7cc391d
Replaced stable annotation that was accidentally removed.
alex-griffiths 981dac3
Fix failing from_utf8 intra-doc-link
alex-griffiths File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
use core::fmt; | ||
use core::iter::{FusedIterator, TrustedLen}; | ||
use core::mem::{self}; | ||
use core::ptr::{self, NonNull}; | ||
use core::slice; | ||
|
||
use crate::vec::Vec; | ||
|
||
/// A draining iterator for `Vec<T>`. | ||
/// | ||
/// This `struct` is created by [`Vec::drain`]. | ||
#[stable(feature = "drain", since = "1.6.0")] | ||
pub struct Drain<'a, T: 'a> { | ||
/// Index of tail to preserve | ||
pub(super) tail_start: usize, | ||
/// Length of tail | ||
pub(super) tail_len: usize, | ||
/// Current remaining range to remove | ||
pub(super) iter: slice::Iter<'a, T>, | ||
pub(super) vec: NonNull<Vec<T>>, | ||
} | ||
|
||
#[stable(feature = "collection_debug", since = "1.17.0")] | ||
impl<T: fmt::Debug> fmt::Debug for Drain<'_, T> { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
f.debug_tuple("Drain").field(&self.iter.as_slice()).finish() | ||
} | ||
} | ||
|
||
impl<'a, T> Drain<'a, T> { | ||
/// Returns the remaining items of this iterator as a slice. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ``` | ||
/// let mut vec = vec!['a', 'b', 'c']; | ||
/// let mut drain = vec.drain(..); | ||
/// assert_eq!(drain.as_slice(), &['a', 'b', 'c']); | ||
/// let _ = drain.next().unwrap(); | ||
/// assert_eq!(drain.as_slice(), &['b', 'c']); | ||
/// ``` | ||
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")] | ||
pub fn as_slice(&self) -> &[T] { | ||
self.iter.as_slice() | ||
} | ||
} | ||
|
||
#[stable(feature = "vec_drain_as_slice", since = "1.46.0")] | ||
impl<'a, T> AsRef<[T]> for Drain<'a, T> { | ||
fn as_ref(&self) -> &[T] { | ||
self.as_slice() | ||
} | ||
} | ||
|
||
#[stable(feature = "drain", since = "1.6.0")] | ||
unsafe impl<T: Sync> Sync for Drain<'_, T> {} | ||
#[stable(feature = "drain", since = "1.6.0")] | ||
unsafe impl<T: Send> Send for Drain<'_, T> {} | ||
|
||
#[stable(feature = "drain", since = "1.6.0")] | ||
impl<T> Iterator for Drain<'_, T> { | ||
type Item = T; | ||
|
||
#[inline] | ||
fn next(&mut self) -> Option<T> { | ||
self.iter.next().map(|elt| unsafe { ptr::read(elt as *const _) }) | ||
} | ||
|
||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.iter.size_hint() | ||
} | ||
} | ||
|
||
#[stable(feature = "drain", since = "1.6.0")] | ||
impl<T> DoubleEndedIterator for Drain<'_, T> { | ||
#[inline] | ||
fn next_back(&mut self) -> Option<T> { | ||
self.iter.next_back().map(|elt| unsafe { ptr::read(elt as *const _) }) | ||
} | ||
} | ||
|
||
#[stable(feature = "drain", since = "1.6.0")] | ||
impl<T> Drop for Drain<'_, T> { | ||
fn drop(&mut self) { | ||
/// Continues dropping the remaining elements in the `Drain`, then moves back the | ||
/// un-`Drain`ed elements to restore the original `Vec`. | ||
struct DropGuard<'r, 'a, T>(&'r mut Drain<'a, T>); | ||
|
||
impl<'r, 'a, T> Drop for DropGuard<'r, 'a, T> { | ||
fn drop(&mut self) { | ||
// Continue the same loop we have below. If the loop already finished, this does | ||
// nothing. | ||
self.0.for_each(drop); | ||
|
||
if self.0.tail_len > 0 { | ||
unsafe { | ||
let source_vec = self.0.vec.as_mut(); | ||
// memmove back untouched tail, update to new length | ||
let start = source_vec.len(); | ||
let tail = self.0.tail_start; | ||
if tail != start { | ||
let src = source_vec.as_ptr().add(tail); | ||
let dst = source_vec.as_mut_ptr().add(start); | ||
ptr::copy(src, dst, self.0.tail_len); | ||
} | ||
source_vec.set_len(start + self.0.tail_len); | ||
} | ||
} | ||
} | ||
} | ||
|
||
// exhaust self first | ||
while let Some(item) = self.next() { | ||
let guard = DropGuard(self); | ||
drop(item); | ||
mem::forget(guard); | ||
} | ||
|
||
// Drop a `DropGuard` to move back the non-drained tail of `self`. | ||
DropGuard(self); | ||
} | ||
} | ||
|
||
#[stable(feature = "drain", since = "1.6.0")] | ||
impl<T> ExactSizeIterator for Drain<'_, T> { | ||
fn is_empty(&self) -> bool { | ||
self.iter.is_empty() | ||
} | ||
} | ||
|
||
#[unstable(feature = "trusted_len", issue = "37572")] | ||
unsafe impl<T> TrustedLen for Drain<'_, T> {} | ||
|
||
#[stable(feature = "fused", since = "1.26.0")] | ||
impl<T> FusedIterator for Drain<'_, T> {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//! A module for working with iterators and string slices. | ||
use crate::iter::FusedIterator; | ||
use crate::str::Chars; | ||
|
||
/// An iterator over the [`char`]s of a string slice, and their positions. | ||
/// | ||
/// This struct is created by the [`char_indices`] method on [`str`]. | ||
/// See its documentation for more. | ||
/// | ||
/// [`char_indices`]: str::char_indices | ||
#[derive(Clone, Debug)] | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
pub struct CharIndices<'a> { | ||
pub(super) front_offset: usize, | ||
pub(super) iter: Chars<'a>, | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a> Iterator for CharIndices<'a> { | ||
type Item = (usize, char); | ||
|
||
#[inline] | ||
fn next(&mut self) -> Option<(usize, char)> { | ||
let pre_len = self.iter.iter.len(); | ||
match self.iter.next() { | ||
None => None, | ||
Some(ch) => { | ||
let index = self.front_offset; | ||
let len = self.iter.iter.len(); | ||
self.front_offset += pre_len - len; | ||
Some((index, ch)) | ||
} | ||
} | ||
} | ||
|
||
#[inline] | ||
fn count(self) -> usize { | ||
self.iter.count() | ||
} | ||
|
||
#[inline] | ||
fn size_hint(&self) -> (usize, Option<usize>) { | ||
self.iter.size_hint() | ||
} | ||
|
||
#[inline] | ||
fn last(mut self) -> Option<(usize, char)> { | ||
// No need to go through the entire string. | ||
self.next_back() | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
impl<'a> DoubleEndedIterator for CharIndices<'a> { | ||
#[inline] | ||
fn next_back(&mut self) -> Option<(usize, char)> { | ||
self.iter.next_back().map(|ch| { | ||
let index = self.front_offset + self.iter.iter.len(); | ||
(index, ch) | ||
}) | ||
} | ||
} | ||
|
||
#[stable(feature = "fused", since = "1.26.0")] | ||
impl FusedIterator for CharIndices<'_> {} | ||
|
||
impl<'a> CharIndices<'a> { | ||
/// Views the underlying data as a subslice of the original data. | ||
/// | ||
/// This has the same lifetime as the original slice, and so the | ||
/// iterator can continue to be used while this exists. | ||
#[stable(feature = "iter_to_slice", since = "1.4.0")] | ||
#[inline] | ||
pub fn as_str(&self) -> &'a str { | ||
self.iter.as_str() | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.