From 18df8d6e559174700e302369c2fe0d9c7c143e66 Mon Sep 17 00:00:00 2001 From: Kevin Reid Date: Mon, 30 Aug 2021 20:20:14 -0700 Subject: [PATCH 01/26] Expand documentation for `FpCategory`. I intend these changes to be helpful to readers who are not yet familiar with the quirks of floating-point numbers. Additionally, I felt it was misleading to describe `Nan` as being the result of division by zero, since most divisions by zero (except for 0/0) produce `Infinite` floats, so I moved that remark to the `Infinite` variant with adjustment. The first sentence of the `Nan` documentation is copied from `f32`; I followed the example of the `f64` documentation by referring to `f32` for general concepts, rather than duplicating the text. --- library/core/src/num/mod.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 09b7418bec0d9..360ca9b700b7a 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -778,23 +778,41 @@ impl usize { #[derive(Copy, Clone, PartialEq, Eq, Debug)] #[stable(feature = "rust1", since = "1.0.0")] pub enum FpCategory { - /// "Not a Number", often obtained by dividing by zero. + /// NaN (not a number): this value results from calculations like `(-1.0).sqrt()`. + /// + /// See [the documentation for `f32`](f32) for more information on the unusual properties + /// of NaN. #[stable(feature = "rust1", since = "1.0.0")] Nan, - /// Positive or negative infinity. + /// Positive or negative infinity, which often results from dividing a nonzero number + /// by zero. #[stable(feature = "rust1", since = "1.0.0")] Infinite, /// Positive or negative zero. + /// + /// See [the documentation for `f32`](f32) for more information on the signedness of zeroes. #[stable(feature = "rust1", since = "1.0.0")] Zero, - /// De-normalized floating point representation (less precise than `Normal`). + /// “Subnormal” or “denormal” floating point representation (less precise, relative to + /// their magnitude, than [`Normal`]). + /// + /// Subnormal numbers are larger in magnitude than [`Zero`] but smaller in magnitude than all + /// [`Normal`] numbers. + /// + /// [`Normal`]: Self::Normal + /// [`Zero`]: Self::Zero #[stable(feature = "rust1", since = "1.0.0")] Subnormal, - /// A regular floating point number. + /// A regular floating point number, not any of the exceptional categories. + /// + /// The smallest positive normal numbers are [`f32::MIN_POSITIVE`] and [`f64::MIN_POSITIVE`], + /// and the largest positive normal numbers are [`f32::MAX`] and [`f64::MAX`]. (Unlike signed + /// integers, floating point numbers are symmetric in their range, so negating any of these + /// constants will produce their negative counterpart.) #[stable(feature = "rust1", since = "1.0.0")] Normal, } From 25b6f9b68b6ff4bdcce01feaa5259ff2786c4851 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomasz=20Mi=C4=85sko?= Date: Tue, 28 Sep 2021 00:00:00 +0000 Subject: [PATCH 02/26] print-type-sizes: skip field printing for primitives --- compiler/rustc_middle/src/ty/layout.rs | 7 +++++-- src/test/ui/print_type_sizes/uninhabited.rs | 2 +- src/test/ui/print_type_sizes/uninhabited.stdout | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index cfbbec374a172..2c3c21e7a393b 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -1805,8 +1805,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { match layout.variants { Variants::Single { index } => { - debug!("print-type-size `{:#?}` variant {}", layout, adt_def.variants[index].ident); - if !adt_def.variants.is_empty() { + if !adt_def.variants.is_empty() && layout.fields != FieldsShape::Primitive { + debug!( + "print-type-size `{:#?}` variant {}", + layout, adt_def.variants[index].ident + ); let variant_def = &adt_def.variants[index]; let fields: Vec<_> = variant_def.fields.iter().map(|f| f.ident.name).collect(); record( diff --git a/src/test/ui/print_type_sizes/uninhabited.rs b/src/test/ui/print_type_sizes/uninhabited.rs index c234547bd14b1..06a62db4ebb0f 100644 --- a/src/test/ui/print_type_sizes/uninhabited.rs +++ b/src/test/ui/print_type_sizes/uninhabited.rs @@ -11,5 +11,5 @@ fn start(_: isize, _: *const *const u8) -> isize { let _x: Option = None; let _y: Result = Ok(42); - 0 + let _z: Result = loop {}; } diff --git a/src/test/ui/print_type_sizes/uninhabited.stdout b/src/test/ui/print_type_sizes/uninhabited.stdout index 2a8706f7ac551..5eb5384bce340 100644 --- a/src/test/ui/print_type_sizes/uninhabited.stdout +++ b/src/test/ui/print_type_sizes/uninhabited.stdout @@ -3,3 +3,4 @@ print-type-size variant `Ok`: 4 bytes print-type-size field `.0`: 4 bytes print-type-size type: `std::option::Option`: 0 bytes, alignment: 1 bytes print-type-size variant `None`: 0 bytes +print-type-size type: `std::result::Result`: 0 bytes, alignment: 1 bytes From 6cc91cb3d87fc2342664a0bf498734cdcceda771 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 28 Sep 2021 14:59:33 +0200 Subject: [PATCH 03/26] Rename `std::thread::available_onccurrency` to `std::thread::available_parallelism` --- library/std/src/sys/hermit/thread.rs | 2 +- library/std/src/sys/sgx/thread.rs | 2 +- library/std/src/sys/unix/thread.rs | 2 +- library/std/src/sys/unsupported/thread.rs | 2 +- library/std/src/sys/wasi/thread.rs | 2 +- library/std/src/sys/wasm/atomics/thread.rs | 2 +- library/std/src/sys/windows/thread.rs | 2 +- library/std/src/thread/mod.rs | 10 +++++----- library/test/src/helpers/concurrency.rs | 2 +- library/test/src/lib.rs | 2 +- src/doc/rustc/src/tests/index.md | 4 ++-- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/library/std/src/sys/hermit/thread.rs b/library/std/src/sys/hermit/thread.rs index 8be25f84999d2..81b21fbbb1656 100644 --- a/library/std/src/sys/hermit/thread.rs +++ b/library/std/src/sys/hermit/thread.rs @@ -97,7 +97,7 @@ impl Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { unsupported() } diff --git a/library/std/src/sys/sgx/thread.rs b/library/std/src/sys/sgx/thread.rs index cbb8ba964018a..d745a61961404 100644 --- a/library/std/src/sys/sgx/thread.rs +++ b/library/std/src/sys/sgx/thread.rs @@ -137,7 +137,7 @@ impl Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { unsupported() } diff --git a/library/std/src/sys/unix/thread.rs b/library/std/src/sys/unix/thread.rs index 133ad3ea420b8..6fae31fa71e3b 100644 --- a/library/std/src/sys/unix/thread.rs +++ b/library/std/src/sys/unix/thread.rs @@ -263,7 +263,7 @@ impl Drop for Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { cfg_if::cfg_if! { if #[cfg(any( target_os = "android", diff --git a/library/std/src/sys/unsupported/thread.rs b/library/std/src/sys/unsupported/thread.rs index dc75d4ee6725c..a8db251de2017 100644 --- a/library/std/src/sys/unsupported/thread.rs +++ b/library/std/src/sys/unsupported/thread.rs @@ -31,7 +31,7 @@ impl Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { unsupported() } diff --git a/library/std/src/sys/wasi/thread.rs b/library/std/src/sys/wasi/thread.rs index 9ec02bbec2644..2e4e474c4492c 100644 --- a/library/std/src/sys/wasi/thread.rs +++ b/library/std/src/sys/wasi/thread.rs @@ -64,7 +64,7 @@ impl Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { unsupported() } diff --git a/library/std/src/sys/wasm/atomics/thread.rs b/library/std/src/sys/wasm/atomics/thread.rs index a66ab0837570d..16418a06226e4 100644 --- a/library/std/src/sys/wasm/atomics/thread.rs +++ b/library/std/src/sys/wasm/atomics/thread.rs @@ -40,7 +40,7 @@ impl Thread { pub fn join(self) {} } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { unsupported() } diff --git a/library/std/src/sys/windows/thread.rs b/library/std/src/sys/windows/thread.rs index a5293133b3ab0..75f70c2076ee1 100644 --- a/library/std/src/sys/windows/thread.rs +++ b/library/std/src/sys/windows/thread.rs @@ -100,7 +100,7 @@ impl Thread { } } -pub fn available_concurrency() -> io::Result { +pub fn available_parallelism() -> io::Result { let res = unsafe { let mut sysinfo: c::SYSTEM_INFO = crate::mem::zeroed(); c::GetSystemInfo(&mut sysinfo); diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index f44df845bf4dd..b6b48208ac7b3 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1455,12 +1455,12 @@ fn _assert_sync_and_send() { /// /// ``` /// # #![allow(dead_code)] -/// #![feature(available_concurrency)] +/// #![feature(available_parallelism)] /// use std::thread; /// -/// let count = thread::available_concurrency().map(|n| n.get()).unwrap_or(1); +/// let count = thread::available_parallelism().map(|n| n.get()).unwrap_or(1); /// ``` -#[unstable(feature = "available_concurrency", issue = "74479")] -pub fn available_concurrency() -> io::Result { - imp::available_concurrency() +#[unstable(feature = "available_parallelism", issue = "74479")] +pub fn available_parallelism() -> io::Result { + imp::available_parallelism() } diff --git a/library/test/src/helpers/concurrency.rs b/library/test/src/helpers/concurrency.rs index c39a9b0ec0233..e25f524ec0566 100644 --- a/library/test/src/helpers/concurrency.rs +++ b/library/test/src/helpers/concurrency.rs @@ -9,6 +9,6 @@ pub fn get_concurrency() -> usize { _ => panic!("RUST_TEST_THREADS is `{}`, should be a positive integer.", value), } } else { - thread::available_concurrency().map(|n| n.get()).unwrap_or(1) + thread::available_parallelism().map(|n| n.get()).unwrap_or(1) } } diff --git a/library/test/src/lib.rs b/library/test/src/lib.rs index 251f099f28af4..6732c6c61c204 100644 --- a/library/test/src/lib.rs +++ b/library/test/src/lib.rs @@ -23,7 +23,7 @@ #![feature(libc)] #![feature(rustc_private)] #![feature(nll)] -#![feature(available_concurrency)] +#![feature(available_parallelism)] #![feature(bench_black_box)] #![feature(internal_output_capture)] #![feature(panic_unwind)] diff --git a/src/doc/rustc/src/tests/index.md b/src/doc/rustc/src/tests/index.md index ec23d4fe0dbd3..04e20fdd41c0f 100644 --- a/src/doc/rustc/src/tests/index.md +++ b/src/doc/rustc/src/tests/index.md @@ -161,7 +161,7 @@ The following options affect how tests are executed. Sets the number of threads to use for running tests in parallel. By default, uses the amount of concurrency available on the hardware as indicated by -[`available_concurrency`]. +[`available_parallelism`]. This can also be specified with the `RUST_TEST_THREADS` environment variable. @@ -265,7 +265,7 @@ Experimental support for using custom test harnesses is available on the [`--test` option]: ../command-line-arguments.md#option-test [`-Z panic-abort-tests`]: https://github.com/rust-lang/rust/issues/67650 -[`available_concurrency`]: ../../std/thread/fn.available_concurrency.html +[`available_parallelism`]: ../../std/thread/fn.available_parallelism.html [`cargo test`]: ../../cargo/commands/cargo-test.html [`libtest`]: ../../test/index.html [`main` function]: ../../reference/crates-and-source-files.html#main-functions From fe11483afa90628106971993049b4fd2f0dae6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Thu, 29 Jul 2021 19:39:56 +0200 Subject: [PATCH 04/26] Add functions to add unsigned and signed integers --- library/core/src/lib.rs | 1 + library/core/src/num/mod.rs | 16 ++--- library/core/src/num/uint_macros.rs | 102 +++++++++++++++++++++++++++- library/std/src/io/cursor.rs | 7 +- library/std/src/lib.rs | 1 + 5 files changed, 112 insertions(+), 15 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 4408b5a3d2088..2e419625d14f6 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -159,6 +159,7 @@ #![feature(trait_alias)] #![feature(transparent_unions)] #![feature(try_blocks)] +#![feature(uint_add_signed)] #![feature(unboxed_closures)] #![feature(unsized_fn_params)] // diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 59b68cbe9c0ce..8966a9c11d2b4 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -245,7 +245,7 @@ const ASCII_CASE_MASK: u8 = 0b0010_0000; #[lang = "u8"] impl u8 { widening_impl! { u8, u16, 8 } - uint_impl! { u8, u8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]", + uint_impl! { u8, u8, i8, 8, 255, 2, "0x82", "0xa", "0x12", "0x12", "0x48", "[0x12]", "[0x12]", "", "" } /// Checks if the value is within the ASCII range. @@ -779,21 +779,21 @@ impl u8 { #[lang = "u16"] impl u16 { widening_impl! { u16, u32, 16 } - uint_impl! { u16, u16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", + uint_impl! { u16, u16, i16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", "", "" } } #[lang = "u32"] impl u32 { widening_impl! { u32, u64, 32 } - uint_impl! { u32, u32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678", + uint_impl! { u32, u32, i32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", "", "" } } #[lang = "u64"] impl u64 { widening_impl! { u64, u128, 64 } - uint_impl! { u64, u64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa", + uint_impl! { u64, u64, i64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", @@ -802,7 +802,7 @@ impl u64 { #[lang = "u128"] impl u128 { - uint_impl! { u128, u128, 128, 340282366920938463463374607431768211455, 16, + uint_impl! { u128, u128, i128, 128, 340282366920938463463374607431768211455, 16, "0x13f40000000000000000000000004f76", "0x4f7613f4", "0x12345678901234567890123456789012", "0x12907856341290785634129078563412", "0x48091e6a2c48091e6a2c48091e6a2c48", "[0x12, 0x90, 0x78, 0x56, 0x34, 0x12, 0x90, 0x78, \ @@ -816,7 +816,7 @@ impl u128 { #[lang = "usize"] impl usize { widening_impl! { usize, u32, 16 } - uint_impl! { usize, u16, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", + uint_impl! { usize, u16, isize, 16, 65535, 4, "0xa003", "0x3a", "0x1234", "0x3412", "0x2c48", "[0x34, 0x12]", "[0x12, 0x34]", usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() } } @@ -824,7 +824,7 @@ impl usize { #[lang = "usize"] impl usize { widening_impl! { usize, u64, 32 } - uint_impl! { usize, u32, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678", + uint_impl! { usize, u32, isize, 32, 4294967295, 8, "0x10000b3", "0xb301", "0x12345678", "0x78563412", "0x1e6a2c48", "[0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78]", usize_isize_to_xe_bytes_doc!(), usize_isize_from_xe_bytes_doc!() } } @@ -833,7 +833,7 @@ impl usize { #[lang = "usize"] impl usize { widening_impl! { usize, u128, 64 } - uint_impl! { usize, u64, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa", + uint_impl! { usize, u64, isize, 64, 18446744073709551615, 12, "0xaa00000000006e1", "0x6e10aa", "0x1234567890123456", "0x5634129078563412", "0x6a2c48091e6a2c48", "[0x56, 0x34, 0x12, 0x90, 0x78, 0x56, 0x34, 0x12]", "[0x12, 0x34, 0x56, 0x78, 0x90, 0x12, 0x34, 0x56]", diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 8ce8266263091..67d72a171350b 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1,5 +1,5 @@ macro_rules! uint_impl { - ($SelfT:ty, $ActualT:ident, $BITS:expr, $MaxV:expr, + ($SelfT:ty, $ActualT:ident, $SignedT:ident, $BITS:expr, $MaxV:expr, $rot:expr, $rot_op:expr, $rot_result:expr, $swap_op:expr, $swapped:expr, $reversed:expr, $le_bytes:expr, $be_bytes:expr, $to_xe_bytes_doc:expr, $from_xe_bytes_doc:expr) => { @@ -442,6 +442,29 @@ macro_rules! uint_impl { unsafe { intrinsics::unchecked_add(self, rhs) } } + /// Checked addition with a signed integer. Computes `self + rhs`, + /// returning `None` if overflow occurred. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(uint_add_signed)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(2), Some(3));")] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(-2), None);")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);")] + /// ``` + #[unstable(feature = "uint_add_signed", issue = "none")] + #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn checked_add_signed(self, rhs: $SignedT) -> Option { + let (a, b) = self.overflowing_add_signed(rhs); + if unlikely!(b) {None} else {Some(a)} + } + /// Checked integer subtraction. Computes `self - rhs`, returning /// `None` if overflow occurred. /// @@ -995,6 +1018,32 @@ macro_rules! uint_impl { intrinsics::saturating_add(self, rhs) } + /// Saturating addition with a signed integer. Computes `self + rhs`, + /// saturating at the numeric bounds instead of overflowing. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(uint_add_signed)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_signed(2), 3);")] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_signed(-2), 0);")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).saturating_add_signed(4), ", stringify!($SelfT), "::MAX);")] + /// ``` + #[unstable(feature = "uint_add_signed", issue = "none")] + #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn saturating_add_signed(self, rhs: $SignedT) -> Self { + if rhs >= 0 { + self.saturating_add(rhs as Self) + } else { + self.saturating_sub(rhs.unsigned_abs()) + } + } + /// Saturating integer subtraction. Computes `self - rhs`, saturating /// at the numeric bounds instead of overflowing. /// @@ -1111,6 +1160,28 @@ macro_rules! uint_impl { intrinsics::wrapping_add(self, rhs) } + /// Wrapping (modular) addition with a signed integer. Computes + /// `self + rhs`, wrapping around at the boundary of the type. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(uint_add_signed)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_add_signed(2), 3);")] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_add_signed(-2), ", stringify!($SelfT), "::MAX);")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).wrapping_add_signed(4), 1);")] + /// ``` + #[unstable(feature = "uint_add_signed", issue = "none")] + #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn wrapping_add_signed(self, rhs: $SignedT) -> Self { + self.wrapping_add(rhs as Self) + } + /// Wrapping (modular) subtraction. Computes `self - rhs`, /// wrapping around at the boundary of the type. /// @@ -1435,6 +1506,35 @@ macro_rules! uint_impl { (c, b | d) } + /// Calculates `self` + `rhs` with a signed `rhs` + /// + /// Returns a tuple of the addition along with a boolean indicating + /// whether an arithmetic overflow would occur. If an overflow would + /// have occurred then the wrapped value is returned. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(uint_add_signed)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_signed(2), (3, false));")] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_signed(-2), (", stringify!($SelfT), "::MAX, true));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).overflowing_add_signed(4), (1, true));")] + /// ``` + #[unstable(feature = "uint_add_signed", issue = "none")] + #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn overflowing_add_signed(self, rhs: $SignedT) -> (Self, bool) { + if rhs >= 0 { + self.overflowing_add(rhs as Self) + } else { + self.overflowing_sub(rhs.unsigned_abs()) + } + } + /// Calculates `self` - `rhs` /// /// Returns a tuple of the subtraction along with a boolean indicating diff --git a/library/std/src/io/cursor.rs b/library/std/src/io/cursor.rs index 25cc5e67ad14e..980b2531192e8 100644 --- a/library/std/src/io/cursor.rs +++ b/library/std/src/io/cursor.rs @@ -292,12 +292,7 @@ where SeekFrom::End(n) => (self.inner.as_ref().len() as u64, n), SeekFrom::Current(n) => (self.pos, n), }; - let new_pos = if offset >= 0 { - base_pos.checked_add(offset as u64) - } else { - base_pos.checked_sub((offset.wrapping_neg()) as u64) - }; - match new_pos { + match base_pos.checked_add_signed(offset) { Some(n) => { self.pos = n; Ok(self.pos) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index b33a3c5d22fe1..e9a1aa41a63db 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -333,6 +333,7 @@ #![feature(try_blocks)] #![feature(try_reserve)] #![feature(try_reserve_kind)] +#![feature(uint_add_signed)] #![feature(unboxed_closures)] #![feature(unwrap_infallible)] #![feature(vec_into_raw_parts)] From ab9f8a0b593a832f98188cd755bd467eeb9416d4 Mon Sep 17 00:00:00 2001 From: Alphyr <47725341+a1phyr@users.noreply.github.com> Date: Fri, 30 Jul 2021 12:11:18 +0200 Subject: [PATCH 05/26] Apply suggestion for `overflowing_add_signed` Co-authored-by: kennytm --- library/core/src/num/uint_macros.rs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 67d72a171350b..2c4097a30a1e1 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1528,11 +1528,8 @@ macro_rules! uint_impl { without modifying the original"] #[inline] pub const fn overflowing_add_signed(self, rhs: $SignedT) -> (Self, bool) { - if rhs >= 0 { - self.overflowing_add(rhs as Self) - } else { - self.overflowing_sub(rhs.unsigned_abs()) - } + let (res, overflowed) = self.overflowing_add(rhs as Self); + (res, overflowed ^ (rhs < 0)) } /// Calculates `self` - `rhs` From b5dd5227ee7785174f006a5281622c52533c6075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sat, 7 Aug 2021 11:26:34 +0200 Subject: [PATCH 06/26] Fix doc test --- library/core/src/num/uint_macros.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 2c4097a30a1e1..e6c675edabcc3 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -453,7 +453,7 @@ macro_rules! uint_impl { /// # #![feature(uint_add_signed)] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(2), Some(3));")] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(-2), None);")] - #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add(3), None);")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add_signed(3), None);")] /// ``` #[unstable(feature = "uint_add_signed", issue = "none")] #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] From 9faf6213558c0f0158eff5f2a911dbd6ab804605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sat, 7 Aug 2021 12:11:59 +0200 Subject: [PATCH 07/26] Add methods to add/sub `uX` to/from `iX` --- library/core/src/lib.rs | 2 +- library/core/src/num/int_macros.rs | 190 ++++++++++++++++++++++++++++ library/core/src/num/uint_macros.rs | 24 ++-- library/std/src/lib.rs | 2 +- 4 files changed, 204 insertions(+), 14 deletions(-) diff --git a/library/core/src/lib.rs b/library/core/src/lib.rs index 2e419625d14f6..f41eeae9cc1fa 100644 --- a/library/core/src/lib.rs +++ b/library/core/src/lib.rs @@ -142,6 +142,7 @@ #![feature(link_llvm_intrinsics)] #![feature(llvm_asm)] #![feature(min_specialization)] +#![feature(mixed_integer_ops)] #![cfg_attr(not(bootstrap), feature(must_not_suspend))] #![feature(negative_impls)] #![feature(never_type)] @@ -159,7 +160,6 @@ #![feature(trait_alias)] #![feature(transparent_unions)] #![feature(try_blocks)] -#![feature(uint_add_signed)] #![feature(unboxed_closures)] #![feature(unsized_fn_params)] // diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index daef5c98967cc..5f299687780ef 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -433,6 +433,28 @@ macro_rules! int_impl { unsafe { intrinsics::unchecked_add(self, rhs) } } + /// Checked addition with an unsigned integer. Computes `self + rhs`, + /// returning `None` if overflow occurred. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_unsigned(2), Some(3));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add_unsigned(3), None);")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn checked_add_unsigned(self, rhs: $UnsignedT) -> Option { + let (a, b) = self.overflowing_add_unsigned(rhs); + if unlikely!(b) {None} else {Some(a)} + } + /// Checked integer subtraction. Computes `self - rhs`, returning `None` if /// overflow occurred. /// @@ -479,6 +501,28 @@ macro_rules! int_impl { unsafe { intrinsics::unchecked_sub(self, rhs) } } + /// Checked addition with an unsigned integer. Computes `self + rhs`, + /// returning `None` if overflow occurred. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_sub_unsigned(2), Some(-1));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).checked_sub_unsigned(3), None);")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn checked_sub_unsigned(self, rhs: $UnsignedT) -> Option { + let (a, b) = self.overflowing_sub_unsigned(rhs); + if unlikely!(b) {None} else {Some(a)} + } + /// Checked integer multiplication. Computes `self * rhs`, returning `None` if /// overflow occurred. /// @@ -822,6 +866,31 @@ macro_rules! int_impl { intrinsics::saturating_add(self, rhs) } + /// Saturating addition with an unsigned integer. Computes `self + rhs`, + /// saturating at the numeric bounds instead of overflowing. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_unsigned(2), 3);")] + #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.saturating_add_unsigned(100), ", stringify!($SelfT), "::MAX);")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn saturating_add_unsigned(self, rhs: $UnsignedT) -> Self { + // Overflow can only happen at the upper bound + match self.checked_add_unsigned(rhs) { + Some(x) => x, + None => Self::MAX, + } + } + /// Saturating integer subtraction. Computes `self - rhs`, saturating at the /// numeric bounds instead of overflowing. /// @@ -843,6 +912,31 @@ macro_rules! int_impl { intrinsics::saturating_sub(self, rhs) } + /// Saturating substraction with an unsigned integer. Computes `self - rhs`, + /// saturating at the numeric bounds instead of overflowing. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".saturating_sub_unsigned(127), -27);")] + #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MIN.saturating_sub_unsigned(100), ", stringify!($SelfT), "::MIN);")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn saturating_sub_unsigned(self, rhs: $UnsignedT) -> Self { + // Overflow can only happen at the lower bound + match self.checked_sub_unsigned(rhs) { + Some(x) => x, + None => Self::MIN, + } + } + /// Saturating integer negation. Computes `-self`, returning `MAX` if `self == MIN` /// instead of overflowing. /// @@ -998,6 +1092,27 @@ macro_rules! int_impl { intrinsics::wrapping_add(self, rhs) } + /// Wrapping (modular) addition with an unsigned integer. Computes + /// `self + rhs`, wrapping around at the boundary of the type. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(100", stringify!($SelfT), ".wrapping_add_unsigned(27), 127);")] + #[doc = concat!("assert_eq!(", stringify!($SelfT), "::MAX.wrapping_add_unsigned(2), ", stringify!($SelfT), "::MIN + 1);")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline(always)] + pub const fn wrapping_add_unsigned(self, rhs: $UnsignedT) -> Self { + self.wrapping_add(rhs as Self) + } + /// Wrapping (modular) subtraction. Computes `self - rhs`, wrapping around at the /// boundary of the type. /// @@ -1018,6 +1133,27 @@ macro_rules! int_impl { intrinsics::wrapping_sub(self, rhs) } + /// Wrapping (modular) substraction with an unsigned integer. Computes + /// `self - rhs`, wrapping around at the boundary of the type. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(0", stringify!($SelfT), ".wrapping_sub_unsigned(127), -127);")] + #[doc = concat!("assert_eq!((-2", stringify!($SelfT), ").wrapping_sub_unsigned(", stringify!($UnsignedT), "::MAX), -1);")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline(always)] + pub const fn wrapping_sub_unsigned(self, rhs: $UnsignedT) -> Self { + self.wrapping_sub(rhs as Self) + } + /// Wrapping (modular) multiplication. Computes `self * rhs`, wrapping around at /// the boundary of the type. /// @@ -1368,6 +1504,33 @@ macro_rules! int_impl { (sum as $SelfT, carry) } + /// Calculates `self` + `rhs` with an unsigned `rhs` + /// + /// Returns a tuple of the addition along with a boolean indicating + /// whether an arithmetic overflow would occur. If an overflow would + /// have occurred then the wrapped value is returned. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_unsigned(2), (3, false));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN).overflowing_add_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MAX, false));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).overflowing_add_unsigned(3), (", stringify!($SelfT), "::MIN, true));")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn overflowing_add_unsigned(self, rhs: $UnsignedT) -> (Self, bool) { + let rhs = rhs as Self; + let (res, overflowed) = self.overflowing_add(rhs); + (res, overflowed ^ (rhs < 0)) + } + /// Calculates `self` - `rhs` /// /// Returns a tuple of the subtraction along with a boolean indicating whether an arithmetic overflow @@ -1419,6 +1582,33 @@ macro_rules! int_impl { (sum as $SelfT, borrow) } + /// Calculates `self` - `rhs` with an unsigned `rhs` + /// + /// Returns a tuple of the substraction along with a boolean indicating + /// whether an arithmetic overflow would occur. If an overflow would + /// have occurred then the wrapped value is returned. + /// + /// # Examples + /// + /// Basic usage: + /// + /// ``` + /// # #![feature(mixed_integer_ops)] + #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_sub_unsigned(2), (-1, false));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX).overflowing_sub_unsigned(", stringify!($UnsignedT), "::MAX), (", stringify!($SelfT), "::MIN, false));")] + #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MIN + 2).overflowing_sub_unsigned(3), (", stringify!($SelfT), "::MAX, true));")] + /// ``` + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] + #[must_use = "this returns the result of the operation, \ + without modifying the original"] + #[inline] + pub const fn overflowing_sub_unsigned(self, rhs: $UnsignedT) -> (Self, bool) { + let rhs = rhs as Self; + let (res, overflowed) = self.overflowing_sub(rhs); + (res, overflowed ^ (rhs < 0)) + } + /// Calculates the multiplication of `self` and `rhs`. /// /// Returns a tuple of the multiplication along with a boolean indicating whether an arithmetic overflow diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index e6c675edabcc3..5a65f77a87993 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -450,13 +450,13 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - /// # #![feature(uint_add_signed)] + /// # #![feature(mixed_integer_ops)] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(2), Some(3));")] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".checked_add_signed(-2), None);")] #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).checked_add_signed(3), None);")] /// ``` - #[unstable(feature = "uint_add_signed", issue = "none")] - #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1026,13 +1026,13 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - /// # #![feature(uint_add_signed)] + /// # #![feature(mixed_integer_ops)] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_signed(2), 3);")] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".saturating_add_signed(-2), 0);")] #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).saturating_add_signed(4), ", stringify!($SelfT), "::MAX);")] /// ``` - #[unstable(feature = "uint_add_signed", issue = "none")] - #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1168,13 +1168,13 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - /// # #![feature(uint_add_signed)] + /// # #![feature(mixed_integer_ops)] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_add_signed(2), 3);")] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".wrapping_add_signed(-2), ", stringify!($SelfT), "::MAX);")] #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).wrapping_add_signed(4), 1);")] /// ``` - #[unstable(feature = "uint_add_signed", issue = "none")] - #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] @@ -1517,13 +1517,13 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - /// # #![feature(uint_add_signed)] + /// # #![feature(mixed_integer_ops)] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_signed(2), (3, false));")] #[doc = concat!("assert_eq!(1", stringify!($SelfT), ".overflowing_add_signed(-2), (", stringify!($SelfT), "::MAX, true));")] #[doc = concat!("assert_eq!((", stringify!($SelfT), "::MAX - 2).overflowing_add_signed(4), (1, true));")] /// ``` - #[unstable(feature = "uint_add_signed", issue = "none")] - #[rustc_const_unstable(feature = "uint_add_signed", issue = "none")] + #[unstable(feature = "mixed_integer_ops", issue = "87840")] + #[rustc_const_unstable(feature = "mixed_integer_ops", issue = "87840")] #[must_use = "this returns the result of the operation, \ without modifying the original"] #[inline] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index e9a1aa41a63db..1781a3cb7c402 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -297,6 +297,7 @@ #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_uninit_array)] #![feature(min_specialization)] +#![feature(mixed_integer_ops)] #![cfg_attr(not(bootstrap), feature(must_not_suspend))] #![feature(needs_panic_runtime)] #![feature(negative_impls)] @@ -333,7 +334,6 @@ #![feature(try_blocks)] #![feature(try_reserve)] #![feature(try_reserve_kind)] -#![feature(uint_add_signed)] #![feature(unboxed_closures)] #![feature(unwrap_infallible)] #![feature(vec_into_raw_parts)] From 70e55a8938bb84542f73a127edd5c91f2c8bd0aa Mon Sep 17 00:00:00 2001 From: Alphyr <47725341+a1phyr@users.noreply.github.com> Date: Sun, 3 Oct 2021 22:44:07 +0200 Subject: [PATCH 08/26] Apply suggestions Co-authored-by: kennytm --- library/core/src/num/int_macros.rs | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 5f299687780ef..540b7d36625af 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -501,7 +501,7 @@ macro_rules! int_impl { unsafe { intrinsics::unchecked_sub(self, rhs) } } - /// Checked addition with an unsigned integer. Computes `self + rhs`, + /// Checked subtraction with an unsigned integer. Computes `self - rhs`, /// returning `None` if overflow occurred. /// /// # Examples @@ -885,10 +885,7 @@ macro_rules! int_impl { #[inline] pub const fn saturating_add_unsigned(self, rhs: $UnsignedT) -> Self { // Overflow can only happen at the upper bound - match self.checked_add_unsigned(rhs) { - Some(x) => x, - None => Self::MAX, - } + self.checked_add_unsigned(rhs).unwrap_or(Self::MAX) } /// Saturating integer subtraction. Computes `self - rhs`, saturating at the @@ -912,7 +909,7 @@ macro_rules! int_impl { intrinsics::saturating_sub(self, rhs) } - /// Saturating substraction with an unsigned integer. Computes `self - rhs`, + /// Saturating subtraction with an unsigned integer. Computes `self - rhs`, /// saturating at the numeric bounds instead of overflowing. /// /// # Examples @@ -931,10 +928,7 @@ macro_rules! int_impl { #[inline] pub const fn saturating_sub_unsigned(self, rhs: $UnsignedT) -> Self { // Overflow can only happen at the lower bound - match self.checked_sub_unsigned(rhs) { - Some(x) => x, - None => Self::MIN, - } + self.checked_sub_unsigned(rhs).unwrap_or(Self::MIN) } /// Saturating integer negation. Computes `-self`, returning `MAX` if `self == MIN` @@ -1133,7 +1127,7 @@ macro_rules! int_impl { intrinsics::wrapping_sub(self, rhs) } - /// Wrapping (modular) substraction with an unsigned integer. Computes + /// Wrapping (modular) subtraction with an unsigned integer. Computes /// `self - rhs`, wrapping around at the boundary of the type. /// /// # Examples @@ -1584,7 +1578,7 @@ macro_rules! int_impl { /// Calculates `self` - `rhs` with an unsigned `rhs` /// - /// Returns a tuple of the substraction along with a boolean indicating + /// Returns a tuple of the subtraction along with a boolean indicating /// whether an arithmetic overflow would occur. If an overflow would /// have occurred then the wrapped value is returned. /// From 4846fd92c0cc82545c5fd33c9ab3007f03f0f9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Sun, 3 Oct 2021 22:56:34 +0200 Subject: [PATCH 09/26] Revert suggested use of `unwrap_or` --- library/core/src/num/int_macros.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/library/core/src/num/int_macros.rs b/library/core/src/num/int_macros.rs index 540b7d36625af..5bdb6ed91761f 100644 --- a/library/core/src/num/int_macros.rs +++ b/library/core/src/num/int_macros.rs @@ -885,7 +885,11 @@ macro_rules! int_impl { #[inline] pub const fn saturating_add_unsigned(self, rhs: $UnsignedT) -> Self { // Overflow can only happen at the upper bound - self.checked_add_unsigned(rhs).unwrap_or(Self::MAX) + // We cannot use `unwrap_or` here because it is not `const` + match self.checked_add_unsigned(rhs) { + Some(x) => x, + None => Self::MAX, + } } /// Saturating integer subtraction. Computes `self - rhs`, saturating at the @@ -928,7 +932,11 @@ macro_rules! int_impl { #[inline] pub const fn saturating_sub_unsigned(self, rhs: $UnsignedT) -> Self { // Overflow can only happen at the lower bound - self.checked_sub_unsigned(rhs).unwrap_or(Self::MIN) + // We cannot use `unwrap_or` here because it is not `const` + match self.checked_sub_unsigned(rhs) { + Some(x) => x, + None => Self::MIN, + } } /// Saturating integer negation. Computes `-self`, returning `MAX` if `self == MIN` From a8a40ea9a4947a7b46421564517ee2aa4e3711f0 Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Fri, 1 Oct 2021 06:17:15 -0400 Subject: [PATCH 10/26] librustdoc: Use correct heading levels. - Avoid multiple

s on a page. - The tags should follow a semantic hierarchy. - Cap at h6 (no h7) --- .../src/error_codes/E0001.md | 2 +- .../src/error_codes/E0002.md | 2 +- .../src/error_codes/E0007.md | 2 +- .../src/error_codes/E0009.md | 2 +- .../src/error_codes/E0014.md | 2 +- .../src/error_codes/E0073.md | 2 +- .../src/error_codes/E0074.md | 2 +- .../src/error_codes/E0087.md | 2 +- .../src/error_codes/E0088.md | 2 +- .../src/error_codes/E0089.md | 2 +- .../src/error_codes/E0090.md | 2 +- .../src/error_codes/E0110.md | 2 +- .../src/error_codes/E0136.md | 2 +- .../src/error_codes/E0137.md | 2 +- .../src/error_codes/E0139.md | 2 +- .../src/error_codes/E0154.md | 2 +- .../src/error_codes/E0162.md | 2 +- .../src/error_codes/E0165.md | 2 +- .../src/error_codes/E0193.md | 2 +- .../src/error_codes/E0205.md | 2 +- .../src/error_codes/E0211.md | 2 +- .../src/error_codes/E0243.md | 2 +- .../src/error_codes/E0244.md | 2 +- .../src/error_codes/E0251.md | 2 +- .../src/error_codes/E0256.md | 2 +- .../src/error_codes/E0281.md | 2 +- .../src/error_codes/E0297.md | 2 +- .../src/error_codes/E0301.md | 2 +- .../src/error_codes/E0302.md | 2 +- .../src/error_codes/E0303.md | 2 +- .../src/error_codes/E0329.md | 2 +- .../src/error_codes/E0383.md | 2 +- .../src/error_codes/E0386.md | 2 +- .../src/error_codes/E0387.md | 2 +- .../src/error_codes/E0388.md | 2 +- .../src/error_codes/E0389.md | 2 +- .../src/error_codes/E0398.md | 2 +- .../src/error_codes/E0399.md | 2 +- .../src/error_codes/E0439.md | 2 +- .../src/error_codes/E0447.md | 2 +- .../src/error_codes/E0448.md | 2 +- .../src/error_codes/E0497.md | 2 +- .../src/error_codes/E0504.md | 2 +- .../src/error_codes/E0595.md | 2 +- .../src/error_codes/E0619.md | 2 +- .../src/error_codes/E0633.md | 2 +- .../src/error_codes/E0665.md | 2 +- .../src/error_codes/E0671.md | 2 +- src/librustdoc/externalfiles.rs | 4 +- src/librustdoc/html/markdown.rs | 21 +++++--- src/librustdoc/html/markdown/tests.rs | 32 ++++++------ src/librustdoc/html/render/mod.rs | 52 ++++++++++++++----- src/librustdoc/html/render/print_item.rs | 10 ++-- src/librustdoc/html/static/css/rustdoc.css | 19 ++++--- src/librustdoc/html/static/css/themes/ayu.css | 2 +- .../html/static/css/themes/dark.css | 2 +- .../html/static/css/themes/light.css | 2 +- src/librustdoc/markdown.rs | 2 +- src/test/rustdoc/external-cross.rs | 2 +- src/test/rustdoc/external-doc.rs | 6 +-- src/test/rustdoc/issue-42760.rs | 2 +- src/test/rustdoc/short-docblock.rs | 4 +- src/test/rustdoc/smart-punct.rs | 2 +- src/tools/error_index_generator/main.rs | 3 +- src/tools/tidy/src/error_codes_check.rs | 4 +- 65 files changed, 147 insertions(+), 118 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0001.md b/compiler/rustc_error_codes/src/error_codes/E0001.md index 90756780d1502..cd6e15f581f3b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0001.md +++ b/compiler/rustc_error_codes/src/error_codes/E0001.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error suggests that the expression arm corresponding to the noted pattern will never be reached as for all possible values of the expression being diff --git a/compiler/rustc_error_codes/src/error_codes/E0002.md b/compiler/rustc_error_codes/src/error_codes/E0002.md index 5cb59da10e00b..4e7aa7fb9ed81 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0002.md +++ b/compiler/rustc_error_codes/src/error_codes/E0002.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error indicates that an empty match expression is invalid because the type it is matching on is non-empty (there exist values of this type). In safe code diff --git a/compiler/rustc_error_codes/src/error_codes/E0007.md b/compiler/rustc_error_codes/src/error_codes/E0007.md index 2c22b86af9246..d30de4af0eb37 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0007.md +++ b/compiler/rustc_error_codes/src/error_codes/E0007.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error indicates that the bindings in a match arm would require a value to be moved into more than one location, thus violating unique ownership. Code diff --git a/compiler/rustc_error_codes/src/error_codes/E0009.md b/compiler/rustc_error_codes/src/error_codes/E0009.md index aaabba0434993..6aab44cb4d6ec 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0009.md +++ b/compiler/rustc_error_codes/src/error_codes/E0009.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. In a pattern, all values that don't implement the `Copy` trait have to be bound the same way. The goal here is to avoid binding simultaneously by-move and diff --git a/compiler/rustc_error_codes/src/error_codes/E0014.md b/compiler/rustc_error_codes/src/error_codes/E0014.md index 2c69957e9f642..27ae8f098987a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0014.md +++ b/compiler/rustc_error_codes/src/error_codes/E0014.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Constants can only be initialized by a constant value or, in a future version of Rust, a call to a const function. This error indicates the use diff --git a/compiler/rustc_error_codes/src/error_codes/E0073.md b/compiler/rustc_error_codes/src/error_codes/E0073.md index a5aea86ff2d9d..39c16bc438fea 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0073.md +++ b/compiler/rustc_error_codes/src/error_codes/E0073.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You cannot define a struct (or enum) `Foo` that requires an instance of `Foo` in order to make a new `Foo` value. This is because there would be no way a diff --git a/compiler/rustc_error_codes/src/error_codes/E0074.md b/compiler/rustc_error_codes/src/error_codes/E0074.md index 785d6de226d3d..026acac99e74f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0074.md +++ b/compiler/rustc_error_codes/src/error_codes/E0074.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. When using the `#[simd]` attribute on a tuple struct, the components of the tuple struct must all be of a concrete, nongeneric type so the compiler can diff --git a/compiler/rustc_error_codes/src/error_codes/E0087.md b/compiler/rustc_error_codes/src/error_codes/E0087.md index 9d292186f0fa5..cd2da0469bb63 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0087.md +++ b/compiler/rustc_error_codes/src/error_codes/E0087.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Too many type arguments were supplied for a function. For example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0088.md b/compiler/rustc_error_codes/src/error_codes/E0088.md index 7780ad5b56e03..6b565507ce4a3 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0088.md +++ b/compiler/rustc_error_codes/src/error_codes/E0088.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You gave too many lifetime arguments. Erroneous code example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0089.md b/compiler/rustc_error_codes/src/error_codes/E0089.md index 504fbc7b96a98..b78f95f266c19 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0089.md +++ b/compiler/rustc_error_codes/src/error_codes/E0089.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Too few type arguments were supplied for a function. For example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0090.md b/compiler/rustc_error_codes/src/error_codes/E0090.md index e091bb6c9f2f7..7b07a86dc25a4 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0090.md +++ b/compiler/rustc_error_codes/src/error_codes/E0090.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You gave too few lifetime arguments. Example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0110.md b/compiler/rustc_error_codes/src/error_codes/E0110.md index b9fe406ffb9bd..91f599ff1dcfb 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0110.md +++ b/compiler/rustc_error_codes/src/error_codes/E0110.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You tried to provide a lifetime to a type which doesn't need it. See `E0109` for more details. diff --git a/compiler/rustc_error_codes/src/error_codes/E0136.md b/compiler/rustc_error_codes/src/error_codes/E0136.md index 15cf09a18cbde..0a74558e75b05 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0136.md +++ b/compiler/rustc_error_codes/src/error_codes/E0136.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. More than one `main` function was found. diff --git a/compiler/rustc_error_codes/src/error_codes/E0137.md b/compiler/rustc_error_codes/src/error_codes/E0137.md index d4e19170f3f7b..ba6f02add9494 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0137.md +++ b/compiler/rustc_error_codes/src/error_codes/E0137.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. More than one function was declared with the `#[main]` attribute. diff --git a/compiler/rustc_error_codes/src/error_codes/E0139.md b/compiler/rustc_error_codes/src/error_codes/E0139.md index a116cf29395fa..e7ad2a6f44dc1 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0139.md +++ b/compiler/rustc_error_codes/src/error_codes/E0139.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. There are various restrictions on transmuting between types in Rust; for example types being transmuted must have the same size. To apply all these restrictions, diff --git a/compiler/rustc_error_codes/src/error_codes/E0154.md b/compiler/rustc_error_codes/src/error_codes/E0154.md index e437a71897c66..9c954839eee6b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0154.md +++ b/compiler/rustc_error_codes/src/error_codes/E0154.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Imports (`use` statements) are not allowed after non-item statements, such as variable declarations and expression statements. diff --git a/compiler/rustc_error_codes/src/error_codes/E0162.md b/compiler/rustc_error_codes/src/error_codes/E0162.md index 0161c9325c211..2e0f387e3521f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0162.md +++ b/compiler/rustc_error_codes/src/error_codes/E0162.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. An `if let` pattern attempts to match the pattern, and enters the body if the match was successful. If the match is irrefutable (when it cannot fail to diff --git a/compiler/rustc_error_codes/src/error_codes/E0165.md b/compiler/rustc_error_codes/src/error_codes/E0165.md index 7bcd6c0cbf379..3222b7a87eb65 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0165.md +++ b/compiler/rustc_error_codes/src/error_codes/E0165.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. A `while let` pattern attempts to match the pattern, and enters the body if the match was successful. If the match is irrefutable (when it cannot fail to diff --git a/compiler/rustc_error_codes/src/error_codes/E0193.md b/compiler/rustc_error_codes/src/error_codes/E0193.md index e29a949ffba91..6e7ebbaddf921 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0193.md +++ b/compiler/rustc_error_codes/src/error_codes/E0193.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. `where` clauses must use generic type parameters: it does not make sense to use them otherwise. An example causing this error: diff --git a/compiler/rustc_error_codes/src/error_codes/E0205.md b/compiler/rustc_error_codes/src/error_codes/E0205.md index 7916f53ad3b41..07bbd1f68347b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0205.md +++ b/compiler/rustc_error_codes/src/error_codes/E0205.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. An attempt to implement the `Copy` trait for an enum failed because one of the variants does not implement `Copy`. To fix this, you must implement `Copy` for diff --git a/compiler/rustc_error_codes/src/error_codes/E0211.md b/compiler/rustc_error_codes/src/error_codes/E0211.md index 77289f019005e..2485367e09712 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0211.md +++ b/compiler/rustc_error_codes/src/error_codes/E0211.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You used a function or type which doesn't fit the requirements for where it was used. Erroneous code examples: diff --git a/compiler/rustc_error_codes/src/error_codes/E0243.md b/compiler/rustc_error_codes/src/error_codes/E0243.md index 5d3d1828bf59b..ef4a837ec2172 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0243.md +++ b/compiler/rustc_error_codes/src/error_codes/E0243.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error indicates that not enough type parameters were found in a type or trait. diff --git a/compiler/rustc_error_codes/src/error_codes/E0244.md b/compiler/rustc_error_codes/src/error_codes/E0244.md index 5187b7b05d2c1..31c5b4542e28f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0244.md +++ b/compiler/rustc_error_codes/src/error_codes/E0244.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error indicates that too many type parameters were found in a type or trait. diff --git a/compiler/rustc_error_codes/src/error_codes/E0251.md b/compiler/rustc_error_codes/src/error_codes/E0251.md index 4121dd27877a0..7b048db5ece3e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0251.md +++ b/compiler/rustc_error_codes/src/error_codes/E0251.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Two items of the same name cannot be imported without rebinding one of the items under a new local name. diff --git a/compiler/rustc_error_codes/src/error_codes/E0256.md b/compiler/rustc_error_codes/src/error_codes/E0256.md index 385376cdade91..1b518b1615b64 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0256.md +++ b/compiler/rustc_error_codes/src/error_codes/E0256.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You can't import a type or module when the name of the item being imported is the same as another type or submodule defined in the module. diff --git a/compiler/rustc_error_codes/src/error_codes/E0281.md b/compiler/rustc_error_codes/src/error_codes/E0281.md index 1d7904b67ddb4..2d8ead0b0181c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0281.md +++ b/compiler/rustc_error_codes/src/error_codes/E0281.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. You tried to supply a type which doesn't implement some trait in a location which expected that trait. This error typically occurs when working with diff --git a/compiler/rustc_error_codes/src/error_codes/E0297.md b/compiler/rustc_error_codes/src/error_codes/E0297.md index 66c31376d8b28..001e0f3089e15 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0297.md +++ b/compiler/rustc_error_codes/src/error_codes/E0297.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Patterns used to bind names must be irrefutable. That is, they must guarantee that a name will be extracted in all cases. Instead of pattern matching the diff --git a/compiler/rustc_error_codes/src/error_codes/E0301.md b/compiler/rustc_error_codes/src/error_codes/E0301.md index 485e19fbb8d9c..7b1e02051dc4e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0301.md +++ b/compiler/rustc_error_codes/src/error_codes/E0301.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Mutable borrows are not allowed in pattern guards, because matching cannot have side effects. Side effects could alter the matched object or the environment diff --git a/compiler/rustc_error_codes/src/error_codes/E0302.md b/compiler/rustc_error_codes/src/error_codes/E0302.md index e6ac9d590c88f..c56500fcebce8 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0302.md +++ b/compiler/rustc_error_codes/src/error_codes/E0302.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Assignments are not allowed in pattern guards, because matching cannot have side effects. Side effects could alter the matched object or the environment diff --git a/compiler/rustc_error_codes/src/error_codes/E0303.md b/compiler/rustc_error_codes/src/error_codes/E0303.md index 459906047cc87..750b766f5bfdf 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0303.md +++ b/compiler/rustc_error_codes/src/error_codes/E0303.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Sub-bindings, e.g. `ref x @ Some(ref y)` are now allowed under `#![feature(bindings_after_at)]` and checked to make sure that diff --git a/compiler/rustc_error_codes/src/error_codes/E0329.md b/compiler/rustc_error_codes/src/error_codes/E0329.md index 37d84a1a89bfe..36114316e8803 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0329.md +++ b/compiler/rustc_error_codes/src/error_codes/E0329.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. An attempt was made to access an associated constant through either a generic type parameter or `Self`. This is not supported yet. An example causing this diff --git a/compiler/rustc_error_codes/src/error_codes/E0383.md b/compiler/rustc_error_codes/src/error_codes/E0383.md index fd2b0b08fb007..309eb2b59eb97 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0383.md +++ b/compiler/rustc_error_codes/src/error_codes/E0383.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to partially reinitialize a structure that is currently uninitialized. diff --git a/compiler/rustc_error_codes/src/error_codes/E0386.md b/compiler/rustc_error_codes/src/error_codes/E0386.md index de3b468b6e4ac..5e45a2b40cefa 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0386.md +++ b/compiler/rustc_error_codes/src/error_codes/E0386.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to mutate the target of a mutable reference stored inside an immutable container. diff --git a/compiler/rustc_error_codes/src/error_codes/E0387.md b/compiler/rustc_error_codes/src/error_codes/E0387.md index 38ad19bd6aa9a..ddc838bdca1b3 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0387.md +++ b/compiler/rustc_error_codes/src/error_codes/E0387.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to mutate or mutably reference data that a closure has captured immutably. diff --git a/compiler/rustc_error_codes/src/error_codes/E0388.md b/compiler/rustc_error_codes/src/error_codes/E0388.md index 512fb42e6ecb5..13ef94a48553b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0388.md +++ b/compiler/rustc_error_codes/src/error_codes/E0388.md @@ -1 +1 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. diff --git a/compiler/rustc_error_codes/src/error_codes/E0389.md b/compiler/rustc_error_codes/src/error_codes/E0389.md index 9f064e44c8209..19bb6ec408131 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0389.md +++ b/compiler/rustc_error_codes/src/error_codes/E0389.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. An attempt was made to mutate data using a non-mutable reference. This commonly occurs when attempting to assign to a non-mutable reference of a diff --git a/compiler/rustc_error_codes/src/error_codes/E0398.md b/compiler/rustc_error_codes/src/error_codes/E0398.md index 75d86979e3c87..12e0eb1a5d5dd 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0398.md +++ b/compiler/rustc_error_codes/src/error_codes/E0398.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. In Rust 1.3, the default object lifetime bounds are expected to change, as described in [RFC 1156]. You are getting a warning because the compiler diff --git a/compiler/rustc_error_codes/src/error_codes/E0399.md b/compiler/rustc_error_codes/src/error_codes/E0399.md index 6ea6054b41779..c3e9616c60698 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0399.md +++ b/compiler/rustc_error_codes/src/error_codes/E0399.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler +### Note: this error code is no longer emitted by the compiler You implemented a trait, overriding one or more of its associated types but did not reimplement its default methods. diff --git a/compiler/rustc_error_codes/src/error_codes/E0439.md b/compiler/rustc_error_codes/src/error_codes/E0439.md index 24268aef2222a..85e965c4eee62 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0439.md +++ b/compiler/rustc_error_codes/src/error_codes/E0439.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. The length of the platform-intrinsic function `simd_shuffle` wasn't specified. diff --git a/compiler/rustc_error_codes/src/error_codes/E0447.md b/compiler/rustc_error_codes/src/error_codes/E0447.md index af8cd8d6d5202..e880ff4637da7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0447.md +++ b/compiler/rustc_error_codes/src/error_codes/E0447.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. The `pub` keyword was used inside a function. diff --git a/compiler/rustc_error_codes/src/error_codes/E0448.md b/compiler/rustc_error_codes/src/error_codes/E0448.md index ba096f9e984ae..f4bd184188824 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0448.md +++ b/compiler/rustc_error_codes/src/error_codes/E0448.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. The `pub` keyword was used inside a public enum. diff --git a/compiler/rustc_error_codes/src/error_codes/E0497.md b/compiler/rustc_error_codes/src/error_codes/E0497.md index ef2882415d24a..12004996384a2 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0497.md +++ b/compiler/rustc_error_codes/src/error_codes/E0497.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. A stability attribute was used outside of the standard library. diff --git a/compiler/rustc_error_codes/src/error_codes/E0504.md b/compiler/rustc_error_codes/src/error_codes/E0504.md index bcbd00a8690a4..640cfad656f71 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0504.md +++ b/compiler/rustc_error_codes/src/error_codes/E0504.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to move a borrowed variable into a closure. diff --git a/compiler/rustc_error_codes/src/error_codes/E0595.md b/compiler/rustc_error_codes/src/error_codes/E0595.md index e6729013243f6..96fbb5e410ae7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0595.md +++ b/compiler/rustc_error_codes/src/error_codes/E0595.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Closures cannot mutate immutable captured variables. diff --git a/compiler/rustc_error_codes/src/error_codes/E0619.md b/compiler/rustc_error_codes/src/error_codes/E0619.md index f516de43095bd..d33154058dd37 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0619.md +++ b/compiler/rustc_error_codes/src/error_codes/E0619.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. The type-checker needed to know the type of an expression, but that type had not yet been inferred. diff --git a/compiler/rustc_error_codes/src/error_codes/E0633.md b/compiler/rustc_error_codes/src/error_codes/E0633.md index 5b6c15c82eb63..f6e8a4042ed35 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0633.md +++ b/compiler/rustc_error_codes/src/error_codes/E0633.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. The `unwind` attribute was malformed. diff --git a/compiler/rustc_error_codes/src/error_codes/E0665.md b/compiler/rustc_error_codes/src/error_codes/E0665.md index ae54d6d15798d..db5e088cc501e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0665.md +++ b/compiler/rustc_error_codes/src/error_codes/E0665.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. The `Default` trait was derived on an enum. diff --git a/compiler/rustc_error_codes/src/error_codes/E0671.md b/compiler/rustc_error_codes/src/error_codes/E0671.md index d4dbfb7a5d8e6..a68273f752e73 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0671.md +++ b/compiler/rustc_error_codes/src/error_codes/E0671.md @@ -1,4 +1,4 @@ -#### Note: this error code is no longer emitted by the compiler. +### Note: this error code is no longer emitted by the compiler. Const parameters cannot depend on type parameters. The following is therefore invalid: diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 56d2ca57218c5..1fd5e2d5ef67e 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -39,14 +39,14 @@ impl ExternalHtml { let bc = format!( "{}{}", bc, - Markdown(&m_bc, &[], id_map, codes, edition, playground).into_string() + Markdown(&m_bc, &[], id_map, codes, edition, playground, 0).into_string() ); let ac = load_external_files(after_content, diag)?; let m_ac = load_external_files(md_after_content, diag)?; let ac = format!( "{}{}", ac, - Markdown(&m_ac, &[], id_map, codes, edition, playground).into_string() + Markdown(&m_ac, &[], id_map, codes, edition, playground, 0).into_string() ); Some(ExternalHtml { in_header: ih, before_content: bc, after_content: ac }) } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index fda2512a05036..56b580a05188c 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -12,7 +12,7 @@ //! //! let s = "My *markdown* _text_"; //! let mut id_map = IdMap::new(); -//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None); +//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None, 0); //! let html = md.into_string(); //! // ... something using html //! ``` @@ -47,6 +47,8 @@ use pulldown_cmark::{ #[cfg(test)] mod tests; +const MAX_HEADER_LEVEL: u32 = 6; + /// Options for rendering Markdown in the main body of documentation. pub(crate) fn main_body_opts() -> Options { Options::ENABLE_TABLES @@ -78,6 +80,7 @@ pub struct Markdown<'a>( /// Default edition to use when parsing doctests (to add a `fn main`). pub Edition, pub &'a Option, + pub u32, ); /// A tuple struct like `Markdown` that renders the markdown with a table of contents. crate struct MarkdownWithToc<'a>( @@ -489,11 +492,12 @@ struct HeadingLinks<'a, 'b, 'ids, I> { toc: Option<&'b mut TocBuilder>, buf: VecDeque>, id_map: &'ids mut IdMap, + level: u32, } impl<'a, 'b, 'ids, I> HeadingLinks<'a, 'b, 'ids, I> { - fn new(iter: I, toc: Option<&'b mut TocBuilder>, ids: &'ids mut IdMap) -> Self { - HeadingLinks { inner: iter, toc, buf: VecDeque::new(), id_map: ids } + fn new(iter: I, toc: Option<&'b mut TocBuilder>, ids: &'ids mut IdMap, level: u32) -> Self { + HeadingLinks { inner: iter, toc, buf: VecDeque::new(), id_map: ids, level } } } @@ -530,6 +534,7 @@ impl<'a, 'b, 'ids, I: Iterator>> Iterator self.buf.push_front((Event::Html(format!("{} ", sec).into()), 0..0)); } + let level = std::cmp::min(level + self.level + 1, MAX_HEADER_LEVEL); self.buf.push_back((Event::Html(format!("", level).into()), 0..0)); let start_tags = format!( @@ -1005,7 +1010,7 @@ impl LangString { impl Markdown<'_> { pub fn into_string(self) -> String { - let Markdown(md, links, mut ids, codes, edition, playground) = self; + let Markdown(md, links, mut ids, codes, edition, playground, level) = self; // This is actually common enough to special-case if md.is_empty() { @@ -1026,7 +1031,7 @@ impl Markdown<'_> { let mut s = String::with_capacity(md.len() * 3 / 2); - let p = HeadingLinks::new(p, None, &mut ids); + let p = HeadingLinks::new(p, None, &mut ids, level); let p = Footnotes::new(p); let p = LinkReplacer::new(p.map(|(ev, _)| ev), links); let p = TableWrapper::new(p); @@ -1048,7 +1053,7 @@ impl MarkdownWithToc<'_> { let mut toc = TocBuilder::new(); { - let p = HeadingLinks::new(p, Some(&mut toc), &mut ids); + let p = HeadingLinks::new(p, Some(&mut toc), &mut ids, 0); let p = Footnotes::new(p); let p = TableWrapper::new(p.map(|(ev, _)| ev)); let p = CodeBlocks::new(p, codes, edition, playground); @@ -1077,7 +1082,7 @@ impl MarkdownHtml<'_> { let mut s = String::with_capacity(md.len() * 3 / 2); - let p = HeadingLinks::new(p, None, &mut ids); + let p = HeadingLinks::new(p, None, &mut ids, 0); let p = Footnotes::new(p); let p = TableWrapper::new(p.map(|(ev, _)| ev)); let p = CodeBlocks::new(p, codes, edition, playground); @@ -1295,7 +1300,7 @@ crate fn markdown_links(md: &str) -> Vec { // There's no need to thread an IdMap through to here because // the IDs generated aren't going to be emitted anywhere. let mut ids = IdMap::new(); - let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids)); + let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids, 0)); for ev in iter { if let Event::Start(Tag::Link(kind, dest, _)) = ev.0 { diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 1e4cf3381f6a3..c6af7e5847c52 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -147,33 +147,33 @@ fn test_lang_string_tokenizer() { fn test_header() { fn t(input: &str, expect: &str) { let mut map = IdMap::new(); - let output = - Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None).into_string(); + let output = Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0) + .into_string(); assert_eq!(output, expect, "original: {}", input); } t( "# Foo bar", - "

Foo bar

", + "

Foo bar

", ); t( "## Foo-bar_baz qux", - "

\ - Foo-bar_baz qux

", + "

\ + Foo-bar_baz qux

", ); t( "### **Foo** *bar* baz!?!& -_qux_-%", - "

\ + "

\ Foo \ bar baz!?!& -qux-%\ -

", +

", ); t( "#### **Foo?** & \\*bar?!* _`baz`_ ❤ #qux", - "

\ + "

\ Foo? & *bar?!* \ baz ❤ #qux\ -
", + ", ); } @@ -182,39 +182,39 @@ fn test_header_ids_multiple_blocks() { let mut map = IdMap::new(); fn t(map: &mut IdMap, input: &str, expect: &str) { let output = - Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None).into_string(); + Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0).into_string(); assert_eq!(output, expect, "original: {}", input); } t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Panics", - "

