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

Rollup of 11 pull requests #35994

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
e4dd785
Correct formatting docs: fmt::Result != io::Result<()>
Stebalien Aug 20, 2016
f2655e2
Note that formatters should not return spurious errors.
Stebalien Aug 20, 2016
31b7ff4
refactor range examples
matthew-piziak Aug 17, 2016
33560ee
add links to interesting items in `std::ptr` documentation
matthew-piziak Aug 21, 2016
a377adb
Improve Path and PathBuf docs
GuillaumeGomez Aug 18, 2016
c7d5f7e
Rust has type aliases, not typedefs.
Stebalien Aug 23, 2016
b400a43
add `fn main` wrappers to enable Rust Playground "Run" button
matthew-piziak Aug 23, 2016
28f057d
accumulate vector and assert for RangeFrom and RangeInclusive examples
matthew-piziak Aug 17, 2016
ff3a761
add more-evocative examples for `Shl` and `Shr`
matthew-piziak Aug 20, 2016
711333f
add a note that whitespace alignment is nonidiomatic
matthew-piziak Aug 23, 2016
bf22a7a
Updated code sample in chapter on syntax extensions.
regexident Aug 24, 2016
6f93d3c
Make E0094 underline better
kyrias Aug 24, 2016
874a20d
Update E0277 to new error format
0xmohit Aug 25, 2016
905644d
Rename {uint,int} methods to {usize,isize}.
frewsxcv Aug 24, 2016
e4871c4
Update E0453 to new error format
0xmohit Aug 25, 2016
80571b8
Rollup merge of #35758 - matthew-piziak:vec-assert-over-println-remai…
steveklabnik Aug 25, 2016
3c2386b
Rollup merge of #35759 - matthew-piziak:refactor-range-examples, r=st…
steveklabnik Aug 25, 2016
97b7813
Rollup merge of #35786 - GuillaumeGomez:paths_doc, r=steveklabnik
steveklabnik Aug 25, 2016
04a53e5
Rollup merge of #35862 - Stebalien:fmt-docs, r=steveklabnik
steveklabnik Aug 25, 2016
5729fc6
Rollup merge of #35863 - matthew-piziak:shl-example, r=steveklabnik
steveklabnik Aug 25, 2016
8912567
Rollup merge of #35880 - matthew-piziak:ptr-linking, r=steveklabnik
steveklabnik Aug 25, 2016
f8e05a7
Rollup merge of #35962 - regexident:compiler-plugin-docs, r=steveklabnik
steveklabnik Aug 25, 2016
cc1b3d3
Rollup merge of #35977 - frewsxcv:usize-isize, r=eddyb
steveklabnik Aug 25, 2016
e0ddf61
Rollup merge of #35980 - kyrias:E0094-underline, r=jonathandturner
steveklabnik Aug 25, 2016
eaa222d
Rollup merge of #35985 - 0xmohit:pr/error-code-E0277, r=jonathandturner
steveklabnik Aug 25, 2016
c1c6d6c
Rollup merge of #35989 - 0xmohit:pr/error-code-E0453, r=jonathandturner
steveklabnik Aug 25, 2016
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
6 changes: 3 additions & 3 deletions src/doc/book/compiler-plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ extern crate rustc;
extern crate rustc_plugin;

use syntax::parse::token;
use syntax::ast::TokenTree;
use syntax::tokenstream::TokenTree;
use syntax::ext::base::{ExtCtxt, MacResult, DummyResult, MacEager};
use syntax::ext::build::AstBuilder; // trait for expr_usize
use syntax_pos::Span;
use syntax::ext::quote::rt::Span;
use rustc_plugin::Registry;

fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
Expand All @@ -69,7 +69,7 @@ fn expand_rn(cx: &mut ExtCtxt, sp: Span, args: &[TokenTree])
}

