From 0cc8fe5d4306c560b4a2668b01e2df97a4eb80c4 Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 12 Dec 2019 16:03:23 +0200 Subject: [PATCH 1/7] Change fmt docs for more delegations --- src/libcore/fmt/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index e2f49ee25a756..7450a33a1c2bc 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -455,7 +455,10 @@ impl Display for Arguments<'_> { /// /// impl fmt::Debug for Point { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -/// write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y) +/// f.debug_struct("Point") +/// .field("x", &self.x) +/// .field("y", &self.y) +/// .finish() /// } /// } /// @@ -528,7 +531,10 @@ pub trait Debug { /// /// impl fmt::Debug for Position { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - /// write!(f, "({:?}, {:?})", self.longitude, self.latitude) + /// f.debug_tuple("") + /// .field(&self.longitude) + /// .field(&self.latitude) + /// .finish() /// } /// } /// @@ -912,8 +918,8 @@ pub trait Pointer { /// /// impl fmt::LowerExp for Length { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -/// let val = self.0; -/// write!(f, "{}e1", val / 10) +/// let val = f64::from(self.0); +/// fmt::LowerExp::fmt(&val, f) // delegate to f64's implementation /// } /// } /// @@ -955,8 +961,8 @@ pub trait LowerExp { /// /// impl fmt::UpperExp for Length { /// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { -/// let val = self.0; -/// write!(f, "{}E1", val / 10) +/// let val = f64::from(self.0); +/// fmt::UpperExp::fmt(&val, f) // delegate to f64's implementation /// } /// } /// From a9d6889e4d211e251e2f37cca358f61e488cb7cc Mon Sep 17 00:00:00 2001 From: Elichai Turkel Date: Thu, 12 Dec 2019 16:03:40 +0200 Subject: [PATCH 2/7] Replace prints in fmt docs with asserts --- src/libcore/fmt/mod.rs | 102 ++++++++++++++++++++++++++--------------- 1 file changed, 64 insertions(+), 38 deletions(-) diff --git a/src/libcore/fmt/mod.rs b/src/libcore/fmt/mod.rs index 7450a33a1c2bc..05b037fbffa32 100644 --- a/src/libcore/fmt/mod.rs +++ b/src/libcore/fmt/mod.rs @@ -63,7 +63,7 @@ pub mod rt { /// /// let pythagorean_triple = Triangle { a: 3.0, b: 4.0, c: 5.0 }; /// -/// println!("{}", pythagorean_triple); +/// assert_eq!(format!("{}", pythagorean_triple), "(3, 4, 5)"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub type Result = result::Result<(), Error>; @@ -440,7 +440,7 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {:?}", origin); +/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }"); /// ``` /// /// Manually implementing: @@ -464,22 +464,16 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {:?}", origin); +/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }"); /// ``` /// -/// This outputs: -/// -/// ```text -/// The origin is: Point { x: 0, y: 0 } -/// ``` -/// -/// There are a number of `debug_*` methods on [`Formatter`] to help you with manual -/// implementations, such as [`debug_struct`][debug_struct]. +/// There are a number of helper methods on the [`Formatter`] struct to help you with manual +/// implementations, such as [`debug_struct`]. /// /// `Debug` implementations using either `derive` or the debug builder API /// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`. /// -/// [debug_struct]: ../../std/fmt/struct.Formatter.html#method.debug_struct +/// [`debug_struct`]: ../../std/fmt/struct.Formatter.html#method.debug_struct /// [`Formatter`]: ../../std/fmt/struct.Formatter.html /// /// Pretty-printing with `#?`: @@ -493,17 +487,13 @@ impl Display for Arguments<'_> { /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {:#?}", origin); -/// ``` -/// -/// This outputs: -/// -/// ```text -/// The origin is: Point { +/// assert_eq!(format!("The origin is: {:#?}", origin), +/// "The origin is: Point { /// x: 0, -/// y: 0 -/// } +/// y: 0, +/// }"); /// ``` + #[stable(feature = "rust1", since = "1.0.0")] #[rustc_on_unimplemented( on( @@ -538,8 +528,13 @@ pub trait Debug { /// } /// } /// - /// assert_eq!("(1.987, 2.983)".to_owned(), - /// format!("{:?}", Position { longitude: 1.987, latitude: 2.983, })); + /// let position = Position { longitude: 1.987, latitude: 2.983 }; + /// assert_eq!(format!("{:?}", position), "(1.987, 2.983)"); + /// + /// assert_eq!(format!("{:#?}", position), "( + /// 1.987, + /// 2.983, + /// )"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] fn fmt(&self, f: &mut Formatter<'_>) -> Result; @@ -590,7 +585,7 @@ pub use macros::Debug; /// /// let origin = Point { x: 0, y: 0 }; /// -/// println!("The origin is: {}", origin); +/// assert_eq!(format!("The origin is: {}", origin), "The origin is: (0, 0)"); /// ``` #[rustc_on_unimplemented( on( @@ -624,7 +619,7 @@ pub trait Display { /// } /// } /// - /// assert_eq!("(1.987, 2.983)".to_owned(), + /// assert_eq!("(1.987, 2.983)", /// format!("{}", Position { longitude: 1.987, latitude: 2.983, })); /// ``` #[stable(feature = "rust1", since = "1.0.0")] @@ -674,7 +669,9 @@ pub trait Display { /// /// let l = Length(9); /// -/// println!("l as octal is: {:o}", l); +/// assert_eq!(format!("l as octal is: {:o}", l), "l as octal is: 11"); +/// +/// assert_eq!(format!("l as octal is: {:#06o}", l), "l as octal is: 0o0011"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Octal { @@ -724,7 +721,12 @@ pub trait Octal { /// /// let l = Length(107); /// -/// println!("l as binary is: {:b}", l); +/// assert_eq!(format!("l as binary is: {:b}", l), "l as binary is: 1101011"); +/// +/// assert_eq!( +/// format!("l as binary is: {:#032b}", l), +/// "l as binary is: 0b000000000000000000000001101011" +/// ); /// ``` /// /// [module]: ../../std/fmt/index.html @@ -783,7 +785,9 @@ pub trait Binary { /// /// let l = Length(9); /// -/// println!("l as hex is: {:x}", l); +/// assert_eq!(format!("l as hex is: {:x}", l), "l as hex is: 9"); +/// +/// assert_eq!(format!("l as hex is: {:#010x}", l), "l as hex is: 0x00000009"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerHex { @@ -834,9 +838,11 @@ pub trait LowerHex { /// } /// } /// -/// let l = Length(9); +/// let l = Length(i32::max_value()); +/// +/// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF"); /// -/// println!("l as hex is: {:X}", l); +/// assert_eq!(format!("l as hex is: {:#010X}", l), "l as hex is: 0x7FFFFFFF"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperHex { @@ -883,6 +889,10 @@ pub trait UpperHex { /// let l = Length(42); /// /// println!("l is in memory here: {:p}", l); +/// +/// let l_ptr = format!("{:018p}", l); +/// assert_eq!(l_ptr.len(), 18); +/// assert_eq!(&l_ptr[..2], "0x"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait Pointer { @@ -925,7 +935,15 @@ pub trait Pointer { /// /// let l = Length(100); /// -/// println!("l in scientific notation is: {:e}", l); +/// assert_eq!( +/// format!("l in scientific notation is: {:e}", l), +/// "l in scientific notation is: 1e2" +/// ); +/// +/// assert_eq!( +/// format!("l in scientific notation is: {:05e}", l), +/// "l in scientific notation is: 001e2" +/// ); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait LowerExp { @@ -968,7 +986,15 @@ pub trait LowerExp { /// /// let l = Length(100); /// -/// println!("l in scientific notation is: {:E}", l); +/// assert_eq!( +/// format!("l in scientific notation is: {:E}", l), +/// "l in scientific notation is: 1E2" +/// ); +/// +/// assert_eq!( +/// format!("l in scientific notation is: {:05E}", l), +/// "l in scientific notation is: 001E2" +/// ); /// ``` #[stable(feature = "rust1", since = "1.0.0")] pub trait UpperExp { @@ -1813,8 +1839,7 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// // prints "[10, 11]" - /// println!("{:?}", Foo(vec![10, 11])); + /// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "[10, 11]"); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> { @@ -1837,8 +1862,7 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// // prints "{10, 11}" - /// println!("{:?}", Foo(vec![10, 11])); + /// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "{10, 11}"); /// ``` /// /// [`format_args!`]: ../../std/macro.format_args.html @@ -1896,8 +1920,10 @@ impl<'a> Formatter<'a> { /// } /// } /// - /// // prints "{"A": 10, "B": 11}" - /// println!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])); + /// assert_eq!( + /// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])), + /// r#"{"A": 10, "B": 11}"# + /// ); /// ``` #[stable(feature = "debug_builders", since = "1.2.0")] pub fn debug_map<'b>(&'b mut self) -> DebugMap<'b, 'a> { From c6321a4df897ab9f32224f493c9e3ee8890cb443 Mon Sep 17 00:00:00 2001 From: Andre Bogus Date: Fri, 13 Dec 2019 19:14:23 +0100 Subject: [PATCH 3/7] Add benchmarks for string::insert(_str) --- src/liballoc/benches/string.rs | 40 ++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/liballoc/benches/string.rs b/src/liballoc/benches/string.rs index 2933014cb58e9..599c8b1682851 100644 --- a/src/liballoc/benches/string.rs +++ b/src/liballoc/benches/string.rs @@ -122,3 +122,43 @@ fn bench_to_string(b: &mut Bencher) { Lorem ipsum dolor sit amet, consectetur. "; b.iter(|| s.to_string()) } + +#[bench] +fn bench_insert_char_short(b: &mut Bencher) { + let s = "Hello, World!"; + b.iter(|| { + let mut x = String::from(s); + black_box(&mut x).insert(6, black_box(' ')); + x + }) +} + +#[bench] +fn bench_insert_char_long(b: &mut Bencher) { + let s = "Hello, World!"; + b.iter(|| { + let mut x = String::from(s); + black_box(&mut x).insert(6, black_box('❤')); + x + }) +} + +#[bench] +fn bench_insert_str_short(b: &mut Bencher) { + let s = "Hello, World!"; + b.iter(|| { + let mut x = String::from(s); + black_box(&mut x).insert_str(6, black_box(" ")); + x + }) +} + +#[bench] +fn bench_insert_str_long(b: &mut Bencher) { + let s = "Hello, World!"; + b.iter(|| { + let mut x = String::from(s); + black_box(&mut x).insert_str(6, black_box(" rustic ")); + x + }) +} From cbd1e73124dbd35cde4b5cafff127a4e54fef9fe Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Mon, 16 Dec 2019 08:52:50 -0500 Subject: [PATCH 4/7] Set release channel on non-dist builders Toolstate publication only runs if the channel is "nightly" and previously the toolstate builders did not know that the channel was nightly (since they are not dist builders). A look through bootstrap seems to indicate that nothing should directly depend on the channel being set to `-dev` on the test builders, though this may cause some problems with UI tests (if for some reason they're dumping the channel into stderr), but we cannot find evidence of such so hopefully this is fine. --- src/bootstrap/toolstate.rs | 6 +++--- src/ci/run.sh | 7 ++++++- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index a6d9ef38e57b1..b5ebf835506b8 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -13,13 +13,13 @@ use std::env; // Each cycle is 42 days long (6 weeks); the last week is 35..=42 then. const BETA_WEEK_START: u64 = 35; -#[cfg(linux)] +#[cfg(target_os = "linux")] const OS: Option<&str> = Some("linux"); #[cfg(windows)] const OS: Option<&str> = Some("windows"); -#[cfg(all(not(linux), not(windows)))] +#[cfg(all(not(target_os = "linux"), not(windows)))] const OS: Option<&str> = None; type ToolstateData = HashMap, ToolState>; @@ -379,7 +379,7 @@ fn change_toolstate( let mut regressed = false; for repo_state in old_toolstate { let tool = &repo_state.tool; - let state = if cfg!(linux) { + let state = if cfg!(target_os = "linux") { &repo_state.linux } else if cfg!(windows) { &repo_state.windows diff --git a/src/ci/run.sh b/src/ci/run.sh index 38d1d2baf2507..73c3a964f5396 100755 --- a/src/ci/run.sh +++ b/src/ci/run.sh @@ -44,8 +44,13 @@ fi # FIXME: need a scheme for changing this `nightly` value to `beta` and `stable` # either automatically or manually. export RUST_RELEASE_CHANNEL=nightly + +# Always set the release channel for bootstrap; this is normally not important (i.e., only dist +# builds would seem to matter) but in practice bootstrap wants to know whether we're targeting +# master, beta, or stable with a build to determine whether to run some checks (notably toolstate). +RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" + if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then - RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo" RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1" From bfc02bdd3ce81caa8faecb5e5980d177bc165abe Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut <38361244+LeSeulArtichaut@users.noreply.github.com> Date: Thu, 19 Dec 2019 12:58:42 +0100 Subject: [PATCH 5/7] Fix documentation typo --- src/librustc_interface/interface.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index beb2465bd4a1a..2365fc3ee2e4d 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -25,7 +25,7 @@ use syntax_pos::edition; pub type Result = result::Result; /// Represents a compiler session. -/// Can be used run `rustc_interface` queries. +/// Can be used to run `rustc_interface` queries. /// Created by passing `Config` to `run_compiler`. pub struct Compiler { pub(crate) sess: Lrc, From df93bab13582ac905061eb0df0f19bbb626e0dad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20K=C4=85dzio=C5=82ka?= Date: Thu, 19 Dec 2019 19:09:20 +0100 Subject: [PATCH 6/7] Correct the todo! stabilization version --- src/libcore/macros/mod.rs | 2 +- src/libstd/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libcore/macros/mod.rs b/src/libcore/macros/mod.rs index cf460745ffa30..dd06da7a6d23e 100644 --- a/src/libcore/macros/mod.rs +++ b/src/libcore/macros/mod.rs @@ -686,7 +686,7 @@ macro_rules! unimplemented { /// } /// ``` #[macro_export] -#[stable(feature = "todo_macro", since = "1.39.0")] +#[stable(feature = "todo_macro", since = "1.40.0")] macro_rules! todo { () => (panic!("not yet implemented")); ($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+))); diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 340313b06dd40..9930b8f63af5b 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -524,8 +524,8 @@ pub use core::{ unreachable, write, writeln, - // Unstable todo, + // Unstable matches, }; From 1787b2b5aba0231ce26a05c4f7a2d6caf8263f0c Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Thu, 19 Dec 2019 13:48:36 -0500 Subject: [PATCH 7/7] Fix toolstate history format We were inserting *before* the existing newline, so we should prepend it not append it to our inserted string. --- src/bootstrap/toolstate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/toolstate.rs b/src/bootstrap/toolstate.rs index a6d9ef38e57b1..7e547c7799bc1 100644 --- a/src/bootstrap/toolstate.rs +++ b/src/bootstrap/toolstate.rs @@ -413,7 +413,7 @@ fn change_toolstate( let history_path = format!("rust-toolstate/history/{}.tsv", OS.expect("linux/windows only")); let mut file = t!(fs::read_to_string(&history_path)); let end_of_first_line = file.find('\n').unwrap(); - file.insert_str(end_of_first_line, &format!("{}\t{}\n", commit, toolstate_serialized)); + file.insert_str(end_of_first_line, &format!("\n{}\t{}", commit, toolstate_serialized)); t!(fs::write(&history_path, file)); }