From 5e22e3025ce0079ff54f17ebe99e9d00a34a8cf6 Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Tue, 23 Aug 2016 02:07:50 +0200 Subject: [PATCH 01/14] Implement more traits for `std::io::ErrorKind` This makes it possible to use it as key in various maps. --- src/libstd/io/error.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index 5333b0a531eae..aa6ec75e3fc0c 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -83,7 +83,7 @@ struct Custom { /// It is used with the [`io::Error`] type. /// /// [`io::Error`]: struct.Error.html -#[derive(Copy, PartialEq, Eq, Clone, Debug)] +#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] #[stable(feature = "rust1", since = "1.0.0")] #[allow(deprecated)] pub enum ErrorKind { @@ -152,10 +152,6 @@ pub enum ErrorKind { /// Interrupted operations can typically be retried. #[stable(feature = "rust1", since = "1.0.0")] Interrupted, - /// Any I/O error not part of this list. - #[stable(feature = "rust1", since = "1.0.0")] - Other, - /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. /// @@ -164,8 +160,12 @@ pub enum ErrorKind { /// read. #[stable(feature = "read_exact", since = "1.6.0")] UnexpectedEof, - /// Any I/O error not part of this list. + #[stable(feature = "rust1", since = "1.0.0")] + Other, + + /// A marker variant that tells the compiler that users of this enum cannot + /// match it exhaustively. #[unstable(feature = "io_error_internals", reason = "better expressed through extensible enums that this \ enum cannot be exhaustively matched against", From c2d064efa1e31ffc0a6bfcc6847bf386a44c1f9e Mon Sep 17 00:00:00 2001 From: Tobias Bucher Date: Wed, 24 Aug 2016 11:56:28 +0200 Subject: [PATCH 02/14] Restore old ordering of `io::ErrorKind`s --- src/libstd/io/error.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libstd/io/error.rs b/src/libstd/io/error.rs index aa6ec75e3fc0c..99108e85b90d7 100644 --- a/src/libstd/io/error.rs +++ b/src/libstd/io/error.rs @@ -152,6 +152,10 @@ pub enum ErrorKind { /// Interrupted operations can typically be retried. #[stable(feature = "rust1", since = "1.0.0")] Interrupted, + /// Any I/O error not part of this list. + #[stable(feature = "rust1", since = "1.0.0")] + Other, + /// An error returned when an operation could not be completed because an /// "end of file" was reached prematurely. /// @@ -160,9 +164,6 @@ pub enum ErrorKind { /// read. #[stable(feature = "read_exact", since = "1.6.0")] UnexpectedEof, - /// Any I/O error not part of this list. - #[stable(feature = "rust1", since = "1.0.0")] - Other, /// A marker variant that tells the compiler that users of this enum cannot /// match it exhaustively. From f74063136375fec1208ab937314b0f4ca7f92cbe Mon Sep 17 00:00:00 2001 From: Andrew Paseltiner Date: Sun, 28 Aug 2016 19:21:04 -0400 Subject: [PATCH 03/14] Add test for #28324 Closes #28324 --- src/test/compile-fail/issue-28324.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/compile-fail/issue-28324.rs diff --git a/src/test/compile-fail/issue-28324.rs b/src/test/compile-fail/issue-28324.rs new file mode 100644 index 0000000000000..13ce41f4dcc54 --- /dev/null +++ b/src/test/compile-fail/issue-28324.rs @@ -0,0 +1,18 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +extern { + static error_message_count: u32; +} + +pub static BAZ: u32 = *&error_message_count; +//~^ ERROR cannot refer to other statics by value + +fn main() {} From 9ce47e318aa1b8ec9442d19e40b8d00c99b65239 Mon Sep 17 00:00:00 2001 From: king6cong Date: Mon, 29 Aug 2016 16:53:38 +0800 Subject: [PATCH 04/14] fix git submodule status check --- src/bootstrap/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index a487c95fec200..dbf29cda49212 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -528,7 +528,7 @@ impl Build { let path = Path::new(line[1..].split(' ').skip(1).next().unwrap()); let state = if line.starts_with('-') { State::NotInitialized - } else if line.starts_with('*') { + } else if line.starts_with('+') { State::OutOfSync } else if line.starts_with(' ') { State::MaybeDirty From 987ef784fd9cf4e9039f84e3a052e81349108b69 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Mon, 29 Aug 2016 22:31:28 +0300 Subject: [PATCH 05/14] Fix the test_variadic_ptr fn on printf-less sys Fixes #36076 --- src/libcoretest/ptr.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/libcoretest/ptr.rs b/src/libcoretest/ptr.rs index e0a9f4e5d422c..f7fe61896f85e 100644 --- a/src/libcoretest/ptr.rs +++ b/src/libcoretest/ptr.rs @@ -173,12 +173,16 @@ fn test_unsized_unique() { } #[test] -fn test_variadic_fnptr() { +#[allow(warnings)] +// Have a symbol for the test below. It doesn’t need to be an actual variadic function, match the +// ABI, or even point to an actual executable code, because the function itself is never invoked. +#[no_mangle] +pub fn test_variadic_fnptr() { use core::hash::{Hash, SipHasher}; - extern "C" { - fn printf(_: *const u8, ...); + extern { + fn test_variadic_fnptr(_: u64, ...) -> f64; } - let p: unsafe extern "C" fn(*const u8, ...) = printf; + let p: unsafe extern fn(u64, ...) -> f64 = test_variadic_fnptr; let q = p.clone(); assert_eq!(p, q); assert!(!(p < q)); From f53415fe0ded6c889f89890a0af0cd4066372980 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Tue, 30 Aug 2016 02:16:18 +0300 Subject: [PATCH 06/14] Unignore the json tests on 32-bit platforms cc #14064 --- src/libserialize/json.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libserialize/json.rs b/src/libserialize/json.rs index 6c4b6c4506b81..a032332ada440 100644 --- a/src/libserialize/json.rs +++ b/src/libserialize/json.rs @@ -3592,7 +3592,6 @@ mod tests { } } #[test] - #[cfg_attr(target_pointer_width = "32", ignore)] // FIXME(#14064) fn test_streaming_parser() { assert_stream_equal( r#"{ "foo":"bar", "array" : [0, 1, 2, 3, 4, 5], "idents":[null,true,false]}"#, @@ -3631,7 +3630,6 @@ mod tests { } #[test] - #[cfg_attr(target_pointer_width = "32", ignore)] // FIXME(#14064) fn test_read_object_streaming() { assert_eq!(last_event("{ "), Error(SyntaxError(EOFWhileParsingObject, 1, 3))); assert_eq!(last_event("{1"), Error(SyntaxError(KeyMustBeAString, 1, 2))); @@ -3715,7 +3713,6 @@ mod tests { ); } #[test] - #[cfg_attr(target_pointer_width = "32", ignore)] // FIXME(#14064) fn test_read_array_streaming() { assert_stream_equal( "[]", From 8341f6451bef4fa16ba6a51d4d73923f2f1b539d Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 30 Aug 2016 05:34:21 +0300 Subject: [PATCH 07/14] Fix run-pass/signal-exit-status to not trigger UB by writing to NULL. --- src/test/run-pass/signal-exit-status.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-pass/signal-exit-status.rs b/src/test/run-pass/signal-exit-status.rs index c7759ca743bbb..8a2bbc83c424e 100644 --- a/src/test/run-pass/signal-exit-status.rs +++ b/src/test/run-pass/signal-exit-status.rs @@ -18,7 +18,7 @@ pub fn main() { let args: Vec = env::args().collect(); if args.len() >= 2 && args[1] == "signal" { // Raise a segfault. - unsafe { *(0 as *mut isize) = 0; } + unsafe { *(1 as *mut isize) = 0; } } else { let status = Command::new(&args[0]).arg("signal").status().unwrap(); assert!(status.code().is_none()); From ba69bc8b405f7e48eebda9f08f06fdf23af9027f Mon Sep 17 00:00:00 2001 From: Matthew Piziak Date: Tue, 23 Aug 2016 11:41:04 -0400 Subject: [PATCH 08/14] replace `BitAndAssign` example with something more evocative This is the augmented-assignment version of PR #35809. r? @GuillaumeGomez improved documentation a la PR #35993 --- src/libcore/ops.rs | 60 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/src/libcore/ops.rs b/src/libcore/ops.rs index 282f281047e47..1bac3224d318b 100644 --- a/src/libcore/ops.rs +++ b/src/libcore/ops.rs @@ -1291,24 +1291,66 @@ rem_assign_impl! { usize u8 u16 u32 u64 isize i8 i16 i32 i64 f32 f64 } /// /// # Examples /// -/// A trivial implementation of `BitAndAssign`. When `Foo &= Foo` happens, it ends up -/// calling `bitand_assign`, and therefore, `main` prints `Bitwise And-ing!`. +/// In this example, the `&=` operator is lifted to a trivial `Scalar` type. /// /// ``` /// use std::ops::BitAndAssign; /// -/// struct Foo; +/// #[derive(Debug, PartialEq)] +/// struct Scalar(bool); /// -/// impl BitAndAssign for Foo { -/// fn bitand_assign(&mut self, _rhs: Foo) { -/// println!("Bitwise And-ing!"); +/// impl BitAndAssign for Scalar { +/// // rhs is the "right-hand side" of the expression `a &= b` +/// fn bitand_assign(&mut self, rhs: Self) { +/// *self = Scalar(self.0 & rhs.0) /// } /// } /// -/// # #[allow(unused_assignments)] /// fn main() { -/// let mut foo = Foo; -/// foo &= Foo; +/// let mut scalar = Scalar(true); +/// scalar &= Scalar(true); +/// assert_eq!(scalar, Scalar(true)); +/// +/// let mut scalar = Scalar(true); +/// scalar &= Scalar(false); +/// assert_eq!(scalar, Scalar(false)); +/// +/// let mut scalar = Scalar(false); +/// scalar &= Scalar(true); +/// assert_eq!(scalar, Scalar(false)); +/// +/// let mut scalar = Scalar(false); +/// scalar &= Scalar(false); +/// assert_eq!(scalar, Scalar(false)); +/// } +/// ``` +/// +/// In this example, the `BitAndAssign` trait is implemented for a +/// `BooleanVector` struct. +/// +/// ``` +/// use std::ops::BitAndAssign; +/// +/// #[derive(Debug, PartialEq)] +/// struct BooleanVector(Vec); +/// +/// impl BitAndAssign for BooleanVector { +/// // rhs is the "right-hand side" of the expression `a &= b` +/// fn bitand_assign(&mut self, rhs: Self) { +/// assert_eq!(self.0.len(), rhs.0.len()); +/// *self = BooleanVector(self.0 +/// .iter() +/// .zip(rhs.0.iter()) +/// .map(|(x, y)| *x && *y) +/// .collect()); +/// } +/// } +/// +/// fn main() { +/// let mut bv = BooleanVector(vec![true, true, false, false]); +/// bv &= BooleanVector(vec![true, false, true, false]); +/// let expected = BooleanVector(vec![true, false, false, false]); +/// assert_eq!(bv, expected); /// } /// ``` #[lang = "bitand_assign"] From d4ca5613a043e5f2b0ac8b4d7770be1f7f6e2349 Mon Sep 17 00:00:00 2001 From: Eugene R Gonzalez Date: Wed, 17 Aug 2016 21:02:53 -0400 Subject: [PATCH 09/14] Change E0259 to the new error format Fixed E0259 unit test Added name of conflict to E0259's note --- src/librustc_resolve/lib.rs | 6 +++++- src/test/compile-fail/E0259.rs | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index d90a932a63d86..51f093054650d 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -3366,7 +3366,11 @@ impl<'a> Resolver<'a> { }; let mut err = match (old_binding.is_extern_crate(), binding.is_extern_crate()) { - (true, true) => struct_span_err!(self.session, span, E0259, "{}", msg), + (true, true) => { + let mut e = struct_span_err!(self.session, span, E0259, "{}", msg); + e.span_label(span, &format!("`{}` was already imported", name)); + e + }, (true, _) | (_, true) if binding.is_import() || old_binding.is_import() => { let mut e = struct_span_err!(self.session, span, E0254, "{}", msg); e.span_label(span, &"already imported"); diff --git a/src/test/compile-fail/E0259.rs b/src/test/compile-fail/E0259.rs index 6b7e86138594b..d3e876e2527fe 100644 --- a/src/test/compile-fail/E0259.rs +++ b/src/test/compile-fail/E0259.rs @@ -9,6 +9,10 @@ // except according to those terms. extern crate collections; -extern crate libc as collections; //~ ERROR E0259 +//~^ NOTE previous import of `collections` here + +extern crate libc as collections; +//~^ ERROR E0259 +//~| NOTE `collections` was already imported fn main() {} From 189dee6da11c36bf074fc2e568d356a1bae46b91 Mon Sep 17 00:00:00 2001 From: zjhmale Date: Mon, 29 Aug 2016 22:49:16 +0800 Subject: [PATCH 10/14] Update E0393 to new error format --- src/librustc_typeck/astconv.rs | 13 +++++++------ src/test/compile-fail/E0393.rs | 5 ++++- src/test/compile-fail/issue-21950.rs | 7 +++++-- src/test/compile-fail/issue-22370.rs | 4 +++- src/test/compile-fail/issue-22560.rs | 10 +++++++--- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index f24a7cf2121eb..e04bd581f4648 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -515,12 +515,13 @@ impl<'o, 'gcx: 'tcx, 'tcx> AstConv<'gcx, 'tcx>+'o { // defaults. This will lead to an ICE if we are not // careful! if default_needs_object_self(def) { - span_err!(tcx.sess, span, E0393, - "the type parameter `{}` must be explicitly specified \ - in an object type because its default value `{}` references \ - the type `Self`", - def.name, - default); + struct_span_err!(tcx.sess, span, E0393, + "the type parameter `{}` must be explicitly specified", + def.name) + .span_label(span, &format!("missing reference to `{}`", def.name)) + .note(&format!("because of the default `Self` reference, \ + type parameters must be specified on object types")) + .emit(); tcx.types.err } else { // This is a default type parameter. diff --git a/src/test/compile-fail/E0393.rs b/src/test/compile-fail/E0393.rs index 1b89555c8ced1..f045e873519cd 100644 --- a/src/test/compile-fail/E0393.rs +++ b/src/test/compile-fail/E0393.rs @@ -10,7 +10,10 @@ trait A {} -fn together_we_will_rule_the_galaxy(son: &A) {} //~ ERROR E0393 +fn together_we_will_rule_the_galaxy(son: &A) {} +//~^ ERROR E0393 +//~| NOTE missing reference to `T` +//~| NOTE because of the default `Self` reference, type parameters must be specified on object types fn main() { } diff --git a/src/test/compile-fail/issue-21950.rs b/src/test/compile-fail/issue-21950.rs index 1028923ec82fd..935f3480db24a 100644 --- a/src/test/compile-fail/issue-21950.rs +++ b/src/test/compile-fail/issue-21950.rs @@ -15,6 +15,9 @@ use std::ops::Add; fn main() { let x = &10 as &Add; - //~^ ERROR the type parameter `RHS` must be explicitly specified in an object type because its default value `Self` references the type `Self` - //~| ERROR the value of the associated type `Output` (from the trait `std::ops::Add`) must be specified + //~^ ERROR E0393 + //~| NOTE missing reference to `RHS` + //~| NOTE because of the default `Self` reference, type parameters must be specified on object types + //~| ERROR E0191 + //~| NOTE missing associated type `Output` value } diff --git a/src/test/compile-fail/issue-22370.rs b/src/test/compile-fail/issue-22370.rs index 4c6652d812c8c..51f342e3f0a43 100644 --- a/src/test/compile-fail/issue-22370.rs +++ b/src/test/compile-fail/issue-22370.rs @@ -13,6 +13,8 @@ trait A {} fn f(a: &A) {} -//~^ ERROR the type parameter `T` must be explicitly specified in an object type because its default value `Self` references the type `Self` +//~^ ERROR E0393 +//~| NOTE missing reference to `T` +//~| NOTE because of the default `Self` reference, type parameters must be specified on object types fn main() {} diff --git a/src/test/compile-fail/issue-22560.rs b/src/test/compile-fail/issue-22560.rs index 20ec2d64ae6a8..45b110bf5631d 100644 --- a/src/test/compile-fail/issue-22560.rs +++ b/src/test/compile-fail/issue-22560.rs @@ -13,9 +13,13 @@ use std::ops::{Add, Sub}; type Test = Add + - //~^ ERROR the type parameter `RHS` must be explicitly specified in an object type because its default value `Self` references the type `Self` - //~^^ ERROR the value of the associated type `Output` (from the trait `std::ops::Add`) must be specified [E0191] + //~^ ERROR E0393 + //~| NOTE missing reference to `RHS` + //~| NOTE because of the default `Self` reference, type parameters must be specified on object types + //~| ERROR E0191 + //~| NOTE missing associated type `Output` value Sub; - //~^ ERROR only the builtin traits can be used as closure or object bounds + //~^ ERROR E0225 + //~| NOTE non-builtin trait used as bounds fn main() { } From 5b5b8536b039b1574f1426aa136f2d527e9e6b58 Mon Sep 17 00:00:00 2001 From: Stefan Schindler Date: Wed, 31 Aug 2016 01:04:56 +0200 Subject: [PATCH 11/14] Update man pages --- man/rustc.1 | 2 +- man/rustdoc.1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/man/rustc.1 b/man/rustc.1 index 0eaf89a560fb8..1656255956191 100644 --- a/man/rustc.1 +++ b/man/rustc.1 @@ -1,4 +1,4 @@ -.TH RUSTC "1" "August 2016" "rustc 1.12.0" "User Commands" +.TH RUSTC "1" "September 2016" "rustc 1.13.0" "User Commands" .SH NAME rustc \- The Rust compiler .SH SYNOPSIS diff --git a/man/rustdoc.1 b/man/rustdoc.1 index 3fb5757f4ff24..4d885bd14363f 100644 --- a/man/rustdoc.1 +++ b/man/rustdoc.1 @@ -1,4 +1,4 @@ -.TH RUSTDOC "1" "August 2016" "rustdoc 1.12.0" "User Commands" +.TH RUSTDOC "1" "September 2016" "rustdoc 1.13.0" "User Commands" .SH NAME rustdoc \- generate documentation from Rust source code .SH SYNOPSIS From b712f74508f278a407b27c5b66d3dff1637bb6fa Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 29 Aug 2016 00:07:03 +0200 Subject: [PATCH 12/14] Add missing urls into convert module --- src/libcore/convert.rs | 55 ++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index 8e7e2abfc1e17..5191cd7601064 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -42,17 +42,23 @@ /// A cheap, reference-to-reference conversion. /// -/// `AsRef` is very similar to, but different than, `Borrow`. See +/// `AsRef` is very similar to, but different than, [`Borrow`]. See /// [the book][book] for more. /// /// [book]: ../../book/borrow-and-asref.html +/// [`Borrow`]: ../../std/borrow/trait.Borrow.html /// /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which -/// returns an `Option` or a `Result`. +/// returns an [`Option`] or a [`Result`]. +/// +/// [`Option`]: ../../std/option/enum.Option.html +/// [`Result`]: ../../std/result/enum.Result.html /// /// # Examples /// -/// Both `String` and `&str` implement `AsRef`: +/// Both [`String`] and `&str` implement `AsRef`: +/// +/// [`String`]: ../../std/string/struct.String.html /// /// ``` /// fn is_hello>(s: T) { @@ -81,7 +87,10 @@ pub trait AsRef { /// A cheap, mutable reference-to-mutable reference conversion. /// /// **Note: this trait must not fail**. If the conversion can fail, use a dedicated method which -/// returns an `Option` or a `Result`. +/// returns an [`Option`] or a [`Result`]. +/// +/// [`Option`]: ../../std/option/enum.Option.html +/// [`Result`]: ../../std/result/enum.Result.html /// /// # Generic Impls /// @@ -97,16 +106,16 @@ pub trait AsMut { /// A conversion that consumes `self`, which may or may not be expensive. /// -/// **Note: this trait must not fail**. If the conversion can fail, use `TryInto` or a dedicated -/// method which returns an `Option` or a `Result`. +/// **Note: this trait must not fail**. If the conversion can fail, use [`TryInto`] or a dedicated +/// method which returns an [`Option`] or a [`Result`]. /// /// Library authors should not directly implement this trait, but should prefer implementing -/// the `From` trait, which offers greater flexibility and provides an equivalent `Into` +/// the [`From`][From] trait, which offers greater flexibility and provides an equivalent `Into` /// implementation for free, thanks to a blanket implementation in the standard library. /// /// # Examples /// -/// `String` implements `Into>`: +/// [`String`] implements `Into>`: /// /// ``` /// fn is_hello>>(s: T) { @@ -120,9 +129,15 @@ pub trait AsMut { /// /// # Generic Impls /// -/// - `From for U` implies `Into for T` -/// - `into()` is reflexive, which means that `Into for T` is implemented +/// - `[From][From] for U` implies `Into for T` +/// - [`into()`] is reflexive, which means that `Into for T` is implemented /// +/// [`TryInto`]: trait.TryInto.html +/// [`Option`]: ../../std/option/enum.Option.html +/// [`Result`]: ../../std/result/enum.Result.html +/// [`String`]: ../../std/string/struct.String.html +/// [From]: trait.From.html +/// [`into()`]: trait.Into.html#tymethod.into #[stable(feature = "rust1", since = "1.0.0")] pub trait Into: Sized { /// Performs the conversion. @@ -132,12 +147,12 @@ pub trait Into: Sized { /// Construct `Self` via a conversion. /// -/// **Note: this trait must not fail**. If the conversion can fail, use `TryFrom` or a dedicated -/// method which returns an `Option` or a `Result`. +/// **Note: this trait must not fail**. If the conversion can fail, use [`TryFrom`] or a dedicated +/// method which returns an [`Option`] or a [`Result`]. /// /// # Examples /// -/// `String` implements `From<&str>`: +/// [`String`] implements `From<&str>`: /// /// ``` /// let string = "hello".to_string(); @@ -147,9 +162,15 @@ pub trait Into: Sized { /// ``` /// # Generic impls /// -/// - `From for U` implies `Into for T` -/// - `from()` is reflexive, which means that `From for T` is implemented +/// - `From for U` implies `[Into] for T` +/// - [`from()`] is reflexive, which means that `From for T` is implemented /// +/// [`TryFrom`]: trait.TryFrom.html +/// [`Option`]: ../../std/option/enum.Option.html +/// [`Result`]: ../../std/result/enum.Result.html +/// [`String`]: ../../std/string/struct.String.html +/// [Into]: trait.Into.html +/// [`from()`]: trait.From.html#tymethod.from #[stable(feature = "rust1", since = "1.0.0")] pub trait From: Sized { /// Performs the conversion. @@ -160,8 +181,10 @@ pub trait From: Sized { /// An attempted conversion that consumes `self`, which may or may not be expensive. /// /// Library authors should not directly implement this trait, but should prefer implementing -/// the `TryFrom` trait, which offers greater flexibility and provides an equivalent `TryInto` +/// the [`TryFrom`] trait, which offers greater flexibility and provides an equivalent `TryInto` /// implementation for free, thanks to a blanket implementation in the standard library. +/// +/// [`TryFrom`]: trait.TryFrom.html #[unstable(feature = "try_from", issue = "33417")] pub trait TryInto: Sized { /// The type returned in the event of a conversion error. From 3f7432a39926e555f47725f27c48c79b9b6e4897 Mon Sep 17 00:00:00 2001 From: Chiu-Hsiang Hsu Date: Wed, 31 Aug 2016 22:45:05 +0800 Subject: [PATCH 13/14] Change 'rustc::plugin' to 'rustc_plugin' in doc comment --- src/librustc_plugin/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_plugin/lib.rs b/src/librustc_plugin/lib.rs index e60a657ba193d..91e0fd636c9c1 100644 --- a/src/librustc_plugin/lib.rs +++ b/src/librustc_plugin/lib.rs @@ -27,7 +27,7 @@ //! //! extern crate rustc; //! -//! use rustc::plugin::Registry; +//! use rustc_plugin::Registry; //! //! #[plugin_registrar] //! pub fn plugin_registrar(reg: &mut Registry) { From 96e3103cfec430ef03dee1a9125f2f519c7ebc22 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Thu, 18 Aug 2016 17:50:28 +0200 Subject: [PATCH 14/14] Improve Path and PathBuf docs --- src/libstd/fs.rs | 7 +- src/libstd/path.rs | 176 ++++++++++++++++++++++++++++++++++++--------- 2 files changed, 149 insertions(+), 34 deletions(-) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index b78db24e44b70..f8b816d548a49 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1511,8 +1511,11 @@ pub fn remove_dir_all>(path: P) -> io::Result<()> { /// Returns an iterator over the entries within a directory. /// -/// The iterator will yield instances of `io::Result`. 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`]: struct.DirEntry.html /// /// # Platform-specific behavior /// diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 2d19561139b58..ac750d5009f49 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -986,11 +986,16 @@ impl<'a> cmp::Ord for Components<'a> { // Basic types and traits //////////////////////////////////////////////////////////////////////////////// -/// An owned, mutable path (akin to `String`). +/// An owned, mutable path (akin to [`String`]). /// -/// This type provides methods like `push` and `set_extension` that mutate the -/// path in place. It also implements `Deref` to `Path`, meaning that all -/// methods on `Path` slices are available on `PathBuf` values as well. +/// This type provides methods like [`push`] and [`set_extension`] that mutate +/// the path in place. It also implements [`Deref`] to [`Path`], meaning that +/// all methods on [`Path`] slices are available on `PathBuf` values as well. +/// +/// [`String`]: ../string/struct.String.html +/// [`Path`]: struct.Path.html +/// [`push`]: struct.PathBuf.html#method.push +/// [`set_extension`]: struct.PathBuf.html#method.set_extension /// /// More details about the overall approach can be found in /// the module documentation. @@ -1017,12 +1022,31 @@ impl PathBuf { } /// Allocates an empty `PathBuf`. + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let path = PathBuf::new(); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn new() -> PathBuf { PathBuf { inner: OsString::new() } } - /// Coerces to a `Path` slice. + /// Coerces to a [`Path`] slice. + /// + /// [`Path`]: struct.Path.html + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; + /// + /// let p = PathBuf::from("/test"); + /// assert_eq!(Path::new("/test"), p.as_path()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn as_path(&self) -> &Path { self @@ -1087,10 +1111,26 @@ impl PathBuf { self.inner.push(path); } - /// Truncate `self` to `self.parent()`. + /// Truncate `self` to [`self.parent()`]. /// - /// Returns false and does nothing if `self.file_name()` is `None`. + /// Returns false and does nothing if [`self.file_name()`] is `None`. /// Otherwise, returns `true`. + /// + /// [`self.parent()`]: struct.PathBuf.html#method.parent + /// [`self.file_name()`]: struct.PathBuf.html#method.file_name + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; + /// + /// let mut p = PathBuf::from("/test/test.rs"); + /// + /// p.pop(); + /// assert_eq!(Path::new("/test"), p.as_path()); + /// p.pop(); + /// assert_eq!(Path::new("/"), p.as_path()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn pop(&mut self) -> bool { match self.parent().map(|p| p.as_u8_slice().len()) { @@ -1102,11 +1142,13 @@ impl PathBuf { } } - /// Updates `self.file_name()` to `file_name`. + /// Updates [`self.file_name()`] to `file_name`. /// - /// If `self.file_name()` was `None`, this is equivalent to pushing + /// If [`self.file_name()`] was `None`, this is equivalent to pushing /// `file_name`. /// + /// [`self.file_name()`]: struct.PathBuf.html#method.file_name + /// /// # Examples /// /// ``` @@ -1133,12 +1175,29 @@ impl PathBuf { self.push(file_name); } - /// Updates `self.extension()` to `extension`. + /// Updates [`self.extension()`] to `extension`. + /// + /// If [`self.file_name()`] is `None`, does nothing and returns `false`. + /// + /// Otherwise, returns `true`; if [`self.extension()`] is `None`, the + /// extension is added; otherwise it is replaced. + /// + /// [`self.file_name()`]: struct.PathBuf.html#method.file_name + /// [`self.extension()`]: struct.PathBuf.html#method.extension + /// + /// # Examples + /// + /// ``` + /// use std::path::{Path, PathBuf}; /// - /// If `self.file_name()` is `None`, does nothing and returns `false`. + /// let mut p = PathBuf::from("/feel/the"); /// - /// Otherwise, returns `true`; if `self.extension()` is `None`, the extension - /// is added; otherwise it is replaced. + /// p.set_extension("force"); + /// assert_eq!(Path::new("/feel/the.force"), p.as_path()); + /// + /// p.set_extension("dark_side"); + /// assert_eq!(Path::new("/feel/the.dark_side"), p.as_path()); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn set_extension>(&mut self, extension: S) -> bool { self._set_extension(extension.as_ref()) @@ -1163,7 +1222,18 @@ impl PathBuf { true } - /// Consumes the `PathBuf`, yielding its internal `OsString` storage. + /// Consumes the `PathBuf`, yielding its internal [`OsString`] storage. + /// + /// [`OsString`]: ../ffi/struct.OsString.html + /// + /// # Examples + /// + /// ``` + /// use std::path::PathBuf; + /// + /// let p = PathBuf::from("/the/head"); + /// let os_str = p.into_os_string(); + /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub fn into_os_string(self) -> OsString { self.inner @@ -1301,7 +1371,7 @@ impl Into for PathBuf { } } -/// A slice of a path (akin to `str`). +/// A slice of a path (akin to [`str`]). /// /// This type supports a number of operations for inspecting a path, including /// breaking the path into its components (separated by `/` or `\`, depending on @@ -1310,7 +1380,10 @@ impl Into for PathBuf { /// the module documentation. /// /// This is an *unsized* type, meaning that it must always be used behind a -/// pointer like `&` or `Box`. +/// pointer like `&` or [`Box`]. +/// +/// [`str`]: ../primitive.str.html +/// [`Box`]: ../boxed/struct.Box.html /// /// # Examples /// @@ -1372,7 +1445,9 @@ impl Path { unsafe { mem::transmute(s.as_ref()) } } - /// Yields the underlying `OsStr` slice. + /// Yields the underlying [`OsStr`] slice. + /// + /// [`OsStr`]: ../ffi/struct.OsStr.html /// /// # Examples /// @@ -1387,10 +1462,12 @@ impl Path { &self.inner } - /// Yields a `&str` slice if the `Path` is valid unicode. + /// Yields a [`&str`] slice if the `Path` is valid unicode. /// /// This conversion may entail doing a check for UTF-8 validity. /// + /// [`&str`]: ../primitive.str.html + /// /// # Examples /// /// ``` @@ -1404,10 +1481,12 @@ impl Path { self.inner.to_str() } - /// Converts a `Path` to a `Cow`. + /// Converts a `Path` to a [`Cow`]. /// /// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER. /// + /// [`Cow`]: ../borrow/enum.Cow.html + /// /// # Examples /// /// ``` @@ -1421,7 +1500,9 @@ impl Path { self.inner.to_string_lossy() } - /// Converts a `Path` to an owned `PathBuf`. + /// Converts a `Path` to an owned [`PathBuf`]. + /// + /// [`PathBuf`]: struct.PathBuf.html /// /// # Examples /// @@ -1569,6 +1650,18 @@ impl Path { /// /// If `base` is not a prefix of `self` (i.e. `starts_with` /// returns `false`), returns `Err`. + /// + /// # Examples + /// + /// ``` + /// use std::path::Path; + /// + /// let path = Path::new("/test/haha/foo.txt"); + /// + /// assert_eq!(path.strip_prefix("/test"), Ok(Path::new("haha/foo.txt"))); + /// assert_eq!(path.strip_prefix("test").is_ok(), false); + /// assert_eq!(path.strip_prefix("/haha").is_ok(), false); + /// ``` #[stable(since = "1.7.0", feature = "path_strip_prefix")] pub fn strip_prefix<'a, P: ?Sized>(&'a self, base: &'a P) -> Result<&'a Path, StripPrefixError> @@ -1630,7 +1723,9 @@ impl Path { iter_after(self.components().rev(), child.components().rev()).is_some() } - /// Extracts the stem (non-extension) portion of `self.file_name()`. + /// Extracts the stem (non-extension) portion of [`self.file_name()`]. + /// + /// [`self.file_name()`]: struct.Path.html#method.file_name /// /// The stem is: /// @@ -1653,7 +1748,9 @@ impl Path { self.file_name().map(split_file_at_dot).and_then(|(before, after)| before.or(after)) } - /// Extracts the extension of `self.file_name()`, if possible. + /// Extracts the extension of [`self.file_name()`], if possible. + /// + /// [`self.file_name()`]: struct.Path.html#method.file_name /// /// The extension is: /// @@ -1676,9 +1773,12 @@ impl Path { self.file_name().map(split_file_at_dot).and_then(|(before, after)| before.and(after)) } - /// Creates an owned `PathBuf` with `path` adjoined to `self`. + /// Creates an owned [`PathBuf`] with `path` adjoined to `self`. + /// + /// See [`PathBuf::push`] for more details on what it means to adjoin a path. /// - /// See `PathBuf::push` for more details on what it means to adjoin a path. + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::push`]: struct.PathBuf.html#method.push /// /// # Examples /// @@ -1698,9 +1798,12 @@ impl Path { buf } - /// Creates an owned `PathBuf` like `self` but with the given file name. + /// Creates an owned [`PathBuf`] like `self` but with the given file name. /// - /// See `PathBuf::set_file_name` for more details. + /// See [`PathBuf::set_file_name`] for more details. + /// + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::set_file_name`]: struct.PathBuf.html#method.set_file_name /// /// # Examples /// @@ -1721,9 +1824,12 @@ impl Path { buf } - /// Creates an owned `PathBuf` like `self` but with the given extension. + /// Creates an owned [`PathBuf`] like `self` but with the given extension. + /// + /// See [`PathBuf::set_extension`] for more details. /// - /// See `PathBuf::set_extension` for more details. + /// [`PathBuf`]: struct.PathBuf.html + /// [`PathBuf::set_extension`]: struct.PathBuf.html#method.set_extension /// /// # Examples /// @@ -1771,7 +1877,9 @@ impl Path { } } - /// Produce an iterator over the path's components viewed as `OsStr` slices. + /// Produce an iterator over the path's components viewed as [`OsStr`] slices. + /// + /// [`OsStr`]: ../ffi/struct.OsStr.html /// /// # Examples /// @@ -1790,9 +1898,11 @@ impl Path { Iter { inner: self.components() } } - /// Returns an object that implements `Display` for safely printing paths + /// Returns an object that implements [`Display`] for safely printing paths /// that may contain non-Unicode data. /// + /// [`Display`]: ../fmt/trait.Display.html + /// /// # Examples /// /// ``` @@ -1854,11 +1964,13 @@ impl Path { /// Returns an iterator over the entries within a directory. /// - /// The iterator will yield instances of `io::Result`. 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. /// /// This is an alias to [`fs::read_dir`]. /// + /// [`io::Result`]: ../io/type.Result.html + /// [`DirEntry`]: ../fs/struct.DirEntry.html /// [`fs::read_dir`]: ../fs/fn.read_dir.html #[stable(feature = "path_ext", since = "1.5.0")] pub fn read_dir(&self) -> io::Result {