let text = match args[0] {
TokenTree::Token(_, token::Ident(s, _)) => s.to_string(),
TokenTree::Token(_, token::Ident(s)) => s.to_string(),
_ => {
cx.span_err(sp, "argument should be a single identifier");
return DummyResult::any(sp);
Expand Down
12 changes: 9 additions & 3 deletions src/libcollections/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,15 @@
//! provides some helper methods.
//!
//! Additionally, the return value of this function is `fmt::Result` which is a
//! typedef to `Result<(), std::io::Error>` (also known as `std::io::Result<()>`).
//! Formatting implementations should ensure that they return errors from `write!`
//! correctly (propagating errors upward).
//! type alias of `Result<(), std::fmt::Error>`. Formatting implementations
//! should ensure that they propagate errors from the `Formatter` (e.g., when
//! calling `write!`) however, they should never return errors spuriously. That
//! is, a formatting implementation must and may only return an error if the
//! passed-in `Formatter` returns an error. This is because, contrary to what
//! the function signature might suggest, string formatting is an infallible
//! operation. This function only returns a result because writing to the
//! underlying stream might fail and it must provide a way to propagate the fact
//! that an error has occurred back up the stack.
//!
//! An example of implementing the formatting traits would look
//! like:
Expand Down
15 changes: 10 additions & 5 deletions src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,20 @@ extern "rust-intrinsic" {
/// trait objects, because they can't be read out onto the stack and
/// dropped normally.
///
/// * It is friendlier to the optimizer to do this over `ptr::read` when
/// dropping manually allocated memory (e.g. when writing Box/Rc/Vec),
/// as the compiler doesn't need to prove that it's sound to elide the
/// copy.
/// * It is friendlier to the optimizer to do this over [`ptr::read`] when
/// dropping manually allocated memory (e.g. when writing
/// [`Box`]/[`Rc`]/[`Vec`]), as the compiler doesn't need to prove that
/// it's sound to elide the copy.
///
/// # Undefined Behavior
///
/// This has all the same safety problems as `ptr::read` with respect to
/// This has all the same safety problems as [`ptr::read`] with respect to
/// invalid pointers, types, and double drops.
///
/// [`ptr::read`]: fn.read.html
/// [`Box`]: ../boxed/struct.Box.html
/// [`Rc`]: ../rc/struct.Rc.html
/// [`Vec`]: ../vec/struct.Vec.html
#[stable(feature = "drop_in_place", since = "1.8.0")]
pub fn drop_in_place<T: ?Sized>(to_drop: *mut T);

Expand Down
32 changes: 10 additions & 22 deletions src/libcore/iter/range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,12 @@ impl<A: Step> ops::RangeFrom<A> {
/// # Examples
///
/// ```
/// # #![feature(step_by)]
///
/// for i in (0u8..).step_by(2).take(10) {
/// println!("{}", i);
/// #![feature(step_by)]
/// fn main() {
/// let result: Vec<_> = (0..).step_by(2).take(5).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
/// }
/// ```
///
/// This prints the first ten even natural integers (0 to 18).
#[unstable(feature = "step_by", reason = "recent addition",
issue = "27741")]
pub fn step_by(self, by: A) -> StepBy<A, Self> {
Expand All @@ -295,8 +293,10 @@ impl<A: Step> ops::Range<A> {
///
/// ```
/// #![feature(step_by)]
/// let result: Vec<_> = (0..10).step_by(2).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
/// fn main() {
/// let result: Vec<_> = (0..10).step_by(2).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
/// }
/// ```
#[unstable(feature = "step_by", reason = "recent addition",
issue = "27741")]
Expand All @@ -319,20 +319,8 @@ impl<A: Step> ops::RangeInclusive<A> {
/// ```
/// #![feature(step_by, inclusive_range_syntax)]
///
/// for i in (0...10).step_by(2) {
/// println!("{}", i);
/// }
/// ```
///
/// This prints:
///
/// ```text
/// 0
/// 2
/// 4
/// 6
/// 8
/// 10
/// let result: Vec<_> = (0...10).step_by(2).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]);
/// ```
#[unstable(feature = "step_by", reason = "recent addition",
issue = "27741")]
Expand Down
164 changes: 126 additions & 38 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,26 @@
//! ```
//!
//! See the documentation for each trait for an example implementation.
//!
//! This example shows the behavior of the various `Range*` structs.
//!
//! ```rust
//! #![feature(inclusive_range_syntax)]
//! fn main() {
//! let arr = [0, 1, 2, 3, 4];
//!
//! assert_eq!(arr[ .. ], [0,1,2,3,4]); // RangeFull
//! assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
//! assert_eq!(arr[1.. ], [ 1,2,3,4]); // RangeFrom
//! assert_eq!(arr[1..3], [ 1,2 ]); // Range
//!
//! assert_eq!(arr[ ...3], [0,1,2,3 ]); // RangeToIncusive
//! assert_eq!(arr[1...3], [ 1,2,3 ]); // RangeInclusive
//! }
//! ```
//!
//! Note: whitespace alignment is not idiomatic Rust. An exception is made in
//! this case to facilitate comparison.

#![stable(feature = "rust1", since = "1.0.0")]

Expand Down Expand Up @@ -969,25 +989,54 @@ bitxor_impl! { bool usize u8 u16 u32 u64 isize i8 i16 i32 i64 }
///
/// # Examples
///
/// A trivial implementation of `Shl`. When `Foo << Foo` happens, it ends up
/// calling `shl`, and therefore, `main` prints `Shifting left!`.
/// An implementation of `Shl` that lifts the `<<` operation on integers to a
/// `Scalar` struct.
///
/// ```
/// use std::ops::Shl;
///
/// struct Foo;
/// #[derive(PartialEq, Debug)]
/// struct Scalar(usize);
///
/// impl Shl<Foo> for Foo {
/// type Output = Foo;
/// impl Shl<Scalar> for Scalar {
/// type Output = Self;
///
/// fn shl(self, _rhs: Foo) -> Foo {
/// println!("Shifting left!");
/// self
/// fn shl(self, Scalar(rhs): Self) -> Scalar {
/// let Scalar(lhs) = self;
/// Scalar(lhs << rhs)
/// }
/// }
/// fn main() {
/// assert_eq!(Scalar(4) << Scalar(2), Scalar(16));
/// }
/// ```
///
/// An implementation of `Shl` that spins a vector leftward by a given amount.
///
/// ```
/// use std::ops::Shl;
///
/// #[derive(PartialEq, Debug)]
/// struct SpinVector<T: Clone> {
/// vec: Vec<T>,
/// }
///
/// impl<T: Clone> Shl<usize> for SpinVector<T> {
/// type Output = Self;
///
/// fn shl(self, rhs: usize) -> SpinVector<T> {
/// // rotate the vector by `rhs` places
/// let (a, b) = self.vec.split_at(rhs);
/// let mut spun_vector: Vec<T> = vec![];
/// spun_vector.extend_from_slice(b);
/// spun_vector.extend_from_slice(a);
/// SpinVector { vec: spun_vector }
/// }
/// }
///
/// fn main() {
/// Foo << Foo;
/// assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } << 2,
/// SpinVector { vec: vec![2, 3, 4, 0, 1] });
/// }
/// ```
#[lang = "shl"]
Expand Down Expand Up @@ -1041,25 +1090,54 @@ shl_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
///
/// # Examples
///
/// A trivial implementation of `Shr`. When `Foo >> Foo` happens, it ends up
/// calling `shr`, and therefore, `main` prints `Shifting right!`.
/// An implementation of `Shr` that lifts the `>>` operation on integers to a
/// `Scalar` struct.
///
/// ```
/// use std::ops::Shr;
///
/// struct Foo;
/// #[derive(PartialEq, Debug)]
/// struct Scalar(usize);
///
/// impl Shr<Foo> for Foo {
/// type Output = Foo;
/// impl Shr<Scalar> for Scalar {
/// type Output = Self;
///
/// fn shr(self, _rhs: Foo) -> Foo {
/// println!("Shifting right!");
/// self
/// fn shr(self, Scalar(rhs): Self) -> Scalar {
/// let Scalar(lhs) = self;
/// Scalar(lhs >> rhs)
/// }
/// }
/// fn main() {
/// assert_eq!(Scalar(16) >> Scalar(2), Scalar(4));
/// }
/// ```
///
/// An implementation of `Shr` that spins a vector rightward by a given amount.
///
/// ```
/// use std::ops::Shr;
///
/// #[derive(PartialEq, Debug)]
/// struct SpinVector<T: Clone> {
/// vec: Vec<T>,
/// }
///
/// impl<T: Clone> Shr<usize> for SpinVector<T> {
/// type Output = Self;
///
/// fn shr(self, rhs: usize) -> SpinVector<T> {
/// // rotate the vector by `rhs` places
/// let (a, b) = self.vec.split_at(self.vec.len() - rhs);
/// let mut spun_vector: Vec<T> = vec![];
/// spun_vector.extend_from_slice(b);
/// spun_vector.extend_from_slice(a);
/// SpinVector { vec: spun_vector }
/// }
/// }
///
/// fn main() {
/// Foo >> Foo;
/// assert_eq!(SpinVector { vec: vec![0, 1, 2, 3, 4] } >> 2,
/// SpinVector { vec: vec![3, 4, 0, 1, 2] });
/// }
/// ```
#[lang = "shr"]
Expand Down Expand Up @@ -1738,11 +1816,12 @@ pub trait IndexMut<Idx: ?Sized>: Index<Idx> {
///
/// ```
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ .. ], [0,1,2,3]); // RangeFull
/// assert_eq!(arr[ ..3], [0,1,2 ]);
/// assert_eq!(arr[1.. ], [ 1,2,3]);
/// assert_eq!(arr[1..3], [ 1,2 ]);
/// assert_eq!(arr[ .. ], [0, 1, 2, 3]);
/// ```
///
/// See the [module examples] for the behavior of other range structs.
///
/// [module examples]: ../#Examples
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeFull;
Expand All @@ -1767,12 +1846,13 @@ impl fmt::Debug for RangeFull {
/// assert_eq!(3+4+5, (3..6).sum());
///
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ .. ], [0,1,2,3]);
/// assert_eq!(arr[ ..3], [0,1,2 ]);
/// assert_eq!(arr[1.. ], [ 1,2,3]);
/// assert_eq!(arr[1..3], [ 1,2 ]); // Range
/// assert_eq!(arr[1..3], [1, 2]);
/// }
/// ```
///
/// See the [module examples] for the behavior of other range structs.
///
/// [module examples]: ../#Examples
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Range<Idx> {
Expand Down Expand Up @@ -1830,12 +1910,13 @@ impl<Idx: PartialOrd<Idx>> Range<Idx> {
/// assert_eq!(2+3+4, (2..).take(3).sum());
///
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ .. ], [0,1,2,3]);
/// assert_eq!(arr[ ..3], [0,1,2 ]);
/// assert_eq!(arr[1.. ], [ 1,2,3]); // RangeFrom
/// assert_eq!(arr[1..3], [ 1,2 ]);
/// assert_eq!(arr[1.. ], [1, 2, 3]);
/// }
/// ```
///
/// See the [module examples] for the behavior of other range structs.
///
/// [module examples]: ../#Examples
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeFrom<Idx> {
Expand Down Expand Up @@ -1880,12 +1961,13 @@ impl<Idx: PartialOrd<Idx>> RangeFrom<Idx> {
/// assert_eq!((..5), std::ops::RangeTo{ end: 5 });
///
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ .. ], [0,1,2,3]);
/// assert_eq!(arr[ ..3], [0,1,2 ]); // RangeTo
/// assert_eq!(arr[1.. ], [ 1,2,3]);
/// assert_eq!(arr[1..3], [ 1,2 ]);
/// assert_eq!(arr[ ..3], [0, 1, 2]);
/// }
/// ```
///
/// See the [module examples] for the behavior of other range structs.
///
/// [module examples]: ../#Examples
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct RangeTo<Idx> {
Expand Down Expand Up @@ -1932,10 +2014,13 @@ impl<Idx: PartialOrd<Idx>> RangeTo<Idx> {
/// assert_eq!(3+4+5, (3...5).sum());
///
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ ...2], [0,1,2 ]);
/// assert_eq!(arr[1...2], [ 1,2 ]); // RangeInclusive
/// assert_eq!(arr[1...2], [1, 2]);
/// }
/// ```
///
/// See the [module examples] for the behavior of other range structs.
///
/// [module examples]: ../#Examples
#[derive(Clone, PartialEq, Eq, Hash)] // not Copy -- see #27186
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
pub enum RangeInclusive<Idx> {
Expand Down Expand Up @@ -2019,10 +2104,13 @@ impl<Idx: PartialOrd<Idx>> RangeInclusive<Idx> {
/// assert_eq!((...5), std::ops::RangeToInclusive{ end: 5 });
///
/// let arr = [0, 1, 2, 3];
/// assert_eq!(arr[ ...2], [0,1,2 ]); // RangeToInclusive
/// assert_eq!(arr[1...2], [ 1,2 ]);
/// assert_eq!(arr[ ...2], [0, 1, 2]);
/// }
/// ```
///
/// See the [module examples] for the behavior of other range structs.
///
/// [module examples]: ../#Examples
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
#[unstable(feature = "inclusive_range", reason = "recently added, follows RFC", issue = "28237")]
pub struct RangeToInclusive<Idx> {
Expand Down
Loading