Panics

", + "

Panics

", ); t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Main", - "

Main

", + "

Main

", ); t( &mut map, "# Example", - "

Example

", + "

Example

", ); t( &mut map, "# Panics", - "

Panics

", + "

Panics

", ); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 5045a99800ab1..69f39bb58a853 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -471,19 +471,35 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result, item: &clean::Item, parent: Option<&clean::Item>) { + document_at_level(w, cx, item, parent, 0) +} + +fn document_at_level( + w: &mut Buffer, + cx: &Context<'_>, + item: &clean::Item, + parent: Option<&clean::Item>, + level: u32, +) { if let Some(ref name) = item.name { info!("Documenting {}", name); } document_item_info(w, cx, item, parent); if parent.is_none() { - document_full_collapsible(w, item, cx); + document_full_collapsible(w, item, cx, level); } else { - document_full(w, item, cx); + document_full(w, item, cx, level); } } /// Render md_text as markdown. -fn render_markdown(w: &mut Buffer, cx: &Context<'_>, md_text: &str, links: Vec) { +fn render_markdown( + w: &mut Buffer, + cx: &Context<'_>, + md_text: &str, + links: Vec, + level: u32, +) { let mut ids = cx.id_map.borrow_mut(); write!( w, @@ -494,7 +510,8 @@ fn render_markdown(w: &mut Buffer, cx: &Context<'_>, md_text: &str, links: Vec) { - document_full_inner(w, item, cx, true); +fn document_full_collapsible(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, level: u32) { + document_full_inner(w, item, cx, true, level); } -fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>) { - document_full_inner(w, item, cx, false); +fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, level: u32) { + document_full_inner(w, item, cx, false, level); } -fn document_full_inner(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_collapsible: bool) { +fn document_full_inner( + w: &mut Buffer, + item: &clean::Item, + cx: &Context<'_>, + is_collapsible: bool, + level: u32, +) { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { debug!("Doc block: =====\n{}\n=====", s); if is_collapsible { @@ -549,10 +572,10 @@ fn document_full_inner(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, is_ Expand description\ ", ); - render_markdown(w, cx, &s, item.links(cx)); + render_markdown(w, cx, &s, item.links(cx), level); w.write_str(""); } else { - render_markdown(w, cx, &s, item.links(cx)); + render_markdown(w, cx, &s, item.links(cx), level); } } } @@ -1321,7 +1344,7 @@ fn render_impl( // because impls can't have a stability. if item.doc_value().is_some() { document_item_info(&mut info_buffer, cx, it, Some(parent)); - document_full(&mut doc_buffer, item, cx); + document_full(&mut doc_buffer, item, cx, 0); short_documented = false; } else { // In case the item isn't documented, @@ -1339,7 +1362,7 @@ fn render_impl( } else { document_item_info(&mut info_buffer, cx, item, Some(parent)); if rendering_params.show_def_docs { - document_full(&mut doc_buffer, item, cx); + document_full(&mut doc_buffer, item, cx, 3); short_documented = false; } } @@ -1579,7 +1602,8 @@ fn render_impl( &mut ids, cx.shared.codes, cx.shared.edition(), - &cx.shared.playground + &cx.shared.playground, + 0 ) .into_string() ); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index fa0d211efe630..59a6925d8b459 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -16,10 +16,10 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants}; use super::{ - collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl, - render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre, - render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context, - ImplRenderingParameters, + collect_paths_for_type, document, document_at_level, ensure_trailing_slash, item_ty_to_strs, + notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code, + render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink, + AssocItemLink, Context, ImplRenderingParameters, }; use crate::clean::{self, GetDefId}; use crate::formats::item_type::ItemType; @@ -626,7 +626,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); let mut content = Buffer::empty_from(w); - document(&mut content, cx, m, Some(t)); + document_at_level(&mut content, cx, m, Some(t), 3); let toggled = !content.is_empty(); if toggled { write!(w, "
"); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index eb7cc9309f416..925d76956ab77 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -126,7 +126,7 @@ h2 { h3 { font-size: 1.3em; } -h1, h2, h3, h4 { +h1, h2, h3, h4, h5, h6 { font-weight: 500; margin: 20px 0 15px 0; padding-bottom: 6px; @@ -179,7 +179,7 @@ div.impl-items > div { padding-left: 0; } -h1, h2, h3, h4, +h1, h2, h3, h4, h5, h6, .sidebar, a.source, .search-input, .search-results .result-name, .content table td:first-child > a, .item-left > a, @@ -501,21 +501,20 @@ nav.sub { white-space: pre-wrap; } -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom: 1px solid; } -.top-doc .docblock h1 { font-size: 1.3em; } -.top-doc .docblock h2 { font-size: 1.15em; } -.top-doc .docblock h3, +.top-doc .docblock h2 { font-size: 1.3em; } +.top-doc .docblock h3 { font-size: 1.15em; } .top-doc .docblock h4, -.top-doc .docblock h5 { +.top-doc .docblock h5, +.top-doc .docblock h6 { font-size: 1em; } -.docblock h1 { font-size: 1em; } -.docblock h2 { font-size: 0.95em; } -.docblock h3, .docblock h4, .docblock h5 { font-size: 0.9em; } +.docblock h5 { font-size: 1em; } +.docblock h6 { font-size: 0.95em; } .docblock { margin-left: 24px; diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index c79801e830876..0fb4f95acdf34 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -136,7 +136,7 @@ pre, .rustdoc.source .example-wrap { border-right: 1px solid #ffb44c; } -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { +.docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom-color: #5c6773; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index d2e54070acd68..4fb6f7b38bbf2 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -93,7 +93,7 @@ pre, .rustdoc.source .example-wrap { background-color: #0a042f !important; } -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { +.docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom-color: #DDD; } diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 25d810560c146..62134f025c82a 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -93,7 +93,7 @@ pre, .rustdoc.source .example-wrap { background-color: #f6fdb0 !important; } -.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5 { +.docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom-color: #ddd; } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 2ae4897dc3496..82e6231782c1e 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -70,7 +70,7 @@ crate fn render>( let text = if !options.markdown_no_toc { MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string() } else { - Markdown(text, &[], &mut ids, error_codes, edition, &playground).into_string() + Markdown(text, &[], &mut ids, error_codes, edition, &playground, 0).into_string() }; let err = write!( diff --git a/src/test/rustdoc/external-cross.rs b/src/test/rustdoc/external-cross.rs index 056ed3534624b..3f8e16882911a 100644 --- a/src/test/rustdoc/external-cross.rs +++ b/src/test/rustdoc/external-cross.rs @@ -6,5 +6,5 @@ extern crate external_cross; // @has host/struct.NeedMoreDocs.html -// @has - '//h1' 'Cross-crate imported docs' +// @has - '//h2' 'Cross-crate imported docs' pub use external_cross::NeedMoreDocs; diff --git a/src/test/rustdoc/external-doc.rs b/src/test/rustdoc/external-doc.rs index fc29cb252e26c..bd322d67a370d 100644 --- a/src/test/rustdoc/external-doc.rs +++ b/src/test/rustdoc/external-doc.rs @@ -1,6 +1,6 @@ // @has external_doc/struct.IncludeStrDocs.html -// @has - '//h1' 'External Docs' -// @has - '//h2' 'Inline Docs' +// @has - '//h2' 'External Docs' +// @has - '//h3' 'Inline Docs' #[doc = include_str!("auxiliary/external-doc.md")] /// ## Inline Docs pub struct IncludeStrDocs; @@ -8,7 +8,7 @@ pub struct IncludeStrDocs; macro_rules! dir { () => { "auxiliary" } } // @has external_doc/struct.EagerExpansion.html -// @has - '//h1' 'External Docs' +// @has - '//h2' 'External Docs' #[doc = include_str!(concat!(dir!(), "/external-doc.md"))] /// ## Inline Docs pub struct EagerExpansion; diff --git a/src/test/rustdoc/issue-42760.rs b/src/test/rustdoc/issue-42760.rs index b07dc3f6e967b..4944f8157014e 100644 --- a/src/test/rustdoc/issue-42760.rs +++ b/src/test/rustdoc/issue-42760.rs @@ -1,5 +1,5 @@ // @has issue_42760/struct.NonGen.html -// @has - '//h1' 'Example' +// @has - '//h2' 'Example' /// Item docs. /// diff --git a/src/test/rustdoc/short-docblock.rs b/src/test/rustdoc/short-docblock.rs index 74fa783174da8..17c44eab091a6 100644 --- a/src/test/rustdoc/short-docblock.rs +++ b/src/test/rustdoc/short-docblock.rs @@ -2,7 +2,7 @@ // @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'fooo' // @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h1' 'fooo' -// @has foo/fn.foo.html '//h1[@id="fooo"]/a[@href="#fooo"]' 'fooo' +// @has foo/fn.foo.html '//h2[@id="fooo"]/a[@href="#fooo"]' 'fooo' /// # fooo /// @@ -11,7 +11,7 @@ pub fn foo() {} // @has foo/index.html '//*[@class="item-right docblock-short"]/p' 'mooood' // @!has foo/index.html '//*[@class="item-right docblock-short"]/p/h2' 'mooood' -// @has foo/foo/index.html '//h2[@id="mooood"]/a[@href="#mooood"]' 'mooood' +// @has foo/foo/index.html '//h3[@id="mooood"]/a[@href="#mooood"]' 'mooood' /// ## mooood /// diff --git a/src/test/rustdoc/smart-punct.rs b/src/test/rustdoc/smart-punct.rs index 5319892c99c23..7ae5bd6994579 100644 --- a/src/test/rustdoc/smart-punct.rs +++ b/src/test/rustdoc/smart-punct.rs @@ -21,7 +21,7 @@ //! ``` // @has "foo/index.html" "//p" "This is the “start” of the ‘document’! How’d you know that “it’s” the start?" -// @has "foo/index.html" "//h1" "Header with “smart punct’”" +// @has "foo/index.html" "//h2" "Header with “smart punct’”" // @has "foo/index.html" '//a[@href="https://www.rust-lang.org"]' "link with “smart punct’” – yessiree!" // @has "foo/index.html" '//code' "this inline code -- it shouldn't have \"smart punct\"" // @has "foo/index.html" '//pre' "let x = \"don't smart-punct me -- please!\";" diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 01a3fc812b208..1ba283b178120 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -125,7 +125,8 @@ impl Formatter for HTMLFormatter { &mut id_map, ErrorCodes::Yes, DEFAULT_EDITION, - &Some(playground) + &Some(playground), + 0 ) .into_string() )? diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index 53c75a463390d..ae169d383b273 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -49,7 +49,7 @@ fn check_error_code_explanation( } else if s.contains("compile-fail") { invalid_compile_fail_format = true; } - } else if s.starts_with("#### Note: this error code is no longer emitted by the compiler") { + } else if s.starts_with("### Note: this error code is no longer emitted by the compiler") { if !found_error_code { error_codes.get_mut(&err_code).map(|x| x.has_test = true); found_error_code = true; @@ -64,7 +64,7 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool { for line in f.lines() { let s = line.trim(); - if s.starts_with("#### Note: this error code is no longer emitted by the compiler") { + if s.starts_with("### Note: this error code is no longer emitted by the compiler") { return true; } if s.starts_with("```") { From 03fbc160cd79556f9b99c37c2580e3da9826c432 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Mon, 4 Oct 2021 11:04:01 +0200 Subject: [PATCH 11/26] Add doc aliases to `std::thread::available_parallelism` --- library/std/src/thread/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index b6b48208ac7b3..e24a3cb898627 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -1460,6 +1460,8 @@ fn _assert_sync_and_send() { /// /// let count = thread::available_parallelism().map(|n| n.get()).unwrap_or(1); /// ``` +#[doc(alias = "hardware_concurrency")] // Alias for C++ `std::thread::hardware_concurrency`. +#[doc(alias = "available_concurrency")] // Alias for a name we gave this API on unstable. #[unstable(feature = "available_parallelism", issue = "74479")] pub fn available_parallelism() -> io::Result { imp::available_parallelism() From 47edde1086412b36e9efd6098b191ec15a2a760a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20du=20Garreau?= Date: Mon, 4 Oct 2021 18:52:17 +0200 Subject: [PATCH 12/26] Optimize `saturating_add_signed` --- library/core/src/num/uint_macros.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/library/core/src/num/uint_macros.rs b/library/core/src/num/uint_macros.rs index 5a65f77a87993..96375b82582ed 100644 --- a/library/core/src/num/uint_macros.rs +++ b/library/core/src/num/uint_macros.rs @@ -1037,10 +1037,13 @@ macro_rules! uint_impl { without modifying the original"] #[inline] pub const fn saturating_add_signed(self, rhs: $SignedT) -> Self { - if rhs >= 0 { - self.saturating_add(rhs as Self) + let (res, overflow) = self.overflowing_add(rhs as Self); + if overflow == (rhs < 0) { + res + } else if overflow { + Self::MAX } else { - self.saturating_sub(rhs.unsigned_abs()) + 0 } } From 388bcc1cb086c567f17a4933bfb1d3f14eb19fb7 Mon Sep 17 00:00:00 2001 From: Fabian Wolff Date: Mon, 4 Oct 2021 21:15:02 +0200 Subject: [PATCH 13/26] Fix suggestion to borrow when casting from pointer to reference --- compiler/rustc_typeck/src/check/cast.rs | 44 +++++++++++++++---- src/test/ui/cast/issue-89497.fixed | 10 +++++ src/test/ui/cast/issue-89497.rs | 10 +++++ src/test/ui/cast/issue-89497.stderr | 15 +++++++ src/test/ui/error-codes/E0605.stderr | 5 ++- src/test/ui/issues/issue-2995.stderr | 5 ++- .../ui/mismatched_types/cast-rfc0401.stderr | 5 ++- 7 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 src/test/ui/cast/issue-89497.fixed create mode 100644 src/test/ui/cast/issue-89497.rs create mode 100644 src/test/ui/cast/issue-89497.stderr diff --git a/compiler/rustc_typeck/src/check/cast.rs b/compiler/rustc_typeck/src/check/cast.rs index 4ea7a8694c075..fe0de61ab89e2 100644 --- a/compiler/rustc_typeck/src/check/cast.rs +++ b/compiler/rustc_typeck/src/check/cast.rs @@ -351,7 +351,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { ); let mut sugg = None; let mut sugg_mutref = false; - if let ty::Ref(reg, _, mutbl) = *self.cast_ty.kind() { + if let ty::Ref(reg, cast_ty, mutbl) = *self.cast_ty.kind() { if let ty::RawPtr(TypeAndMut { ty: expr_ty, .. }) = *self.expr_ty.kind() { if fcx .try_coerce( @@ -366,7 +366,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { ) .is_ok() { - sugg = Some(format!("&{}*", mutbl.prefix_str())); + sugg = Some((format!("&{}*", mutbl.prefix_str()), cast_ty == expr_ty)); } } else if let ty::Ref(expr_reg, expr_ty, expr_mutbl) = *self.expr_ty.kind() { if expr_mutbl == Mutability::Not @@ -400,7 +400,7 @@ impl<'a, 'tcx> CastCheck<'tcx> { ) .is_ok() { - sugg = Some(format!("&{}", mutbl.prefix_str())); + sugg = Some((format!("&{}", mutbl.prefix_str()), false)); } } else if let ty::RawPtr(TypeAndMut { mutbl, .. }) = *self.cast_ty.kind() { if fcx @@ -416,19 +416,47 @@ impl<'a, 'tcx> CastCheck<'tcx> { ) .is_ok() { - sugg = Some(format!("&{}", mutbl.prefix_str())); + sugg = Some((format!("&{}", mutbl.prefix_str()), false)); } } if sugg_mutref { err.span_label(self.span, "invalid cast"); err.span_note(self.expr.span, "this reference is immutable"); err.span_note(self.cast_span, "trying to cast to a mutable reference type"); - } else if let Some(sugg) = sugg { + } else if let Some((sugg, remove_cast)) = sugg { err.span_label(self.span, "invalid cast"); - err.span_suggestion_verbose( - self.expr.span.shrink_to_lo(), + + let has_parens = fcx + .tcx + .sess + .source_map() + .span_to_snippet(self.expr.span) + .map_or(false, |snip| snip.starts_with("(")); + + // Very crude check to see whether the expression must be wrapped + // in parentheses for the suggestion to work (issue #89497). + // Can/should be extended in the future. + let needs_parens = !has_parens + && match self.expr.kind { + hir::ExprKind::Cast(..) => true, + _ => false, + }; + + let mut suggestion = vec![(self.expr.span.shrink_to_lo(), sugg)]; + if needs_parens { + suggestion[0].1 += "("; + suggestion.push((self.expr.span.shrink_to_hi(), ")".to_string())); + } + if remove_cast { + suggestion.push(( + self.expr.span.shrink_to_hi().to(self.cast_span), + String::new(), + )); + } + + err.multipart_suggestion_verbose( "consider borrowing the value", - sugg, + suggestion, Applicability::MachineApplicable, ); } else if !matches!( diff --git a/src/test/ui/cast/issue-89497.fixed b/src/test/ui/cast/issue-89497.fixed new file mode 100644 index 0000000000000..04c10a5f79ed4 --- /dev/null +++ b/src/test/ui/cast/issue-89497.fixed @@ -0,0 +1,10 @@ +// Regression test for issue #89497. + +// run-rustfix + +fn main() { + let pointer: usize = &1_i32 as *const i32 as usize; + let _reference: &'static i32 = unsafe { &*(pointer as *const i32) }; + //~^ ERROR: non-primitive cast + //~| HELP: consider borrowing the value +} diff --git a/src/test/ui/cast/issue-89497.rs b/src/test/ui/cast/issue-89497.rs new file mode 100644 index 0000000000000..76301b704c81c --- /dev/null +++ b/src/test/ui/cast/issue-89497.rs @@ -0,0 +1,10 @@ +// Regression test for issue #89497. + +// run-rustfix + +fn main() { + let pointer: usize = &1_i32 as *const i32 as usize; + let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 }; + //~^ ERROR: non-primitive cast + //~| HELP: consider borrowing the value +} diff --git a/src/test/ui/cast/issue-89497.stderr b/src/test/ui/cast/issue-89497.stderr new file mode 100644 index 0000000000000..3726f8a41015e --- /dev/null +++ b/src/test/ui/cast/issue-89497.stderr @@ -0,0 +1,15 @@ +error[E0605]: non-primitive cast: `*const i32` as `&'static i32` + --> $DIR/issue-89497.rs:7:45 + | +LL | let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid cast + | +help: consider borrowing the value + | +LL - let _reference: &'static i32 = unsafe { pointer as *const i32 as &'static i32 }; +LL + let _reference: &'static i32 = unsafe { &*(pointer as *const i32) }; + | + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0605`. diff --git a/src/test/ui/error-codes/E0605.stderr b/src/test/ui/error-codes/E0605.stderr index e5647ee6d0968..d082b6c10cc2a 100644 --- a/src/test/ui/error-codes/E0605.stderr +++ b/src/test/ui/error-codes/E0605.stderr @@ -12,8 +12,9 @@ LL | v as &u8; | help: consider borrowing the value | -LL | &*v as &u8; - | ++ +LL - v as &u8; +LL + &*v; + | error: aborting due to 2 previous errors diff --git a/src/test/ui/issues/issue-2995.stderr b/src/test/ui/issues/issue-2995.stderr index 455d32e233ab9..7616f987d7312 100644 --- a/src/test/ui/issues/issue-2995.stderr +++ b/src/test/ui/issues/issue-2995.stderr @@ -6,8 +6,9 @@ LL | let _q: &isize = p as &isize; | help: consider borrowing the value | -LL | let _q: &isize = &*p as &isize; - | ++ +LL - let _q: &isize = p as &isize; +LL + let _q: &isize = &*p; + | error: aborting due to previous error diff --git a/src/test/ui/mismatched_types/cast-rfc0401.stderr b/src/test/ui/mismatched_types/cast-rfc0401.stderr index a47eb87cff06c..7f91d5ed42ce4 100644 --- a/src/test/ui/mismatched_types/cast-rfc0401.stderr +++ b/src/test/ui/mismatched_types/cast-rfc0401.stderr @@ -28,8 +28,9 @@ LL | let _ = v as &u8; | help: consider borrowing the value | -LL | let _ = &*v as &u8; - | ++ +LL - let _ = v as &u8; +LL + let _ = &*v; + | error[E0605]: non-primitive cast: `*const u8` as `E` --> $DIR/cast-rfc0401.rs:30:13 From 4a6aa6e4063a8ecd9810c04a5dae9e8ff2f664d6 Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Mon, 4 Oct 2021 20:49:07 -0400 Subject: [PATCH 14/26] Fix heading for methods on trait impls. --- src/librustdoc/html/render/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 69f39bb58a853..532dce99c0dc2 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -1344,7 +1344,7 @@ fn render_impl( // because impls can't have a stability. if item.doc_value().is_some() { document_item_info(&mut info_buffer, cx, it, Some(parent)); - document_full(&mut doc_buffer, item, cx, 0); + document_full(&mut doc_buffer, item, cx, 3); short_documented = false; } else { // In case the item isn't documented, From 6518a0a8b9570b6d347a3c7b2c9b95e66cbbd013 Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Mon, 4 Oct 2021 21:08:58 -0400 Subject: [PATCH 15/26] Change `Markdown(...)` to `Markdown { ... }` --- src/librustdoc/externalfiles.rs | 22 +++++++++++-- src/librustdoc/html/markdown.rs | 42 ++++++++++++++++++------- src/librustdoc/html/markdown/tests.rs | 24 +++++++++++--- src/librustdoc/html/render/mod.rs | 38 +++++++++++----------- src/librustdoc/markdown.rs | 11 ++++++- src/tools/error_index_generator/main.rs | 18 +++++------ 6 files changed, 108 insertions(+), 47 deletions(-) diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 1fd5e2d5ef67e..5cb654a606f34 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -39,14 +39,32 @@ impl ExternalHtml { let bc = format!( "{}{}", bc, - Markdown(&m_bc, &[], id_map, codes, edition, playground, 0).into_string() + Markdown { + content: &m_bc, + links: &[], + ids: id_map, + error_codes: codes, + edition, + playground, + heading_level: 0 + } + .into_string() ); let ac = load_external_files(after_content, diag)?; let m_ac = load_external_files(md_after_content, diag)?; let ac = format!( "{}{}", ac, - Markdown(&m_ac, &[], id_map, codes, edition, playground, 0).into_string() + Markdown { + content: &m_ac, + links: &[], + ids: id_map, + error_codes: codes, + edition, + playground, + heading_level: 0 + } + .into_string() ); Some(ExternalHtml { in_header: ih, before_content: bc, after_content: ac }) } diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 56b580a05188c..da1482f4e6969 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -12,7 +12,15 @@ //! //! let s = "My *markdown* _text_"; //! let mut id_map = IdMap::new(); -//! let md = Markdown(s, &[], &mut id_map, ErrorCodes::Yes, Edition::Edition2015, &None, 0); +//! let md = Markdown { +//! content: s, +//! links: &[], +//! ids: &mut id_map, +//! error_codes: ErrorCodes::Yes, +//! edition: Edition::Edition2015, +//! playground: &None, +//! heading_level: 0 +//! }; //! let html = md.into_string(); //! // ... something using html //! ``` @@ -69,19 +77,21 @@ pub(crate) fn summary_opts() -> Options { /// When `to_string` is called, this struct will emit the HTML corresponding to /// the rendered version of the contained markdown string. -pub struct Markdown<'a>( - pub &'a str, +pub struct Markdown<'a> { + pub content: &'a str, /// A list of link replacements. - pub &'a [RenderedLink], + pub links: &'a [RenderedLink], /// The current list of used header IDs. - pub &'a mut IdMap, + pub ids: &'a mut IdMap, /// Whether to allow the use of explicit error codes in doctest lang strings. - pub ErrorCodes, + pub error_codes: ErrorCodes, /// Default edition to use when parsing doctests (to add a `fn main`). - pub Edition, - pub &'a Option, - pub u32, -); + pub edition: Edition, + pub playground: &'a Option, + /// Offset at which we render headings. + /// E.g. if `heading_level: 1`, then `# something` renders an `

` instead of `

` + pub heading_level: u32, +} /// A tuple struct like `Markdown` that renders the markdown with a table of contents. crate struct MarkdownWithToc<'a>( crate &'a str, @@ -1010,7 +1020,15 @@ impl LangString { impl Markdown<'_> { pub fn into_string(self) -> String { - let Markdown(md, links, mut ids, codes, edition, playground, level) = self; + let Markdown { + content: md, + links, + mut ids, + error_codes: codes, + edition, + playground, + heading_level, + } = self; // This is actually common enough to special-case if md.is_empty() { @@ -1031,7 +1049,7 @@ impl Markdown<'_> { let mut s = String::with_capacity(md.len() * 3 / 2); - let p = HeadingLinks::new(p, None, &mut ids, level); + let p = HeadingLinks::new(p, None, &mut ids, heading_level); let p = Footnotes::new(p); let p = LinkReplacer::new(p.map(|(ev, _)| ev), links); let p = TableWrapper::new(p); diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index c6af7e5847c52..b2c18c24011d6 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -147,8 +147,16 @@ fn test_lang_string_tokenizer() { fn test_header() { fn t(input: &str, expect: &str) { let mut map = IdMap::new(); - let output = Markdown(input, &[], &mut map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0) - .into_string(); + let output = Markdown { + content: input, + links: &[], + ids: &mut map, + error_codes: ErrorCodes::Yes, + edition: DEFAULT_EDITION, + playground: &None, + heading_level: 0, + } + .into_string(); assert_eq!(output, expect, "original: {}", input); } @@ -181,8 +189,16 @@ fn test_header() { fn test_header_ids_multiple_blocks() { let mut map = IdMap::new(); fn t(map: &mut IdMap, input: &str, expect: &str) { - let output = - Markdown(input, &[], map, ErrorCodes::Yes, DEFAULT_EDITION, &None, 0).into_string(); + let output = Markdown { + content: input, + links: &[], + ids: map, + error_codes: ErrorCodes::Yes, + edition: DEFAULT_EDITION, + playground: &None, + heading_level: 0, + } + .into_string(); assert_eq!(output, expect, "original: {}", input); } diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 532dce99c0dc2..164d745336823 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -498,21 +498,21 @@ fn render_markdown( cx: &Context<'_>, md_text: &str, links: Vec, - level: u32, + heading_level: u32, ) { let mut ids = cx.id_map.borrow_mut(); write!( w, "
{}
", - Markdown( - md_text, - &links, - &mut ids, - cx.shared.codes, - cx.shared.edition(), - &cx.shared.playground, - level - ) + Markdown { + content: md_text, + links: &links, + ids: &mut ids, + error_codes: cx.shared.codes, + edition: cx.shared.edition(), + playground: &cx.shared.playground, + heading_level, + } .into_string() ) } @@ -1596,15 +1596,15 @@ fn render_impl( write!( w, "
{}
", - Markdown( - &*dox, - &i.impl_item.links(cx), - &mut ids, - cx.shared.codes, - cx.shared.edition(), - &cx.shared.playground, - 0 - ) + Markdown { + content: &*dox, + links: &i.impl_item.links(cx), + ids: &mut ids, + error_codes: cx.shared.codes, + edition: cx.shared.edition(), + playground: &cx.shared.playground, + heading_level: 0 + } .into_string() ); } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 82e6231782c1e..962712f5b9175 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -70,7 +70,16 @@ crate fn render>( let text = if !options.markdown_no_toc { MarkdownWithToc(text, &mut ids, error_codes, edition, &playground).into_string() } else { - Markdown(text, &[], &mut ids, error_codes, edition, &playground, 0).into_string() + Markdown { + content: text, + links: &[], + ids: &mut ids, + error_codes, + edition, + playground: &playground, + heading_level: 0, + } + .into_string() }; let err = write!( diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index 1ba283b178120..f3c5d65935f66 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -119,15 +119,15 @@ impl Formatter for HTMLFormatter { write!( output, "{}", - Markdown( - desc, - &[], - &mut id_map, - ErrorCodes::Yes, - DEFAULT_EDITION, - &Some(playground), - 0 - ) + Markdown { + content: desc, + links: &[], + ids: &mut id_map, + error_codes: ErrorCodes::Yes, + edition: DEFAULT_EDITION, + playground: &Some(playground), + heading_level: 0 + } .into_string() )? } From 13558ee0a06c544e68978766d0508b62ef3e22f7 Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Mon, 4 Oct 2021 21:28:26 -0400 Subject: [PATCH 16/26] No need to default offset since we always override it. --- src/librustdoc/externalfiles.rs | 4 +- src/librustdoc/html/markdown.rs | 4 +- src/librustdoc/html/markdown/tests.rs | 4 +- src/librustdoc/html/render/mod.rs | 12 ++---- src/librustdoc/html/render/print_item.rs | 50 ++++++++++++------------ src/tools/error_index_generator/main.rs | 2 +- 6 files changed, 36 insertions(+), 40 deletions(-) diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 5cb654a606f34..cb5c9edcde570 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -46,7 +46,7 @@ impl ExternalHtml { error_codes: codes, edition, playground, - heading_level: 0 + heading_level: 1 } .into_string() ); @@ -62,7 +62,7 @@ impl ExternalHtml { error_codes: codes, edition, playground, - heading_level: 0 + heading_level: 1 } .into_string() ); diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index da1482f4e6969..ef2f2f90301fb 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -19,7 +19,7 @@ //! error_codes: ErrorCodes::Yes, //! edition: Edition::Edition2015, //! playground: &None, -//! heading_level: 0 +//! heading_level: 1 //! }; //! let html = md.into_string(); //! // ... something using html @@ -544,7 +544,7 @@ impl<'a, 'b, 'ids, I: Iterator>> Iterator self.buf.push_front((Event::Html(format!("{} ", sec).into()), 0..0)); } - let level = std::cmp::min(level + self.level + 1, MAX_HEADER_LEVEL); + let level = std::cmp::min(level + self.level, MAX_HEADER_LEVEL); self.buf.push_back((Event::Html(format!("", level).into()), 0..0)); let start_tags = format!( diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index b2c18c24011d6..ee6a19978969e 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -154,7 +154,7 @@ fn test_header() { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &None, - heading_level: 0, + heading_level: 1, } .into_string(); assert_eq!(output, expect, "original: {}", input); @@ -196,7 +196,7 @@ fn test_header_ids_multiple_blocks() { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &None, - heading_level: 0, + heading_level: 1, } .into_string(); assert_eq!(output, expect, "original: {}", input); diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 164d745336823..8cf11e526fe38 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -470,11 +470,7 @@ fn settings(root_path: &str, suffix: &str, themes: &[StylePath]) -> Result, item: &clean::Item, parent: Option<&clean::Item>) { - document_at_level(w, cx, item, parent, 0) -} - -fn document_at_level( +fn document( w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, @@ -1344,7 +1340,7 @@ fn render_impl( // because impls can't have a stability. if item.doc_value().is_some() { document_item_info(&mut info_buffer, cx, it, Some(parent)); - document_full(&mut doc_buffer, item, cx, 3); + document_full(&mut doc_buffer, item, cx, 4); short_documented = false; } else { // In case the item isn't documented, @@ -1362,7 +1358,7 @@ fn render_impl( } else { document_item_info(&mut info_buffer, cx, item, Some(parent)); if rendering_params.show_def_docs { - document_full(&mut doc_buffer, item, cx, 3); + document_full(&mut doc_buffer, item, cx, 4); short_documented = false; } } @@ -1603,7 +1599,7 @@ fn render_impl( error_codes: cx.shared.codes, edition: cx.shared.edition(), playground: &cx.shared.playground, - heading_level: 0 + heading_level: 1 } .into_string() ); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index 59a6925d8b459..f26ee84569b49 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -16,10 +16,10 @@ use rustc_span::symbol::{kw, sym, Symbol}; use rustc_target::abi::{Layout, Primitive, TagEncoding, Variants}; use super::{ - collect_paths_for_type, document, document_at_level, ensure_trailing_slash, item_ty_to_strs, - notable_traits_decl, render_assoc_item, render_assoc_items, render_attributes_in_code, - render_attributes_in_pre, render_impl, render_stability_since_raw, write_srclink, - AssocItemLink, Context, ImplRenderingParameters, + collect_paths_for_type, document, ensure_trailing_slash, item_ty_to_strs, notable_traits_decl, + render_assoc_item, render_assoc_items, render_attributes_in_code, render_attributes_in_pre, + render_impl, render_stability_since_raw, write_srclink, AssocItemLink, Context, + ImplRenderingParameters, }; use crate::clean::{self, GetDefId}; use crate::formats::item_type::ItemType; @@ -173,7 +173,7 @@ fn toggle_close(w: &mut Buffer) { } fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) { - document(w, cx, item, None); + document(w, cx, item, None, 1); let mut indices = (0..items.len()).filter(|i| !items[*i].is_stripped()).collect::>(); @@ -485,7 +485,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean:: notable_traits = notable_traits_decl(&f.decl, cx), ); }); - document(w, cx, it, None) + document(w, cx, it, None, 1) } fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) { @@ -608,7 +608,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra }); // Trait documentation - document(w, cx, it, None); + document(w, cx, it, None, 1); fn write_small_section_header(w: &mut Buffer, id: &str, title: &str, extra_content: &str) { write!( @@ -626,7 +626,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); let mut content = Buffer::empty_from(w); - document_at_level(&mut content, cx, m, Some(t), 3); + document(&mut content, cx, m, Some(t), 4); let toggled = !content.is_empty(); if toggled { write!(w, "
"); @@ -840,7 +840,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea ); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); // Render any items associated directly to this alias, as otherwise they // won't be visible anywhere in the docs. It would be nice to also show @@ -862,7 +862,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean: ); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); // Render any items associated directly to this alias, as otherwise they // won't be visible anywhere in the docs. It would be nice to also show @@ -893,7 +893,7 @@ fn item_typedef( ); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); let def_id = it.def_id.expect_def_id(); // Render any items associated directly to this alias, as otherwise they @@ -911,7 +911,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni }); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); let mut fields = s .fields @@ -944,7 +944,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni if let Some(stability_class) = field.stability_class(cx.tcx()) { write!(w, "", stab = stability_class); } - document(w, cx, field, Some(it)); + document(w, cx, field, Some(it), 1); } } let def_id = it.def_id.expect_def_id(); @@ -1026,7 +1026,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum }); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); if !e.variants.is_empty() { write!( @@ -1055,7 +1055,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum w.write_str(""); render_stability_since(w, variant, it, cx.tcx()); w.write_str(""); - document(w, cx, variant, Some(it)); + document(w, cx, variant, Some(it), 1); document_non_exhaustive(w, variant); use crate::clean::Variant; @@ -1095,7 +1095,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum f = field.name.as_ref().unwrap(), t = ty.print(cx) ); - document(w, cx, field, Some(variant)); + document(w, cx, field, Some(variant), 1); } _ => unreachable!(), } @@ -1122,7 +1122,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac None, ); }); - document(w, cx, it, None) + document(w, cx, it, None, 1) } fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) { @@ -1152,11 +1152,11 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean }); } } - document(w, cx, it, None) + document(w, cx, it, None, 1) } fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { - document(w, cx, it, None); + document(w, cx, it, None, 1); render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All) } @@ -1195,7 +1195,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean:: } }); - document(w, cx, it, None) + document(w, cx, it, None, 1) } fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Struct) { @@ -1206,7 +1206,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St }); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); let mut fields = s .fields @@ -1242,7 +1242,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St name = field_name, ty = ty.print(cx) ); - document(w, cx, field, Some(it)); + document(w, cx, field, Some(it), 1); } } } @@ -1263,7 +1263,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St typ = s.type_.print(cx) ); }); - document(w, cx, it, None) + document(w, cx, it, None, 1) } fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { @@ -1278,13 +1278,13 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { ); }); - document(w, cx, it, None); + document(w, cx, it, None, 1); render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All) } fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { - document(w, cx, it, None) + document(w, cx, it, None, 1) } /// Compare two strings treating multi-digit numbers as single units (i.e. natural sort order). diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index f3c5d65935f66..f89f28242a228 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -126,7 +126,7 @@ impl Formatter for HTMLFormatter { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &Some(playground), - heading_level: 0 + heading_level: 1 } .into_string() )? From f1425c7c3e62b519354d1a178181a66dad943b4e Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Mon, 4 Oct 2021 21:54:00 -0400 Subject: [PATCH 17/26] heading_level: u32 -> heading_offset: HeadingOffset --- src/librustdoc/externalfiles.rs | 6 ++-- src/librustdoc/html/markdown.rs | 41 +++++++++++++++------- src/librustdoc/html/markdown/tests.rs | 6 ++-- src/librustdoc/html/render/mod.rs | 42 +++++++++++++--------- src/librustdoc/html/render/print_item.rs | 44 ++++++++++++------------ src/librustdoc/markdown.rs | 6 ++-- src/tools/error_index_generator/main.rs | 4 +-- 7 files changed, 88 insertions(+), 61 deletions(-) diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index cb5c9edcde570..302fc5a677771 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -1,4 +1,4 @@ -use crate::html::markdown::{ErrorCodes, IdMap, Markdown, Playground}; +use crate::html::markdown::{ErrorCodes, HeadingOffset, IdMap, Markdown, Playground}; use crate::rustc_span::edition::Edition; use std::fs; use std::path::Path; @@ -46,7 +46,7 @@ impl ExternalHtml { error_codes: codes, edition, playground, - heading_level: 1 + heading_offset: HeadingOffset::H2, } .into_string() ); @@ -62,7 +62,7 @@ impl ExternalHtml { error_codes: codes, edition, playground, - heading_level: 1 + heading_offset: HeadingOffset::H2, } .into_string() ); diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index ef2f2f90301fb..9f2e282fce1c3 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -8,7 +8,7 @@ //! extern crate rustc_span; //! //! use rustc_span::edition::Edition; -//! use rustdoc::html::markdown::{IdMap, Markdown, ErrorCodes}; +//! use rustdoc::html::markdown::{HeadingOffset, IdMap, Markdown, ErrorCodes}; //! //! let s = "My *markdown* _text_"; //! let mut id_map = IdMap::new(); @@ -19,7 +19,7 @@ //! error_codes: ErrorCodes::Yes, //! edition: Edition::Edition2015, //! playground: &None, -//! heading_level: 1 +//! heading_offset: HeadingOffset::H2, //! }; //! let html = md.into_string(); //! // ... something using html @@ -75,6 +75,16 @@ pub(crate) fn summary_opts() -> Options { | Options::ENABLE_SMART_PUNCTUATION } +#[derive(Debug, Clone, Copy)] +pub enum HeadingOffset { + H1 = 0, + H2, + H3, + H4, + H5, + H6, +} + /// When `to_string` is called, this struct will emit the HTML corresponding to /// the rendered version of the contained markdown string. pub struct Markdown<'a> { @@ -89,8 +99,8 @@ pub struct Markdown<'a> { pub edition: Edition, pub playground: &'a Option, /// Offset at which we render headings. - /// E.g. if `heading_level: 1`, then `# something` renders an `

` instead of `

` - pub heading_level: u32, + /// E.g. if `heading_offset: HeadingOffset::H2`, then `# something` renders an `

`. + pub heading_offset: HeadingOffset, } /// A tuple struct like `Markdown` that renders the markdown with a table of contents. crate struct MarkdownWithToc<'a>( @@ -502,12 +512,17 @@ struct HeadingLinks<'a, 'b, 'ids, I> { toc: Option<&'b mut TocBuilder>, buf: VecDeque>, id_map: &'ids mut IdMap, - level: u32, + heading_offset: HeadingOffset, } impl<'a, 'b, 'ids, I> HeadingLinks<'a, 'b, 'ids, I> { - fn new(iter: I, toc: Option<&'b mut TocBuilder>, ids: &'ids mut IdMap, level: u32) -> Self { - HeadingLinks { inner: iter, toc, buf: VecDeque::new(), id_map: ids, level } + fn new( + iter: I, + toc: Option<&'b mut TocBuilder>, + ids: &'ids mut IdMap, + heading_offset: HeadingOffset, + ) -> Self { + HeadingLinks { inner: iter, toc, buf: VecDeque::new(), id_map: ids, heading_offset } } } @@ -544,7 +559,7 @@ impl<'a, 'b, 'ids, I: Iterator>> Iterator self.buf.push_front((Event::Html(format!("{} ", sec).into()), 0..0)); } - let level = std::cmp::min(level + self.level, MAX_HEADER_LEVEL); + let level = std::cmp::min(level + (self.heading_offset as u32), MAX_HEADER_LEVEL); self.buf.push_back((Event::Html(format!("", level).into()), 0..0)); let start_tags = format!( @@ -1027,7 +1042,7 @@ impl Markdown<'_> { error_codes: codes, edition, playground, - heading_level, + heading_offset, } = self; // This is actually common enough to special-case @@ -1049,7 +1064,7 @@ impl Markdown<'_> { let mut s = String::with_capacity(md.len() * 3 / 2); - let p = HeadingLinks::new(p, None, &mut ids, heading_level); + let p = HeadingLinks::new(p, None, &mut ids, heading_offset); let p = Footnotes::new(p); let p = LinkReplacer::new(p.map(|(ev, _)| ev), links); let p = TableWrapper::new(p); @@ -1071,7 +1086,7 @@ impl MarkdownWithToc<'_> { let mut toc = TocBuilder::new(); { - let p = HeadingLinks::new(p, Some(&mut toc), &mut ids, 0); + let p = HeadingLinks::new(p, Some(&mut toc), &mut ids, HeadingOffset::H1); let p = Footnotes::new(p); let p = TableWrapper::new(p.map(|(ev, _)| ev)); let p = CodeBlocks::new(p, codes, edition, playground); @@ -1100,7 +1115,7 @@ impl MarkdownHtml<'_> { let mut s = String::with_capacity(md.len() * 3 / 2); - let p = HeadingLinks::new(p, None, &mut ids, 0); + let p = HeadingLinks::new(p, None, &mut ids, HeadingOffset::H1); let p = Footnotes::new(p); let p = TableWrapper::new(p.map(|(ev, _)| ev)); let p = CodeBlocks::new(p, codes, edition, playground); @@ -1318,7 +1333,7 @@ crate fn markdown_links(md: &str) -> Vec { // There's no need to thread an IdMap through to here because // the IDs generated aren't going to be emitted anywhere. let mut ids = IdMap::new(); - let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids, 0)); + let iter = Footnotes::new(HeadingLinks::new(p, None, &mut ids, HeadingOffset::H1)); for ev in iter { if let Event::Start(Tag::Link(kind, dest, _)) = ev.0 { diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index ee6a19978969e..68ab002f13867 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -1,5 +1,5 @@ use super::{find_testable_code, plain_text_summary, short_markdown_summary}; -use super::{ErrorCodes, IdMap, Ignore, LangString, Markdown, MarkdownHtml}; +use super::{ErrorCodes, HeadingOffset, IdMap, Ignore, LangString, Markdown, MarkdownHtml}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; #[test] @@ -154,7 +154,7 @@ fn test_header() { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &None, - heading_level: 1, + heading_offset: HeadingOffset::H2, } .into_string(); assert_eq!(output, expect, "original: {}", input); @@ -196,7 +196,7 @@ fn test_header_ids_multiple_blocks() { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &None, - heading_level: 1, + heading_offset: HeadingOffset::H2, } .into_string(); assert_eq!(output, expect, "original: {}", input); diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 8cf11e526fe38..11682afdf899b 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -67,7 +67,7 @@ use crate::html::format::{ href, print_abi_with_space, print_constness_with_space, print_default_space, print_generic_bounds, print_where_clause, Buffer, HrefError, PrintWithSpace, }; -use crate::html::markdown::{Markdown, MarkdownHtml, MarkdownSummaryLine}; +use crate::html::markdown::{HeadingOffset, Markdown, MarkdownHtml, MarkdownSummaryLine}; /// A pair of name and its optional document. crate type NameDoc = (String, Option); @@ -475,16 +475,16 @@ fn document( cx: &Context<'_>, item: &clean::Item, parent: Option<&clean::Item>, - level: u32, + heading_offset: HeadingOffset, ) { if let Some(ref name) = item.name { info!("Documenting {}", name); } document_item_info(w, cx, item, parent); if parent.is_none() { - document_full_collapsible(w, item, cx, level); + document_full_collapsible(w, item, cx, heading_offset); } else { - document_full(w, item, cx, level); + document_full(w, item, cx, heading_offset); } } @@ -494,7 +494,7 @@ fn render_markdown( cx: &Context<'_>, md_text: &str, links: Vec, - heading_level: u32, + heading_offset: HeadingOffset, ) { let mut ids = cx.id_map.borrow_mut(); write!( @@ -507,7 +507,7 @@ fn render_markdown( error_codes: cx.shared.codes, edition: cx.shared.edition(), playground: &cx.shared.playground, - heading_level, + heading_offset, } .into_string() ) @@ -544,12 +544,22 @@ fn document_short( } } -fn document_full_collapsible(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, level: u32) { - document_full_inner(w, item, cx, true, level); +fn document_full_collapsible( + w: &mut Buffer, + item: &clean::Item, + cx: &Context<'_>, + heading_offset: HeadingOffset, +) { + document_full_inner(w, item, cx, true, heading_offset); } -fn document_full(w: &mut Buffer, item: &clean::Item, cx: &Context<'_>, level: u32) { - document_full_inner(w, item, cx, false, level); +fn document_full( + w: &mut Buffer, + item: &clean::Item, + cx: &Context<'_>, + heading_offset: HeadingOffset, +) { + document_full_inner(w, item, cx, false, heading_offset); } fn document_full_inner( @@ -557,7 +567,7 @@ fn document_full_inner( item: &clean::Item, cx: &Context<'_>, is_collapsible: bool, - level: u32, + heading_offset: HeadingOffset, ) { if let Some(s) = cx.shared.maybe_collapsed_doc_value(item) { debug!("Doc block: =====\n{}\n=====", s); @@ -568,10 +578,10 @@ fn document_full_inner( Expand description\

", ); - render_markdown(w, cx, &s, item.links(cx), level); + render_markdown(w, cx, &s, item.links(cx), heading_offset); w.write_str("
"); } else { - render_markdown(w, cx, &s, item.links(cx), level); + render_markdown(w, cx, &s, item.links(cx), heading_offset); } } } @@ -1340,7 +1350,7 @@ fn render_impl( // because impls can't have a stability. if item.doc_value().is_some() { document_item_info(&mut info_buffer, cx, it, Some(parent)); - document_full(&mut doc_buffer, item, cx, 4); + document_full(&mut doc_buffer, item, cx, HeadingOffset::H5); short_documented = false; } else { // In case the item isn't documented, @@ -1358,7 +1368,7 @@ fn render_impl( } else { document_item_info(&mut info_buffer, cx, item, Some(parent)); if rendering_params.show_def_docs { - document_full(&mut doc_buffer, item, cx, 4); + document_full(&mut doc_buffer, item, cx, HeadingOffset::H5); short_documented = false; } } @@ -1599,7 +1609,7 @@ fn render_impl( error_codes: cx.shared.codes, edition: cx.shared.edition(), playground: &cx.shared.playground, - heading_level: 1 + heading_offset: HeadingOffset::H2 } .into_string() ); diff --git a/src/librustdoc/html/render/print_item.rs b/src/librustdoc/html/render/print_item.rs index f26ee84569b49..9b39a3eeaf0fa 100644 --- a/src/librustdoc/html/render/print_item.rs +++ b/src/librustdoc/html/render/print_item.rs @@ -30,7 +30,7 @@ use crate::html::format::{ }; use crate::html::highlight; use crate::html::layout::Page; -use crate::html::markdown::MarkdownSummaryLine; +use crate::html::markdown::{HeadingOffset, MarkdownSummaryLine}; const ITEM_TABLE_OPEN: &'static str = "
"; const ITEM_TABLE_CLOSE: &'static str = "
"; @@ -173,7 +173,7 @@ fn toggle_close(w: &mut Buffer) { } fn item_module(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item, items: &[clean::Item]) { - document(w, cx, item, None, 1); + document(w, cx, item, None, HeadingOffset::H2); let mut indices = (0..items.len()).filter(|i| !items[*i].is_stripped()).collect::>(); @@ -485,7 +485,7 @@ fn item_function(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, f: &clean:: notable_traits = notable_traits_decl(&f.decl, cx), ); }); - document(w, cx, it, None, 1) + document(w, cx, it, None, HeadingOffset::H2) } fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Trait) { @@ -608,7 +608,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra }); // Trait documentation - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); fn write_small_section_header(w: &mut Buffer, id: &str, title: &str, extra_content: &str) { write!( @@ -626,7 +626,7 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra let item_type = m.type_(); let id = cx.derive_id(format!("{}.{}", item_type, name)); let mut content = Buffer::empty_from(w); - document(&mut content, cx, m, Some(t), 4); + document(&mut content, cx, m, Some(t), HeadingOffset::H5); let toggled = !content.is_empty(); if toggled { write!(w, "
"); @@ -840,7 +840,7 @@ fn item_trait_alias(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clea ); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); // Render any items associated directly to this alias, as otherwise they // won't be visible anywhere in the docs. It would be nice to also show @@ -862,7 +862,7 @@ fn item_opaque_ty(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean: ); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); // Render any items associated directly to this alias, as otherwise they // won't be visible anywhere in the docs. It would be nice to also show @@ -893,7 +893,7 @@ fn item_typedef( ); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); let def_id = it.def_id.expect_def_id(); // Render any items associated directly to this alias, as otherwise they @@ -911,7 +911,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni }); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); let mut fields = s .fields @@ -944,7 +944,7 @@ fn item_union(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Uni if let Some(stability_class) = field.stability_class(cx.tcx()) { write!(w, "", stab = stability_class); } - document(w, cx, field, Some(it), 1); + document(w, cx, field, Some(it), HeadingOffset::H2); } } let def_id = it.def_id.expect_def_id(); @@ -1026,7 +1026,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum }); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); if !e.variants.is_empty() { write!( @@ -1055,7 +1055,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum w.write_str(""); render_stability_since(w, variant, it, cx.tcx()); w.write_str(""); - document(w, cx, variant, Some(it), 1); + document(w, cx, variant, Some(it), HeadingOffset::H2); document_non_exhaustive(w, variant); use crate::clean::Variant; @@ -1095,7 +1095,7 @@ fn item_enum(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, e: &clean::Enum f = field.name.as_ref().unwrap(), t = ty.print(cx) ); - document(w, cx, field, Some(variant), 1); + document(w, cx, field, Some(variant), HeadingOffset::H2); } _ => unreachable!(), } @@ -1122,7 +1122,7 @@ fn item_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Mac None, ); }); - document(w, cx, it, None, 1) + document(w, cx, it, None, HeadingOffset::H2) } fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean::ProcMacro) { @@ -1152,11 +1152,11 @@ fn item_proc_macro(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, m: &clean }); } } - document(w, cx, it, None, 1) + document(w, cx, it, None, HeadingOffset::H2) } fn item_primitive(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All) } @@ -1195,7 +1195,7 @@ fn item_constant(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, c: &clean:: } }); - document(w, cx, it, None, 1) + document(w, cx, it, None, HeadingOffset::H2) } fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::Struct) { @@ -1206,7 +1206,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St }); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); let mut fields = s .fields @@ -1242,7 +1242,7 @@ fn item_struct(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St name = field_name, ty = ty.print(cx) ); - document(w, cx, field, Some(it), 1); + document(w, cx, field, Some(it), HeadingOffset::H2); } } } @@ -1263,7 +1263,7 @@ fn item_static(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, s: &clean::St typ = s.type_.print(cx) ); }); - document(w, cx, it, None, 1) + document(w, cx, it, None, HeadingOffset::H2) } fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { @@ -1278,13 +1278,13 @@ fn item_foreign_type(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { ); }); - document(w, cx, it, None, 1); + document(w, cx, it, None, HeadingOffset::H2); render_assoc_items(w, cx, it, it.def_id.expect_def_id(), AssocItemRender::All) } fn item_keyword(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item) { - document(w, cx, it, None, 1) + document(w, cx, it, None, HeadingOffset::H2) } /// Compare two strings treating multi-digit numbers as single units (i.e. natural sort order). diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 962712f5b9175..47b24d40edc27 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -10,7 +10,9 @@ use crate::config::{Options, RenderOptions}; use crate::doctest::{Collector, TestOptions}; use crate::html::escape::Escape; use crate::html::markdown; -use crate::html::markdown::{find_testable_code, ErrorCodes, IdMap, Markdown, MarkdownWithToc}; +use crate::html::markdown::{ + find_testable_code, ErrorCodes, HeadingOffset, IdMap, Markdown, MarkdownWithToc, +}; /// Separate any lines at the start of the file that begin with `# ` or `%`. fn extract_leading_metadata(s: &str) -> (Vec<&str>, &str) { @@ -77,7 +79,7 @@ crate fn render>( error_codes, edition, playground: &playground, - heading_level: 0, + heading_offset: HeadingOffset::H1, } .into_string() }; diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index f89f28242a228..e796934961094 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -14,7 +14,7 @@ use std::path::PathBuf; use rustc_span::edition::DEFAULT_EDITION; -use rustdoc::html::markdown::{ErrorCodes, IdMap, Markdown, Playground}; +use rustdoc::html::markdown::{ErrorCodes, HeadingOffset, IdMap, Markdown, Playground}; pub struct ErrorMetadata { pub description: Option, @@ -126,7 +126,7 @@ impl Formatter for HTMLFormatter { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &Some(playground), - heading_level: 1 + heading_offset: HeadingOffset::H2, } .into_string() )? From 08a4f24f6873bff2845e1e52f2785a8a903ac133 Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Mon, 4 Oct 2021 21:54:48 -0400 Subject: [PATCH 18/26] Add tests for ensuring docblock headings. --- .../rustdoc/issue-89309-heading-levels.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/rustdoc/issue-89309-heading-levels.rs diff --git a/src/test/rustdoc/issue-89309-heading-levels.rs b/src/test/rustdoc/issue-89309-heading-levels.rs new file mode 100644 index 0000000000000..bb706c28ffa51 --- /dev/null +++ b/src/test/rustdoc/issue-89309-heading-levels.rs @@ -0,0 +1,29 @@ +#![crate_name = "foo"] + +// @has foo/trait.Read.html +// @has - '//h2' 'Trait examples' +/// # Trait examples +pub trait Read { + // @has - '//h5' 'Function examples' + /// # Function examples + fn read(&mut self, buf: &mut [u8]) -> Result; +} + +pub struct Foo; + +// @has foo/struct.Foo.html +impl Foo { + // @has - '//h5' 'Implementation header' + /// # Implementation header + pub fn bar(&self) -> usize { + 1 + } +} + +impl Read for Foo { + // @has - '//h5' 'Trait implementation header' + /// # Trait implementation header + fn read(&mut self, buf: &mut [u8]) -> Result { + Ok(1) + } +} From c79447e708541abda1e5075385c9ef8810ebc715 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 4 Oct 2021 22:11:53 +0100 Subject: [PATCH 19/26] library std, libc dependency update to solve #87528 build. --- Cargo.lock | 4 ++-- library/std/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a4e1ab6c1e4a8..b596e09828afa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1892,9 +1892,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.99" +version = "0.2.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" +checksum = "dd8f7255a17a627354f321ef0055d63b898c6fb27eff628af4d1b66b7331edf6" dependencies = [ "rustc-std-workspace-core", ] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 2b77dc54ab35c..6bc445c6f2b07 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -15,7 +15,7 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../panic_unwind", optional = true } panic_abort = { path = "../panic_abort" } core = { path = "../core" } -libc = { version = "0.2.99", default-features = false, features = ['rustc-dep-of-std'] } +libc = { version = "0.2.103", default-features = false, features = ['rustc-dep-of-std'] } compiler_builtins = { version = "0.1.44" } profiler_builtins = { path = "../profiler_builtins", optional = true } unwind = { path = "../unwind" } From b2e4e59fbe201ff23fd2911f2650827ad46902b9 Mon Sep 17 00:00:00 2001 From: DeveloperC286 Date: Fri, 17 Sep 2021 18:25:21 +0100 Subject: [PATCH 20/26] refactor: VecDeques Drain fields to private --- .../alloc/src/collections/vec_deque/drain.rs | 19 +++++++++++---- .../alloc/src/collections/vec_deque/mod.rs | 24 +++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/drain.rs b/library/alloc/src/collections/vec_deque/drain.rs index dfa0227dea3b8..05f94da6de70d 100644 --- a/library/alloc/src/collections/vec_deque/drain.rs +++ b/library/alloc/src/collections/vec_deque/drain.rs @@ -18,10 +18,21 @@ pub struct Drain< T: 'a, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, > { - pub(crate) after_tail: usize, - pub(crate) after_head: usize, - pub(crate) iter: Iter<'a, T>, - pub(crate) deque: NonNull>, + after_tail: usize, + after_head: usize, + iter: Iter<'a, T>, + deque: NonNull>, +} + +impl<'a, T, A: Allocator> Drain<'a, T, A> { + pub(super) unsafe fn new( + after_tail: usize, + after_head: usize, + iter: Iter<'a, T>, + deque: NonNull>, + ) -> Self { + Drain { after_tail, after_head, iter, deque } + } } #[stable(feature = "collection_debug", since = "1.17.0")] diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index f4de2b2ebe5dc..ea3136cae42b5 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1269,19 +1269,17 @@ impl VecDeque { // the drain is complete and the Drain destructor is run. self.head = drain_tail; - Drain { - deque: NonNull::from(&mut *self), - after_tail: drain_head, - after_head: head, - iter: Iter { - tail: drain_tail, - head: drain_head, - // Crucially, we only create shared references from `self` here and read from - // it. We do not write to `self` nor reborrow to a mutable reference. - // Hence the raw pointer we created above, for `deque`, remains valid. - ring: unsafe { self.buffer_as_slice() }, - }, - } + let deque = NonNull::from(&mut *self); + let iter = Iter { + tail: drain_tail, + head: drain_head, + // Crucially, we only create shared references from `self` here and read from + // it. We do not write to `self` nor reborrow to a mutable reference. + // Hence the raw pointer we created above, for `deque`, remains valid. + ring: unsafe { self.buffer_as_slice() }, + }; + + unsafe { Drain::new(drain_head, head, iter, deque) } } /// Clears the `VecDeque`, removing all values. From 5af61cb114e4af46e5c1c6c97b4556d5f007536f Mon Sep 17 00:00:00 2001 From: DeveloperC Date: Sat, 25 Sep 2021 13:55:45 +0100 Subject: [PATCH 21/26] refactor: VecDeques IterMut fields to private Made the fields of VecDeque's IterMut private by creating a IterMut::new(...) function to create a new instance of IterMut and migrating usage to use IterMut::new(...). --- .../src/collections/vec_deque/iter_mut.rs | 19 +++++++++++++++---- .../alloc/src/collections/vec_deque/mod.rs | 18 ++++++------------ 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/library/alloc/src/collections/vec_deque/iter_mut.rs b/library/alloc/src/collections/vec_deque/iter_mut.rs index 7700b31cf5b46..31e6e3b06af5f 100644 --- a/library/alloc/src/collections/vec_deque/iter_mut.rs +++ b/library/alloc/src/collections/vec_deque/iter_mut.rs @@ -13,10 +13,21 @@ use super::{count, wrap_index, RingSlices}; #[stable(feature = "rust1", since = "1.0.0")] pub struct IterMut<'a, T: 'a> { // Internal safety invariant: the entire slice is dereferencable. - pub(crate) ring: *mut [T], - pub(crate) tail: usize, - pub(crate) head: usize, - pub(crate) phantom: PhantomData<&'a mut [T]>, + ring: *mut [T], + tail: usize, + head: usize, + phantom: PhantomData<&'a mut [T]>, +} + +impl<'a, T> IterMut<'a, T> { + pub(super) unsafe fn new( + ring: *mut [T], + tail: usize, + head: usize, + phantom: PhantomData<&'a mut [T]>, + ) -> Self { + IterMut { ring, tail, head, phantom } + } } // SAFETY: we do nothing thread-local and there is no interior mutability, diff --git a/library/alloc/src/collections/vec_deque/mod.rs b/library/alloc/src/collections/vec_deque/mod.rs index f4de2b2ebe5dc..54fcb358ede1b 100644 --- a/library/alloc/src/collections/vec_deque/mod.rs +++ b/library/alloc/src/collections/vec_deque/mod.rs @@ -1000,12 +1000,9 @@ impl VecDeque { pub fn iter_mut(&mut self) -> IterMut<'_, T> { // SAFETY: The internal `IterMut` safety invariant is established because the // `ring` we create is a dereferencable slice for lifetime '_. - IterMut { - tail: self.tail, - head: self.head, - ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()), - phantom: PhantomData, - } + let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()); + + unsafe { IterMut::new(ring, self.tail, self.head, PhantomData) } } /// Returns a pair of slices which contain, in order, the contents of the @@ -1192,12 +1189,9 @@ impl VecDeque { // SAFETY: The internal `IterMut` safety invariant is established because the // `ring` we create is a dereferencable slice for lifetime '_. - IterMut { - tail, - head, - ring: ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()), - phantom: PhantomData, - } + let ring = ptr::slice_from_raw_parts_mut(self.ptr(), self.cap()); + + unsafe { IterMut::new(ring, tail, head, PhantomData) } } /// Creates a draining iterator that removes the specified range in the From 3c974adb4c4c6de497a36dec362af6c0928c7367 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Sun, 3 Oct 2021 15:25:26 -0500 Subject: [PATCH 22/26] Note specific regions involved in 'borrowed data escapes' error Fixes #67007 Currently, a 'borrowed data escapes' error does not mention the specific lifetime involved (except indirectly through a suggestion about adding a lifetime bound). We now explain the specific lifetime relationship that failed to hold, which improves otherwise vague error messages. --- .../src/diagnostics/region_errors.rs | 21 +++++++++++ .../async-await/issues/issue-62097.nll.stderr | 10 ++++-- .../dyn-trait.nll.stderr | 9 +++-- src/test/ui/issues/issue-16683.nll.stderr | 13 +++++-- src/test/ui/issues/issue-17758.nll.stderr | 13 +++++-- ...etime-bound-will-change-warning.nll.stderr | 18 +++++++--- ...oximated-shorter-to-static-no-bound.stderr | 9 +++-- ...mated-shorter-to-static-wrong-bound.stderr | 9 +++-- src/test/ui/nll/issue-67007-escaping-data.rs | 26 ++++++++++++++ .../ui/nll/issue-67007-escaping-data.stderr | 21 +++++++++++ .../ui/nll/outlives-suggestion-simple.stderr | 9 ++++- .../user-annotations/closure-substs.stderr | 9 +++-- .../object-lifetime-default-mybox.nll.stderr | 9 +++-- src/test/ui/regions/issue-78262.nll.stderr | 7 ++-- .../ui/regions/issue-78262.polonius.stderr | 7 ++-- ...nvariant-static-error-reporting.nll.stderr | 9 +++-- ...hod-type-parameters-trait-bound.nll.stderr | 13 ++++--- ...rait-with-implicit-static-bound.nll.stderr | 36 ++++++++++++++----- 18 files changed, 209 insertions(+), 39 deletions(-) create mode 100644 src/test/ui/nll/issue-67007-escaping-data.rs create mode 100644 src/test/ui/nll/issue-67007-escaping-data.stderr diff --git a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs index d05cfebc5f02e..11cdbe84accb7 100644 --- a/compiler/rustc_borrowck/src/diagnostics/region_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/region_errors.rs @@ -498,6 +498,27 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { diag.span_label(*span, format!("`{}` escapes the {} body here", fr_name, escapes_from)); } + // Only show an extra note if we can find an 'error region' for both of the region + // variables. This avoids showing a noisy note that just mentions 'synthetic' regions + // that don't help the user understand the error. + if self.to_error_region(errci.fr).is_some() + && self.to_error_region(errci.outlived_fr).is_some() + { + let fr_region_name = self.give_region_a_name(errci.fr).unwrap(); + fr_region_name.highlight_region_name(&mut diag); + let outlived_fr_region_name = self.give_region_a_name(errci.outlived_fr).unwrap(); + outlived_fr_region_name.highlight_region_name(&mut diag); + + diag.span_label( + *span, + format!( + "{}requires that `{}` must outlive `{}`", + category.description(), + fr_region_name, + outlived_fr_region_name, + ), + ); + } diag } diff --git a/src/test/ui/async-await/issues/issue-62097.nll.stderr b/src/test/ui/async-await/issues/issue-62097.nll.stderr index e71bcf5822808..786f621326049 100644 --- a/src/test/ui/async-await/issues/issue-62097.nll.stderr +++ b/src/test/ui/async-await/issues/issue-62097.nll.stderr @@ -20,9 +20,15 @@ error[E0521]: borrowed data escapes outside of associated function --> $DIR/issue-62097.rs:13:9 | LL | pub async fn run_dummy_fn(&self) { - | ----- `self` is a reference that is only valid in the associated function body + | ----- + | | + | `self` is a reference that is only valid in the associated function body + | let's call the lifetime of this reference `'1` LL | foo(|| self.bar()).await; - | ^^^^^^^^^^^^^^^^^^ `self` escapes the associated function body here + | ^^^^^^^^^^^^^^^^^^ + | | + | `self` escapes the associated function body here + | argument requires that `'1` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr b/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr index e49bd9da754d6..88c260b18cbb0 100644 --- a/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr +++ b/src/test/ui/impl-header-lifetime-elision/dyn-trait.nll.stderr @@ -2,9 +2,14 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/dyn-trait.rs:20:5 | LL | fn with_dyn_debug_static<'a>(x: Box) { - | - `x` is a reference that is only valid in the function body + | -- - `x` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | static_val(x); - | ^^^^^^^^^^^^^ `x` escapes the function body here + | ^^^^^^^^^^^^^ + | | + | `x` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-16683.nll.stderr b/src/test/ui/issues/issue-16683.nll.stderr index 51d86eaf9e60c..0e8f520353fba 100644 --- a/src/test/ui/issues/issue-16683.nll.stderr +++ b/src/test/ui/issues/issue-16683.nll.stderr @@ -1,10 +1,19 @@ error[E0521]: borrowed data escapes outside of associated function --> $DIR/issue-16683.rs:4:9 | +LL | trait T<'a> { + | -- lifetime `'a` defined here +LL | fn a(&'a self) -> &'a bool; LL | fn b(&self) { - | ----- `self` is a reference that is only valid in the associated function body + | ----- + | | + | `self` is a reference that is only valid in the associated function body + | let's call the lifetime of this reference `'1` LL | self.a(); - | ^^^^^^^^ `self` escapes the associated function body here + | ^^^^^^^^ + | | + | `self` escapes the associated function body here + | argument requires that `'1` must outlive `'a` error: aborting due to previous error diff --git a/src/test/ui/issues/issue-17758.nll.stderr b/src/test/ui/issues/issue-17758.nll.stderr index 075c141ed7af6..b929fdbf3687a 100644 --- a/src/test/ui/issues/issue-17758.nll.stderr +++ b/src/test/ui/issues/issue-17758.nll.stderr @@ -1,10 +1,19 @@ error[E0521]: borrowed data escapes outside of associated function --> $DIR/issue-17758.rs:7:9 | +LL | trait Foo<'a> { + | -- lifetime `'a` defined here +LL | fn foo(&'a self); LL | fn bar(&self) { - | ----- `self` is a reference that is only valid in the associated function body + | ----- + | | + | `self` is a reference that is only valid in the associated function body + | let's call the lifetime of this reference `'1` LL | self.foo(); - | ^^^^^^^^^^ `self` escapes the associated function body here + | ^^^^^^^^^^ + | | + | `self` escapes the associated function body here + | argument requires that `'1` must outlive `'a` error: aborting due to previous error diff --git a/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr b/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr index 050d5fcf05ef4..6f3f84096e400 100644 --- a/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr +++ b/src/test/ui/lifetimes/lifetime-bound-will-change-warning.nll.stderr @@ -2,19 +2,29 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/lifetime-bound-will-change-warning.rs:34:5 | LL | fn test2<'a>(x: &'a Box) { - | - `x` is a reference that is only valid in the function body + | -- - `x` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | // but ref_obj will not, so warn. LL | ref_obj(x) - | ^^^^^^^^^^ `x` escapes the function body here + | ^^^^^^^^^^ + | | + | `x` escapes the function body here + | argument requires that `'a` must outlive `'static` error[E0521]: borrowed data escapes outside of function --> $DIR/lifetime-bound-will-change-warning.rs:39:5 | LL | fn test2cc<'a>(x: &'a Box) { - | - `x` is a reference that is only valid in the function body + | -- - `x` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | // same as test2, but cross crate LL | lib::ref_obj(x) - | ^^^^^^^^^^^^^^^ `x` escapes the function body here + | ^^^^^^^^^^^^^^^ + | | + | `x` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index d17a40a95c1b8..d77793291c5c5 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -38,14 +38,19 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:32:5 | LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { - | ------ `cell_a` is a reference that is only valid in the function body + | -- ------ `cell_a` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { LL | | LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) LL | | }); - | |______^ `cell_a` escapes the function body here + | | ^ + | | | + | |______`cell_a` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index 06c46ec8259a0..cc67270ad20c1 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -38,14 +38,19 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:35:5 | LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { - | ------ `cell_a` is a reference that is only valid in the function body + | -- ------ `cell_a` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { LL | | LL | | LL | | // Only works if 'x: 'y: LL | | demand_y(x, y, x.get()) LL | | }); - | |______^ `cell_a` escapes the function body here + | | ^ + | | | + | |______`cell_a` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/nll/issue-67007-escaping-data.rs b/src/test/ui/nll/issue-67007-escaping-data.rs new file mode 100644 index 0000000000000..8c21737e05fe8 --- /dev/null +++ b/src/test/ui/nll/issue-67007-escaping-data.rs @@ -0,0 +1,26 @@ +// Regression test for issue #67007 +// Ensures that we show information about the specific regions involved + +#![feature(nll)] + +// Covariant over 'a, invariant over 'tcx +struct FnCtxt<'a, 'tcx: 'a>(&'a (), *mut &'tcx ()); + +impl<'a, 'tcx> FnCtxt<'a, 'tcx> { + fn use_it(&self, _: &'tcx ()) {} +} + +struct Consumer<'tcx>(&'tcx ()); + +impl<'tcx> Consumer<'tcx> { + fn bad_method<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) { + let other = self.use_fcx(fcx); //~ ERROR borrowed data + fcx.use_it(other); + } + + fn use_fcx<'a>(&self, _: &FnCtxt<'a, 'tcx>) -> &'a () { + &() + } +} + +fn main() {} diff --git a/src/test/ui/nll/issue-67007-escaping-data.stderr b/src/test/ui/nll/issue-67007-escaping-data.stderr new file mode 100644 index 0000000000000..2834d6fb0d214 --- /dev/null +++ b/src/test/ui/nll/issue-67007-escaping-data.stderr @@ -0,0 +1,21 @@ +error[E0521]: borrowed data escapes outside of associated function + --> $DIR/issue-67007-escaping-data.rs:17:21 + | +LL | impl<'tcx> Consumer<'tcx> { + | ---- lifetime `'tcx` defined here +LL | fn bad_method<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) { + | -- ----- --- `fcx` is a reference that is only valid in the associated function body + | | | + | | `self` declared here, outside of the associated function body + | lifetime `'a` defined here +LL | let other = self.use_fcx(fcx); + | ^^^^^^^^^^^^^^^^^ + | | + | `fcx` escapes the associated function body here + | argument requires that `'a` must outlive `'tcx` + | + = help: consider adding the following bound: `'a: 'tcx` + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/outlives-suggestion-simple.stderr b/src/test/ui/nll/outlives-suggestion-simple.stderr index fa85ce2799083..3b2017d2d03a1 100644 --- a/src/test/ui/nll/outlives-suggestion-simple.stderr +++ b/src/test/ui/nll/outlives-suggestion-simple.stderr @@ -92,13 +92,20 @@ LL | self.x error[E0521]: borrowed data escapes outside of associated function --> $DIR/outlives-suggestion-simple.rs:73:9 | +LL | impl<'a> Foo2<'a> { + | -- lifetime `'a` defined here +LL | // should not produce outlives suggestions to name 'self LL | fn get_bar(&self) -> Bar2 { | ----- | | | `self` declared here, outside of the associated function body | `self` is a reference that is only valid in the associated function body + | let's call the lifetime of this reference `'1` LL | Bar2::new(&self) - | ^^^^^^^^^^^^^^^^ `self` escapes the associated function body here + | ^^^^^^^^^^^^^^^^ + | | + | `self` escapes the associated function body here + | argument requires that `'1` must outlive `'a` error: aborting due to 9 previous errors diff --git a/src/test/ui/nll/user-annotations/closure-substs.stderr b/src/test/ui/nll/user-annotations/closure-substs.stderr index 55bb3a6090c01..20002e4591d1a 100644 --- a/src/test/ui/nll/user-annotations/closure-substs.stderr +++ b/src/test/ui/nll/user-annotations/closure-substs.stderr @@ -28,9 +28,14 @@ error[E0521]: borrowed data escapes outside of closure --> $DIR/closure-substs.rs:29:9 | LL | |x: &i32, b: fn(&'static i32)| { - | - `x` is a reference that is only valid in the closure body + | - - let's call the lifetime of this reference `'1` + | | + | `x` is a reference that is only valid in the closure body LL | b(x); - | ^^^^ `x` escapes the closure body here + | ^^^^ + | | + | `x` escapes the closure body here + | argument requires that `'1` must outlive `'static` error: aborting due to 4 previous errors diff --git a/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr b/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr index 6ce1b2eed85d2..af20c5e5fc0da 100644 --- a/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr +++ b/src/test/ui/object-lifetime/object-lifetime-default-mybox.nll.stderr @@ -15,9 +15,14 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/object-lifetime-default-mybox.rs:31:5 | LL | fn load2<'a>(ss: &MyBox) -> MyBox { - | -- `ss` is a reference that is only valid in the function body + | -- -- `ss` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | load0(ss) - | ^^^^^^^^^ `ss` escapes the function body here + | ^^^^^^^^^ + | | + | `ss` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to 2 previous errors diff --git a/src/test/ui/regions/issue-78262.nll.stderr b/src/test/ui/regions/issue-78262.nll.stderr index a35d6fd9bf885..721dafac0be76 100644 --- a/src/test/ui/regions/issue-78262.nll.stderr +++ b/src/test/ui/regions/issue-78262.nll.stderr @@ -2,8 +2,11 @@ error[E0521]: borrowed data escapes outside of closure --> $DIR/issue-78262.rs:14:26 | LL | let f = |x: &dyn TT| x.func(); - | - ^^^^^^^^ `x` escapes the closure body here - | | + | - - ^^^^^^^^ + | | | | + | | | `x` escapes the closure body here + | | | argument requires that `'1` must outlive `'static` + | | let's call the lifetime of this reference `'1` | `x` is a reference that is only valid in the closure body error: aborting due to previous error diff --git a/src/test/ui/regions/issue-78262.polonius.stderr b/src/test/ui/regions/issue-78262.polonius.stderr index a35d6fd9bf885..721dafac0be76 100644 --- a/src/test/ui/regions/issue-78262.polonius.stderr +++ b/src/test/ui/regions/issue-78262.polonius.stderr @@ -2,8 +2,11 @@ error[E0521]: borrowed data escapes outside of closure --> $DIR/issue-78262.rs:14:26 | LL | let f = |x: &dyn TT| x.func(); - | - ^^^^^^^^ `x` escapes the closure body here - | | + | - - ^^^^^^^^ + | | | | + | | | `x` escapes the closure body here + | | | argument requires that `'1` must outlive `'static` + | | let's call the lifetime of this reference `'1` | `x` is a reference that is only valid in the closure body error: aborting due to previous error diff --git a/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr b/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr index 7221759dbd450..e220cbf555956 100644 --- a/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr +++ b/src/test/ui/regions/region-invariant-static-error-reporting.nll.stderr @@ -2,10 +2,15 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/region-invariant-static-error-reporting.rs:15:9 | LL | fn unify<'a>(x: Option>, f: fn(Invariant<'a>)) { - | - `x` is a reference that is only valid in the function body + | -- - `x` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | let bad = if x.is_some() { LL | x.unwrap() - | ^^^^^^^^^^ `x` escapes the function body here + | ^^^^^^^^^^ + | | + | `x` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to previous error diff --git a/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr b/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr index ed7b17c207c30..83d6e13dc0a68 100644 --- a/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr +++ b/src/test/ui/regions/regions-bounded-method-type-parameters-trait-bound.nll.stderr @@ -2,12 +2,17 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/regions-bounded-method-type-parameters-trait-bound.rs:20:5 | LL | fn caller2<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) { - | - - `b` is a reference that is only valid in the function body - | | - | `a` declared here, outside of the function body + | -- -- - - `b` is a reference that is only valid in the function body + | | | | + | | | `a` declared here, outside of the function body + | | lifetime `'b` defined here + | lifetime `'a` defined here LL | // Here the value provided for 'y is 'b, and hence 'b:'a does not hold. LL | f.method(b); - | ^^^^^^^^^^^ `b` escapes the function body here + | ^^^^^^^^^^^ + | | + | `b` escapes the function body here + | argument requires that `'b` must outlive `'a` | = help: consider adding the following bound: `'b: 'a` diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr index 32a2de1e84d8f..a1ef32c5445b5 100644 --- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr +++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr @@ -2,33 +2,53 @@ error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:20:9 | LL | fn use_it<'a, T>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a { - | --- `val` is a reference that is only valid in the function body + | -- --- `val` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | val.use_self::() - | ^^^^^^^^^^^^^^^^^^^ `val` escapes the function body here + | ^^^^^^^^^^^^^^^^^^^ + | | + | `val` escapes the function body here + | argument requires that `'a` must outlive `'static` error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:69:9 | LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a { - | --- `val` is a reference that is only valid in the function body + | -- --- `val` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | val.use_self() - | ^^^^^^^^^^^^^^ `val` escapes the function body here + | ^^^^^^^^^^^^^^ + | | + | `val` escapes the function body here + | argument requires that `'a` must outlive `'static` error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:88:9 | LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> { - | --- `val` is a reference that is only valid in the function body + | -- --- `val` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | val.use_self() - | ^^^^^^^^^^^^^^ `val` escapes the function body here + | ^^^^^^^^^^^^^^ + | | + | `val` escapes the function body here + | argument requires that `'a` must outlive `'static` error[E0521]: borrowed data escapes outside of function --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:108:9 | LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a { - | --- `val` is a reference that is only valid in the function body + | -- --- `val` is a reference that is only valid in the function body + | | + | lifetime `'a` defined here LL | MyTrait::use_self(val) - | ^^^^^^^^^^^^^^^^^^^^^^ `val` escapes the function body here + | ^^^^^^^^^^^^^^^^^^^^^^ + | | + | `val` escapes the function body here + | argument requires that `'a` must outlive `'static` error: aborting due to 4 previous errors From edfd6d591b51da089b65c68ece0aecd1e9b8a42b Mon Sep 17 00:00:00 2001 From: Ellen Date: Wed, 6 Oct 2021 04:37:07 +0100 Subject: [PATCH 23/26] test --- .../const_eval_resolve_canonical.rs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs diff --git a/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs b/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs new file mode 100644 index 0000000000000..b79bc262d2bac --- /dev/null +++ b/src/test/ui/const-generics/generic_const_exprs/const_eval_resolve_canonical.rs @@ -0,0 +1,29 @@ +// run-pass +#![feature(generic_const_exprs)] +#![allow(incomplete_features)] + +trait Foo { + type Assoc: Default; +} + +impl Foo<0> for () { + type Assoc = u32; +} + +impl Foo<3> for () { + type Assoc = i64; +} + +fn foo(_: T) -> <() as Foo<{ N + 1 }>>::Assoc +where + (): Foo<{ N + 1 }>, +{ + Default::default() +} + +fn main() { + // Test that we can correctly infer `T` which requires evaluating + // `{ N + 1 }` which has substs containing an inference var + let mut _q = Default::default(); + _q = foo::<_, 2>(_q); +} From b386959aca1fd25431b8f58b96ddefa556a4bd27 Mon Sep 17 00:00:00 2001 From: Ximin Luo Date: Wed, 6 Oct 2021 10:22:03 +0100 Subject: [PATCH 24/26] fix: alloc-optimisation is only for rust llvm --- src/test/codegen/alloc-optimisation.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/codegen/alloc-optimisation.rs b/src/test/codegen/alloc-optimisation.rs index 5b27f3f45457d..aee93b93e3737 100644 --- a/src/test/codegen/alloc-optimisation.rs +++ b/src/test/codegen/alloc-optimisation.rs @@ -1,4 +1,5 @@ // +// no-system-llvm // min-llvm-version: 10.0.1 // compile-flags: -O #![crate_type="lib"] From 742d8be5e6c1cedfde503424036b597c514079ae Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Wed, 6 Oct 2021 07:27:13 -0400 Subject: [PATCH 25/26] Restore h1 styles, which got accidentally removed. --- src/librustdoc/html/static/css/themes/ayu.css | 2 +- src/librustdoc/html/static/css/themes/dark.css | 2 +- src/librustdoc/html/static/css/themes/light.css | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/html/static/css/themes/ayu.css b/src/librustdoc/html/static/css/themes/ayu.css index 0fb4f95acdf34..0fd6462a8f5dd 100644 --- a/src/librustdoc/html/static/css/themes/ayu.css +++ b/src/librustdoc/html/static/css/themes/ayu.css @@ -136,7 +136,7 @@ pre, .rustdoc.source .example-wrap { border-right: 1px solid #ffb44c; } -.docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom-color: #5c6773; } diff --git a/src/librustdoc/html/static/css/themes/dark.css b/src/librustdoc/html/static/css/themes/dark.css index 4fb6f7b38bbf2..d863701dd73c7 100644 --- a/src/librustdoc/html/static/css/themes/dark.css +++ b/src/librustdoc/html/static/css/themes/dark.css @@ -93,7 +93,7 @@ pre, .rustdoc.source .example-wrap { background-color: #0a042f !important; } -.docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom-color: #DDD; } diff --git a/src/librustdoc/html/static/css/themes/light.css b/src/librustdoc/html/static/css/themes/light.css index 62134f025c82a..28d2e99a3d073 100644 --- a/src/librustdoc/html/static/css/themes/light.css +++ b/src/librustdoc/html/static/css/themes/light.css @@ -93,7 +93,7 @@ pre, .rustdoc.source .example-wrap { background-color: #f6fdb0 !important; } -.docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { +.docblock h1, .docblock h2, .docblock h3, .docblock h4, .docblock h5, .docblock h6 { border-bottom-color: #ddd; } From 1f86a8e2a058d7f12b25406a53576b08817677fe Mon Sep 17 00:00:00 2001 From: Mukund Lakshman Date: Wed, 6 Oct 2021 07:58:41 -0400 Subject: [PATCH 26/26] Revert the rustc_error_codes changes. --- compiler/rustc_error_codes/src/error_codes/E0001.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0002.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0007.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0009.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0014.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0073.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0074.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0087.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0088.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0089.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0090.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0110.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0136.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0137.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0139.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0154.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0162.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0165.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0193.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0205.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0211.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0243.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0244.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0251.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0256.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0281.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0297.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0301.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0302.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0303.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0329.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0383.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0386.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0387.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0388.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0389.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0398.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0399.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0439.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0447.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0448.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0497.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0504.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0595.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0619.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0633.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0665.md | 2 +- compiler/rustc_error_codes/src/error_codes/E0671.md | 2 +- src/tools/error_index_generator/main.rs | 2 +- src/tools/tidy/src/error_codes_check.rs | 4 ++-- 50 files changed, 51 insertions(+), 51 deletions(-) diff --git a/compiler/rustc_error_codes/src/error_codes/E0001.md b/compiler/rustc_error_codes/src/error_codes/E0001.md index cd6e15f581f3b..90756780d1502 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0001.md +++ b/compiler/rustc_error_codes/src/error_codes/E0001.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error suggests that the expression arm corresponding to the noted pattern will never be reached as for all possible values of the expression being diff --git a/compiler/rustc_error_codes/src/error_codes/E0002.md b/compiler/rustc_error_codes/src/error_codes/E0002.md index 4e7aa7fb9ed81..5cb59da10e00b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0002.md +++ b/compiler/rustc_error_codes/src/error_codes/E0002.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error indicates that an empty match expression is invalid because the type it is matching on is non-empty (there exist values of this type). In safe code diff --git a/compiler/rustc_error_codes/src/error_codes/E0007.md b/compiler/rustc_error_codes/src/error_codes/E0007.md index d30de4af0eb37..2c22b86af9246 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0007.md +++ b/compiler/rustc_error_codes/src/error_codes/E0007.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error indicates that the bindings in a match arm would require a value to be moved into more than one location, thus violating unique ownership. Code diff --git a/compiler/rustc_error_codes/src/error_codes/E0009.md b/compiler/rustc_error_codes/src/error_codes/E0009.md index 6aab44cb4d6ec..aaabba0434993 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0009.md +++ b/compiler/rustc_error_codes/src/error_codes/E0009.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. In a pattern, all values that don't implement the `Copy` trait have to be bound the same way. The goal here is to avoid binding simultaneously by-move and diff --git a/compiler/rustc_error_codes/src/error_codes/E0014.md b/compiler/rustc_error_codes/src/error_codes/E0014.md index 27ae8f098987a..2c69957e9f642 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0014.md +++ b/compiler/rustc_error_codes/src/error_codes/E0014.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Constants can only be initialized by a constant value or, in a future version of Rust, a call to a const function. This error indicates the use diff --git a/compiler/rustc_error_codes/src/error_codes/E0073.md b/compiler/rustc_error_codes/src/error_codes/E0073.md index 39c16bc438fea..a5aea86ff2d9d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0073.md +++ b/compiler/rustc_error_codes/src/error_codes/E0073.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You cannot define a struct (or enum) `Foo` that requires an instance of `Foo` in order to make a new `Foo` value. This is because there would be no way a diff --git a/compiler/rustc_error_codes/src/error_codes/E0074.md b/compiler/rustc_error_codes/src/error_codes/E0074.md index 026acac99e74f..785d6de226d3d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0074.md +++ b/compiler/rustc_error_codes/src/error_codes/E0074.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. When using the `#[simd]` attribute on a tuple struct, the components of the tuple struct must all be of a concrete, nongeneric type so the compiler can diff --git a/compiler/rustc_error_codes/src/error_codes/E0087.md b/compiler/rustc_error_codes/src/error_codes/E0087.md index cd2da0469bb63..9d292186f0fa5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0087.md +++ b/compiler/rustc_error_codes/src/error_codes/E0087.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Too many type arguments were supplied for a function. For example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0088.md b/compiler/rustc_error_codes/src/error_codes/E0088.md index 6b565507ce4a3..7780ad5b56e03 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0088.md +++ b/compiler/rustc_error_codes/src/error_codes/E0088.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You gave too many lifetime arguments. Erroneous code example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0089.md b/compiler/rustc_error_codes/src/error_codes/E0089.md index b78f95f266c19..504fbc7b96a98 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0089.md +++ b/compiler/rustc_error_codes/src/error_codes/E0089.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Too few type arguments were supplied for a function. For example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0090.md b/compiler/rustc_error_codes/src/error_codes/E0090.md index 7b07a86dc25a4..e091bb6c9f2f7 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0090.md +++ b/compiler/rustc_error_codes/src/error_codes/E0090.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You gave too few lifetime arguments. Example: diff --git a/compiler/rustc_error_codes/src/error_codes/E0110.md b/compiler/rustc_error_codes/src/error_codes/E0110.md index 91f599ff1dcfb..b9fe406ffb9bd 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0110.md +++ b/compiler/rustc_error_codes/src/error_codes/E0110.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You tried to provide a lifetime to a type which doesn't need it. See `E0109` for more details. diff --git a/compiler/rustc_error_codes/src/error_codes/E0136.md b/compiler/rustc_error_codes/src/error_codes/E0136.md index 0a74558e75b05..15cf09a18cbde 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0136.md +++ b/compiler/rustc_error_codes/src/error_codes/E0136.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. More than one `main` function was found. diff --git a/compiler/rustc_error_codes/src/error_codes/E0137.md b/compiler/rustc_error_codes/src/error_codes/E0137.md index ba6f02add9494..d4e19170f3f7b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0137.md +++ b/compiler/rustc_error_codes/src/error_codes/E0137.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. More than one function was declared with the `#[main]` attribute. diff --git a/compiler/rustc_error_codes/src/error_codes/E0139.md b/compiler/rustc_error_codes/src/error_codes/E0139.md index e7ad2a6f44dc1..a116cf29395fa 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0139.md +++ b/compiler/rustc_error_codes/src/error_codes/E0139.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. There are various restrictions on transmuting between types in Rust; for example types being transmuted must have the same size. To apply all these restrictions, diff --git a/compiler/rustc_error_codes/src/error_codes/E0154.md b/compiler/rustc_error_codes/src/error_codes/E0154.md index 9c954839eee6b..e437a71897c66 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0154.md +++ b/compiler/rustc_error_codes/src/error_codes/E0154.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Imports (`use` statements) are not allowed after non-item statements, such as variable declarations and expression statements. diff --git a/compiler/rustc_error_codes/src/error_codes/E0162.md b/compiler/rustc_error_codes/src/error_codes/E0162.md index 2e0f387e3521f..0161c9325c211 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0162.md +++ b/compiler/rustc_error_codes/src/error_codes/E0162.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. An `if let` pattern attempts to match the pattern, and enters the body if the match was successful. If the match is irrefutable (when it cannot fail to diff --git a/compiler/rustc_error_codes/src/error_codes/E0165.md b/compiler/rustc_error_codes/src/error_codes/E0165.md index 3222b7a87eb65..7bcd6c0cbf379 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0165.md +++ b/compiler/rustc_error_codes/src/error_codes/E0165.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. A `while let` pattern attempts to match the pattern, and enters the body if the match was successful. If the match is irrefutable (when it cannot fail to diff --git a/compiler/rustc_error_codes/src/error_codes/E0193.md b/compiler/rustc_error_codes/src/error_codes/E0193.md index 6e7ebbaddf921..e29a949ffba91 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0193.md +++ b/compiler/rustc_error_codes/src/error_codes/E0193.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. `where` clauses must use generic type parameters: it does not make sense to use them otherwise. An example causing this error: diff --git a/compiler/rustc_error_codes/src/error_codes/E0205.md b/compiler/rustc_error_codes/src/error_codes/E0205.md index 07bbd1f68347b..7916f53ad3b41 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0205.md +++ b/compiler/rustc_error_codes/src/error_codes/E0205.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. An attempt to implement the `Copy` trait for an enum failed because one of the variants does not implement `Copy`. To fix this, you must implement `Copy` for diff --git a/compiler/rustc_error_codes/src/error_codes/E0211.md b/compiler/rustc_error_codes/src/error_codes/E0211.md index 2485367e09712..77289f019005e 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0211.md +++ b/compiler/rustc_error_codes/src/error_codes/E0211.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You used a function or type which doesn't fit the requirements for where it was used. Erroneous code examples: diff --git a/compiler/rustc_error_codes/src/error_codes/E0243.md b/compiler/rustc_error_codes/src/error_codes/E0243.md index ef4a837ec2172..5d3d1828bf59b 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0243.md +++ b/compiler/rustc_error_codes/src/error_codes/E0243.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error indicates that not enough type parameters were found in a type or trait. diff --git a/compiler/rustc_error_codes/src/error_codes/E0244.md b/compiler/rustc_error_codes/src/error_codes/E0244.md index 31c5b4542e28f..5187b7b05d2c1 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0244.md +++ b/compiler/rustc_error_codes/src/error_codes/E0244.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error indicates that too many type parameters were found in a type or trait. diff --git a/compiler/rustc_error_codes/src/error_codes/E0251.md b/compiler/rustc_error_codes/src/error_codes/E0251.md index 7b048db5ece3e..4121dd27877a0 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0251.md +++ b/compiler/rustc_error_codes/src/error_codes/E0251.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Two items of the same name cannot be imported without rebinding one of the items under a new local name. diff --git a/compiler/rustc_error_codes/src/error_codes/E0256.md b/compiler/rustc_error_codes/src/error_codes/E0256.md index 1b518b1615b64..385376cdade91 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0256.md +++ b/compiler/rustc_error_codes/src/error_codes/E0256.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You can't import a type or module when the name of the item being imported is the same as another type or submodule defined in the module. diff --git a/compiler/rustc_error_codes/src/error_codes/E0281.md b/compiler/rustc_error_codes/src/error_codes/E0281.md index 2d8ead0b0181c..1d7904b67ddb4 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0281.md +++ b/compiler/rustc_error_codes/src/error_codes/E0281.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. You tried to supply a type which doesn't implement some trait in a location which expected that trait. This error typically occurs when working with diff --git a/compiler/rustc_error_codes/src/error_codes/E0297.md b/compiler/rustc_error_codes/src/error_codes/E0297.md index 001e0f3089e15..66c31376d8b28 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0297.md +++ b/compiler/rustc_error_codes/src/error_codes/E0297.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Patterns used to bind names must be irrefutable. That is, they must guarantee that a name will be extracted in all cases. Instead of pattern matching the diff --git a/compiler/rustc_error_codes/src/error_codes/E0301.md b/compiler/rustc_error_codes/src/error_codes/E0301.md index 7b1e02051dc4e..485e19fbb8d9c 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0301.md +++ b/compiler/rustc_error_codes/src/error_codes/E0301.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Mutable borrows are not allowed in pattern guards, because matching cannot have side effects. Side effects could alter the matched object or the environment diff --git a/compiler/rustc_error_codes/src/error_codes/E0302.md b/compiler/rustc_error_codes/src/error_codes/E0302.md index c56500fcebce8..e6ac9d590c88f 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0302.md +++ b/compiler/rustc_error_codes/src/error_codes/E0302.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Assignments are not allowed in pattern guards, because matching cannot have side effects. Side effects could alter the matched object or the environment diff --git a/compiler/rustc_error_codes/src/error_codes/E0303.md b/compiler/rustc_error_codes/src/error_codes/E0303.md index 750b766f5bfdf..459906047cc87 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0303.md +++ b/compiler/rustc_error_codes/src/error_codes/E0303.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Sub-bindings, e.g. `ref x @ Some(ref y)` are now allowed under `#![feature(bindings_after_at)]` and checked to make sure that diff --git a/compiler/rustc_error_codes/src/error_codes/E0329.md b/compiler/rustc_error_codes/src/error_codes/E0329.md index 36114316e8803..37d84a1a89bfe 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0329.md +++ b/compiler/rustc_error_codes/src/error_codes/E0329.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. An attempt was made to access an associated constant through either a generic type parameter or `Self`. This is not supported yet. An example causing this diff --git a/compiler/rustc_error_codes/src/error_codes/E0383.md b/compiler/rustc_error_codes/src/error_codes/E0383.md index 309eb2b59eb97..fd2b0b08fb007 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0383.md +++ b/compiler/rustc_error_codes/src/error_codes/E0383.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to partially reinitialize a structure that is currently uninitialized. diff --git a/compiler/rustc_error_codes/src/error_codes/E0386.md b/compiler/rustc_error_codes/src/error_codes/E0386.md index 5e45a2b40cefa..de3b468b6e4ac 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0386.md +++ b/compiler/rustc_error_codes/src/error_codes/E0386.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to mutate the target of a mutable reference stored inside an immutable container. diff --git a/compiler/rustc_error_codes/src/error_codes/E0387.md b/compiler/rustc_error_codes/src/error_codes/E0387.md index ddc838bdca1b3..38ad19bd6aa9a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0387.md +++ b/compiler/rustc_error_codes/src/error_codes/E0387.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to mutate or mutably reference data that a closure has captured immutably. diff --git a/compiler/rustc_error_codes/src/error_codes/E0388.md b/compiler/rustc_error_codes/src/error_codes/E0388.md index 13ef94a48553b..512fb42e6ecb5 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0388.md +++ b/compiler/rustc_error_codes/src/error_codes/E0388.md @@ -1 +1 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. diff --git a/compiler/rustc_error_codes/src/error_codes/E0389.md b/compiler/rustc_error_codes/src/error_codes/E0389.md index 19bb6ec408131..9f064e44c8209 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0389.md +++ b/compiler/rustc_error_codes/src/error_codes/E0389.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. An attempt was made to mutate data using a non-mutable reference. This commonly occurs when attempting to assign to a non-mutable reference of a diff --git a/compiler/rustc_error_codes/src/error_codes/E0398.md b/compiler/rustc_error_codes/src/error_codes/E0398.md index 12e0eb1a5d5dd..75d86979e3c87 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0398.md +++ b/compiler/rustc_error_codes/src/error_codes/E0398.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. In Rust 1.3, the default object lifetime bounds are expected to change, as described in [RFC 1156]. You are getting a warning because the compiler diff --git a/compiler/rustc_error_codes/src/error_codes/E0399.md b/compiler/rustc_error_codes/src/error_codes/E0399.md index c3e9616c60698..6ea6054b41779 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0399.md +++ b/compiler/rustc_error_codes/src/error_codes/E0399.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler +#### Note: this error code is no longer emitted by the compiler You implemented a trait, overriding one or more of its associated types but did not reimplement its default methods. diff --git a/compiler/rustc_error_codes/src/error_codes/E0439.md b/compiler/rustc_error_codes/src/error_codes/E0439.md index 85e965c4eee62..24268aef2222a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0439.md +++ b/compiler/rustc_error_codes/src/error_codes/E0439.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. The length of the platform-intrinsic function `simd_shuffle` wasn't specified. diff --git a/compiler/rustc_error_codes/src/error_codes/E0447.md b/compiler/rustc_error_codes/src/error_codes/E0447.md index e880ff4637da7..af8cd8d6d5202 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0447.md +++ b/compiler/rustc_error_codes/src/error_codes/E0447.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. The `pub` keyword was used inside a function. diff --git a/compiler/rustc_error_codes/src/error_codes/E0448.md b/compiler/rustc_error_codes/src/error_codes/E0448.md index f4bd184188824..ba096f9e984ae 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0448.md +++ b/compiler/rustc_error_codes/src/error_codes/E0448.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. The `pub` keyword was used inside a public enum. diff --git a/compiler/rustc_error_codes/src/error_codes/E0497.md b/compiler/rustc_error_codes/src/error_codes/E0497.md index 12004996384a2..ef2882415d24a 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0497.md +++ b/compiler/rustc_error_codes/src/error_codes/E0497.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. A stability attribute was used outside of the standard library. diff --git a/compiler/rustc_error_codes/src/error_codes/E0504.md b/compiler/rustc_error_codes/src/error_codes/E0504.md index 640cfad656f71..bcbd00a8690a4 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0504.md +++ b/compiler/rustc_error_codes/src/error_codes/E0504.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. This error occurs when an attempt is made to move a borrowed variable into a closure. diff --git a/compiler/rustc_error_codes/src/error_codes/E0595.md b/compiler/rustc_error_codes/src/error_codes/E0595.md index 96fbb5e410ae7..e6729013243f6 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0595.md +++ b/compiler/rustc_error_codes/src/error_codes/E0595.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Closures cannot mutate immutable captured variables. diff --git a/compiler/rustc_error_codes/src/error_codes/E0619.md b/compiler/rustc_error_codes/src/error_codes/E0619.md index d33154058dd37..f516de43095bd 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0619.md +++ b/compiler/rustc_error_codes/src/error_codes/E0619.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. The type-checker needed to know the type of an expression, but that type had not yet been inferred. diff --git a/compiler/rustc_error_codes/src/error_codes/E0633.md b/compiler/rustc_error_codes/src/error_codes/E0633.md index f6e8a4042ed35..5b6c15c82eb63 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0633.md +++ b/compiler/rustc_error_codes/src/error_codes/E0633.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. The `unwind` attribute was malformed. diff --git a/compiler/rustc_error_codes/src/error_codes/E0665.md b/compiler/rustc_error_codes/src/error_codes/E0665.md index db5e088cc501e..ae54d6d15798d 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0665.md +++ b/compiler/rustc_error_codes/src/error_codes/E0665.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. The `Default` trait was derived on an enum. diff --git a/compiler/rustc_error_codes/src/error_codes/E0671.md b/compiler/rustc_error_codes/src/error_codes/E0671.md index a68273f752e73..d4dbfb7a5d8e6 100644 --- a/compiler/rustc_error_codes/src/error_codes/E0671.md +++ b/compiler/rustc_error_codes/src/error_codes/E0671.md @@ -1,4 +1,4 @@ -### Note: this error code is no longer emitted by the compiler. +#### Note: this error code is no longer emitted by the compiler. Const parameters cannot depend on type parameters. The following is therefore invalid: diff --git a/src/tools/error_index_generator/main.rs b/src/tools/error_index_generator/main.rs index e796934961094..5b3da5893ea7e 100644 --- a/src/tools/error_index_generator/main.rs +++ b/src/tools/error_index_generator/main.rs @@ -126,7 +126,7 @@ impl Formatter for HTMLFormatter { error_codes: ErrorCodes::Yes, edition: DEFAULT_EDITION, playground: &Some(playground), - heading_offset: HeadingOffset::H2, + heading_offset: HeadingOffset::H1, } .into_string() )? diff --git a/src/tools/tidy/src/error_codes_check.rs b/src/tools/tidy/src/error_codes_check.rs index ae169d383b273..53c75a463390d 100644 --- a/src/tools/tidy/src/error_codes_check.rs +++ b/src/tools/tidy/src/error_codes_check.rs @@ -49,7 +49,7 @@ fn check_error_code_explanation( } else if s.contains("compile-fail") { invalid_compile_fail_format = true; } - } else if s.starts_with("### Note: this error code is no longer emitted by the compiler") { + } else if s.starts_with("#### Note: this error code is no longer emitted by the compiler") { if !found_error_code { error_codes.get_mut(&err_code).map(|x| x.has_test = true); found_error_code = true; @@ -64,7 +64,7 @@ fn check_if_error_code_is_test_in_explanation(f: &str, err_code: &str) -> bool { for line in f.lines() { let s = line.trim(); - if s.starts_with("### Note: this error code is no longer emitted by the compiler") { + if s.starts_with("#### Note: this error code is no longer emitted by the compiler") { return true; } if s.starts_with("```") {