Skip to content

Commit 19b3813

Browse files
committed
Auto merge of #67440 - Mark-Simulacrum:rollup-z59a7ky, r=Mark-Simulacrum
Rollup of 6 pull requests Successful merges: - #67253 (Add more delegations to the fmt docs and add doctests) - #67281 (add string.insert benchmarks) - #67351 (Set release channel on non-dist builders) - #67421 (Fix internal documentation typo) - #67432 (Fix toolstate history format) - #67436 (Correct the todo! stabilization version) Failed merges: r? @ghost
2 parents 0de96d3 + 5f64777 commit 19b3813

File tree

7 files changed

+129
-52
lines changed

7 files changed

+129
-52
lines changed

src/bootstrap/toolstate.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ use std::env;
1313
// Each cycle is 42 days long (6 weeks); the last week is 35..=42 then.
1414
const BETA_WEEK_START: u64 = 35;
1515

16-
#[cfg(linux)]
16+
#[cfg(target_os = "linux")]
1717
const OS: Option<&str> = Some("linux");
1818

1919
#[cfg(windows)]
2020
const OS: Option<&str> = Some("windows");
2121

22-
#[cfg(all(not(linux), not(windows)))]
22+
#[cfg(all(not(target_os = "linux"), not(windows)))]
2323
const OS: Option<&str> = None;
2424

