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 #35808

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
dcee93a
replace Add example with something more evocative of addition
matthew-piziak Aug 16, 2016
0dc13ee
updated E0395 to new error format
clementmiao Aug 18, 2016
dae1406
updated E0396 to new error format
clementmiao Aug 18, 2016
6976991
Fix tiny spelling mistake in book
ErikUggeldahl Aug 18, 2016
c2b6f72
Add a few doc examples for `std::ffi::OsStr`.
frewsxcv Aug 18, 2016
d56f9ff
Improve Path and PathBuf docs
GuillaumeGomez Aug 18, 2016
06302cb
Fix minor typo
cantino Aug 18, 2016
96bd6cf
demonstrate `RHS != Self` use cases for `Add` and `Sub`
matthew-piziak Aug 18, 2016
161cb36
Update error message for E0084
pliniker Aug 18, 2016
a516dbb
note that calling drop() explicitly is a compiler error
matthew-piziak Aug 16, 2016
6c66eaa
replace `AddAssign` example with something more evocative of addition
matthew-piziak Aug 18, 2016
511f8df
Rollup merge of #35709 - matthew-piziak:add-trait-example, r=Guillaum…
steveklabnik Aug 18, 2016
b0b57cf
Rollup merge of #35710 - matthew-piziak:explicit-drop, r=steveklabnik
steveklabnik Aug 18, 2016
4ea6a6f
Rollup merge of #35775 - frewsxcv:os-str-doc-examples, r=GuillaumeGomez
steveklabnik Aug 18, 2016
9163713
Rollup merge of #35778 - clementmiao:E0395_new_error_format, r=jonath…
steveklabnik Aug 18, 2016
090c17d
Rollup merge of #35780 - clementmiao:E0396_new_err_format, r=jonathan…
steveklabnik Aug 18, 2016
1355589
Rollup merge of #35781 - ErikUggeldahl:spellingfix, r=apasel422
steveklabnik Aug 18, 2016
089b84d
Rollup merge of #35786 - GuillaumeGomez:paths_doc, r=steveklabnik
steveklabnik Aug 18, 2016
443a2ac
Rollup merge of #35793 - matthew-piziak:add-rhs-example, r=steveklabnik
steveklabnik Aug 18, 2016
3d9bc76
Rollup merge of #35794 - cantino:fix-typo, r=apasel422
steveklabnik Aug 18, 2016
9dea71e
Rollup merge of #35804 - pliniker:master, r=jonathandturner
steveklabnik Aug 18, 2016
5daf280
Rollup merge of #35806 - matthew-piziak:addassign-example, r=stevekla…
steveklabnik Aug 18, 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
4 changes: 2 additions & 2 deletions src/doc/book/borrow-and-asref.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ different. Here’s a quick refresher on what these two traits mean.

# Borrow

The `Borrow` trait is used when you’re writing a datastructure, and you want to
The `Borrow` trait is used when you’re writing a data structure, and you want to
use either an owned or borrowed type as synonymous for some purpose.

For example, [`HashMap`][hashmap] has a [`get` method][get] which uses `Borrow`:
Expand Down Expand Up @@ -86,7 +86,7 @@ We can see how they’re kind of the same: they both deal with owned and borrowe
versions of some type. However, they’re a bit different.

Choose `Borrow` when you want to abstract over different kinds of borrowing, or
when you’re building a datastructure that treats owned and borrowed values in
when you’re building a data structure that treats owned and borrowed values in
equivalent ways, such as hashing and comparison.

