Skip to content

Rollup of 11 pull requests #29039

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 25 commits into from
Oct 14, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
987560a
Add regression test for #22814
frewsxcv Oct 12, 2015
ed2a11d
require a method callee's type to outlive the call
arielb1 Oct 12, 2015
42e0b8b
Fix Lifetime Elision link in lifetimes.md
corincerami Oct 13, 2015
22dc408
Avoid using getDataLayout, deprecated in LLVM 3.7
sanxiyn Oct 13, 2015
3db5012
rustfmt suggested changes.
Oct 12, 2015
5943af3
Re-running updated rustfmt on liblog.
Oct 13, 2015
94946db
Manually alligned comments.
Oct 13, 2015
1bdf4ad
rustfmt libfmt_macros
mseri Oct 13, 2015
5b8335e
fixups
mseri Oct 13, 2015
12224be
Unhide some code from the Traits section
Seeker14491 Oct 13, 2015
70c70b7
Document the free functions of std::iter
steveklabnik Oct 13, 2015
19a2a76
Rustfmt-ing librustc_bitflags.
Oct 13, 2015
1454b42
Revert "fixups"
mseri Oct 13, 2015
fda2f73
fix link on std::result::Result
rutsky Oct 13, 2015
0e969d2
Rollup merge of #28991 - goyox86:goyox86/rustfmting-liblog-II, r=alex…
Manishearth Oct 14, 2015
8f3e05d
Rollup merge of #29004 - frewsxcv:regression-test-22814, r=alexcrichton
Manishearth Oct 14, 2015
cdefef2
Rollup merge of #29006 - arielb1:callee-outlives-call, r=pnkfelix
Manishearth Oct 14, 2015
5dc2955
Rollup merge of #29013 - chrisccerami:fix_broken_lifetime_elision_lin…
Manishearth Oct 14, 2015
3636c8b
Rollup merge of #29016 - sanxiyn:data-layout, r=alexcrichton
Manishearth Oct 14, 2015
3002662
Rollup merge of #29024 - mseri:patch-1, r=nrc
Manishearth Oct 14, 2015
570756f
Rollup merge of #29028 - Seeker14491:patch-1, r=Manishearth
Manishearth Oct 14, 2015
cdd8ed2
Rollup merge of #29029 - steveklabnik:iter_function_docs, r=alexcrichton
Manishearth Oct 14, 2015
36a597c
Rollup merge of #29032 - goyox86:goyox86/rusfmting-librustc_bitflags,…
Manishearth Oct 14, 2015
b330df2
Rollup merge of #29035 - rutsky:patch-6, r=steveklabnik
Manishearth Oct 14, 2015
66b58d1
fix tidy
Manishearth Oct 14, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/doc/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1435,11 +1435,11 @@ struct Foo;

trait Shape { fn area(&self) -> f64; }
trait Circle : Shape { fn radius(&self) -> f64; }
# impl Shape for Foo {
# fn area(&self) -> f64 {
# 0.0
# }
# }
impl Shape for Foo {
fn area(&self) -> f64 {
0.0
}
}
impl Circle for Foo {
fn radius(&self) -> f64 {
println!("calling area: {}", self.area());
Expand Down
2 changes: 1 addition & 1 deletion src/doc/trpl/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ associated with it, but the compiler lets you elide (i.e. omit, see
["Lifetime Elision"][lifetime-elision] below) them in common cases.
Before we get to that, though, let’s break the explicit example down:

[lifetime-elision]: #user-content-lifetime-elision
[lifetime-elision]: #lifetime-elision

```rust,ignore
fn bar<'a>(...)
Expand Down
110 changes: 109 additions & 1 deletion src/libcore/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3032,7 +3032,52 @@ impl<A: Clone> DoubleEndedIterator for Repeat<A> {
fn next_back(&mut self) -> Option<A> { Some(self.element.clone()) }
}

/// Creates a new iterator that endlessly repeats the element `elt`.
/// Creates a new iterator that endlessly repeats a single element.
///
/// The `repeat()` function repeats a single value over and over and over and
/// over and over and 🔁.
///
/// Infinite iterators like `repeat()` are often used with adapters like
/// [`take()`], in order to make them finite.
///
/// [`take()`]: trait.Iterator.html#method.take
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::iter;
///
/// // the number four 4ever:
/// let mut fours = iter::repeat(4);
///
/// assert_eq!(Some(4), fours.next());
/// assert_eq!(Some(4), fours.next());
/// assert_eq!(Some(4), fours.next());
/// assert_eq!(Some(4), fours.next());
/// assert_eq!(Some(4), fours.next());
///
/// // yup, still four
/// assert_eq!(Some(4), fours.next());
/// ```
///
/// Going finite with [`take()`]:
///
/// ```
/// use std::iter;
///
/// // that last example was too many fours. Let's only have four fours.
/// let mut four_fours = iter::repeat(4).take(4);
///
/// assert_eq!(Some(4), four_fours.next());
/// assert_eq!(Some(4), four_fours.next());
/// assert_eq!(Some(4), four_fours.next());
/// assert_eq!(Some(4), four_fours.next());
///
/// // ... and now we're done
/// assert_eq!(None, four_fours.next());
/// ```
#[inline]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn repeat<T: Clone>(elt: T) -> Repeat<T> {
Expand Down Expand Up @@ -3089,6 +3134,19 @@ impl<T> Default for Empty<T> {
}

/// Creates an iterator that yields nothing.
///
/// # Exampes
///
/// Basic usage:
///
/// ```
/// use std::iter;
///
/// // this could have been an iterator over i32, but alas, it's just not.
/// let mut nope = iter::empty::<i32>();
///
/// assert_eq!(None, nope.next());
/// ```
#[stable(feature = "iter_empty", since = "1.2.0")]
pub fn empty<T>() -> Empty<T> {
Empty(marker::PhantomData)
Expand Down Expand Up @@ -3129,6 +3187,56 @@ impl<T> ExactSizeIterator for Once<T> {
}

/// Creates an iterator that yields an element exactly once.
///
/// This is commonly used to adapt a single value into a [`chain()`] of other
/// kinds of iteration. Maybe you have an iterator that covers almost
/// everything, but you need an extra special case. Maybe you have a function
/// which works on iterators, but you only need to process one value.
///
/// [`chain()`]: trait.Iterator.html#method.chain
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// use std::iter;
///
/// // one is the loneliest number
/// let mut one = iter::once(1);
///
/// assert_eq!(Some(1), one.next());
///
/// // just one, that's all we get
/// assert_eq!(None, one.next());
/// ```
///
/// Chaining together with another iterator. Let's say that we want to iterate
/// over each file of the `.foo` directory, but also a configuration file,
/// `.foorc`:
///
/// ```no_run
/// use std::iter;
/// use std::fs;
/// use std::path::PathBuf;
///
/// let dirs = fs::read_dir(".foo").unwrap();
///
/// // we need to convert from an iterator of DirEntry-s to an iterator of
/// // PathBufs, so we use map
/// let dirs = dirs.map(|file| file.unwrap().path());
///
/// // now, our iterator just for our config file
/// let config = iter::once(PathBuf::from(".foorc"));
///
/// // chain the two iterators together into one big iterator
/// let files = dirs.chain(config);
///
/// // this will give us all of the files in .foo as well as .foorc
/// for f in files {
/// println!("{:?}", f);
/// }
/// ```
#[stable(feature = "iter_once", since = "1.2.0")]
pub fn once<T>(value: T) -> Once<T> {
Once { inner: Some(value).into_iter() }
Expand Down
Loading