2525
type ToolstateData = HashMap<Box<str>, ToolState>;
@@ -379,7 +379,7 @@ fn change_toolstate(
379379
let mut regressed = false;
380380
for repo_state in old_toolstate {
381381
let tool = &repo_state.tool;
382-
let state = if cfg!(linux) {
382+
let state = if cfg!(target_os = "linux") {
383383
&repo_state.linux
384384
} else if cfg!(windows) {
385385
&repo_state.windows
@@ -413,7 +413,7 @@ fn change_toolstate(
413413
let history_path = format!("rust-toolstate/history/{}.tsv", OS.expect("linux/windows only"));
414414
let mut file = t!(fs::read_to_string(&history_path));
415415
let end_of_first_line = file.find('\n').unwrap();
416-
file.insert_str(end_of_first_line, &format!("{}\t{}\n", commit, toolstate_serialized));
416+
file.insert_str(end_of_first_line, &format!("\n{}\t{}", commit, toolstate_serialized));
417417
t!(fs::write(&history_path, file));
418418
}
419419

src/ci/run.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,13 @@ fi
4444
# FIXME: need a scheme for changing this `nightly` value to `beta` and `stable`
4545
# either automatically or manually.
4646
export RUST_RELEASE_CHANNEL=nightly
47+
48+
# Always set the release channel for bootstrap; this is normally not important (i.e., only dist
49+
# builds would seem to matter) but in practice bootstrap wants to know whether we're targeting
50+
# master, beta, or stable with a build to determine whether to run some checks (notably toolstate).
51+
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
52+
4753
if [ "$DEPLOY$DEPLOY_ALT" = "1" ]; then
48-
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --release-channel=$RUST_RELEASE_CHANNEL"
4954
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --enable-llvm-static-stdcpp"
5055
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --set rust.remap-debuginfo"
5156
RUST_CONFIGURE_ARGS="$RUST_CONFIGURE_ARGS --debuginfo-level-std=1"

src/liballoc/benches/string.rs

+40
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,43 @@ fn bench_to_string(b: &mut Bencher) {
122122
Lorem ipsum dolor sit amet, consectetur. ";
123123
b.iter(|| s.to_string())
124124
}
125+
126+
#[bench]
127+
fn bench_insert_char_short(b: &mut Bencher) {
128+
let s = "Hello, World!";
129+
b.iter(|| {
130+
let mut x = String::from(s);
131+
black_box(&mut x).insert(6, black_box(' '));
132+
x
133+
})
134+
}
135+
136+
#[bench]
137+
fn bench_insert_char_long(b: &mut Bencher) {
138+
let s = "Hello, World!";
139+
b.iter(|| {
140+
let mut x = String::from(s);
141+
black_box(&mut x).insert(6, black_box('❤'));
142+
x
143+
})
144+
}
145+
146+
#[bench]
147+
fn bench_insert_str_short(b: &mut Bencher) {
148+
let s = "Hello, World!";
149+
b.iter(|| {
150+
let mut x = String::from(s);
151+
black_box(&mut x).insert_str(6, black_box(" "));
152+
x
153+
})
154+
}
155+
156+
#[bench]
157+
fn bench_insert_str_long(b: &mut Bencher) {
158+
let s = "Hello, World!";
159+
b.iter(|| {
160+
let mut x = String::from(s);
161+
black_box(&mut x).insert_str(6, black_box(" rustic "));
162+
x
163+
})
164+
}

src/libcore/fmt/mod.rs

+76-44
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub mod rt {
6363
///
6464
/// let pythagorean_triple = Triangle { a: 3.0, b: 4.0, c: 5.0 };
6565
///
66-
/// println!("{}", pythagorean_triple);
66+
/// assert_eq!(format!("{}", pythagorean_triple), "(3, 4, 5)");
6767
/// ```
6868
#[stable(feature = "rust1", since = "1.0.0")]
6969
pub type Result = result::Result<(), Error>;
@@ -440,7 +440,7 @@ impl Display for Arguments<'_> {
440440
///
441441
/// let origin = Point { x: 0, y: 0 };
442442
///
443-
/// println!("The origin is: {:?}", origin);
443+
/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }");
444444
/// ```
445445
///
446446
/// Manually implementing:
@@ -455,28 +455,25 @@ impl Display for Arguments<'_> {
455455
///
456456
/// impl fmt::Debug for Point {
457457
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
458-
/// write!(f, "Point {{ x: {}, y: {} }}", self.x, self.y)
458+
/// f.debug_struct("Point")
459+
/// .field("x", &self.x)
460+
/// .field("y", &self.y)
461+
/// .finish()
459462
/// }
460463
/// }
461464
///
462465
/// let origin = Point { x: 0, y: 0 };
463466
///
464-
/// println!("The origin is: {:?}", origin);
467+
/// assert_eq!(format!("The origin is: {:?}", origin), "The origin is: Point { x: 0, y: 0 }");
465468
/// ```
466469
///
467-
/// This outputs:
468-
///
469-
/// ```text
470-
/// The origin is: Point { x: 0, y: 0 }
471-
/// ```
472-
///
473-
/// There are a number of `debug_*` methods on [`Formatter`] to help you with manual
474-
/// implementations, such as [`debug_struct`][debug_struct].
470+
/// There are a number of helper methods on the [`Formatter`] struct to help you with manual
471+
/// implementations, such as [`debug_struct`].
475472
///
476473
/// `Debug` implementations using either `derive` or the debug builder API
477474
/// on [`Formatter`] support pretty-printing using the alternate flag: `{:#?}`.
478475
///
479-
/// [debug_struct]: ../../std/fmt/struct.Formatter.html#method.debug_struct
476+
/// [`debug_struct`]: ../../std/fmt/struct.Formatter.html#method.debug_struct
480477
/// [`Formatter`]: ../../std/fmt/struct.Formatter.html
481478
///
482479
/// Pretty-printing with `#?`:
@@ -490,17 +487,13 @@ impl Display for Arguments<'_> {
490487
///
491488
/// let origin = Point { x: 0, y: 0 };
492489
///
493-
/// println!("The origin is: {:#?}", origin);
494-
/// ```
495-
///
496-
/// This outputs:
497-
///
498-
/// ```text
499-
/// The origin is: Point {
490+
/// assert_eq!(format!("The origin is: {:#?}", origin),
491+
/// "The origin is: Point {
500492
/// x: 0,
501-
/// y: 0
502-
/// }
493+
/// y: 0,
494+
/// }");
503495
/// ```
496+
504497
#[stable(feature = "rust1", since = "1.0.0")]
505498
#[rustc_on_unimplemented(
506499
on(
@@ -528,12 +521,20 @@ pub trait Debug {
528521
///
529522
/// impl fmt::Debug for Position {
530523
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
531-
/// write!(f, "({:?}, {:?})", self.longitude, self.latitude)
524+
/// f.debug_tuple("")
525+
/// .field(&self.longitude)
526+
/// .field(&self.latitude)
527+
/// .finish()
532528
/// }
533529
/// }
534530
///
535-
/// assert_eq!("(1.987, 2.983)".to_owned(),
536-
/// format!("{:?}", Position { longitude: 1.987, latitude: 2.983, }));
531+
/// let position = Position { longitude: 1.987, latitude: 2.983 };
532+
/// assert_eq!(format!("{:?}", position), "(1.987, 2.983)");
533+
///
534+
/// assert_eq!(format!("{:#?}", position), "(
535+
/// 1.987,
536+
/// 2.983,
537+
/// )");
537538
/// ```
538539
#[stable(feature = "rust1", since = "1.0.0")]
539540
fn fmt(&self, f: &mut Formatter<'_>) -> Result;
@@ -584,7 +585,7 @@ pub use macros::Debug;
584585
///
585586
/// let origin = Point { x: 0, y: 0 };
586587
///
587-
/// println!("The origin is: {}", origin);
588+
/// assert_eq!(format!("The origin is: {}", origin), "The origin is: (0, 0)");
588589
/// ```
589590
#[rustc_on_unimplemented(
590591
on(
@@ -618,7 +619,7 @@ pub trait Display {
618619
/// }
619620
/// }
620621
///
621-
/// assert_eq!("(1.987, 2.983)".to_owned(),
622+
/// assert_eq!("(1.987, 2.983)",
622623
/// format!("{}", Position { longitude: 1.987, latitude: 2.983, }));
623624
/// ```
624625
#[stable(feature = "rust1", since = "1.0.0")]
@@ -668,7 +669,9 @@ pub trait Display {
668669
///
669670
/// let l = Length(9);
670671
///
671-
/// println!("l as octal is: {:o}", l);
672+
/// assert_eq!(format!("l as octal is: {:o}", l), "l as octal is: 11");
673+
///
674+
/// assert_eq!(format!("l as octal is: {:#06o}", l), "l as octal is: 0o0011");
672675
/// ```
673676
#[stable(feature = "rust1", since = "1.0.0")]
674677
pub trait Octal {
@@ -718,7 +721,12 @@ pub trait Octal {
718721
///
719722
/// let l = Length(107);
720723
///
721-
/// println!("l as binary is: {:b}", l);
724+
/// assert_eq!(format!("l as binary is: {:b}", l), "l as binary is: 1101011");
725+
///
726+
/// assert_eq!(
727+
/// format!("l as binary is: {:#032b}", l),
728+
/// "l as binary is: 0b000000000000000000000001101011"
729+
/// );
722730
/// ```
723731
///
724732
/// [module]: ../../std/fmt/index.html
@@ -777,7 +785,9 @@ pub trait Binary {
777785
///
778786
/// let l = Length(9);
779787
///
780-
/// println!("l as hex is: {:x}", l);
788+
/// assert_eq!(format!("l as hex is: {:x}", l), "l as hex is: 9");
789+
///
790+
/// assert_eq!(format!("l as hex is: {:#010x}", l), "l as hex is: 0x00000009");
781791
/// ```
782792
#[stable(feature = "rust1", since = "1.0.0")]
783793
pub trait LowerHex {
@@ -828,9 +838,11 @@ pub trait LowerHex {
828838
/// }
829839
/// }
830840
///
831-
/// let l = Length(9);
841+
/// let l = Length(i32::max_value());
832842
///
833-
/// println!("l as hex is: {:X}", l);
843+
/// assert_eq!(format!("l as hex is: {:X}", l), "l as hex is: 7FFFFFFF");
844+
///
845+
/// assert_eq!(format!("l as hex is: {:#010X}", l), "l as hex is: 0x7FFFFFFF");
834846
/// ```
835847
#[stable(feature = "rust1", since = "1.0.0")]
836848
pub trait UpperHex {
@@ -877,6 +889,10 @@ pub trait UpperHex {
877889
/// let l = Length(42);
878890
///
879891
/// println!("l is in memory here: {:p}", l);
892+
///
893+
/// let l_ptr = format!("{:018p}", l);
894+
/// assert_eq!(l_ptr.len(), 18);
895+
/// assert_eq!(&l_ptr[..2], "0x");
880896
/// ```
881897
#[stable(feature = "rust1", since = "1.0.0")]
882898
pub trait Pointer {
@@ -912,14 +928,22 @@ pub trait Pointer {
912928
///
913929
/// impl fmt::LowerExp for Length {
914930
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
915-
/// let val = self.0;
916-
/// write!(f, "{}e1", val / 10)
931+
/// let val = f64::from(self.0);
932+
/// fmt::LowerExp::fmt(&val, f) // delegate to f64's implementation
917933
/// }
918934
/// }
919935
///
920936
/// let l = Length(100);
921937
///
922-
/// println!("l in scientific notation is: {:e}", l);
938+
/// assert_eq!(
939+
/// format!("l in scientific notation is: {:e}", l),
940+
/// "l in scientific notation is: 1e2"
941+
/// );
942+
///
943+
/// assert_eq!(
944+
/// format!("l in scientific notation is: {:05e}", l),
945+
/// "l in scientific notation is: 001e2"
946+
/// );
923947
/// ```
924948
#[stable(feature = "rust1", since = "1.0.0")]
925949
pub trait LowerExp {
@@ -955,14 +979,22 @@ pub trait LowerExp {
955979
///
956980
/// impl fmt::UpperExp for Length {
957981
/// fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
958-
/// let val = self.0;
959-
/// write!(f, "{}E1", val / 10)
982+
/// let val = f64::from(self.0);
983+
/// fmt::UpperExp::fmt(&val, f) // delegate to f64's implementation
960984
/// }
961985
/// }
962986
///
963987
/// let l = Length(100);
964988
///
965-
/// println!("l in scientific notation is: {:E}", l);
989+
/// assert_eq!(
990+
/// format!("l in scientific notation is: {:E}", l),
991+
/// "l in scientific notation is: 1E2"
992+
/// );
993+
///
994+
/// assert_eq!(
995+
/// format!("l in scientific notation is: {:05E}", l),
996+
/// "l in scientific notation is: 001E2"
997+
/// );
966998
/// ```
967999
#[stable(feature = "rust1", since = "1.0.0")]
9681000
pub trait UpperExp {
@@ -1807,8 +1839,7 @@ impl<'a> Formatter<'a> {
18071839
/// }
18081840
/// }
18091841
///
1810-
/// // prints "[10, 11]"
1811-
/// println!("{:?}", Foo(vec![10, 11]));
1842+
/// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "[10, 11]");
18121843
/// ```
18131844
#[stable(feature = "debug_builders", since = "1.2.0")]
18141845
pub fn debug_list<'b>(&'b mut self) -> DebugList<'b, 'a> {
@@ -1831,8 +1862,7 @@ impl<'a> Formatter<'a> {
18311862
/// }
18321863
/// }
18331864
///
1834-
/// // prints "{10, 11}"
1835-
/// println!("{:?}", Foo(vec![10, 11]));
1865+
/// assert_eq!(format!("{:?}", Foo(vec![10, 11])), "{10, 11}");
18361866
/// ```
18371867
///
18381868
/// [`format_args!`]: ../../std/macro.format_args.html
@@ -1890,8 +1920,10 @@ impl<'a> Formatter<'a> {
18901920
/// }
18911921
/// }
18921922
///
1893-
/// // prints "{"A": 10, "B": 11}"
1894-
/// println!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)]));
1923+
/// assert_eq!(
1924+
/// format!("{:?}", Foo(vec![("A".to_string(), 10), ("B".to_string(), 11)])),
1925+
/// r#"{"A": 10, "B": 11}"#
1926+
/// );
18951927
/// ```
18961928
#[stable(feature = "debug_builders", since = "1.2.0")]
18971929
pub fn debug_map<'b>(&'b mut self) -> DebugMap<'b, 'a> {

src/libcore/macros/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@ macro_rules! unimplemented {
686686
/// }
687687
/// ```
688688
#[macro_export]
689-
#[stable(feature = "todo_macro", since = "1.39.0")]
689+
#[stable(feature = "todo_macro", since = "1.40.0")]
690690
macro_rules! todo {
691691
() => (panic!("not yet implemented"));
692692
($($arg:tt)+) => (panic!("not yet implemented: {}", $crate::format_args!($($arg)+)));

src/librustc_interface/interface.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use syntax_pos::edition;
2525
pub type Result<T> = result::Result<T, ErrorReported>;
2626

2727
/// Represents a compiler session.
28-
/// Can be used run `rustc_interface` queries.
28+
/// Can be used to run `rustc_interface` queries.
2929
/// Created by passing `Config` to `run_compiler`.
3030
pub struct Compiler {
3131
pub(crate) sess: Lrc<Session>,

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ pub use core::{
524524
unreachable,
525525
write,
526526
writeln,
527-
// Unstable
528527
todo,
528+
// Unstable
529529
matches,
530530
};
531531

0 commit comments

Comments
 (0)