From 950a249e7869ab8287c4c0d4b78174d5803a0c13 Mon Sep 17 00:00:00 2001 From: Dmitry Murzin Date: Wed, 5 Jul 2023 16:18:32 +0300 Subject: [PATCH 1/6] Add `suggestion` for some `#[deprecated]` items --- library/alloc/src/lib.rs | 1 + library/alloc/src/slice.rs | 2 +- library/core/src/error.rs | 3 ++- library/core/src/mem/mod.rs | 4 ++-- library/core/src/str/mod.rs | 2 +- library/std/src/os/unix/process.rs | 6 +++++- library/std/src/sync/condvar.rs | 6 +++++- library/std/src/thread/mod.rs | 8 ++++++-- ...issue-84637-deprecated-associated-function.fixed | 2 ++ .../issue-84637-deprecated-associated-function.rs | 2 ++ ...ssue-84637-deprecated-associated-function.stderr | 13 ++++++++++++- 11 files changed, 39 insertions(+), 10 deletions(-) diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 967ad3a0e6901..9d9743a437829 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -118,6 +118,7 @@ #![feature(const_waker)] #![feature(core_intrinsics)] #![feature(core_panic)] +#![feature(deprecated_suggestion)] #![feature(dispatch_from_dyn)] #![feature(error_generic_member_access)] #![feature(error_in_core)] diff --git a/library/alloc/src/slice.rs b/library/alloc/src/slice.rs index 093dcbbe8bf77..aa3b7b7e1914b 100644 --- a/library/alloc/src/slice.rs +++ b/library/alloc/src/slice.rs @@ -592,7 +592,7 @@ impl [T] { /// ``` #[rustc_allow_incoherent_impl] #[stable(feature = "rust1", since = "1.0.0")] - #[deprecated(since = "1.3.0", note = "renamed to join")] + #[deprecated(since = "1.3.0", note = "renamed to join", suggestion = "join")] pub fn connect(&self, sep: Separator) -> >::Output where Self: Join, diff --git a/library/core/src/error.rs b/library/core/src/error.rs index 11cb082757864..8b4b34a5a1ef9 100644 --- a/library/core/src/error.rs +++ b/library/core/src/error.rs @@ -114,7 +114,8 @@ pub trait Error: Debug + Display { #[stable(feature = "rust1", since = "1.0.0")] #[deprecated( since = "1.33.0", - note = "replaced by Error::source, which can support downcasting" + note = "replaced by Error::source, which can support downcasting", + suggestion = "source" )] #[allow(missing_docs)] fn cause(&self) -> Option<&dyn Error> { diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index 2fff3f0efd73a..732fcce0f2930 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -413,7 +413,7 @@ pub const unsafe fn size_of_val_raw(val: *const T) -> usize { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -#[deprecated(note = "use `align_of` instead", since = "1.2.0")] +#[deprecated(note = "use `align_of` instead", since = "1.2.0", suggestion = "align_of")] pub fn min_align_of() -> usize { intrinsics::min_align_of::() } @@ -436,7 +436,7 @@ pub fn min_align_of() -> usize { #[inline] #[must_use] #[stable(feature = "rust1", since = "1.0.0")] -#[deprecated(note = "use `align_of_val` instead", since = "1.2.0")] +#[deprecated(note = "use `align_of_val` instead", since = "1.2.0", suggestion = "align_of_val")] pub fn min_align_of_val(val: &T) -> usize { // SAFETY: val is a reference, so it's a valid raw pointer unsafe { intrinsics::min_align_of_val(val) } diff --git a/library/core/src/str/mod.rs b/library/core/src/str/mod.rs index 9a93bb72903f2..5f5d931a26729 100644 --- a/library/core/src/str/mod.rs +++ b/library/core/src/str/mod.rs @@ -993,7 +993,7 @@ impl str { /// An iterator over the lines of a string. #[stable(feature = "rust1", since = "1.0.0")] - #[deprecated(since = "1.4.0", note = "use lines() instead now")] + #[deprecated(since = "1.4.0", note = "use lines() instead now", suggestion = "lines")] #[inline] #[allow(deprecated)] pub fn lines_any(&self) -> LinesAny<'_> { diff --git a/library/std/src/os/unix/process.rs b/library/std/src/os/unix/process.rs index 2b40b672d9f0a..a1d2a77b2e7ac 100644 --- a/library/std/src/os/unix/process.rs +++ b/library/std/src/os/unix/process.rs @@ -109,7 +109,11 @@ pub trait CommandExt: Sealed { /// /// [`pre_exec`]: CommandExt::pre_exec #[stable(feature = "process_exec", since = "1.15.0")] - #[deprecated(since = "1.37.0", note = "should be unsafe, use `pre_exec` instead")] + #[deprecated( + since = "1.37.0", + note = "should be unsafe, use `pre_exec` instead", + suggestion = "pre_exec" + )] fn before_exec(&mut self, f: F) -> &mut process::Command where F: FnMut() -> io::Result<()> + Send + Sync + 'static, diff --git a/library/std/src/sync/condvar.rs b/library/std/src/sync/condvar.rs index 76a1b4a2a86cd..8b5195e94fc40 100644 --- a/library/std/src/sync/condvar.rs +++ b/library/std/src/sync/condvar.rs @@ -305,7 +305,11 @@ impl Condvar { /// } /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[deprecated(since = "1.6.0", note = "replaced by `std::sync::Condvar::wait_timeout`")] + #[deprecated( + since = "1.6.0", + note = "replaced by `std::sync::Condvar::wait_timeout`", + suggestion = "wait_timeout" + )] pub fn wait_timeout_ms<'a, T>( &self, guard: MutexGuard<'a, T>, diff --git a/library/std/src/thread/mod.rs b/library/std/src/thread/mod.rs index e4581c2de7825..762e2f25c122e 100644 --- a/library/std/src/thread/mod.rs +++ b/library/std/src/thread/mod.rs @@ -825,7 +825,7 @@ pub fn panicking() -> bool { /// thread::sleep_ms(2000); /// ``` #[stable(feature = "rust1", since = "1.0.0")] -#[deprecated(since = "1.6.0", note = "replaced by `std::thread::sleep`")] +#[deprecated(since = "1.6.0", note = "replaced by `std::thread::sleep`", suggestion = "sleep")] pub fn sleep_ms(ms: u32) { sleep(Duration::from_millis(ms as u64)) } @@ -1004,7 +1004,11 @@ pub fn park() { /// /// See the [park documentation][`park`] for more detail. #[stable(feature = "rust1", since = "1.0.0")] -#[deprecated(since = "1.6.0", note = "replaced by `std::thread::park_timeout`")] +#[deprecated( + since = "1.6.0", + note = "replaced by `std::thread::park_timeout`", + suggestion = "park_timeout" +)] pub fn park_timeout_ms(ms: u32) { park_timeout(Duration::from_millis(ms as u64)) } diff --git a/tests/ui/deprecation/issue-84637-deprecated-associated-function.fixed b/tests/ui/deprecation/issue-84637-deprecated-associated-function.fixed index 85e882870946b..659b546552229 100644 --- a/tests/ui/deprecation/issue-84637-deprecated-associated-function.fixed +++ b/tests/ui/deprecation/issue-84637-deprecated-associated-function.fixed @@ -6,4 +6,6 @@ fn main() { let _foo = str::trim_start(" aoeu"); //~ ERROR use of deprecated method `core::str::::trim_left`: superseded by `trim_start` [deprecated] let _bar = " aoeu".trim_start(); //~ ERROR use of deprecated method `core::str::::trim_left`: superseded by `trim_start` [deprecated] + + let _baz = ["a", "b"].join(" "); //~ ERROR use of deprecated method `std::slice::::connect`: renamed to join [deprecated] } diff --git a/tests/ui/deprecation/issue-84637-deprecated-associated-function.rs b/tests/ui/deprecation/issue-84637-deprecated-associated-function.rs index 246de2f5e4bfe..cfc6c4450b4ab 100644 --- a/tests/ui/deprecation/issue-84637-deprecated-associated-function.rs +++ b/tests/ui/deprecation/issue-84637-deprecated-associated-function.rs @@ -6,4 +6,6 @@ fn main() { let _foo = str::trim_left(" aoeu"); //~ ERROR use of deprecated method `core::str::::trim_left`: superseded by `trim_start` [deprecated] let _bar = " aoeu".trim_left(); //~ ERROR use of deprecated method `core::str::::trim_left`: superseded by `trim_start` [deprecated] + + let _baz = ["a", "b"].connect(" "); //~ ERROR use of deprecated method `std::slice::::connect`: renamed to join [deprecated] } diff --git a/tests/ui/deprecation/issue-84637-deprecated-associated-function.stderr b/tests/ui/deprecation/issue-84637-deprecated-associated-function.stderr index 3b518d1802bc8..d1f5ea3602a8f 100644 --- a/tests/ui/deprecation/issue-84637-deprecated-associated-function.stderr +++ b/tests/ui/deprecation/issue-84637-deprecated-associated-function.stderr @@ -25,5 +25,16 @@ help: replace the use of the deprecated method LL | let _bar = " aoeu".trim_start(); | ~~~~~~~~~~ -error: aborting due to 2 previous errors +error: use of deprecated method `std::slice::::connect`: renamed to join + --> $DIR/issue-84637-deprecated-associated-function.rs:10:27 + | +LL | let _baz = ["a", "b"].connect(" "); + | ^^^^^^^ + | +help: replace the use of the deprecated method + | +LL | let _baz = ["a", "b"].join(" "); + | ~~~~ + +error: aborting due to 3 previous errors From 98e434a01eafce54fc862fa36f44e0392a6fb9f7 Mon Sep 17 00:00:00 2001 From: Easyoakland <97992568+Easyoakland@users.noreply.github.com> Date: Mon, 7 Aug 2023 20:29:50 -0600 Subject: [PATCH 2/6] Increase clarity about Hash - Eq consistency in HashMap and HashSet docs --- library/std/src/collections/hash/map.rs | 6 ++++-- library/std/src/collections/hash/set.rs | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/library/std/src/collections/hash/map.rs b/library/std/src/collections/hash/map.rs index a083b65604d4e..be173a7ace6d8 100644 --- a/library/std/src/collections/hash/map.rs +++ b/library/std/src/collections/hash/map.rs @@ -49,12 +49,14 @@ use crate::sys; /// ``` /// /// In other words, if two keys are equal, their hashes must be equal. +/// Violating this property is a logic error. /// -/// It is a logic error for a key to be modified in such a way that the key's +/// It is also a logic error for a key to be modified in such a way that the key's /// hash, as determined by the [`Hash`] trait, or its equality, as determined by /// the [`Eq`] trait, changes while it is in the map. This is normally only /// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified, but will +/// +/// The behavior resulting from either logic error is not specified, but will /// be encapsulated to the `HashMap` that observed the logic error and not /// result in undefined behavior. This could include panics, incorrect results, /// aborts, memory leaks, and non-termination. diff --git a/library/std/src/collections/hash/set.rs b/library/std/src/collections/hash/set.rs index 959403e164476..6d85b26af5fa2 100644 --- a/library/std/src/collections/hash/set.rs +++ b/library/std/src/collections/hash/set.rs @@ -24,13 +24,14 @@ use super::map::{map_try_reserve_error, RandomState}; /// ``` /// /// In other words, if two keys are equal, their hashes must be equal. +/// Violating this property is a logic error. /// -/// -/// It is a logic error for a key to be modified in such a way that the key's +/// It is also a logic error for a key to be modified in such a way that the key's /// hash, as determined by the [`Hash`] trait, or its equality, as determined by /// the [`Eq`] trait, changes while it is in the map. This is normally only /// possible through [`Cell`], [`RefCell`], global state, I/O, or unsafe code. -/// The behavior resulting from such a logic error is not specified, but will +/// +/// The behavior resulting from either logic error is not specified, but will /// be encapsulated to the `HashSet` that observed the logic error and not /// result in undefined behavior. This could include panics, incorrect results, /// aborts, memory leaks, and non-termination. From 54bd826d567d588b6ac4ff2bff1f7fbba7229463 Mon Sep 17 00:00:00 2001 From: Waffle Maybe Date: Fri, 18 Aug 2023 04:00:43 +0400 Subject: [PATCH 3/6] Add waffle back to review rotation --- triagebot.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index 2c71b650f68cb..a06195cc33402 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -489,7 +489,7 @@ cc = ["@nnethercote"] [assign] warn_non_default_branch = true contributing_url = "https://rustc-dev-guide.rust-lang.org/getting-started.html" -users_on_vacation = ["jyn514", "WaffleLapkin", "clubby789", "oli-obk"] +users_on_vacation = ["jyn514", "clubby789", "oli-obk"] [assign.adhoc_groups] compiler-team = [ From e94ba4ae78bbca55b14967c05639a7bdf18bab26 Mon Sep 17 00:00:00 2001 From: Konrad Borowski Date: Fri, 18 Aug 2023 00:09:03 +0200 Subject: [PATCH 4/6] Inline strlen_rt in CStr::from_ptr This enables LLVM to optimize this function as if it was strlen without having to enable std-aware LTO. --- library/core/src/ffi/c_str.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index 92e38df404980..163a65c909e45 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -253,7 +253,7 @@ impl CStr { /// ``` /// /// [valid]: core::ptr#safety - #[inline] + #[inline] // inline is necessary for codegen to see strlen. #[must_use] #[stable(feature = "rust1", since = "1.0.0")] #[rustc_const_unstable(feature = "const_cstr_from_ptr", issue = "113219")] @@ -280,6 +280,8 @@ impl CStr { len } + // `inline` is necessary for codegen to see strlen. + #[inline] fn strlen_rt(s: *const c_char) -> usize { extern "C" { /// Provided by libc or compiler_builtins. From fb148f682eb2ebeb2fd332ea43c57c6a5dd14130 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Fri, 18 Aug 2023 09:39:30 +0200 Subject: [PATCH 5/6] `ignore-cross-compile` on `optimization-remarks-dir-pgo` test --- tests/run-make/optimization-remarks-dir-pgo/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/run-make/optimization-remarks-dir-pgo/Makefile b/tests/run-make/optimization-remarks-dir-pgo/Makefile index c88ec1e6cb30c..3bc3d7d142887 100644 --- a/tests/run-make/optimization-remarks-dir-pgo/Makefile +++ b/tests/run-make/optimization-remarks-dir-pgo/Makefile @@ -1,5 +1,6 @@ # needs-profiler-support # ignore-windows-gnu +# ignore-cross-compile # FIXME(mati865): MinGW GCC miscompiles compiler-rt profiling library but with Clang it works # properly. Since we only have GCC on the CI ignore the test for now. From 26fe88fedb19a4118d58a6e439709759f65c63c9 Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Tue, 15 Nov 2022 23:06:53 +0000 Subject: [PATCH 6/6] Add a test to check that inline const is in required_consts Suggested in https://github.com/rust-lang/rust/issues/76001#issuecomment-1315975027 --- tests/ui/inline-const/required-const.rs | 13 +++++++++++++ tests/ui/inline-const/required-const.stderr | 11 +++++++++++ 2 files changed, 24 insertions(+) create mode 100644 tests/ui/inline-const/required-const.rs create mode 100644 tests/ui/inline-const/required-const.stderr diff --git a/tests/ui/inline-const/required-const.rs b/tests/ui/inline-const/required-const.rs new file mode 100644 index 0000000000000..0483410662bfd --- /dev/null +++ b/tests/ui/inline-const/required-const.rs @@ -0,0 +1,13 @@ +// build-fail +// compile-flags: -Zmir-opt-level=3 +#![feature(inline_const)] + +fn foo() { + if false { + const { panic!() } //~ ERROR E0080 + } +} + +fn main() { + foo::(); +} diff --git a/tests/ui/inline-const/required-const.stderr b/tests/ui/inline-const/required-const.stderr new file mode 100644 index 0000000000000..d6948e7acc03a --- /dev/null +++ b/tests/ui/inline-const/required-const.stderr @@ -0,0 +1,11 @@ +error[E0080]: evaluation of `foo::::{constant#0}` failed + --> $DIR/required-const.rs:7:17 + | +LL | const { panic!() } + | ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/required-const.rs:7:17 + | + = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0080`.