Choose `AsRef` when you want to convert something to a reference directly, and
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book/closures.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn call_with_ref<'a, F>(some_closure:F) -> i32
where F: Fn(&'a i32) -> i32 {
```

However this presents a problem with in our case. When you specify the explicit
However this presents a problem in our case. When you specify the explicit
lifetime on a function it binds that lifetime to the *entire* scope of the function
instead of just the invocation scope of our closure. This means that the borrow checker
will see a mutable reference in the same lifetime as our immutable reference and fail
Expand Down
84 changes: 63 additions & 21 deletions src/libcore/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@
//! }
//! ```
//!
//! See the documentation for each trait for a minimum implementation that
//! prints something to the screen.
//! See the documentation for each trait for an example implementation.

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

Expand Down Expand Up @@ -107,6 +106,13 @@ pub trait Drop {
///
/// After this function is over, the memory of `self` will be deallocated.
///
/// This function cannot be called explicitly. This is compiler error
/// [0040]. However, the [`std::mem::drop`] function in the prelude can be
/// used to call the argument's `Drop` implementation.
///
/// [0040]: https://doc.rust-lang.org/error-index.html#E0040
/// [`std::mem::drop`]: https://doc.rust-lang.org/std/mem/fn.drop.html
///
/// # Panics
///
/// Given that a `panic!` will call `drop()` as it unwinds, any `panic!` in
Expand Down Expand Up @@ -171,27 +177,46 @@ macro_rules! forward_ref_binop {
///
/// # Examples
///
/// A trivial implementation of `Add`. When `Foo + Foo` happens, it ends up
/// calling `add`, and therefore, `main` prints `Adding!`.
/// This example creates a `Point` struct that implements the `Add` trait, and
/// then demonstrates adding two `Point`s.
///
/// ```
/// use std::ops::Add;
///
/// struct Foo;
/// #[derive(Debug)]
/// struct Point {
/// x: i32,
/// y: i32,
/// }
///
/// impl Add for Foo {
/// type Output = Foo;
/// impl Add for Point {
/// type Output = Point;
///
/// fn add(self, _rhs: Foo) -> Foo {
/// println!("Adding!");
/// self
/// fn add(self, other: Point) -> Point {
/// Point {
/// x: self.x + other.x,
/// y: self.y + other.y,
/// }
/// }
/// }
///
/// impl PartialEq for Point {
/// fn eq(&self, other: &Self) -> bool {
/// self.x == other.x && self.y == other.y
/// }
/// }
///
/// fn main() {
/// Foo + Foo;
/// assert_eq!(Point { x: 1, y: 0 } + Point { x: 2, y: 3 },
/// Point { x: 3, y: 3 });
/// }
/// ```
///
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
/// [std::time::SystemTime] implements `Add<Duration>`, which permits
/// operations of the form `SystemTime = SystemTime + Duration`.
///
/// [std::time::SystemTime]: ../../time/struct.SystemTime.html
#[lang = "add"]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Add<RHS=Self> {
Expand Down Expand Up @@ -246,6 +271,12 @@ add_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 }
/// Foo - Foo;
/// }
/// ```
///
/// Note that `RHS = Self` by default, but this is not mandatory. For example,
/// [std::time::SystemTime] implements `Sub<Duration>`, which permits
/// operations of the form `SystemTime = SystemTime - Duration`.
///
/// [std::time::SystemTime]: ../../time/struct.SystemTime.html
#[lang = "sub"]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Sub<RHS=Self> {
Expand Down Expand Up @@ -899,25 +930,36 @@ shr_impl_all! { u8 u16 u32 u64 usize i8 i16 i32 i64 isize }
///
/// # Examples
///
/// A trivial implementation of `AddAssign`. When `Foo += Foo` happens, it ends up
/// calling `add_assign`, and therefore, `main` prints `Adding!`.
/// This example creates a `Point` struct that implements the `AddAssign`
/// trait, and then demonstrates add-assigning to a mutable `Point`.
///
/// ```
/// use std::ops::AddAssign;
///
/// struct Foo;
/// #[derive(Debug)]
/// struct Point {
/// x: i32,
/// y: i32,
/// }
///
/// impl AddAssign for Foo {
/// fn add_assign(&mut self, _rhs: Foo) {
/// println!("Adding!");
/// impl AddAssign for Point {
/// fn add_assign(&mut self, other: Point) {
/// *self = Point {
/// x: self.x + other.x,
/// y: self.y + other.y,
/// };
/// }
/// }
///
/// # #[allow(unused_assignments)]
/// fn main() {
/// let mut foo = Foo;
/// foo += Foo;
/// impl PartialEq for Point {
/// fn eq(&self, other: &Self) -> bool {
/// self.x == other.x && self.y == other.y
/// }
/// }
///
/// let mut point = Point { x: 1, y: 0 };
/// point += Point { x: 2, y: 3 };
/// assert_eq!(point, Point { x: 3, y: 3 });
/// ```
#[lang = "add_assign"]
#[stable(feature = "op_assign_traits", since = "1.8.0")]
Expand Down
21 changes: 15 additions & 6 deletions src/librustc_mir/transform/qualify_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,9 +493,13 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {
if let ty::TyRawPtr(_) = base_ty.sty {
this.add(Qualif::NOT_CONST);
if this.mode != Mode::Fn {
span_err!(this.tcx.sess, this.span, E0396,
"raw pointers cannot be dereferenced in {}s",
this.mode);
struct_span_err!(this.tcx.sess,
this.span, E0396,
"raw pointers cannot be dereferenced in {}s",
this.mode)
.span_label(this.span,
&format!("dereference of raw pointer in constant"))
.emit();
}
}
}
Expand Down Expand Up @@ -681,9 +685,14 @@ impl<'a, 'tcx> Visitor<'tcx> for Qualifier<'a, 'tcx, 'tcx> {

self.add(Qualif::NOT_CONST);
if self.mode != Mode::Fn {
span_err!(self.tcx.sess, self.span, E0395,
"raw pointers cannot be compared in {}s",
self.mode);
struct_span_err!(
self.tcx.sess, self.span, E0395,
"raw pointers cannot be compared in {}s",
self.mode)
.span_label(
self.span,
&format!("comparing raw pointers in static"))
.emit();
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1245,8 +1245,11 @@ pub fn check_enum_variants<'a,'tcx>(ccx: &CrateCtxt<'a,'tcx>,
let hint = *ccx.tcx.lookup_repr_hints(def_id).get(0).unwrap_or(&attr::ReprAny);

if hint != attr::ReprAny && vs.is_empty() {
span_err!(ccx.tcx.sess, sp, E0084,
"unsupported representation for zero-variant enum");
struct_span_err!(
ccx.tcx.sess, sp, E0084,
"unsupported representation for zero-variant enum")
.span_label(sp, &format!("unsupported enum representation"))
.emit();
}

let repr_type_ty = ccx.tcx.enum_repr_type(Some(&hint)).to_ty(ccx.tcx);
Expand Down
32 changes: 32 additions & 0 deletions src/libstd/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,14 @@ impl Hash for OsString {

impl OsStr {
/// Coerces into an `OsStr` slice.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
///
/// let os_str = OsStr::new("foo");
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub fn new<S: AsRef<OsStr> + ?Sized>(s: &S) -> &OsStr {
s.as_ref()
Expand Down Expand Up @@ -283,6 +291,18 @@ impl OsStr {
}

/// Checks whether the `OsStr` is empty.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
///
/// let os_str = OsStr::new("");
/// assert!(os_str.is_empty());
///
/// let os_str = OsStr::new("foo");
/// assert!(!os_str.is_empty());
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
pub fn is_empty(&self) -> bool {
self.inner.inner.is_empty()
Expand All @@ -296,6 +316,18 @@ impl OsStr {
/// other methods like `OsString::with_capacity` to avoid reallocations.
///
/// See `OsStr` introduction for more information about encoding.
///
/// # Examples
///
/// ```
/// use std::ffi::OsStr;
///
/// let os_str = OsStr::new("");
/// assert_eq!(os_str.len(), 0);
///
/// let os_str = OsStr::new("foo");
/// assert_eq!(os_str.len(), 3);
/// ```
#[stable(feature = "osstring_simple_functions", since = "1.9.0")]
pub fn len(&self) -> usize {
self.inner.inner.len()
Expand Down
7 changes: 5 additions & 2 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,8 +1511,11 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {

/// Returns an iterator over the entries within a directory.
///
/// The iterator will yield instances of `io::Result<DirEntry>`. New errors may
/// be encountered after an iterator is initially constructed.
/// The iterator will yield instances of [`io::Result<`][`DirEntry`]`>`.
/// New errors may be encountered after an iterator is initially constructed.
///
/// [`io::Result<`]: ../io/type.Result.html
/// [`DirEntry`]: ../fs/struct.DirEntry.html
///
/// # Platform-specific behavior
///
Expand Down
Loading