From fca671b7403cd59e5db82c901670713358be04c1 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 26 Mar 2023 16:18:30 +0200 Subject: [PATCH 01/28] Remove useless drop of reference --- compiler/rustc_infer/src/infer/nll_relate/mod.rs | 2 +- compiler/rustc_middle/src/mir/visit.rs | 3 +-- library/std/src/thread/tests.rs | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_infer/src/infer/nll_relate/mod.rs b/compiler/rustc_infer/src/infer/nll_relate/mod.rs index 9f7b26b87f459..43dbca1fe6435 100644 --- a/compiler/rustc_infer/src/infer/nll_relate/mod.rs +++ b/compiler/rustc_infer/src/infer/nll_relate/mod.rs @@ -885,7 +885,7 @@ where } else { match variables.probe(vid) { TypeVariableValue::Known { value: u } => { - drop(variables); + drop(inner); self.relate(u, u) } TypeVariableValue::Unknown { universe: _universe } => { diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 0a9fcd898b93e..9fa501b8287ea 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -871,12 +871,11 @@ macro_rules! make_mir_visitor { ) { let Constant { span, - user_ty, + user_ty: _, // no visit method for this literal, } = constant; self.visit_span($(& $mutability)? *span); - drop(user_ty); // no visit method for this match literal { ConstantKind::Ty(_) => {} ConstantKind::Val(_, ty) => self.visit_ty($(& $mutability)? *ty, TyContext::Location(location)), diff --git a/library/std/src/thread/tests.rs b/library/std/src/thread/tests.rs index 6c9ce6fa0ddbd..b65e2572cc5e4 100644 --- a/library/std/src/thread/tests.rs +++ b/library/std/src/thread/tests.rs @@ -375,7 +375,9 @@ fn test_scoped_threads_nll() { // this is mostly a *compilation test* for this exact function: fn foo(x: &u8) { thread::scope(|s| { - s.spawn(|| drop(x)); + s.spawn(|| match x { + _ => (), + }); }); } // let's also run it for good measure From 2e952a6a1755ac9147908a41ab344da261e667fe Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 27 Mar 2023 19:29:50 +0200 Subject: [PATCH 02/28] Remove useless drop of copy type --- compiler/rustc_builtin_macros/src/format_foreign.rs | 4 +--- library/core/src/task/poll.rs | 2 +- library/core/src/task/ready.rs | 4 ++-- library/std/src/panicking.rs | 2 +- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_builtin_macros/src/format_foreign.rs b/compiler/rustc_builtin_macros/src/format_foreign.rs index bd9e903b6ba29..bd5356575ca87 100644 --- a/compiler/rustc_builtin_macros/src/format_foreign.rs +++ b/compiler/rustc_builtin_macros/src/format_foreign.rs @@ -562,15 +562,13 @@ pub(crate) mod printf { } if let Type = state { - drop(c); type_ = at.slice_between(next).unwrap(); // Don't use `move_to!` here, as we *can* be at the end of the input. at = next; } - drop(c); - drop(next); + let _ = c; // to avoid never used value end = at; let position = InnerSpan::new(start.at, end.at); diff --git a/library/core/src/task/poll.rs b/library/core/src/task/poll.rs index af5bf441bb25f..46a3822f6f17c 100644 --- a/library/core/src/task/poll.rs +++ b/library/core/src/task/poll.rs @@ -116,7 +116,7 @@ impl Poll { /// let fut = Pin::new(&mut fut); /// /// let num = fut.poll(cx).ready()?; - /// # drop(num); + /// # let _ = num; // to silence unused warning /// // ... use num /// /// Poll::Ready(()) diff --git a/library/core/src/task/ready.rs b/library/core/src/task/ready.rs index b1daf545fbe7b..8d12625e88d0c 100644 --- a/library/core/src/task/ready.rs +++ b/library/core/src/task/ready.rs @@ -22,7 +22,7 @@ use core::task::Poll; /// let fut = Pin::new(&mut fut); /// /// let num = ready!(fut.poll(cx)); -/// # drop(num); +/// # let _ = num; /// // ... use num /// /// Poll::Ready(()) @@ -44,7 +44,7 @@ use core::task::Poll; /// Poll::Ready(t) => t, /// Poll::Pending => return Poll::Pending, /// }; -/// # drop(num); +/// # let _ = num; // to silence unused warning /// # // ... use num /// # /// # Poll::Ready(()) diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index a46a29cbad608..6d59266b6f838 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -541,7 +541,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { // Lazily, the first time this gets called, run the actual string formatting. self.string.get_or_insert_with(|| { let mut s = String::new(); - drop(s.write_fmt(*inner)); + let _err = s.write_fmt(*inner); s }) } From 28d27fd1644b75a6bbd3f7ff85169cfd374e8022 Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Wed, 5 Apr 2023 21:37:15 +0200 Subject: [PATCH 03/28] Set git info env variables when building tools This should fix issue #107094. --- src/bootstrap/tool.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bootstrap/tool.rs b/src/bootstrap/tool.rs index d1fd2e8c42cb0..9736256f91122 100644 --- a/src/bootstrap/tool.rs +++ b/src/bootstrap/tool.rs @@ -319,6 +319,12 @@ pub fn prepare_tool_cargo( cargo.env("CFG_VERSION", builder.rust_version()); cargo.env("CFG_RELEASE_NUM", &builder.version); cargo.env("DOC_RUST_LANG_ORG_CHANNEL", builder.doc_rust_lang_org_channel()); + if let Some(ref ver_date) = builder.rust_info().commit_date() { + cargo.env("CFG_VER_DATE", ver_date); + } + if let Some(ref ver_hash) = builder.rust_info().sha() { + cargo.env("CFG_VER_HASH", ver_hash); + } let info = GitInfo::new(builder.config.omit_git_hash, &dir); if let Some(sha) = info.sha() { From d535af36258f81e542d963aac49ed2f9e5323dcd Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Thu, 6 Apr 2023 22:48:52 +0200 Subject: [PATCH 04/28] Add needs-git-hash header to compiletest This header can be used for tests which check the output of `--version --verbose` commands. --- src/bootstrap/test.rs | 4 ++++ src/tools/compiletest/src/common.rs | 3 +++ src/tools/compiletest/src/header/needs.rs | 5 +++++ src/tools/compiletest/src/header/tests.rs | 10 ++++++++++ src/tools/compiletest/src/main.rs | 2 ++ 5 files changed, 24 insertions(+) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index aedf1ecab13c4..cbdacfc5f80be 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1804,6 +1804,10 @@ note: if you're sure you want to do this, please open an issue as to why. In the cmd.arg("--channel").arg(&builder.config.channel); + if !builder.config.ignore_git { + cmd.arg("--git-hash"); + } + if let Some(commit) = builder.config.download_rustc_commit() { cmd.env("FAKE_DOWNLOAD_RUSTC_PREFIX", format!("/rustc/{commit}")); } diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index d2f494942cf9b..3f36cc5bbcc91 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -303,6 +303,9 @@ pub struct Config { /// The current Rust channel pub channel: String, + /// Whether adding git commit information such as the commit hash has been enabled for building + pub git_hash: bool, + /// The default Rust edition pub edition: Option, diff --git a/src/tools/compiletest/src/header/needs.rs b/src/tools/compiletest/src/header/needs.rs index 35d6179abaa6b..81179480ed810 100644 --- a/src/tools/compiletest/src/header/needs.rs +++ b/src/tools/compiletest/src/header/needs.rs @@ -115,6 +115,11 @@ pub(super) fn handle_needs( condition: cache.x86_64_dlltool, ignore_reason: "ignored when dlltool for x86_64 is not present", }, + Need { + name: "needs-git-hash", + condition: config.git_hash, + ignore_reason: "ignored when git hashes have been omitted for building", + }, ]; let (name, comment) = match ln.split_once([':', ' ']) { diff --git a/src/tools/compiletest/src/header/tests.rs b/src/tools/compiletest/src/header/tests.rs index 9af7bd5e20145..362fba11697be 100644 --- a/src/tools/compiletest/src/header/tests.rs +++ b/src/tools/compiletest/src/header/tests.rs @@ -251,6 +251,16 @@ fn debugger() { assert!(check_ignore(&config, "// ignore-lldb")); } +#[test] +fn git_hash() { + let mut config = config(); + config.git_hash = false; + assert!(check_ignore(&config, "// needs-git-hash")); + + config.git_hash = true; + assert!(!check_ignore(&config, "// needs-git-hash")); +} + #[test] fn sanitizers() { let mut config = config(); diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 4a2b9de8aee6b..c4bef998f3171 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -159,6 +159,7 @@ pub fn parse_config(args: Vec) -> Config { .optflag("", "nocapture", "") .optflag("h", "help", "show this message") .reqopt("", "channel", "current Rust channel", "CHANNEL") + .optflag("", "git-hash", "run tests which rely on commit version being compiled into the binaries") .optopt("", "edition", "default Rust edition", "EDITION"); let (argv0, args_) = args.split_first().unwrap(); @@ -302,6 +303,7 @@ pub fn parse_config(args: Vec) -> Config { rustfix_coverage: matches.opt_present("rustfix-coverage"), has_tidy, channel: matches.opt_str("channel").unwrap(), + git_hash: matches.opt_present("git-hash"), edition: matches.opt_str("edition"), cc: matches.opt_str("cc").unwrap(), From 135e6201fc3dc61bcee1d4186f233570edbbbb8c Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Fri, 7 Apr 2023 19:45:37 +0200 Subject: [PATCH 05/28] Add regression test for issue 107094 --- tests/run-make/issue-107094/Makefile | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100755 tests/run-make/issue-107094/Makefile diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile new file mode 100755 index 0000000000000..7bbaf31a7771d --- /dev/null +++ b/tests/run-make/issue-107094/Makefile @@ -0,0 +1,7 @@ +# needs-git-hash + +include ../tools.mk + +all: + $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" + $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" From 550df4d34b4398a232058641980c1a5619fe152e Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Fri, 7 Apr 2023 20:58:07 +0200 Subject: [PATCH 06/28] Change mode of Makefile of test for issue 107094 --- tests/run-make/issue-107094/Makefile | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 tests/run-make/issue-107094/Makefile diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile old mode 100755 new mode 100644 From bfa87984d272f06b5a3af6ed3030dcdaa53d9cab Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Sun, 9 Apr 2023 12:27:41 +0200 Subject: [PATCH 07/28] Fix error due to renaming of ignore_git --- src/bootstrap/test.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index cbdacfc5f80be..3814dc63ed4dc 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -1804,7 +1804,7 @@ note: if you're sure you want to do this, please open an issue as to why. In the cmd.arg("--channel").arg(&builder.config.channel); - if !builder.config.ignore_git { + if !builder.config.omit_git_hash { cmd.arg("--git-hash"); } From 7859a8e9a55725bd19636baa8d2a1a99b76689bf Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 16 Apr 2023 14:58:56 +0200 Subject: [PATCH 08/28] Don't use `serde_json` to serialize a simple JSON object This avoids `rustc_data_structures` depending on `serde_json` which allows it to be compiled much earlier, unlocking most of rustc. --- Cargo.lock | 1 - compiler/rustc_data_structures/Cargo.toml | 1 - .../rustc_data_structures/src/profiling.rs | 41 +++++++++++++++---- .../src/profiling/tests.rs | 19 +++++++++ 4 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 compiler/rustc_data_structures/src/profiling/tests.rs diff --git a/Cargo.lock b/Cargo.lock index 12be36ef86126..df6f04259549f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4587,7 +4587,6 @@ dependencies = [ "rustc_index", "rustc_macros", "rustc_serialize", - "serde_json", "smallvec", "stable_deref_trait", "stacker", diff --git a/compiler/rustc_data_structures/Cargo.toml b/compiler/rustc_data_structures/Cargo.toml index 2102f09c56a03..39f4bc63c88d1 100644 --- a/compiler/rustc_data_structures/Cargo.toml +++ b/compiler/rustc_data_structures/Cargo.toml @@ -21,7 +21,6 @@ rustc-hash = "1.1.0" rustc_index = { path = "../rustc_index", package = "rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } -serde_json = "1.0.59" smallvec = { version = "1.8.1", features = [ "const_generics", "union", diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 1ed584eafad30..8fa1ac70a78c0 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -87,6 +87,7 @@ use crate::fx::FxHashMap; use std::borrow::Borrow; use std::collections::hash_map::Entry; use std::error::Error; +use std::fmt::Display; use std::fs; use std::intrinsics::unlikely; use std::path::Path; @@ -97,7 +98,6 @@ use std::time::{Duration, Instant}; pub use measureme::EventId; use measureme::{EventIdBuilder, Profiler, SerializableString, StringId}; use parking_lot::RwLock; -use serde_json::json; use smallvec::SmallVec; bitflags::bitflags! { @@ -763,6 +763,31 @@ impl Drop for VerboseTimingGuard<'_> { } } +struct JsonTimePassesEntry<'a> { + pass: &'a str, + time: f64, + start_rss: Option, + end_rss: Option, +} + +impl Display for JsonTimePassesEntry<'_> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + let Self { pass: what, time, start_rss, end_rss } = self; + write!(f, r#"{{"pass":"{what}","time":{time},"rss_start":"#).unwrap(); + match start_rss { + Some(rss) => write!(f, "{rss}")?, + None => write!(f, "null")?, + } + write!(f, r#","rss_end":"#)?; + match end_rss { + Some(rss) => write!(f, "{rss}")?, + None => write!(f, "null")?, + } + write!(f, "}}")?; + Ok(()) + } +} + pub fn print_time_passes_entry( what: &str, dur: Duration, @@ -772,13 +797,10 @@ pub fn print_time_passes_entry( ) { match format { TimePassesFormat::Json => { - let json = json!({ - "pass": what, - "time": dur.as_secs_f64(), - "rss_start": start_rss, - "rss_end": end_rss, - }); - eprintln!("time: {json}"); + let entry = + JsonTimePassesEntry { pass: what, time: dur.as_secs_f64(), start_rss, end_rss }; + + eprintln!(r#"time: {entry}"#); return; } TimePassesFormat::Text => (), @@ -894,3 +916,6 @@ cfg_if! { } } } + +#[cfg(test)] +mod tests; diff --git a/compiler/rustc_data_structures/src/profiling/tests.rs b/compiler/rustc_data_structures/src/profiling/tests.rs new file mode 100644 index 0000000000000..2b09de085da06 --- /dev/null +++ b/compiler/rustc_data_structures/src/profiling/tests.rs @@ -0,0 +1,19 @@ +use super::JsonTimePassesEntry; + +#[test] +fn with_rss() { + let entry = + JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: Some(10), end_rss: Some(20) }; + + assert_eq!(entry.to_string(), r#"{"pass":"typeck","time":56.1,"rss_start":10,"rss_end":20}"#) +} + +#[test] +fn no_rss() { + let entry = JsonTimePassesEntry { pass: "typeck", time: 56.1, start_rss: None, end_rss: None }; + + assert_eq!( + entry.to_string(), + r#"{"pass":"typeck","time":56.1,"rss_start":null,"rss_end":null}"# + ) +} From c9a6e41026d7aa27d897fb83e995447719753076 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 22 Mar 2023 21:56:09 +0000 Subject: [PATCH 09/28] Report allocation errors as panics --- library/alloc/Cargo.toml | 3 ++ library/alloc/src/alloc.rs | 84 ++++++++++++++++++++++++++++++++---- library/alloc/src/lib.rs | 1 + library/std/Cargo.toml | 2 +- library/std/src/lib.rs | 1 + library/std/src/panicking.rs | 43 ++++++++++-------- 6 files changed, 107 insertions(+), 27 deletions(-) diff --git a/library/alloc/Cargo.toml b/library/alloc/Cargo.toml index 95c07abf73106..8975ba3f06bbf 100644 --- a/library/alloc/Cargo.toml +++ b/library/alloc/Cargo.toml @@ -35,3 +35,6 @@ compiler-builtins-mem = ['compiler_builtins/mem'] compiler-builtins-c = ["compiler_builtins/c"] compiler-builtins-no-asm = ["compiler_builtins/no-asm"] compiler-builtins-mangled-names = ["compiler_builtins/mangled-names"] + +# Make panics and failed asserts immediately abort without formatting any message +panic_immediate_abort = ["core/panic_immediate_abort"] diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 6f2ba957bcda0..08c65a96bc744 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -14,6 +14,11 @@ use core::ptr::{self, NonNull}; #[doc(inline)] pub use core::alloc::*; +#[cfg(not(no_global_oom_handling))] +use core::any::Any; +#[cfg(not(no_global_oom_handling))] +use core::panic::BoxMeUp; + #[cfg(test)] mod tests; @@ -343,14 +348,77 @@ pub(crate) unsafe fn box_free(ptr: Unique, alloc: A) } } -// # Allocation error handler +/// Payload passed to the panic handler when `handle_alloc_error` is called. +#[unstable(feature = "panic_oom_payload", issue = "none")] +#[derive(Debug)] +pub struct AllocErrorPanicPayload { + layout: Layout, +} + +impl AllocErrorPanicPayload { + /// Internal function for the standard library to clone a payload. + #[unstable(feature = "std_internals", issue = "none")] + #[doc(hidden)] + pub fn internal_clone(&self) -> Self { + AllocErrorPanicPayload { layout: self.layout } + } + /// Returns the [`Layout`] of the allocation attempt that caused the error. + #[unstable(feature = "panic_oom_payload", issue = "none")] + pub fn layout(&self) -> Layout { + self.layout + } +} + +#[unstable(feature = "std_internals", issue = "none")] #[cfg(not(no_global_oom_handling))] -extern "Rust" { - // This is the magic symbol to call the global alloc error handler. rustc generates - // it to call `__rg_oom` if there is a `#[alloc_error_handler]`, or to call the - // default implementations below (`__rdl_oom`) otherwise. - fn __rust_alloc_error_handler(size: usize, align: usize) -> !; +unsafe impl BoxMeUp for AllocErrorPanicPayload { + fn take_box(&mut self) -> *mut (dyn Any + Send) { + use crate::boxed::Box; + Box::into_raw(Box::new(self.internal_clone())) + } + + fn get(&mut self) -> &(dyn Any + Send) { + self + } +} + +// # Allocation error handler + +#[cfg(all(not(no_global_oom_handling), not(test)))] +fn rust_oom(layout: Layout) -> ! { + if cfg!(feature = "panic_immediate_abort") { + core::intrinsics::abort() + } + + extern "Rust" { + // NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call + // that gets resolved to the `#[panic_handler]` function. + #[lang = "panic_impl"] + fn panic_impl(pi: &core::panic::PanicInfo<'_>) -> !; + + // This symbol is emitted by rustc next to __rust_alloc_error_handler. + // Its value depends on the -Zoom={panic,abort} compiler option. + static __rust_alloc_error_handler_should_panic: u8; + } + + // Hack to work around issues with the lifetime of Arguments. + match format_args!("memory allocation of {} bytes failed", layout.size()) { + fmt => { + // Create a PanicInfo with a custom payload for the panic handler. + let can_unwind = unsafe { __rust_alloc_error_handler_should_panic != 0 }; + let mut pi = core::panic::PanicInfo::internal_constructor( + Some(&fmt), + core::panic::Location::caller(), + can_unwind, + ); + let payload = AllocErrorPanicPayload { layout }; + pi.set_payload(&payload); + + // SAFETY: `panic_impl` is defined in safe Rust code and thus is safe to call. + unsafe { panic_impl(&pi) } + } + } } /// Abort on memory allocation error or failure. @@ -375,9 +443,7 @@ pub const fn handle_alloc_error(layout: Layout) -> ! { } fn rt_error(layout: Layout) -> ! { - unsafe { - __rust_alloc_error_handler(layout.size(), layout.align()); - } + rust_oom(layout); } unsafe { core::intrinsics::const_eval_select((layout,), ct_error, rt_error) } diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index aa240c37e8442..146e366013f30 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -136,6 +136,7 @@ #![feature(maybe_uninit_slice)] #![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_uninit_array_transpose)] +#![feature(panic_internals)] #![feature(pattern)] #![feature(pointer_byte_offsets)] #![feature(provide_any)] diff --git a/library/std/Cargo.toml b/library/std/Cargo.toml index 96c75f97f6e2b..cbd259e677309 100644 --- a/library/std/Cargo.toml +++ b/library/std/Cargo.toml @@ -67,7 +67,7 @@ llvm-libunwind = ["unwind/llvm-libunwind"] system-llvm-libunwind = ["unwind/system-llvm-libunwind"] # Make panics and failed asserts immediately abort without formatting any message -panic_immediate_abort = ["core/panic_immediate_abort"] +panic_immediate_abort = ["alloc/panic_immediate_abort"] # Enable std_detect default features for stdarch/crates/std_detect: # https://github.com/rust-lang/stdarch/blob/master/crates/std_detect/Cargo.toml diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 98fcc76aa98f6..109d6331ade93 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -319,6 +319,7 @@ #![feature(get_mut_unchecked)] #![feature(map_try_insert)] #![feature(new_uninit)] +#![feature(panic_oom_payload)] #![feature(slice_concat_trait)] #![feature(thin_box)] #![feature(try_reserve_kind)] diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index a46a29cbad608..ca4cf68ad54e2 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -245,19 +245,24 @@ fn default_hook(info: &PanicInfo<'_>) { // The current implementation always returns `Some`. let location = info.location().unwrap(); - - let msg = match info.payload().downcast_ref::<&'static str>() { - Some(s) => *s, - None => match info.payload().downcast_ref::() { - Some(s) => &s[..], - None => "Box", - }, - }; let thread = thread_info::current_thread(); let name = thread.as_ref().and_then(|t| t.name()).unwrap_or(""); let write = |err: &mut dyn crate::io::Write| { - let _ = writeln!(err, "thread '{name}' panicked at '{msg}', {location}"); + // Use the panic message directly if available, otherwise take it from + // the payload. + if let Some(msg) = info.message() { + let _ = writeln!(err, "thread '{name}' panicked at '{msg}', {location}"); + } else { + let msg = if let Some(s) = info.payload().downcast_ref::<&'static str>() { + *s + } else if let Some(s) = info.payload().downcast_ref::() { + &s[..] + } else { + "Box" + }; + let _ = writeln!(err, "thread '{name}' panicked at '{msg}', {location}"); + } static FIRST_PANIC: AtomicBool = AtomicBool::new(true); @@ -524,6 +529,8 @@ pub fn panicking() -> bool { #[cfg(not(test))] #[panic_handler] pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { + use alloc::alloc::AllocErrorPanicPayload; + struct PanicPayload<'a> { inner: &'a fmt::Arguments<'a>, string: Option, @@ -550,8 +557,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { unsafe impl<'a> BoxMeUp for PanicPayload<'a> { fn take_box(&mut self) -> *mut (dyn Any + Send) { // We do two allocations here, unfortunately. But (a) they're required with the current - // scheme, and (b) we don't handle panic + OOM properly anyway (see comment in - // begin_panic below). + // scheme, and (b) OOM uses its own separate payload type which doesn't allocate. let contents = mem::take(self.fill()); Box::into_raw(Box::new(contents)) } @@ -576,7 +582,14 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! { let loc = info.location().unwrap(); // The current implementation always returns Some let msg = info.message().unwrap(); // The current implementation always returns Some crate::sys_common::backtrace::__rust_end_short_backtrace(move || { - if let Some(msg) = msg.as_str() { + if let Some(payload) = info.payload().downcast_ref::() { + rust_panic_with_hook( + &mut payload.internal_clone(), + info.message(), + loc, + info.can_unwind(), + ); + } else if let Some(msg) = msg.as_str() { rust_panic_with_hook(&mut StrPanicPayload(msg), info.message(), loc, info.can_unwind()); } else { rust_panic_with_hook( @@ -623,11 +636,7 @@ pub const fn begin_panic(msg: M) -> ! { unsafe impl BoxMeUp for PanicPayload { fn take_box(&mut self) -> *mut (dyn Any + Send) { - // Note that this should be the only allocation performed in this code path. Currently - // this means that panic!() on OOM will invoke this code path, but then again we're not - // really ready for panic on OOM anyway. If we do start doing this, then we should - // propagate this allocation to be performed in the parent of this thread instead of the - // thread that's panicking. + // Note that this should be the only allocation performed in this code path. let data = match self.inner.take() { Some(a) => Box::new(a) as Box, None => process::abort(), From abc0660118cc95f47445fd33502a11dd448f5968 Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Wed, 22 Mar 2023 23:43:20 +0000 Subject: [PATCH 10/28] Remove #[alloc_error_handler] from the compiler and library --- compiler/rustc_builtin_macros/messages.ftl | 2 - .../src/alloc_error_handler.rs | 97 ------------------- compiler/rustc_builtin_macros/src/errors.rs | 7 -- compiler/rustc_builtin_macros/src/lib.rs | 2 - .../example/alloc_example.rs | 7 +- .../rustc_codegen_cranelift/src/allocator.rs | 23 +---- .../example/alloc_example.rs | 7 +- compiler/rustc_codegen_gcc/src/allocator.rs | 34 +------ compiler/rustc_codegen_gcc/src/lib.rs | 4 +- compiler/rustc_codegen_llvm/src/allocator.rs | 48 --------- compiler/rustc_codegen_llvm/src/lib.rs | 3 +- .../src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 13 +-- .../rustc_codegen_ssa/src/traits/backend.rs | 1 - compiler/rustc_feature/src/active.rs | 2 - compiler/rustc_feature/src/removed.rs | 2 + compiler/rustc_metadata/messages.ftl | 10 -- compiler/rustc_metadata/src/creader.rs | 68 ------------- compiler/rustc_metadata/src/errors.rs | 17 ---- compiler/rustc_metadata/src/rmeta/decoder.rs | 4 - .../src/rmeta/decoder/cstore_impl.rs | 3 - compiler/rustc_metadata/src/rmeta/encoder.rs | 1 - compiler/rustc_metadata/src/rmeta/mod.rs | 1 - compiler/rustc_middle/src/query/mod.rs | 11 --- library/alloc/src/alloc.rs | 10 +- library/core/src/macros/mod.rs | 10 -- library/core/src/prelude/v1.rs | 4 +- library/std/src/alloc.rs | 73 +------------- library/std/src/lib.rs | 1 - library/std/src/prelude/v1.rs | 4 +- .../crates/hir-def/src/builtin_attr.rs | 4 - tests/run-make/issue-51671/Makefile | 1 - tests/run-make/issue-51671/app.rs | 7 +- tests/run-make/issue-69368/Makefile | 19 ---- tests/run-make/issue-69368/a.rs | 26 ----- tests/run-make/issue-69368/b.rs | 8 -- tests/run-make/issue-69368/c.rs | 34 ------- .../run-make/wasm-symbols-not-exported/bar.rs | 7 +- .../alloc-error-handler-bad-signature-1.rs | 18 ---- ...alloc-error-handler-bad-signature-1.stderr | 44 --------- .../alloc-error-handler-bad-signature-2.rs | 17 ---- ...alloc-error-handler-bad-signature-2.stderr | 50 ---------- .../alloc-error-handler-bad-signature-3.rs | 15 --- ...alloc-error-handler-bad-signature-3.stderr | 21 ---- .../alloc-error/default-alloc-error-hook.rs | 4 +- .../no_std-alloc-error-handler-custom.rs | 84 ---------------- .../feature-gate-alloc-error-handler.rs | 16 --- .../feature-gate-alloc-error-handler.stderr | 12 --- tests/ui/missing/missing-allocator.rs | 6 -- 49 files changed, 22 insertions(+), 842 deletions(-) delete mode 100644 compiler/rustc_builtin_macros/src/alloc_error_handler.rs delete mode 100644 tests/run-make/issue-69368/Makefile delete mode 100644 tests/run-make/issue-69368/a.rs delete mode 100644 tests/run-make/issue-69368/b.rs delete mode 100644 tests/run-make/issue-69368/c.rs delete mode 100644 tests/ui/alloc-error/alloc-error-handler-bad-signature-1.rs delete mode 100644 tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr delete mode 100644 tests/ui/alloc-error/alloc-error-handler-bad-signature-2.rs delete mode 100644 tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr delete mode 100644 tests/ui/alloc-error/alloc-error-handler-bad-signature-3.rs delete mode 100644 tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr delete mode 100644 tests/ui/allocator/no_std-alloc-error-handler-custom.rs delete mode 100644 tests/ui/feature-gates/feature-gate-alloc-error-handler.rs delete mode 100644 tests/ui/feature-gates/feature-gate-alloc-error-handler.stderr diff --git a/compiler/rustc_builtin_macros/messages.ftl b/compiler/rustc_builtin_macros/messages.ftl index 83dc1ac50e55d..43187c327092a 100644 --- a/compiler/rustc_builtin_macros/messages.ftl +++ b/compiler/rustc_builtin_macros/messages.ftl @@ -4,8 +4,6 @@ builtin_macros_requires_cfg_pattern = builtin_macros_expected_one_cfg_pattern = expected 1 cfg-pattern -builtin_macros_alloc_error_must_be_fn = alloc_error_handler must be a function - builtin_macros_assert_requires_boolean = macro requires a boolean expression as an argument .label = boolean expression required diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs deleted file mode 100644 index 82bae9157e79d..0000000000000 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ /dev/null @@ -1,97 +0,0 @@ -use crate::errors; -use crate::util::check_builtin_macro_attribute; - -use rustc_ast::ptr::P; -use rustc_ast::{self as ast, FnHeader, FnSig, Generics, StmtKind}; -use rustc_ast::{Fn, ItemKind, Stmt, TyKind, Unsafe}; -use rustc_expand::base::{Annotatable, ExtCtxt}; -use rustc_span::symbol::{kw, sym, Ident}; -use rustc_span::Span; -use thin_vec::{thin_vec, ThinVec}; - -pub fn expand( - ecx: &mut ExtCtxt<'_>, - _span: Span, - meta_item: &ast::MetaItem, - item: Annotatable, -) -> Vec { - check_builtin_macro_attribute(ecx, meta_item, sym::alloc_error_handler); - - let orig_item = item.clone(); - - // Allow using `#[alloc_error_handler]` on an item statement - // FIXME - if we get deref patterns, use them to reduce duplication here - let (item, is_stmt, sig_span) = - if let Annotatable::Item(item) = &item - && let ItemKind::Fn(fn_kind) = &item.kind - { - (item, false, ecx.with_def_site_ctxt(fn_kind.sig.span)) - } else if let Annotatable::Stmt(stmt) = &item - && let StmtKind::Item(item) = &stmt.kind - && let ItemKind::Fn(fn_kind) = &item.kind - { - (item, true, ecx.with_def_site_ctxt(fn_kind.sig.span)) - } else { - ecx.sess.parse_sess.span_diagnostic.emit_err(errors::AllocErrorMustBeFn {span: item.span() }); - return vec![orig_item]; - }; - - // Generate a bunch of new items using the AllocFnFactory - let span = ecx.with_def_site_ctxt(item.span); - - // Generate item statements for the allocator methods. - let stmts = thin_vec![generate_handler(ecx, item.ident, span, sig_span)]; - - // Generate anonymous constant serving as container for the allocator methods. - let const_ty = ecx.ty(sig_span, TyKind::Tup(ThinVec::new())); - let const_body = ecx.expr_block(ecx.block(span, stmts)); - let const_item = ecx.item_const(span, Ident::new(kw::Underscore, span), const_ty, const_body); - let const_item = if is_stmt { - Annotatable::Stmt(P(ecx.stmt_item(span, const_item))) - } else { - Annotatable::Item(const_item) - }; - - // Return the original item and the new methods. - vec![orig_item, const_item] -} - -// #[rustc_std_internal_symbol] -// unsafe fn __rg_oom(size: usize, align: usize) -> ! { -// handler(core::alloc::Layout::from_size_align_unchecked(size, align)) -// } -fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span) -> Stmt { - let usize = cx.path_ident(span, Ident::new(sym::usize, span)); - let ty_usize = cx.ty_path(usize); - let size = Ident::from_str_and_span("size", span); - let align = Ident::from_str_and_span("align", span); - - let layout_new = cx.std_path(&[sym::alloc, sym::Layout, sym::from_size_align_unchecked]); - let layout_new = cx.expr_path(cx.path(span, layout_new)); - let layout = cx.expr_call( - span, - layout_new, - thin_vec![cx.expr_ident(span, size), cx.expr_ident(span, align)], - ); - - let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]); - - let never = ast::FnRetTy::Ty(cx.ty(span, TyKind::Never)); - let params = thin_vec![cx.param(span, size, ty_usize.clone()), cx.param(span, align, ty_usize)]; - let decl = cx.fn_decl(params, never); - let header = FnHeader { unsafety: Unsafe::Yes(span), ..FnHeader::default() }; - let sig = FnSig { decl, header, span: span }; - - let body = Some(cx.block_expr(call)); - let kind = ItemKind::Fn(Box::new(Fn { - defaultness: ast::Defaultness::Final, - sig, - generics: Generics::default(), - body, - })); - - let attrs = thin_vec![cx.attr_word(sym::rustc_std_internal_symbol, span)]; - - let item = cx.item(span, Ident::from_str_and_span("__rg_oom", span), attrs, kind); - cx.stmt_item(sig_span, item) -} diff --git a/compiler/rustc_builtin_macros/src/errors.rs b/compiler/rustc_builtin_macros/src/errors.rs index 630f9b87bc3ea..bf0ac3f0ee3f7 100644 --- a/compiler/rustc_builtin_macros/src/errors.rs +++ b/compiler/rustc_builtin_macros/src/errors.rs @@ -19,13 +19,6 @@ pub(crate) struct OneCfgPattern { pub(crate) span: Span, } -#[derive(Diagnostic)] -#[diag(builtin_macros_alloc_error_must_be_fn)] -pub(crate) struct AllocErrorMustBeFn { - #[primary_span] - pub(crate) span: Span, -} - #[derive(Diagnostic)] #[diag(builtin_macros_assert_requires_boolean)] pub(crate) struct AssertRequiresBoolean { diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 37fbd03a6a216..e326c37635a94 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -27,7 +27,6 @@ use rustc_expand::proc_macro::BangProcMacro; use rustc_macros::fluent_messages; use rustc_span::symbol::sym; -mod alloc_error_handler; mod assert; mod cfg; mod cfg_accessible; @@ -102,7 +101,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) { } register_attr! { - alloc_error_handler: alloc_error_handler::expand, bench: test::expand_bench, cfg_accessible: cfg_accessible::Expander, cfg_eval: cfg_eval::expand, diff --git a/compiler/rustc_codegen_cranelift/example/alloc_example.rs b/compiler/rustc_codegen_cranelift/example/alloc_example.rs index 4ede2fe4efe82..e39c3272958be 100644 --- a/compiler/rustc_codegen_cranelift/example/alloc_example.rs +++ b/compiler/rustc_codegen_cranelift/example/alloc_example.rs @@ -1,4 +1,4 @@ -#![feature(start, core_intrinsics, alloc_error_handler)] +#![feature(start, core_intrinsics)] #![no_std] extern crate alloc; @@ -22,11 +22,6 @@ fn panic_handler(_: &core::panic::PanicInfo) -> ! { core::intrinsics::abort(); } -#[alloc_error_handler] -fn alloc_error_handler(_: alloc::alloc::Layout) -> ! { - core::intrinsics::abort(); -} - #[start] fn main(_argc: isize, _argv: *const *const u8) -> isize { let world: Box<&str> = Box::new("Hello World!\0"); diff --git a/compiler/rustc_codegen_cranelift/src/allocator.rs b/compiler/rustc_codegen_cranelift/src/allocator.rs index 2c246ceb37d54..9fb8079a21fc2 100644 --- a/compiler/rustc_codegen_cranelift/src/allocator.rs +++ b/compiler/rustc_codegen_cranelift/src/allocator.rs @@ -6,7 +6,6 @@ use crate::prelude::*; use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS}; use rustc_codegen_ssa::base::allocator_kind_for_codegen; use rustc_session::config::OomStrategy; -use rustc_span::symbol::sym; /// Returns whether an allocator shim was created pub(crate) fn codegen( @@ -15,13 +14,7 @@ pub(crate) fn codegen( unwind_context: &mut UnwindContext, ) -> bool { let Some(kind) = allocator_kind_for_codegen(tcx) else { return false }; - codegen_inner( - module, - unwind_context, - kind, - tcx.alloc_error_handler_kind(()).unwrap(), - tcx.sess.opts.unstable_opts.oom, - ); + codegen_inner(module, unwind_context, kind, tcx.sess.opts.unstable_opts.oom); true } @@ -29,7 +22,6 @@ fn codegen_inner( module: &mut impl Module, unwind_context: &mut UnwindContext, kind: AllocatorKind, - alloc_error_handler_kind: AllocatorKind, oom_strategy: OomStrategy, ) { let usize_ty = module.target_config().pointer_type(); @@ -71,19 +63,6 @@ fn codegen_inner( ); } - let sig = Signature { - call_conv: module.target_config().default_call_conv, - params: vec![AbiParam::new(usize_ty), AbiParam::new(usize_ty)], - returns: vec![], - }; - crate::common::create_wrapper_function( - module, - unwind_context, - sig, - "__rust_alloc_error_handler", - &alloc_error_handler_kind.fn_name(sym::oom), - ); - let data_id = module.declare_data(OomStrategy::SYMBOL, Linkage::Export, false, false).unwrap(); let mut data_ctx = DataContext::new(); data_ctx.set_align(1); diff --git a/compiler/rustc_codegen_gcc/example/alloc_example.rs b/compiler/rustc_codegen_gcc/example/alloc_example.rs index 754e7931412da..faff1dca23f3f 100644 --- a/compiler/rustc_codegen_gcc/example/alloc_example.rs +++ b/compiler/rustc_codegen_gcc/example/alloc_example.rs @@ -1,4 +1,4 @@ -#![feature(start, core_intrinsics, alloc_error_handler, lang_items)] +#![feature(start, core_intrinsics, lang_items)] #![no_std] extern crate alloc; @@ -21,11 +21,6 @@ fn panic_handler(_: &core::panic::PanicInfo) -> ! { core::intrinsics::abort(); } -#[alloc_error_handler] -fn alloc_error_handler(_: alloc::alloc::Layout) -> ! { - core::intrinsics::abort(); -} - #[lang = "eh_personality"] fn eh_personality() -> ! { loop {} diff --git a/compiler/rustc_codegen_gcc/src/allocator.rs b/compiler/rustc_codegen_gcc/src/allocator.rs index 4bad33ee879ee..e90db44ece1fc 100644 --- a/compiler/rustc_codegen_gcc/src/allocator.rs +++ b/compiler/rustc_codegen_gcc/src/allocator.rs @@ -5,11 +5,10 @@ use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS use rustc_middle::bug; use rustc_middle::ty::TyCtxt; use rustc_session::config::OomStrategy; -use rustc_span::symbol::sym; use crate::GccContext; -pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) { +pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_name: &str, kind: AllocatorKind) { let context = &mods.context; let usize = match tcx.sess.target.pointer_width { @@ -87,37 +86,6 @@ pub(crate) unsafe fn codegen(tcx: TyCtxt<'_>, mods: &mut GccContext, _module_nam // as described in https://github.com/rust-lang/rust/commit/77a96ed5646f7c3ee8897693decc4626fe380643 } - let types = [usize, usize]; - let name = "__rust_alloc_error_handler".to_string(); - let args: Vec<_> = types.iter().enumerate() - .map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index))) - .collect(); - let func = context.new_function(None, FunctionType::Exported, void, &args, name, false); - - if tcx.sess.target.default_hidden_visibility { - #[cfg(feature="master")] - func.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden)); - } - - let callee = alloc_error_handler_kind.fn_name(sym::oom); - let args: Vec<_> = types.iter().enumerate() - .map(|(index, typ)| context.new_parameter(None, *typ, &format!("param{}", index))) - .collect(); - let callee = context.new_function(None, FunctionType::Extern, void, &args, callee, false); - #[cfg(feature="master")] - callee.add_attribute(FnAttribute::Visibility(gccjit::Visibility::Hidden)); - - let block = func.new_block("entry"); - - let args = args - .iter() - .enumerate() - .map(|(i, _)| func.get_param(i as i32).to_rvalue()) - .collect::>(); - let _ret = context.new_call(None, callee, &args); - //llvm::LLVMSetTailCall(ret, True); - block.end_with_void_return(None); - let name = OomStrategy::SYMBOL.to_string(); let global = context.new_global(None, GlobalKind::Exported, i8, name); let value = tcx.sess.opts.unstable_opts.oom.should_panic(); diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index 0b661505acc00..be710fefe49cc 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -162,11 +162,11 @@ impl CodegenBackend for GccCodegenBackend { } impl ExtraBackendMethods for GccCodegenBackend { - fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, alloc_error_handler_kind: AllocatorKind) -> Self::Module { + fn codegen_allocator<'tcx>(&self, tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind) -> Self::Module { let mut mods = GccContext { context: Context::default(), }; - unsafe { allocator::codegen(tcx, &mut mods, module_name, kind, alloc_error_handler_kind); } + unsafe { allocator::codegen(tcx, &mut mods, module_name, kind); } mods } diff --git a/compiler/rustc_codegen_llvm/src/allocator.rs b/compiler/rustc_codegen_llvm/src/allocator.rs index 668d929270530..fc9251dda8200 100644 --- a/compiler/rustc_codegen_llvm/src/allocator.rs +++ b/compiler/rustc_codegen_llvm/src/allocator.rs @@ -4,7 +4,6 @@ use rustc_ast::expand::allocator::{AllocatorKind, AllocatorTy, ALLOCATOR_METHODS use rustc_middle::bug; use rustc_middle::ty::TyCtxt; use rustc_session::config::{DebugInfo, OomStrategy}; -use rustc_span::symbol::sym; use crate::debuginfo; use crate::llvm::{self, False, True}; @@ -15,7 +14,6 @@ pub(crate) unsafe fn codegen( module_llvm: &mut ModuleLlvm, module_name: &str, kind: AllocatorKind, - alloc_error_handler_kind: AllocatorKind, ) { let llcx = &*module_llvm.llcx; let llmod = module_llvm.llmod(); @@ -100,52 +98,6 @@ pub(crate) unsafe fn codegen( llvm::LLVMDisposeBuilder(llbuilder); } - // rust alloc error handler - let args = [usize, usize]; // size, align - - let ty = llvm::LLVMFunctionType(void, args.as_ptr(), args.len() as c_uint, False); - let name = "__rust_alloc_error_handler"; - let llfn = llvm::LLVMRustGetOrInsertFunction(llmod, name.as_ptr().cast(), name.len(), ty); - // -> ! DIFlagNoReturn - let no_return = llvm::AttributeKind::NoReturn.create_attr(llcx); - attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[no_return]); - - if tcx.sess.target.default_hidden_visibility { - llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden); - } - if tcx.sess.must_emit_unwind_tables() { - let uwtable = attributes::uwtable_attr(llcx); - attributes::apply_to_llfn(llfn, llvm::AttributePlace::Function, &[uwtable]); - } - - let callee = alloc_error_handler_kind.fn_name(sym::oom); - let callee = llvm::LLVMRustGetOrInsertFunction(llmod, callee.as_ptr().cast(), callee.len(), ty); - // -> ! DIFlagNoReturn - attributes::apply_to_llfn(callee, llvm::AttributePlace::Function, &[no_return]); - llvm::LLVMRustSetVisibility(callee, llvm::Visibility::Hidden); - - let llbb = llvm::LLVMAppendBasicBlockInContext(llcx, llfn, "entry\0".as_ptr().cast()); - - let llbuilder = llvm::LLVMCreateBuilderInContext(llcx); - llvm::LLVMPositionBuilderAtEnd(llbuilder, llbb); - let args = args - .iter() - .enumerate() - .map(|(i, _)| llvm::LLVMGetParam(llfn, i as c_uint)) - .collect::>(); - let ret = llvm::LLVMRustBuildCall( - llbuilder, - ty, - callee, - args.as_ptr(), - args.len() as c_uint, - [].as_ptr(), - 0 as c_uint, - ); - llvm::LLVMSetTailCall(ret, True); - llvm::LLVMBuildRetVoid(llbuilder); - llvm::LLVMDisposeBuilder(llbuilder); - // __rust_alloc_error_handler_should_panic let name = OomStrategy::SYMBOL; let ll_g = llvm::LLVMRustGetOrInsertGlobal(llmod, name.as_ptr().cast(), name.len(), i8); diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 3f77ea77effe3..33d66bcd23784 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -115,11 +115,10 @@ impl ExtraBackendMethods for LlvmCodegenBackend { tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, - alloc_error_handler_kind: AllocatorKind, ) -> ModuleLlvm { let mut module_llvm = ModuleLlvm::new_metadata(tcx, module_name); unsafe { - allocator::codegen(tcx, &mut module_llvm, module_name, kind, alloc_error_handler_kind); + allocator::codegen(tcx, &mut module_llvm, module_name, kind); } module_llvm } diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index d0fd3cd766674..dbf30e42ae44b 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -219,7 +219,7 @@ fn exported_symbols_provider_local( for symbol_name in ALLOCATOR_METHODS .iter() .map(|method| format!("__rust_{}", method.name)) - .chain(["__rust_alloc_error_handler".to_string(), OomStrategy::SYMBOL.to_string()]) + .chain([OomStrategy::SYMBOL.to_string()]) { let exported_symbol = ExportedSymbol::NoDefId(SymbolName::new(tcx, &symbol_name)); diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index c5ca7936a2b45..3e9d29df02cdf 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -635,16 +635,9 @@ pub fn codegen_crate( if let Some(kind) = allocator_kind_for_codegen(tcx) { let llmod_id = cgu_name_builder.build_cgu_name(LOCAL_CRATE, &["crate"], Some("allocator")).to_string(); - let module_llvm = tcx.sess.time("write_allocator_module", || { - backend.codegen_allocator( - tcx, - &llmod_id, - kind, - // If allocator_kind is Some then alloc_error_handler_kind must - // also be Some. - tcx.alloc_error_handler_kind(()).unwrap(), - ) - }); + let module_llvm = tcx + .sess + .time("write_allocator_module", || backend.codegen_allocator(tcx, &llmod_id, kind)); ongoing_codegen.submit_pre_codegened_module_to_llvm( tcx, diff --git a/compiler/rustc_codegen_ssa/src/traits/backend.rs b/compiler/rustc_codegen_ssa/src/traits/backend.rs index 64bebe50ddbf2..2e88b7ce21901 100644 --- a/compiler/rustc_codegen_ssa/src/traits/backend.rs +++ b/compiler/rustc_codegen_ssa/src/traits/backend.rs @@ -123,7 +123,6 @@ pub trait ExtraBackendMethods: CodegenBackend + WriteBackendMethods + Sized + Se tcx: TyCtxt<'tcx>, module_name: &str, kind: AllocatorKind, - alloc_error_handler_kind: AllocatorKind, ) -> Self::Module; /// This generates the codegen unit and returns it along with /// a `u64` giving an estimate of the unit's processing cost. diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs index 48f5bd1cb5048..594e6cca912e7 100644 --- a/compiler/rustc_feature/src/active.rs +++ b/compiler/rustc_feature/src/active.rs @@ -291,8 +291,6 @@ declare_features! ( (active, abi_x86_interrupt, "1.17.0", Some(40180), None), /// Allows additional const parameter types, such as `&'static str` or user defined types (incomplete, adt_const_params, "1.56.0", Some(95174), None), - /// Allows defining an `#[alloc_error_handler]`. - (active, alloc_error_handler, "1.29.0", Some(51540), None), /// Allows trait methods with arbitrary self types. (active, arbitrary_self_types, "1.23.0", Some(44874), None), /// Allows using `const` operands in inline assembly. diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs index 48d9fbfa6d261..568c289e2f714 100644 --- a/compiler/rustc_feature/src/removed.rs +++ b/compiler/rustc_feature/src/removed.rs @@ -47,6 +47,8 @@ declare_features! ( (removed, advanced_slice_patterns, "1.0.0", Some(62254), None, Some("merged into `#![feature(slice_patterns)]`")), + /// Allows defining an `#[alloc_error_handler]`. + (removed, alloc_error_handler, "CURRENT_RUSTC_VERSION", Some(51540), None, Some("now handled by panic handler")), (removed, allocator, "1.0.0", None, None, None), /// Allows a test to fail without failing the whole suite. (removed, allow_fail, "1.19.0", Some(46488), None, Some("removed due to no clear use cases")), diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index 79b8b41725704..f0158aeae851d 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -155,19 +155,9 @@ metadata_no_multiple_global_alloc = metadata_prev_global_alloc = previous global allocator defined here -metadata_no_multiple_alloc_error_handler = - cannot define multiple allocation error handlers - .label = cannot define a new allocation error handler - -metadata_prev_alloc_error_handler = - previous allocation error handler defined here - metadata_conflicting_global_alloc = the `#[global_allocator]` in {$other_crate_name} conflicts with global allocator in: {$crate_name} -metadata_conflicting_alloc_error_handler = - the `#[alloc_error_handler]` in {$other_crate_name} conflicts with allocation error handler in: {$crate_name} - metadata_global_alloc_required = no global memory allocator found but one is required; link to std or add `#[global_allocator]` to a static item that implements the GlobalAlloc trait diff --git a/compiler/rustc_metadata/src/creader.rs b/compiler/rustc_metadata/src/creader.rs index 23aceca06223a..89751b0b72111 100644 --- a/compiler/rustc_metadata/src/creader.rs +++ b/compiler/rustc_metadata/src/creader.rs @@ -38,13 +38,8 @@ pub struct CStore { /// This crate needs an allocator and either provides it itself, or finds it in a dependency. /// If the above is true, then this field denotes the kind of the found allocator. allocator_kind: Option, - /// This crate needs an allocation error handler and either provides it itself, or finds it in a dependency. - /// If the above is true, then this field denotes the kind of the found allocator. - alloc_error_handler_kind: Option, /// This crate has a `#[global_allocator]` item. has_global_allocator: bool, - /// This crate has a `#[alloc_error_handler]` item. - has_alloc_error_handler: bool, /// The interned [StableCrateId]s. pub(crate) stable_crate_ids: StableCrateIdMap, @@ -221,18 +216,10 @@ impl CStore { self.allocator_kind } - pub(crate) fn alloc_error_handler_kind(&self) -> Option { - self.alloc_error_handler_kind - } - pub(crate) fn has_global_allocator(&self) -> bool { self.has_global_allocator } - pub(crate) fn has_alloc_error_handler(&self) -> bool { - self.has_alloc_error_handler - } - pub fn report_unused_deps(&self, tcx: TyCtxt<'_>) { let json_unused_externs = tcx.sess.opts.json_unused_externs; @@ -268,9 +255,7 @@ impl CStore { metas: IndexVec::from_iter(iter::once(None)), injected_panic_runtime: None, allocator_kind: None, - alloc_error_handler_kind: None, has_global_allocator: false, - has_alloc_error_handler: false, stable_crate_ids, unused_externs: Vec::new(), } @@ -776,14 +761,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { } spans => !spans.is_empty(), }; - self.cstore.has_alloc_error_handler = match &*alloc_error_handler_spans(krate) { - [span1, span2, ..] => { - self.sess - .emit_err(errors::NoMultipleAllocErrorHandler { span2: *span2, span1: *span1 }); - true - } - spans => !spans.is_empty(), - }; // Check to see if we actually need an allocator. This desire comes // about through the `#![needs_allocator]` attribute and is typically @@ -824,21 +801,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { } } } - let mut alloc_error_handler = - self.cstore.has_alloc_error_handler.then(|| Symbol::intern("this crate")); - for (_, data) in self.cstore.iter_crate_data() { - if data.has_alloc_error_handler() { - match alloc_error_handler { - Some(other_crate) => { - self.sess.emit_err(errors::ConflictingAllocErrorHandler { - crate_name: data.name(), - other_crate_name: other_crate, - }); - } - None => alloc_error_handler = Some(data.name()), - } - } - } if global_allocator.is_some() { self.cstore.allocator_kind = Some(AllocatorKind::Global); @@ -854,14 +816,6 @@ impl<'a, 'tcx> CrateLoader<'a, 'tcx> { } self.cstore.allocator_kind = Some(AllocatorKind::Default); } - - if alloc_error_handler.is_some() { - self.cstore.alloc_error_handler_kind = Some(AllocatorKind::Global); - } else { - // The alloc crate provides a default allocation error handler if - // one isn't specified. - self.cstore.alloc_error_handler_kind = Some(AllocatorKind::Default); - } } fn inject_dependency_if( @@ -1037,28 +991,6 @@ fn global_allocator_spans(krate: &ast::Crate) -> Vec { f.spans } -fn alloc_error_handler_spans(krate: &ast::Crate) -> Vec { - struct Finder { - name: Symbol, - spans: Vec, - } - impl<'ast> visit::Visitor<'ast> for Finder { - fn visit_item(&mut self, item: &'ast ast::Item) { - if item.ident.name == self.name - && attr::contains_name(&item.attrs, sym::rustc_std_internal_symbol) - { - self.spans.push(item.span); - } - visit::walk_item(self, item) - } - } - - let name = Symbol::intern(&AllocatorKind::Global.fn_name(sym::oom)); - let mut f = Finder { name, spans: Vec::new() }; - visit::walk_crate(&mut f, krate); - f.spans -} - // On Windows the compiler would sometimes intermittently fail to open the // proc-macro DLL with `Error::LoadLibraryExW`. It is suspected that something in the // system still holds a lock on the file, so we retry a few times before calling it diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 51b41b5f6a214..7ecb551a3e596 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -352,16 +352,6 @@ pub struct NoMultipleGlobalAlloc { pub span1: Span, } -#[derive(Diagnostic)] -#[diag(metadata_no_multiple_alloc_error_handler)] -pub struct NoMultipleAllocErrorHandler { - #[primary_span] - #[label] - pub span2: Span, - #[label(metadata_prev_alloc_error_handler)] - pub span1: Span, -} - #[derive(Diagnostic)] #[diag(metadata_conflicting_global_alloc)] pub struct ConflictingGlobalAlloc { @@ -369,13 +359,6 @@ pub struct ConflictingGlobalAlloc { pub other_crate_name: Symbol, } -#[derive(Diagnostic)] -#[diag(metadata_conflicting_alloc_error_handler)] -pub struct ConflictingAllocErrorHandler { - pub crate_name: Symbol, - pub other_crate_name: Symbol, -} - #[derive(Diagnostic)] #[diag(metadata_global_alloc_required)] pub struct GlobalAllocRequired; diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 2930ce75028b7..f7c9379e10989 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -1692,10 +1692,6 @@ impl CrateMetadata { self.root.has_global_allocator } - pub(crate) fn has_alloc_error_handler(&self) -> bool { - self.root.has_alloc_error_handler - } - pub(crate) fn has_default_lib_allocator(&self) -> bool { self.root.has_default_lib_allocator } diff --git a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs index 31798afb852c5..6212597e1ac8d 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs @@ -290,7 +290,6 @@ provide! { tcx, def_id, other, cdata, is_panic_runtime => { cdata.root.panic_runtime } is_compiler_builtins => { cdata.root.compiler_builtins } has_global_allocator => { cdata.root.has_global_allocator } - has_alloc_error_handler => { cdata.root.has_alloc_error_handler } has_panic_handler => { cdata.root.has_panic_handler } is_profiler_runtime => { cdata.root.profiler_runtime } required_panic_strategy => { cdata.root.required_panic_strategy } @@ -379,7 +378,6 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { // resolve! Does this work? Unsure! That's what the issue is about *providers = Providers { allocator_kind: |tcx, ()| CStore::from_tcx(tcx).allocator_kind(), - alloc_error_handler_kind: |tcx, ()| CStore::from_tcx(tcx).alloc_error_handler_kind(), is_private_dep: |_tcx, LocalCrate| false, native_library: |tcx, id| { tcx.native_libraries(id.krate) @@ -496,7 +494,6 @@ pub(in crate::rmeta) fn provide(providers: &mut Providers) { dependency_formats: |tcx, ()| Lrc::new(crate::dependency_format::calculate(tcx)), has_global_allocator: |tcx, LocalCrate| CStore::from_tcx(tcx).has_global_allocator(), - has_alloc_error_handler: |tcx, LocalCrate| CStore::from_tcx(tcx).has_alloc_error_handler(), postorder_cnums: |tcx, ()| { tcx.arena .alloc_slice(&CStore::from_tcx(tcx).crate_dependencies_in_postorder(LOCAL_CRATE)) diff --git a/compiler/rustc_metadata/src/rmeta/encoder.rs b/compiler/rustc_metadata/src/rmeta/encoder.rs index 657b903e0a8af..f9e42fdecdc40 100644 --- a/compiler/rustc_metadata/src/rmeta/encoder.rs +++ b/compiler/rustc_metadata/src/rmeta/encoder.rs @@ -676,7 +676,6 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> { panic_in_drop_strategy: tcx.sess.opts.unstable_opts.panic_in_drop, edition: tcx.sess.edition(), has_global_allocator: tcx.has_global_allocator(LOCAL_CRATE), - has_alloc_error_handler: tcx.has_alloc_error_handler(LOCAL_CRATE), has_panic_handler: tcx.has_panic_handler(LOCAL_CRATE), has_default_lib_allocator: attr::contains_name(&attrs, sym::default_lib_allocator), proc_macro_data, diff --git a/compiler/rustc_metadata/src/rmeta/mod.rs b/compiler/rustc_metadata/src/rmeta/mod.rs index dc77a079b075d..68dc22e31e960 100644 --- a/compiler/rustc_metadata/src/rmeta/mod.rs +++ b/compiler/rustc_metadata/src/rmeta/mod.rs @@ -225,7 +225,6 @@ pub(crate) struct CrateRoot { panic_in_drop_strategy: PanicStrategy, edition: Edition, has_global_allocator: bool, - has_alloc_error_handler: bool, has_panic_handler: bool, has_default_lib_allocator: bool, diff --git a/compiler/rustc_middle/src/query/mod.rs b/compiler/rustc_middle/src/query/mod.rs index 7a5a1603585b1..0cecf8db1af67 100644 --- a/compiler/rustc_middle/src/query/mod.rs +++ b/compiler/rustc_middle/src/query/mod.rs @@ -1460,13 +1460,6 @@ rustc_queries! { desc { "checking if the crate has_global_allocator" } separate_provide_extern } - query has_alloc_error_handler(_: CrateNum) -> bool { - // This query depends on untracked global state in CStore - eval_always - fatal_cycle - desc { "checking if the crate has_alloc_error_handler" } - separate_provide_extern - } query has_panic_handler(_: CrateNum) -> bool { fatal_cycle desc { "checking if the crate has_panic_handler" } @@ -1839,10 +1832,6 @@ rustc_queries! { eval_always desc { "getting the allocator kind for the current crate" } } - query alloc_error_handler_kind(_: ()) -> Option { - eval_always - desc { "alloc error handler kind for the current crate" } - } query upvars_mentioned(def_id: DefId) -> Option<&'tcx FxIndexMap> { desc { |tcx| "collecting upvars mentioned in `{}`", tcx.def_path_str(def_id) } diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 08c65a96bc744..97bedc604da82 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -397,7 +397,7 @@ fn rust_oom(layout: Layout) -> ! { #[lang = "panic_impl"] fn panic_impl(pi: &core::panic::PanicInfo<'_>) -> !; - // This symbol is emitted by rustc next to __rust_alloc_error_handler. + // This symbol is emitted by rustc . // Its value depends on the -Zoom={panic,abort} compiler option. static __rust_alloc_error_handler_should_panic: u8; } @@ -426,13 +426,6 @@ fn rust_oom(layout: Layout) -> ! { /// Callers of memory allocation APIs wishing to abort computation /// in response to an allocation error are encouraged to call this function, /// rather than directly invoking `panic!` or similar. -/// -/// The default behavior of this function is to print a message to standard error -/// and abort the process. -/// It can be replaced with [`set_alloc_error_hook`] and [`take_alloc_error_hook`]. -/// -/// [`set_alloc_error_hook`]: ../../std/alloc/fn.set_alloc_error_hook.html -/// [`take_alloc_error_hook`]: ../../std/alloc/fn.take_alloc_error_hook.html #[stable(feature = "global_alloc", since = "1.28.0")] #[rustc_const_unstable(feature = "const_alloc_error", issue = "92523")] #[cfg(all(not(no_global_oom_handling), not(test)))] @@ -453,6 +446,7 @@ pub const fn handle_alloc_error(layout: Layout) -> ! { #[cfg(all(not(no_global_oom_handling), test))] pub use std::alloc::handle_alloc_error; +#[cfg(bootstrap)] #[cfg(all(not(no_global_oom_handling), not(test)))] #[doc(hidden)] #[allow(unused_attributes)] diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs index 7c93c93b4a019..cc3179ee7801b 100644 --- a/library/core/src/macros/mod.rs +++ b/library/core/src/macros/mod.rs @@ -1531,16 +1531,6 @@ pub(crate) mod builtin { /* compiler built-in */ } - /// Attribute macro applied to a function to register it as a handler for allocation failure. - /// - /// See also [`std::alloc::handle_alloc_error`](../../../std/alloc/fn.handle_alloc_error.html). - #[unstable(feature = "alloc_error_handler", issue = "51540")] - #[allow_internal_unstable(rustc_attrs)] - #[rustc_builtin_macro] - pub macro alloc_error_handler($item:item) { - /* compiler built-in */ - } - /// Keeps the item it's applied to if the passed path is accessible, and removes it otherwise. #[unstable( feature = "cfg_accessible", diff --git a/library/core/src/prelude/v1.rs b/library/core/src/prelude/v1.rs index 10525a16f3a66..9c4c0f6ab7aa5 100644 --- a/library/core/src/prelude/v1.rs +++ b/library/core/src/prelude/v1.rs @@ -76,9 +76,7 @@ pub use crate::macros::builtin::{RustcDecodable, RustcEncodable}; // Do not `doc(no_inline)` so that they become doc items on their own // (no public module for them to be re-exported from). #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] -pub use crate::macros::builtin::{ - alloc_error_handler, bench, derive, global_allocator, test, test_case, -}; +pub use crate::macros::builtin::{bench, derive, global_allocator, test, test_case}; #[unstable(feature = "derive_const", issue = "none")] pub use crate::macros::builtin::derive_const; diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index c5a5991cc81c4..448a8edc29177 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -57,9 +57,8 @@ #![stable(feature = "alloc_module", since = "1.28.0")] use core::intrinsics; +use core::ptr; use core::ptr::NonNull; -use core::sync::atomic::{AtomicPtr, Ordering}; -use core::{mem, ptr}; #[stable(feature = "alloc_module", since = "1.28.0")] #[doc(inline)] @@ -286,76 +285,6 @@ unsafe impl Allocator for System { } } -static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); - -/// Registers a custom allocation error hook, replacing any that was previously registered. -/// -/// The allocation error hook is invoked when an infallible memory allocation fails, before -/// the runtime aborts. The default hook prints a message to standard error, -/// but this behavior can be customized with the [`set_alloc_error_hook`] and -/// [`take_alloc_error_hook`] functions. -/// -/// The hook is provided with a `Layout` struct which contains information -/// about the allocation that failed. -/// -/// The allocation error hook is a global resource. -/// -/// # Examples -/// -/// ``` -/// #![feature(alloc_error_hook)] -/// -/// use std::alloc::{Layout, set_alloc_error_hook}; -/// -/// fn custom_alloc_error_hook(layout: Layout) { -/// panic!("memory allocation of {} bytes failed", layout.size()); -/// } -/// -/// set_alloc_error_hook(custom_alloc_error_hook); -/// ``` -#[unstable(feature = "alloc_error_hook", issue = "51245")] -pub fn set_alloc_error_hook(hook: fn(Layout)) { - HOOK.store(hook as *mut (), Ordering::SeqCst); -} - -/// Unregisters the current allocation error hook, returning it. -/// -/// *See also the function [`set_alloc_error_hook`].* -/// -/// If no custom hook is registered, the default hook will be returned. -#[unstable(feature = "alloc_error_hook", issue = "51245")] -pub fn take_alloc_error_hook() -> fn(Layout) { - let hook = HOOK.swap(ptr::null_mut(), Ordering::SeqCst); - if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } } -} - -fn default_alloc_error_hook(layout: Layout) { - extern "Rust" { - // This symbol is emitted by rustc next to __rust_alloc_error_handler. - // Its value depends on the -Zoom={panic,abort} compiler option. - static __rust_alloc_error_handler_should_panic: u8; - } - - #[allow(unused_unsafe)] - if unsafe { __rust_alloc_error_handler_should_panic != 0 } { - panic!("memory allocation of {} bytes failed", layout.size()); - } else { - rtprintpanic!("memory allocation of {} bytes failed\n", layout.size()); - } -} - -#[cfg(not(test))] -#[doc(hidden)] -#[alloc_error_handler] -#[unstable(feature = "alloc_internals", issue = "none")] -pub fn rust_oom(layout: Layout) -> ! { - let hook = HOOK.load(Ordering::SeqCst); - let hook: fn(Layout) = - if hook.is_null() { default_alloc_error_hook } else { unsafe { mem::transmute(hook) } }; - hook(layout); - crate::process::abort() -} - #[cfg(not(test))] #[doc(hidden)] #[allow(unused_attributes)] diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 109d6331ade93..900df71919b95 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -236,7 +236,6 @@ // // Language features: // tidy-alphabetical-start -#![feature(alloc_error_handler)] #![feature(allocator_internals)] #![feature(allow_internal_unsafe)] #![feature(allow_internal_unstable)] diff --git a/library/std/src/prelude/v1.rs b/library/std/src/prelude/v1.rs index 2aefd7c513dc8..4f325a70b1891 100644 --- a/library/std/src/prelude/v1.rs +++ b/library/std/src/prelude/v1.rs @@ -60,9 +60,7 @@ pub use core::prelude::v1::{RustcDecodable, RustcEncodable}; // Do not `doc(no_inline)` so that they become doc items on their own // (no public module for them to be re-exported from). #[stable(feature = "builtin_macro_prelude", since = "1.38.0")] -pub use core::prelude::v1::{ - alloc_error_handler, bench, derive, global_allocator, test, test_case, -}; +pub use core::prelude::v1::{bench, derive, global_allocator, test, test_case}; #[unstable(feature = "derive_const", issue = "none")] pub use core::prelude::v1::derive_const; diff --git a/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs b/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs index f7c1e683d0d20..e3e5fac98c0e5 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/builtin_attr.rs @@ -381,10 +381,6 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[ rustc_attr!(rustc_allocator, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), rustc_attr!(rustc_nounwind, Normal, template!(Word), WarnFollowing, IMPL_DETAIL), - gated!( - alloc_error_handler, Normal, template!(Word), WarnFollowing, - experimental!(alloc_error_handler) - ), gated!( default_lib_allocator, Normal, template!(Word), WarnFollowing, allocator_internals, experimental!(default_lib_allocator), diff --git a/tests/run-make/issue-51671/Makefile b/tests/run-make/issue-51671/Makefile index c93645369928c..00cf913466238 100644 --- a/tests/run-make/issue-51671/Makefile +++ b/tests/run-make/issue-51671/Makefile @@ -6,4 +6,3 @@ all: $(RUSTC) --emit=obj app.rs nm $(TMPDIR)/app.o | $(CGREP) rust_begin_unwind nm $(TMPDIR)/app.o | $(CGREP) rust_eh_personality - nm $(TMPDIR)/app.o | $(CGREP) __rg_oom diff --git a/tests/run-make/issue-51671/app.rs b/tests/run-make/issue-51671/app.rs index e9dc1e9744fb1..a9d3457bf90e6 100644 --- a/tests/run-make/issue-51671/app.rs +++ b/tests/run-make/issue-51671/app.rs @@ -1,5 +1,5 @@ #![crate_type = "bin"] -#![feature(lang_items, alloc_error_handler)] +#![feature(lang_items)] #![no_main] #![no_std] @@ -13,8 +13,3 @@ fn panic(_: &PanicInfo) -> ! { #[lang = "eh_personality"] fn eh() {} - -#[alloc_error_handler] -fn oom(_: Layout) -> ! { - loop {} -} diff --git a/tests/run-make/issue-69368/Makefile b/tests/run-make/issue-69368/Makefile deleted file mode 100644 index b1229d1b07fc7..0000000000000 --- a/tests/run-make/issue-69368/Makefile +++ /dev/null @@ -1,19 +0,0 @@ -# ignore-cross-compile -include ../tools.mk - -# Test that previously triggered a linker failure with root cause -# similar to one found in the issue #69368. -# -# The crate that provides oom lang item is missing some other lang -# items. Necessary to prevent the use of start-group / end-group. -# -# The weak lang items are defined in a separate compilation units, -# so that linker could omit them if not used. -# -# The crates that need those weak lang items are dependencies of -# crates that provide them. - -all: - $(RUSTC) a.rs - $(RUSTC) b.rs - $(RUSTC) c.rs diff --git a/tests/run-make/issue-69368/a.rs b/tests/run-make/issue-69368/a.rs deleted file mode 100644 index a54f429550e74..0000000000000 --- a/tests/run-make/issue-69368/a.rs +++ /dev/null @@ -1,26 +0,0 @@ -#![crate_type = "rlib"] -#![feature(lang_items)] -#![feature(panic_unwind)] -#![no_std] - -extern crate panic_unwind; - -#[panic_handler] -pub fn panic_handler(_: &core::panic::PanicInfo) -> ! { - loop {} -} - -#[no_mangle] -extern "C" fn __rust_drop_panic() -> ! { - loop {} -} - -#[no_mangle] -extern "C" fn __rust_foreign_exception() -> ! { - loop {} -} - -#[lang = "eh_personality"] -fn eh_personality() { - loop {} -} diff --git a/tests/run-make/issue-69368/b.rs b/tests/run-make/issue-69368/b.rs deleted file mode 100644 index 4d6af0266563b..0000000000000 --- a/tests/run-make/issue-69368/b.rs +++ /dev/null @@ -1,8 +0,0 @@ -#![crate_type = "rlib"] -#![feature(alloc_error_handler)] -#![no_std] - -#[alloc_error_handler] -pub fn error_handler(_: core::alloc::Layout) -> ! { - panic!(); -} diff --git a/tests/run-make/issue-69368/c.rs b/tests/run-make/issue-69368/c.rs deleted file mode 100644 index 729c4249a053a..0000000000000 --- a/tests/run-make/issue-69368/c.rs +++ /dev/null @@ -1,34 +0,0 @@ -#![crate_type = "bin"] -#![feature(start)] -#![no_std] - -extern crate alloc; -extern crate a; -extern crate b; - -use alloc::vec::Vec; -use core::alloc::*; - -struct Allocator; - -unsafe impl GlobalAlloc for Allocator { - unsafe fn alloc(&self, _: Layout) -> *mut u8 { - loop {} - } - - unsafe fn dealloc(&self, _: *mut u8, _: Layout) { - loop {} - } -} - -#[global_allocator] -static ALLOCATOR: Allocator = Allocator; - -#[start] -fn main(argc: isize, _argv: *const *const u8) -> isize { - let mut v = Vec::new(); - for i in 0..argc { - v.push(i); - } - v.iter().sum() -} diff --git a/tests/run-make/wasm-symbols-not-exported/bar.rs b/tests/run-make/wasm-symbols-not-exported/bar.rs index 6ffbd3ec6900d..eb768446b4b92 100644 --- a/tests/run-make/wasm-symbols-not-exported/bar.rs +++ b/tests/run-make/wasm-symbols-not-exported/bar.rs @@ -1,4 +1,4 @@ -#![feature(panic_handler, alloc_error_handler)] +#![feature(panic_handler)] #![crate_type = "cdylib"] #![no_std] @@ -24,11 +24,6 @@ pub extern fn foo(a: u32) -> u32 { a * 2 } -#[alloc_error_handler] -fn a(_: core::alloc::Layout) -> ! { - loop {} -} - #[panic_handler] fn b(_: &core::panic::PanicInfo) -> ! { loop {} diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.rs b/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.rs deleted file mode 100644 index cd06423e3a557..0000000000000 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.rs +++ /dev/null @@ -1,18 +0,0 @@ -// compile-flags:-C panic=abort - -#![feature(alloc_error_handler)] -#![no_std] -#![no_main] - -use core::alloc::Layout; - -#[alloc_error_handler] -fn oom( - info: &Layout, //~^ ERROR mismatched types -) -> () //~^^ ERROR mismatched types -{ - loop {} -} - -#[panic_handler] -fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr b/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr deleted file mode 100644 index de92841d7f18e..0000000000000 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/alloc-error-handler-bad-signature-1.rs:10:1 - | -LL | #[alloc_error_handler] - | ---------------------- in this procedural macro expansion -LL | // fn oom( -LL | || info: &Layout, -LL | || ) -> () - | ||_______- arguments to this function are incorrect -LL | | { -LL | | loop {} -LL | | } - | |__^ expected `&Layout`, found `Layout` - | -note: function defined here - --> $DIR/alloc-error-handler-bad-signature-1.rs:10:4 - | -LL | fn oom( - | ^^^ -LL | info: &Layout, - | ------------- - = note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> $DIR/alloc-error-handler-bad-signature-1.rs:10:1 - | -LL | #[alloc_error_handler] - | ---------------------- in this procedural macro expansion -LL | // fn oom( -LL | || info: &Layout, -LL | || ) -> () - | ||_______^ expected `!`, found `()` -LL | | { -LL | | loop {} -LL | | } - | |__- expected `!` because of return type - | - = note: expected type `!` - found unit type `()` - = note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.rs b/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.rs deleted file mode 100644 index 4f76257fc7267..0000000000000 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.rs +++ /dev/null @@ -1,17 +0,0 @@ -// compile-flags:-C panic=abort - -#![feature(alloc_error_handler)] -#![no_std] -#![no_main] - -struct Layout; - -#[alloc_error_handler] -fn oom( - info: Layout, //~^ ERROR mismatched types -) { //~^^ ERROR mismatched types - loop {} -} - -#[panic_handler] -fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr b/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr deleted file mode 100644 index 7a495380f2ba1..0000000000000 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr +++ /dev/null @@ -1,50 +0,0 @@ -error[E0308]: mismatched types - --> $DIR/alloc-error-handler-bad-signature-2.rs:10:1 - | -LL | #[alloc_error_handler] - | ---------------------- in this procedural macro expansion -LL | // fn oom( -LL | || info: Layout, -LL | || ) { - | ||_- arguments to this function are incorrect -LL | | loop {} -LL | | } - | |__^ expected `Layout`, found `core::alloc::Layout` - | - = note: `core::alloc::Layout` and `Layout` have similar names, but are actually distinct types -note: `core::alloc::Layout` is defined in crate `core` - --> $SRC_DIR/core/src/alloc/layout.rs:LL:COL -note: `Layout` is defined in the current crate - --> $DIR/alloc-error-handler-bad-signature-2.rs:7:1 - | -LL | struct Layout; - | ^^^^^^^^^^^^^ -note: function defined here - --> $DIR/alloc-error-handler-bad-signature-2.rs:10:4 - | -LL | fn oom( - | ^^^ -LL | info: Layout, - | ------------ - = note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info) - -error[E0308]: mismatched types - --> $DIR/alloc-error-handler-bad-signature-2.rs:10:1 - | -LL | #[alloc_error_handler] - | ---------------------- in this procedural macro expansion -LL | // fn oom( -LL | || info: Layout, -LL | || ) { - | ||_^ expected `!`, found `()` -LL | | loop {} -LL | | } - | |__- expected `!` because of return type - | - = note: expected type `!` - found unit type `()` - = note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info) - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0308`. diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.rs b/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.rs deleted file mode 100644 index ea9ad39a70d81..0000000000000 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.rs +++ /dev/null @@ -1,15 +0,0 @@ -// compile-flags:-C panic=abort - -#![feature(alloc_error_handler)] -#![no_std] -#![no_main] - -struct Layout; - -#[alloc_error_handler] -fn oom() -> ! { //~ ERROR function takes 0 arguments but 1 argument was supplied - loop {} -} - -#[panic_handler] -fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } diff --git a/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr b/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr deleted file mode 100644 index eb739b149a103..0000000000000 --- a/tests/ui/alloc-error/alloc-error-handler-bad-signature-3.stderr +++ /dev/null @@ -1,21 +0,0 @@ -error[E0061]: this function takes 0 arguments but 1 argument was supplied - --> $DIR/alloc-error-handler-bad-signature-3.rs:10:1 - | -LL | #[alloc_error_handler] - | ---------------------- in this procedural macro expansion -LL | fn oom() -> ! { - | _-^^^^^^^^^^^^ -LL | | loop {} -LL | | } - | |_- unexpected argument of type `core::alloc::Layout` - | -note: function defined here - --> $DIR/alloc-error-handler-bad-signature-3.rs:10:4 - | -LL | fn oom() -> ! { - | ^^^ - = note: this error originates in the attribute macro `alloc_error_handler` (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 E0061`. diff --git a/tests/ui/alloc-error/default-alloc-error-hook.rs b/tests/ui/alloc-error/default-alloc-error-hook.rs index 8be09500f4e4e..919d4b714a1ae 100644 --- a/tests/ui/alloc-error/default-alloc-error-hook.rs +++ b/tests/ui/alloc-error/default-alloc-error-hook.rs @@ -2,7 +2,7 @@ // ignore-emscripten no processes // ignore-sgx no processes -use std::alloc::{Layout, handle_alloc_error}; +use std::alloc::{handle_alloc_error, Layout}; use std::env; use std::process::Command; use std::str; @@ -24,5 +24,5 @@ fn main() { .strip_suffix("qemu: uncaught target signal 6 (Aborted) - core dumped\n") .unwrap_or(stderr); - assert_eq!(stderr, "memory allocation of 42 bytes failed\n"); + assert!(stderr.contains("memory allocation of 42 bytes failed")); } diff --git a/tests/ui/allocator/no_std-alloc-error-handler-custom.rs b/tests/ui/allocator/no_std-alloc-error-handler-custom.rs deleted file mode 100644 index 2892624339093..0000000000000 --- a/tests/ui/allocator/no_std-alloc-error-handler-custom.rs +++ /dev/null @@ -1,84 +0,0 @@ -// run-pass -// ignore-android no libc -// ignore-emscripten no libc -// ignore-sgx no libc -// ignore-wasm32 no libc -// only-linux -// compile-flags:-C panic=abort -// aux-build:helper.rs - -#![feature(rustc_private, lang_items)] -#![feature(alloc_error_handler)] -#![no_std] -#![no_main] - -extern crate alloc; -extern crate libc; - -// ARM targets need these symbols -#[no_mangle] -pub fn __aeabi_unwind_cpp_pr0() {} - -#[no_mangle] -pub fn __aeabi_unwind_cpp_pr1() {} - -use alloc::boxed::Box; -use alloc::string::ToString; -use core::alloc::{GlobalAlloc, Layout}; -use core::ptr::null_mut; - -extern crate helper; - -struct MyAllocator; - -#[alloc_error_handler] -fn my_oom(layout: Layout) -> ! { - use alloc::fmt::write; - unsafe { - let size = layout.size(); - let mut s = alloc::string::String::new(); - write(&mut s, format_args!("My OOM: failed to allocate {} bytes!\n", size)).unwrap(); - libc::write(libc::STDERR_FILENO, s.as_ptr() as *const _, s.len()); - libc::exit(0) - } -} - -unsafe impl GlobalAlloc for MyAllocator { - unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - if layout.size() < 4096 { libc::malloc(layout.size()) as _ } else { null_mut() } - } - unsafe fn dealloc(&self, _ptr: *mut u8, _layout: Layout) {} -} - -#[global_allocator] -static A: MyAllocator = MyAllocator; - -#[panic_handler] -fn panic(panic_info: &core::panic::PanicInfo) -> ! { - unsafe { - let s = panic_info.to_string(); - const PSTR: &str = "panic occurred: "; - const CR: &str = "\n"; - libc::write(libc::STDERR_FILENO, PSTR.as_ptr() as *const _, PSTR.len()); - libc::write(libc::STDERR_FILENO, s.as_ptr() as *const _, s.len()); - libc::write(libc::STDERR_FILENO, CR.as_ptr() as *const _, CR.len()); - libc::exit(1) - } -} - -// Because we are compiling this code with `-C panic=abort`, this wouldn't normally be needed. -// However, `core` and `alloc` are both compiled with `-C panic=unwind`, which means that functions -// in these libraries will refer to `rust_eh_personality` if LLVM can not *prove* the contents won't -// unwind. So, for this test case we will define the symbol. -#[lang = "eh_personality"] -extern "C" fn rust_eh_personality() {} - -#[derive(Default, Debug)] -struct Page(#[allow(unused_tuple_struct_fields)] [[u64; 32]; 16]); - -#[no_mangle] -fn main(_argc: i32, _argv: *const *const u8) -> isize { - let zero = Box::::new(Default::default()); - helper::work_with(&zero); - 1 -} diff --git a/tests/ui/feature-gates/feature-gate-alloc-error-handler.rs b/tests/ui/feature-gates/feature-gate-alloc-error-handler.rs deleted file mode 100644 index 78d189d20b64d..0000000000000 --- a/tests/ui/feature-gates/feature-gate-alloc-error-handler.rs +++ /dev/null @@ -1,16 +0,0 @@ -// compile-flags:-C panic=abort - -#![no_std] -#![no_main] - -use core::alloc::Layout; - -#[alloc_error_handler] //~ ERROR use of unstable library feature 'alloc_error_handler' -fn oom(info: Layout) -> ! { - loop {} -} - -#[panic_handler] -fn panic(_: &core::panic::PanicInfo) -> ! { - loop {} -} diff --git a/tests/ui/feature-gates/feature-gate-alloc-error-handler.stderr b/tests/ui/feature-gates/feature-gate-alloc-error-handler.stderr deleted file mode 100644 index f414eb463dfbc..0000000000000 --- a/tests/ui/feature-gates/feature-gate-alloc-error-handler.stderr +++ /dev/null @@ -1,12 +0,0 @@ -error[E0658]: use of unstable library feature 'alloc_error_handler' - --> $DIR/feature-gate-alloc-error-handler.rs:8:3 - | -LL | #[alloc_error_handler] - | ^^^^^^^^^^^^^^^^^^^ - | - = note: see issue #51540 for more information - = help: add `#![feature(alloc_error_handler)]` to the crate attributes to enable - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/missing/missing-allocator.rs b/tests/ui/missing/missing-allocator.rs index 2dc509f2c632d..e06e603e3bf94 100644 --- a/tests/ui/missing/missing-allocator.rs +++ b/tests/ui/missing/missing-allocator.rs @@ -3,16 +3,10 @@ #![no_std] #![crate_type = "staticlib"] -#![feature(alloc_error_handler)] #[panic_handler] fn panic(_: &core::panic::PanicInfo) -> ! { loop {} } -#[alloc_error_handler] -fn oom(_: core::alloc::Layout) -> ! { - loop {} -} - extern crate alloc; From ff04b6ab817259b4c9eef8b58da01747d3aad9eb Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 16 Apr 2023 14:33:00 +0200 Subject: [PATCH 11/28] Add `rustc_fluent_macro` to decouple fluent from `rustc_macros` Fluent, with all the icu4x it brings in, takes quite some time to compile. `fluent_messages!` is only needed in further downstream rustc crates, but is blocking more upstream crates like `rustc_index`. By splitting it out, we allow `rustc_macros` to be compiled earlier, which speeds up `x check compiler` by about 5 seconds (and even more after the needless dependency on `serde_json` is removed from `rustc_data_structures`). --- Cargo.lock | 51 ++++- compiler/rustc_ast_lowering/Cargo.toml | 1 + compiler/rustc_ast_lowering/src/lib.rs | 2 +- compiler/rustc_ast_passes/Cargo.toml | 1 + compiler/rustc_ast_passes/src/lib.rs | 2 +- compiler/rustc_attr/Cargo.toml | 1 + compiler/rustc_attr/src/lib.rs | 2 +- compiler/rustc_borrowck/Cargo.toml | 1 + compiler/rustc_borrowck/src/lib.rs | 2 +- compiler/rustc_builtin_macros/Cargo.toml | 1 + compiler/rustc_builtin_macros/src/lib.rs | 2 +- compiler/rustc_codegen_gcc/src/lib.rs | 3 +- compiler/rustc_codegen_llvm/Cargo.toml | 1 + compiler/rustc_codegen_llvm/src/lib.rs | 2 +- compiler/rustc_codegen_ssa/Cargo.toml | 1 + compiler/rustc_codegen_ssa/src/lib.rs | 2 +- compiler/rustc_const_eval/Cargo.toml | 1 + compiler/rustc_const_eval/src/lib.rs | 2 +- compiler/rustc_driver_impl/Cargo.toml | 1 + compiler/rustc_driver_impl/src/lib.rs | 2 +- compiler/rustc_error_messages/Cargo.toml | 1 + compiler/rustc_error_messages/src/lib.rs | 3 +- compiler/rustc_errors/Cargo.toml | 1 + compiler/rustc_errors/src/lib.rs | 2 +- compiler/rustc_expand/Cargo.toml | 1 + compiler/rustc_expand/src/lib.rs | 2 +- compiler/rustc_fluent_macro/Cargo.toml | 17 ++ .../src}/fluent.rs | 2 +- compiler/rustc_fluent_macro/src/lib.rs | 63 ++++++ compiler/rustc_hir_analysis/Cargo.toml | 1 + compiler/rustc_hir_analysis/src/lib.rs | 2 +- compiler/rustc_hir_typeck/Cargo.toml | 1 + compiler/rustc_hir_typeck/src/lib.rs | 2 +- compiler/rustc_incremental/Cargo.toml | 1 + compiler/rustc_incremental/src/lib.rs | 2 +- compiler/rustc_infer/Cargo.toml | 1 + compiler/rustc_infer/src/lib.rs | 2 +- compiler/rustc_interface/Cargo.toml | 1 + compiler/rustc_interface/src/lib.rs | 2 +- compiler/rustc_lint/Cargo.toml | 1 + compiler/rustc_lint/src/lib.rs | 2 +- compiler/rustc_macros/Cargo.toml | 4 - compiler/rustc_macros/src/diagnostics/mod.rs | 2 - compiler/rustc_macros/src/lib.rs | 54 ------ compiler/rustc_metadata/Cargo.toml | 1 + compiler/rustc_metadata/src/lib.rs | 2 +- compiler/rustc_middle/Cargo.toml | 1 + compiler/rustc_middle/src/lib.rs | 2 +- compiler/rustc_mir_build/Cargo.toml | 1 + compiler/rustc_mir_build/src/lib.rs | 2 +- compiler/rustc_mir_dataflow/Cargo.toml | 1 + compiler/rustc_mir_dataflow/src/lib.rs | 2 +- compiler/rustc_monomorphize/Cargo.toml | 1 + compiler/rustc_monomorphize/src/lib.rs | 2 +- compiler/rustc_parse/Cargo.toml | 1 + compiler/rustc_parse/src/lib.rs | 2 +- compiler/rustc_passes/Cargo.toml | 1 + compiler/rustc_passes/src/lib.rs | 2 +- compiler/rustc_plugin_impl/Cargo.toml | 1 + compiler/rustc_plugin_impl/src/lib.rs | 2 +- compiler/rustc_privacy/Cargo.toml | 1 + compiler/rustc_privacy/src/lib.rs | 2 +- compiler/rustc_query_system/Cargo.toml | 1 + compiler/rustc_query_system/src/lib.rs | 2 +- compiler/rustc_resolve/Cargo.toml | 1 + compiler/rustc_resolve/src/lib.rs | 2 +- compiler/rustc_session/Cargo.toml | 1 + compiler/rustc_session/src/lib.rs | 2 +- compiler/rustc_symbol_mangling/Cargo.toml | 1 + compiler/rustc_symbol_mangling/src/lib.rs | 2 +- compiler/rustc_trait_selection/Cargo.toml | 1 + compiler/rustc_trait_selection/src/lib.rs | 2 +- compiler/rustc_ty_utils/Cargo.toml | 1 + compiler/rustc_ty_utils/src/lib.rs | 2 +- tests/ui-fulldeps/fluent-messages/test.rs | 4 +- .../ui-fulldeps/internal-lints/diagnostics.rs | 8 +- .../internal-lints/diagnostics.stderr | 10 +- .../session-diagnostic/diagnostic-derive.rs | 4 +- .../diagnostic-derive.stderr | 182 +++++++++--------- .../subdiagnostic-derive.rs | 4 +- .../subdiagnostic-derive.stderr | 182 +++++++++--------- 81 files changed, 397 insertions(+), 293 deletions(-) create mode 100644 compiler/rustc_fluent_macro/Cargo.toml rename compiler/{rustc_macros/src/diagnostics => rustc_fluent_macro/src}/fluent.rs (99%) create mode 100644 compiler/rustc_fluent_macro/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 12be36ef86126..81e6f944b8100 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4346,6 +4346,7 @@ dependencies = [ "rustc_ast_pretty", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -4369,6 +4370,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_macros", "rustc_parse", "rustc_session", @@ -4396,6 +4398,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_lexer", "rustc_macros", "rustc_serialize", @@ -4424,6 +4427,7 @@ dependencies = [ "rustc_const_eval", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_graphviz", "rustc_hir", "rustc_index", @@ -4453,6 +4457,7 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", + "rustc_fluent_macro", "rustc_lexer", "rustc_lint_defs", "rustc_macros", @@ -4481,6 +4486,7 @@ dependencies = [ "rustc_codegen_ssa", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_fs_util", "rustc_hir", "rustc_index", @@ -4518,6 +4524,7 @@ dependencies = [ "rustc_attr", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_fs_util", "rustc_hir", "rustc_incremental", @@ -4550,6 +4557,7 @@ dependencies = [ "rustc_attr", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", @@ -4624,6 +4632,7 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", + "rustc_fluent_macro", "rustc_hir", "rustc_hir_analysis", "rustc_hir_pretty", @@ -4672,6 +4681,7 @@ dependencies = [ "intl-memoizer", "rustc_baked_icu_data", "rustc_data_structures", + "rustc_fluent_macro", "rustc_macros", "rustc_serialize", "rustc_span", @@ -4688,6 +4698,7 @@ dependencies = [ "rustc_ast_pretty", "rustc_data_structures", "rustc_error_messages", + "rustc_fluent_macro", "rustc_hir", "rustc_lint_defs", "rustc_macros", @@ -4716,6 +4727,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_lexer", "rustc_lint_defs", "rustc_macros", @@ -4736,6 +4748,20 @@ dependencies = [ "rustc_span", ] +[[package]] +name = "rustc_fluent_macro" +version = "0.1.0" +dependencies = [ + "annotate-snippets", + "fluent-bundle", + "fluent-syntax", + "proc-macro2", + "quote", + "syn 2.0.8", + "synstructure 0.13.0", + "unic-langid", +] + [[package]] name = "rustc_fs_util" version = "0.0.0" @@ -4772,6 +4798,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", @@ -4806,6 +4833,7 @@ dependencies = [ "rustc_ast", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_graphviz", "rustc_hir", "rustc_hir_analysis", @@ -4833,6 +4861,7 @@ dependencies = [ "rustc_ast", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_fs_util", "rustc_graphviz", "rustc_hir", @@ -4861,6 +4890,7 @@ version = "0.0.0" dependencies = [ "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -4891,6 +4921,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_expand", + "rustc_fluent_macro", "rustc_fs_util", "rustc_hir", "rustc_hir_analysis", @@ -4940,6 +4971,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", @@ -4993,14 +5025,10 @@ dependencies = [ name = "rustc_macros" version = "0.1.0" dependencies = [ - "annotate-snippets", - "fluent-bundle", - "fluent-syntax", "proc-macro2", "quote", "syn 2.0.8", "synstructure 0.13.0", - "unic-langid", ] [[package]] @@ -5016,6 +5044,7 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", + "rustc_fluent_macro", "rustc_fs_util", "rustc_hir", "rustc_hir_pretty", @@ -5053,6 +5082,7 @@ dependencies = [ "rustc_error_messages", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_graphviz", "rustc_hir", "rustc_index", @@ -5078,6 +5108,7 @@ dependencies = [ "rustc_ast", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", @@ -5101,6 +5132,7 @@ dependencies = [ "rustc_ast", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_graphviz", "rustc_hir", "rustc_index", @@ -5144,6 +5176,7 @@ version = "0.0.0" dependencies = [ "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -5167,6 +5200,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_lexer", "rustc_macros", "rustc_session", @@ -5197,6 +5231,7 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_lexer", @@ -5217,6 +5252,7 @@ dependencies = [ "libloading", "rustc_ast", "rustc_errors", + "rustc_fluent_macro", "rustc_lint", "rustc_macros", "rustc_metadata", @@ -5232,6 +5268,7 @@ dependencies = [ "rustc_attr", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_hir_analysis", "rustc_macros", @@ -5273,6 +5310,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -5300,6 +5338,7 @@ dependencies = [ "rustc_errors", "rustc_expand", "rustc_feature", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_macros", @@ -5333,6 +5372,7 @@ dependencies = [ "rustc_data_structures", "rustc_errors", "rustc_feature", + "rustc_fluent_macro", "rustc_fs_util", "rustc_hir", "rustc_index", @@ -5384,6 +5424,7 @@ dependencies = [ "rustc-demangle", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_macros", "rustc_middle", @@ -5426,6 +5467,7 @@ dependencies = [ "rustc_attr", "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", @@ -5483,6 +5525,7 @@ version = "0.0.0" dependencies = [ "rustc_data_structures", "rustc_errors", + "rustc_fluent_macro", "rustc_hir", "rustc_index", "rustc_infer", diff --git a/compiler/rustc_ast_lowering/Cargo.toml b/compiler/rustc_ast_lowering/Cargo.toml index eb2e82d7988c9..6b0da25650506 100644 --- a/compiler/rustc_ast_lowering/Cargo.toml +++ b/compiler/rustc_ast_lowering/Cargo.toml @@ -12,6 +12,7 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_middle = { path = "../rustc_middle" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index f7ae96b7c4a3d..b7ab2b0aefad6 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -55,13 +55,13 @@ use rustc_data_structures::sync::Lrc; use rustc_errors::{ DiagnosticArgFromDisplay, DiagnosticMessage, Handler, StashKey, SubdiagnosticMessage, }; +use rustc_fluent_macro::fluent_messages; use rustc_hir as hir; use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res}; use rustc_hir::def_id::{LocalDefId, CRATE_DEF_ID}; use rustc_hir::definitions::DefPathData; use rustc_hir::{ConstArg, GenericArg, ItemLocalId, ParamName, TraitCandidate}; use rustc_index::vec::{Idx, IndexSlice, IndexVec}; -use rustc_macros::fluent_messages; use rustc_middle::{ span_bug, ty::{ResolverAstLowering, TyCtxt}, diff --git a/compiler/rustc_ast_passes/Cargo.toml b/compiler/rustc_ast_passes/Cargo.toml index 8bd212073a65a..eb73612352072 100644 --- a/compiler/rustc_ast_passes/Cargo.toml +++ b/compiler/rustc_ast_passes/Cargo.toml @@ -12,6 +12,7 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } rustc_macros = { path = "../rustc_macros" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_parse = { path = "../rustc_parse" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_ast_passes/src/lib.rs b/compiler/rustc_ast_passes/src/lib.rs index e2c666604b3c3..7db413c5bbd42 100644 --- a/compiler/rustc_ast_passes/src/lib.rs +++ b/compiler/rustc_ast_passes/src/lib.rs @@ -13,7 +13,7 @@ #![deny(rustc::diagnostic_outside_of_impl)] use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; pub mod ast_validation; mod errors; diff --git a/compiler/rustc_attr/Cargo.toml b/compiler/rustc_attr/Cargo.toml index 6349ddf31d10b..2c4c3a0c2635b 100644 --- a/compiler/rustc_attr/Cargo.toml +++ b/compiler/rustc_attr/Cargo.toml @@ -9,6 +9,7 @@ edition = "2021" rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_serialize = { path = "../rustc_serialize" } rustc_errors = { path = "../rustc_errors" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_span = { path = "../rustc_span" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_feature = { path = "../rustc_feature" } diff --git a/compiler/rustc_attr/src/lib.rs b/compiler/rustc_attr/src/lib.rs index 49818c14f275b..cfed2acfb3a41 100644 --- a/compiler/rustc_attr/src/lib.rs +++ b/compiler/rustc_attr/src/lib.rs @@ -12,7 +12,7 @@ extern crate rustc_macros; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; mod builtin; mod session_diagnostics; diff --git a/compiler/rustc_borrowck/Cargo.toml b/compiler/rustc_borrowck/Cargo.toml index 87c113f3e30b7..a134cc24d81b5 100644 --- a/compiler/rustc_borrowck/Cargo.toml +++ b/compiler/rustc_borrowck/Cargo.toml @@ -15,6 +15,7 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_lexer = { path = "../rustc_lexer" } diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 70d0a101b4ed9..dcf12beb470a9 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -20,6 +20,7 @@ extern crate tracing; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::graph::dominators::Dominators; use rustc_errors::{Diagnostic, DiagnosticBuilder, DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; use rustc_index::bit_set::ChunkedBitSet; @@ -27,7 +28,6 @@ use rustc_index::vec::{IndexSlice, IndexVec}; use rustc_infer::infer::{ DefiningAnchor, InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin, TyCtxtInferExt, }; -use rustc_macros::fluent_messages; use rustc_middle::mir::{ traversal, Body, ClearCrossCrate, Local, Location, Mutability, NonDivergingIntrinsic, Operand, Place, PlaceElem, PlaceRef, VarDebugInfoContents, diff --git a/compiler/rustc_builtin_macros/Cargo.toml b/compiler/rustc_builtin_macros/Cargo.toml index 336e14ef96630..5f6441660e3bc 100644 --- a/compiler/rustc_builtin_macros/Cargo.toml +++ b/compiler/rustc_builtin_macros/Cargo.toml @@ -17,6 +17,7 @@ rustc_feature = { path = "../rustc_feature" } rustc_lexer = { path = "../rustc_lexer" } rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_macros = { path = "../rustc_macros" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_parse_format = { path = "../rustc_parse_format" } rustc_parse = { path = "../rustc_parse" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_builtin_macros/src/lib.rs b/compiler/rustc_builtin_macros/src/lib.rs index 37fbd03a6a216..134d64ce9cc89 100644 --- a/compiler/rustc_builtin_macros/src/lib.rs +++ b/compiler/rustc_builtin_macros/src/lib.rs @@ -24,7 +24,7 @@ use crate::deriving::*; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; use rustc_expand::base::{MacroExpanderFn, ResolverExpand, SyntaxExtensionKind}; use rustc_expand::proc_macro::BangProcMacro; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_span::symbol::sym; mod alloc_error_handler; diff --git a/compiler/rustc_codegen_gcc/src/lib.rs b/compiler/rustc_codegen_gcc/src/lib.rs index 0b661505acc00..1cabb05de975b 100644 --- a/compiler/rustc_codegen_gcc/src/lib.rs +++ b/compiler/rustc_codegen_gcc/src/lib.rs @@ -27,6 +27,7 @@ extern crate rustc_attr; extern crate rustc_codegen_ssa; extern crate rustc_data_structures; extern crate rustc_errors; +extern crate rustc_fluent_macro; extern crate rustc_hir; extern crate rustc_macros; extern crate rustc_metadata; @@ -76,7 +77,7 @@ use rustc_codegen_ssa::target_features::supported_target_features; use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, Handler, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::ty::TyCtxt; diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index a7ba2f8b69533..bdea565a5a6ad 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -22,6 +22,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_codegen_ssa = { path = "../rustc_codegen_ssa" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_fs_util = { path = "../rustc_fs_util" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_codegen_llvm/src/lib.rs b/compiler/rustc_codegen_llvm/src/lib.rs index 3f77ea77effe3..1f898f7e7bcc1 100644 --- a/compiler/rustc_codegen_llvm/src/lib.rs +++ b/compiler/rustc_codegen_llvm/src/lib.rs @@ -34,7 +34,7 @@ use rustc_codegen_ssa::ModuleCodegen; use rustc_codegen_ssa::{CodegenResults, CompiledModule}; use rustc_data_structures::fx::FxHashMap; use rustc_errors::{DiagnosticMessage, ErrorGuaranteed, FatalError, Handler, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_metadata::EncodedMetadata; use rustc_middle::dep_graph::{WorkProduct, WorkProductId}; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index c55991e00d3ae..272147ae5b009 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -29,6 +29,7 @@ rustc_span = { path = "../rustc_span" } rustc_middle = { path = "../rustc_middle" } rustc_type_ir = { path = "../rustc_type_ir" } rustc_attr = { path = "../rustc_attr" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } diff --git a/compiler/rustc_codegen_ssa/src/lib.rs b/compiler/rustc_codegen_ssa/src/lib.rs index 0ab12314b3c88..26d55618b490a 100644 --- a/compiler/rustc_codegen_ssa/src/lib.rs +++ b/compiler/rustc_codegen_ssa/src/lib.rs @@ -25,8 +25,8 @@ use rustc_ast as ast; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::sync::Lrc; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir::def_id::CrateNum; -use rustc_macros::fluent_messages; use rustc_middle::dep_graph::WorkProduct; use rustc_middle::middle::dependency_format::Dependencies; use rustc_middle::middle::exported_symbols::SymbolExportKind; diff --git a/compiler/rustc_const_eval/Cargo.toml b/compiler/rustc_const_eval/Cargo.toml index 98ac36c1ced73..74030a43c5053 100644 --- a/compiler/rustc_const_eval/Cargo.toml +++ b/compiler/rustc_const_eval/Cargo.toml @@ -14,6 +14,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs index 5ab389d04c7ee..1b66eca97a578 100644 --- a/compiler/rustc_const_eval/src/lib.rs +++ b/compiler/rustc_const_eval/src/lib.rs @@ -34,7 +34,7 @@ pub mod transform; pub mod util; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_middle::ty; use rustc_middle::ty::query::Providers; diff --git a/compiler/rustc_driver_impl/Cargo.toml b/compiler/rustc_driver_impl/Cargo.toml index 73a1f79a020f1..cc4c5a0cacddf 100644 --- a/compiler/rustc_driver_impl/Cargo.toml +++ b/compiler/rustc_driver_impl/Cargo.toml @@ -18,6 +18,7 @@ rustc_const_eval = { path = "../rustc_const_eval" } rustc_error_messages = { path = "../rustc_error_messages" } rustc_expand = { path = "../rustc_expand" } rustc_hir_typeck = { path = "../rustc_hir_typeck" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_incremental = { path = "../rustc_incremental" } rustc_infer = { path = "../rustc_infer" } rustc_mir_build = { path = "../rustc_mir_build" } diff --git a/compiler/rustc_driver_impl/src/lib.rs b/compiler/rustc_driver_impl/src/lib.rs index b9f0e756e65fe..1a80b4fc3140d 100644 --- a/compiler/rustc_driver_impl/src/lib.rs +++ b/compiler/rustc_driver_impl/src/lib.rs @@ -28,10 +28,10 @@ use rustc_errors::{ DiagnosticMessage, ErrorGuaranteed, PResult, SubdiagnosticMessage, TerminalUrl, }; use rustc_feature::find_gated_cfg; +use rustc_fluent_macro::fluent_messages; use rustc_interface::util::{self, collect_crate_types, get_codegen_backend}; use rustc_interface::{interface, Queries}; use rustc_lint::LintStore; -use rustc_macros::fluent_messages; use rustc_metadata::locator; use rustc_session::config::{nightly_options, CG_OPTIONS, Z_OPTIONS}; use rustc_session::config::{ErrorOutputType, Input, OutputType, PrintRequest, TrimmedDefPaths}; diff --git a/compiler/rustc_error_messages/Cargo.toml b/compiler/rustc_error_messages/Cargo.toml index 27783d60be46d..481c94266f271 100644 --- a/compiler/rustc_error_messages/Cargo.toml +++ b/compiler/rustc_error_messages/Cargo.toml @@ -11,6 +11,7 @@ fluent-syntax = "0.11" intl-memoizer = "0.5.1" rustc_baked_icu_data = { path = "../rustc_baked_icu_data" } rustc_data_structures = { path = "../rustc_data_structures" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_error_messages/src/lib.rs b/compiler/rustc_error_messages/src/lib.rs index 6f319b96f2faf..88d94c93bf520 100644 --- a/compiler/rustc_error_messages/src/lib.rs +++ b/compiler/rustc_error_messages/src/lib.rs @@ -12,7 +12,8 @@ use fluent_bundle::FluentResource; use fluent_syntax::parser::ParserError; use icu_provider_adapters::fallback::{LocaleFallbackProvider, LocaleFallbacker}; use rustc_data_structures::sync::Lrc; -use rustc_macros::{fluent_messages, Decodable, Encodable}; +use rustc_fluent_macro::fluent_messages; +use rustc_macros::{Decodable, Encodable}; use rustc_span::Span; use std::borrow::Cow; use std::error::Error; diff --git a/compiler/rustc_errors/Cargo.toml b/compiler/rustc_errors/Cargo.toml index e1ead08ea66bd..46ace8eb2dd8d 100644 --- a/compiler/rustc_errors/Cargo.toml +++ b/compiler/rustc_errors/Cargo.toml @@ -10,6 +10,7 @@ tracing = "0.1" rustc_ast = { path = "../rustc_ast" } rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_error_messages = { path = "../rustc_error_messages" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_serialize = { path = "../rustc_serialize" } rustc_span = { path = "../rustc_span" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_errors/src/lib.rs b/compiler/rustc_errors/src/lib.rs index d20b168904d6f..bdf58241807a0 100644 --- a/compiler/rustc_errors/src/lib.rs +++ b/compiler/rustc_errors/src/lib.rs @@ -38,8 +38,8 @@ pub use rustc_error_messages::{ fallback_fluent_bundle, fluent_bundle, DelayDm, DiagnosticMessage, FluentBundle, LanguageIdentifier, LazyFallbackBundle, MultiSpan, SpanLabel, SubdiagnosticMessage, }; +use rustc_fluent_macro::fluent_messages; pub use rustc_lint_defs::{pluralize, Applicability}; -use rustc_macros::fluent_messages; use rustc_span::source_map::SourceMap; pub use rustc_span::ErrorGuaranteed; use rustc_span::{Loc, Span}; diff --git a/compiler/rustc_expand/Cargo.toml b/compiler/rustc_expand/Cargo.toml index c971714e05bb3..2dae0e3f53c3c 100644 --- a/compiler/rustc_expand/Cargo.toml +++ b/compiler/rustc_expand/Cargo.toml @@ -16,6 +16,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_lexer = { path = "../rustc_lexer" } rustc_lint_defs = { path = "../rustc_lint_defs" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_expand/src/lib.rs b/compiler/rustc_expand/src/lib.rs index ced7531c3fe7e..83a5043b0aa6f 100644 --- a/compiler/rustc_expand/src/lib.rs +++ b/compiler/rustc_expand/src/lib.rs @@ -21,7 +21,7 @@ extern crate tracing; extern crate proc_macro as pm; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; mod placeholders; mod proc_macro_server; diff --git a/compiler/rustc_fluent_macro/Cargo.toml b/compiler/rustc_fluent_macro/Cargo.toml new file mode 100644 index 0000000000000..a45559af71382 --- /dev/null +++ b/compiler/rustc_fluent_macro/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "rustc_fluent_macro" +version = "0.1.0" +edition = "2021" + +[lib] +proc-macro = true + +[dependencies] +annotate-snippets = "0.9" +fluent-bundle = "0.15.2" +fluent-syntax = "0.11" +synstructure = "0.13.0" +syn = { version = "2", features = ["full"] } +proc-macro2 = "1" +quote = "1" +unic-langid = { version = "0.9.0", features = ["macros"] } diff --git a/compiler/rustc_macros/src/diagnostics/fluent.rs b/compiler/rustc_fluent_macro/src/fluent.rs similarity index 99% rename from compiler/rustc_macros/src/diagnostics/fluent.rs rename to compiler/rustc_fluent_macro/src/fluent.rs index 607d51f5608d3..9dffc9a764548 100644 --- a/compiler/rustc_macros/src/diagnostics/fluent.rs +++ b/compiler/rustc_fluent_macro/src/fluent.rs @@ -68,7 +68,7 @@ fn failed(crate_name: &Ident) -> proc_macro::TokenStream { .into() } -/// See [rustc_macros::fluent_messages]. +/// See [rustc_fluent_macro::fluent_messages]. pub(crate) fn fluent_messages(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let crate_name = std::env::var("CARGO_PKG_NAME") // If `CARGO_PKG_NAME` is missing, then we're probably running in a test, so use diff --git a/compiler/rustc_fluent_macro/src/lib.rs b/compiler/rustc_fluent_macro/src/lib.rs new file mode 100644 index 0000000000000..efc4091f30fef --- /dev/null +++ b/compiler/rustc_fluent_macro/src/lib.rs @@ -0,0 +1,63 @@ +#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")] +#![feature(proc_macro_diagnostic)] +#![feature(proc_macro_span)] +#![deny(rustc::untranslatable_diagnostic)] +#![deny(rustc::diagnostic_outside_of_impl)] + +use proc_macro::TokenStream; + +mod fluent; + +/// Implements the `fluent_messages` macro, which performs compile-time validation of the +/// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same +/// messages) and generates constants that make using those messages in diagnostics more ergonomic. +/// +/// For example, given the following invocation of the macro.. +/// +/// ```ignore (rust) +/// fluent_messages! { "./typeck.ftl" } +/// ``` +/// ..where `typeck.ftl` has the following contents.. +/// +/// ```fluent +/// typeck_field_multiply_specified_in_initializer = +/// field `{$ident}` specified more than once +/// .label = used more than once +/// .label_previous_use = first use of `{$ident}` +/// ``` +/// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and +/// will generate the following code: +/// +/// ```ignore (rust) +/// pub static DEFAULT_LOCALE_RESOURCE: &'static [&'static str] = include_str!("./typeck.ftl"); +/// +/// mod fluent_generated { +/// mod typeck { +/// pub const field_multiply_specified_in_initializer: DiagnosticMessage = +/// DiagnosticMessage::fluent("typeck_field_multiply_specified_in_initializer"); +/// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage = +/// DiagnosticMessage::fluent_attr( +/// "typeck_field_multiply_specified_in_initializer", +/// "previous_use_label" +/// ); +/// } +/// } +/// ``` +/// When emitting a diagnostic, the generated constants can be used as follows: +/// +/// ```ignore (rust) +/// let mut err = sess.struct_span_err( +/// span, +/// fluent::typeck::field_multiply_specified_in_initializer +/// ); +/// err.span_default_label(span); +/// err.span_label( +/// previous_use_span, +/// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use +/// ); +/// err.emit(); +/// ``` +#[proc_macro] +pub fn fluent_messages(input: TokenStream) -> TokenStream { + fluent::fluent_messages(input) +} diff --git a/compiler/rustc_hir_analysis/Cargo.toml b/compiler/rustc_hir_analysis/Cargo.toml index fab16b80fb59c..c12e153242886 100644 --- a/compiler/rustc_hir_analysis/Cargo.toml +++ b/compiler/rustc_hir_analysis/Cargo.toml @@ -15,6 +15,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_target = { path = "../rustc_target" } rustc_session = { path = "../rustc_session" } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } diff --git a/compiler/rustc_hir_analysis/src/lib.rs b/compiler/rustc_hir_analysis/src/lib.rs index 27e56180349ef..4c28e28f9646d 100644 --- a/compiler/rustc_hir_analysis/src/lib.rs +++ b/compiler/rustc_hir_analysis/src/lib.rs @@ -99,10 +99,10 @@ mod variance; use rustc_errors::ErrorGuaranteed; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir as hir; use rustc_hir::Node; use rustc_infer::infer::TyCtxtInferExt; -use rustc_macros::fluent_messages; use rustc_middle::middle; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_hir_typeck/Cargo.toml b/compiler/rustc_hir_typeck/Cargo.toml index 093f9bb84486e..13e1ea31c4d54 100644 --- a/compiler/rustc_hir_typeck/Cargo.toml +++ b/compiler/rustc_hir_typeck/Cargo.toml @@ -12,6 +12,7 @@ rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_graphviz = { path = "../rustc_graphviz" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_hir = { path = "../rustc_hir" } diff --git a/compiler/rustc_hir_typeck/src/lib.rs b/compiler/rustc_hir_typeck/src/lib.rs index 45890abad92e3..49da78b18e2a9 100644 --- a/compiler/rustc_hir_typeck/src/lib.rs +++ b/compiler/rustc_hir_typeck/src/lib.rs @@ -59,6 +59,7 @@ use rustc_errors::{ struct_span_err, DiagnosticId, DiagnosticMessage, ErrorGuaranteed, MultiSpan, SubdiagnosticMessage, }; +use rustc_fluent_macro::fluent_messages; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::intravisit::Visitor; @@ -66,7 +67,6 @@ use rustc_hir::{HirIdMap, Node}; use rustc_hir_analysis::astconv::AstConv; use rustc_hir_analysis::check::check_abi; use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; -use rustc_macros::fluent_messages; use rustc_middle::traits; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Ty, TyCtxt}; diff --git a/compiler/rustc_incremental/Cargo.toml b/compiler/rustc_incremental/Cargo.toml index ad89393956e68..59a0623c1e1bf 100644 --- a/compiler/rustc_incremental/Cargo.toml +++ b/compiler/rustc_incremental/Cargo.toml @@ -11,6 +11,7 @@ rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_fs_util = { path = "../rustc_fs_util" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_incremental/src/lib.rs b/compiler/rustc_incremental/src/lib.rs index df958e4a61f4e..11710c368cefe 100644 --- a/compiler/rustc_incremental/src/lib.rs +++ b/compiler/rustc_incremental/src/lib.rs @@ -33,6 +33,6 @@ pub use persist::LoadResult; pub use persist::{build_dep_graph, load_dep_graph, DepGraphFuture}; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_infer/Cargo.toml b/compiler/rustc_infer/Cargo.toml index 02ac83a5e8b25..9dd5868adc71f 100644 --- a/compiler/rustc_infer/Cargo.toml +++ b/compiler/rustc_infer/Cargo.toml @@ -12,6 +12,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_serialize = { path = "../rustc_serialize" } diff --git a/compiler/rustc_infer/src/lib.rs b/compiler/rustc_infer/src/lib.rs index 738a123765152..e92ba05aa6739 100644 --- a/compiler/rustc_infer/src/lib.rs +++ b/compiler/rustc_infer/src/lib.rs @@ -35,7 +35,7 @@ extern crate tracing; extern crate rustc_middle; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; mod errors; pub mod infer; diff --git a/compiler/rustc_interface/Cargo.toml b/compiler/rustc_interface/Cargo.toml index 98d3ab87f9cbd..4569c35e18275 100644 --- a/compiler/rustc_interface/Cargo.toml +++ b/compiler/rustc_interface/Cargo.toml @@ -16,6 +16,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_borrowck = { path = "../rustc_borrowck" } rustc_builtin_macros = { path = "../rustc_builtin_macros" } rustc_expand = { path = "../rustc_expand" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_fs_util = { path = "../rustc_fs_util" } rustc_macros = { path = "../rustc_macros" } rustc_parse = { path = "../rustc_parse" } diff --git a/compiler/rustc_interface/src/lib.rs b/compiler/rustc_interface/src/lib.rs index 9664ba8bd8ac6..51bd8381e93d7 100644 --- a/compiler/rustc_interface/src/lib.rs +++ b/compiler/rustc_interface/src/lib.rs @@ -13,7 +13,7 @@ extern crate tracing; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; mod callbacks; mod errors; diff --git a/compiler/rustc_lint/Cargo.toml b/compiler/rustc_lint/Cargo.toml index abe61406c219c..539eea3d816ae 100644 --- a/compiler/rustc_lint/Cargo.toml +++ b/compiler/rustc_lint/Cargo.toml @@ -11,6 +11,7 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_attr = { path = "../rustc_attr" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_target = { path = "../rustc_target" } rustc_ast = { path = "../rustc_ast" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index b3578540516d0..76f0725790777 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -82,9 +82,9 @@ pub use array_into_iter::ARRAY_INTO_ITER; use rustc_ast as ast; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir as hir; use rustc_hir::def_id::LocalDefId; -use rustc_macros::fluent_messages; use rustc_middle::ty::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::lint::builtin::{ diff --git a/compiler/rustc_macros/Cargo.toml b/compiler/rustc_macros/Cargo.toml index 745983e7e869a..1f1201b0035a9 100644 --- a/compiler/rustc_macros/Cargo.toml +++ b/compiler/rustc_macros/Cargo.toml @@ -7,11 +7,7 @@ edition = "2021" proc-macro = true [dependencies] -annotate-snippets = "0.9" -fluent-bundle = "0.15.2" -fluent-syntax = "0.11" synstructure = "0.13.0" syn = { version = "2", features = ["full"] } proc-macro2 = "1" quote = "1" -unic-langid = { version = "0.9.0", features = ["macros"] } diff --git a/compiler/rustc_macros/src/diagnostics/mod.rs b/compiler/rustc_macros/src/diagnostics/mod.rs index 78df0cd1d341a..bd84681cbb44b 100644 --- a/compiler/rustc_macros/src/diagnostics/mod.rs +++ b/compiler/rustc_macros/src/diagnostics/mod.rs @@ -1,12 +1,10 @@ mod diagnostic; mod diagnostic_builder; mod error; -mod fluent; mod subdiagnostic; mod utils; use diagnostic::{DiagnosticDerive, LintDiagnosticDerive}; -pub(crate) use fluent::fluent_messages; use proc_macro2::TokenStream; use quote::format_ident; use subdiagnostic::SubdiagnosticDeriveBuilder; diff --git a/compiler/rustc_macros/src/lib.rs b/compiler/rustc_macros/src/lib.rs index 737500cc257eb..904f8eb5731ec 100644 --- a/compiler/rustc_macros/src/lib.rs +++ b/compiler/rustc_macros/src/lib.rs @@ -54,60 +54,6 @@ pub fn newtype_index(input: TokenStream) -> TokenStream { newtype::newtype(input) } -/// Implements the `fluent_messages` macro, which performs compile-time validation of the -/// compiler's Fluent resources (i.e. that the resources parse and don't multiply define the same -/// messages) and generates constants that make using those messages in diagnostics more ergonomic. -/// -/// For example, given the following invocation of the macro.. -/// -/// ```ignore (rust) -/// fluent_messages! { "./typeck.ftl" } -/// ``` -/// ..where `typeck.ftl` has the following contents.. -/// -/// ```fluent -/// typeck_field_multiply_specified_in_initializer = -/// field `{$ident}` specified more than once -/// .label = used more than once -/// .label_previous_use = first use of `{$ident}` -/// ``` -/// ...then the macro parse the Fluent resource, emitting a diagnostic if it fails to do so, and -/// will generate the following code: -/// -/// ```ignore (rust) -/// pub static DEFAULT_LOCALE_RESOURCE: &'static [&'static str] = include_str!("./typeck.ftl"); -/// -/// mod fluent_generated { -/// mod typeck { -/// pub const field_multiply_specified_in_initializer: DiagnosticMessage = -/// DiagnosticMessage::fluent("typeck_field_multiply_specified_in_initializer"); -/// pub const field_multiply_specified_in_initializer_label_previous_use: DiagnosticMessage = -/// DiagnosticMessage::fluent_attr( -/// "typeck_field_multiply_specified_in_initializer", -/// "previous_use_label" -/// ); -/// } -/// } -/// ``` -/// When emitting a diagnostic, the generated constants can be used as follows: -/// -/// ```ignore (rust) -/// let mut err = sess.struct_span_err( -/// span, -/// fluent::typeck::field_multiply_specified_in_initializer -/// ); -/// err.span_default_label(span); -/// err.span_label( -/// previous_use_span, -/// fluent::typeck::field_multiply_specified_in_initializer_label_previous_use -/// ); -/// err.emit(); -/// ``` -#[proc_macro] -pub fn fluent_messages(input: TokenStream) -> TokenStream { - diagnostics::fluent_messages(input) -} - decl_derive!([HashStable, attributes(stable_hasher)] => hash_stable::hash_stable_derive); decl_derive!( [HashStable_Generic, attributes(stable_hasher)] => diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index 4d7c133e09bc4..0e54d6aa94618 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -18,6 +18,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_fs_util = { path = "../rustc_fs_util" } rustc_hir = { path = "../rustc_hir" } rustc_hir_pretty = { path = "../rustc_hir_pretty" } diff --git a/compiler/rustc_metadata/src/lib.rs b/compiler/rustc_metadata/src/lib.rs index 81e62eccb8a59..9f664d0f0c8e2 100644 --- a/compiler/rustc_metadata/src/lib.rs +++ b/compiler/rustc_metadata/src/lib.rs @@ -28,7 +28,7 @@ extern crate tracing; pub use rmeta::{provide, provide_extern}; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; mod dependency_format; mod foreign_modules; diff --git a/compiler/rustc_middle/Cargo.toml b/compiler/rustc_middle/Cargo.toml index 5b2ec9029b16e..dfbe8ac0ba3dc 100644 --- a/compiler/rustc_middle/Cargo.toml +++ b/compiler/rustc_middle/Cargo.toml @@ -21,6 +21,7 @@ rustc_errors = { path = "../rustc_errors" } # Used for intra-doc links rustc_error_messages = { path = "../rustc_error_messages" } rustc_feature = { path = "../rustc_feature" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_middle/src/lib.rs b/compiler/rustc_middle/src/lib.rs index b4edb02f6c48d..f389bac3620b3 100644 --- a/compiler/rustc_middle/src/lib.rs +++ b/compiler/rustc_middle/src/lib.rs @@ -74,7 +74,7 @@ extern crate tracing; extern crate smallvec; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; #[cfg(test)] mod tests; diff --git a/compiler/rustc_mir_build/Cargo.toml b/compiler/rustc_mir_build/Cargo.toml index f24b165d7c239..58449ee9eb48d 100644 --- a/compiler/rustc_mir_build/Cargo.toml +++ b/compiler/rustc_mir_build/Cargo.toml @@ -14,6 +14,7 @@ rustc_apfloat = { path = "../rustc_apfloat" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_index = { path = "../rustc_index" } rustc_errors = { path = "../rustc_errors" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_infer = { path = "../rustc_infer" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_mir_build/src/lib.rs b/compiler/rustc_mir_build/src/lib.rs index 3f9236c9dd94c..259f2e433920b 100644 --- a/compiler/rustc_mir_build/src/lib.rs +++ b/compiler/rustc_mir_build/src/lib.rs @@ -25,7 +25,7 @@ pub mod thir; use rustc_middle::ty::query::Providers; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; fluent_messages! { "../messages.ftl" } diff --git a/compiler/rustc_mir_dataflow/Cargo.toml b/compiler/rustc_mir_dataflow/Cargo.toml index 68c61a18d72fc..4a296bb33670f 100644 --- a/compiler/rustc_mir_dataflow/Cargo.toml +++ b/compiler/rustc_mir_dataflow/Cargo.toml @@ -13,6 +13,7 @@ tracing = "0.1" rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_graphviz = { path = "../rustc_graphviz" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index 43caa2ea97392..fc4efb943e6b7 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -16,8 +16,8 @@ extern crate rustc_middle; use rustc_ast::MetaItem; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir::def_id::DefId; -use rustc_macros::fluent_messages; use rustc_middle::ty::{self, TyCtxt}; use rustc_span::symbol::{sym, Symbol}; diff --git a/compiler/rustc_monomorphize/Cargo.toml b/compiler/rustc_monomorphize/Cargo.toml index c8af10576b42f..5ecd68c79bb0f 100644 --- a/compiler/rustc_monomorphize/Cargo.toml +++ b/compiler/rustc_monomorphize/Cargo.toml @@ -13,6 +13,7 @@ tracing = "0.1" rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } diff --git a/compiler/rustc_monomorphize/src/lib.rs b/compiler/rustc_monomorphize/src/lib.rs index 5000fb71937d4..aea9f71902787 100644 --- a/compiler/rustc_monomorphize/src/lib.rs +++ b/compiler/rustc_monomorphize/src/lib.rs @@ -10,8 +10,8 @@ extern crate tracing; extern crate rustc_middle; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir::lang_items::LangItem; -use rustc_macros::fluent_messages; use rustc_middle::traits; use rustc_middle::ty::adjustment::CustomCoerceUnsized; use rustc_middle::ty::query::{Providers, TyCtxtAt}; diff --git a/compiler/rustc_parse/Cargo.toml b/compiler/rustc_parse/Cargo.toml index 3eb158c817cf0..1bd9f66290db1 100644 --- a/compiler/rustc_parse/Cargo.toml +++ b/compiler/rustc_parse/Cargo.toml @@ -12,6 +12,7 @@ rustc_ast_pretty = { path = "../rustc_ast_pretty" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_lexer = { path = "../rustc_lexer" } rustc_macros = { path = "../rustc_macros" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_parse/src/lib.rs b/compiler/rustc_parse/src/lib.rs index 17466cd0e6dce..507f6e4182eec 100644 --- a/compiler/rustc_parse/src/lib.rs +++ b/compiler/rustc_parse/src/lib.rs @@ -20,7 +20,7 @@ use rustc_ast_pretty::pprust; use rustc_data_structures::sync::Lrc; use rustc_errors::{Applicability, Diagnostic, FatalError, Level, PResult}; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_session::parse::ParseSess; use rustc_span::{FileName, SourceFile, Span}; diff --git a/compiler/rustc_passes/Cargo.toml b/compiler/rustc_passes/Cargo.toml index 44f991f8c15b5..0413b5b4fb92d 100644 --- a/compiler/rustc_passes/Cargo.toml +++ b/compiler/rustc_passes/Cargo.toml @@ -12,6 +12,7 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_expand = { path = "../rustc_expand" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_session = { path = "../rustc_session" } rustc_target = { path = "../rustc_target" } diff --git a/compiler/rustc_passes/src/lib.rs b/compiler/rustc_passes/src/lib.rs index b7e07aff42bf2..eca3bae9a1cfd 100644 --- a/compiler/rustc_passes/src/lib.rs +++ b/compiler/rustc_passes/src/lib.rs @@ -19,7 +19,7 @@ extern crate rustc_middle; extern crate tracing; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_middle::ty::query::Providers; mod check_attr; diff --git a/compiler/rustc_plugin_impl/Cargo.toml b/compiler/rustc_plugin_impl/Cargo.toml index fa27bfc61d141..c930b3365fdda 100644 --- a/compiler/rustc_plugin_impl/Cargo.toml +++ b/compiler/rustc_plugin_impl/Cargo.toml @@ -12,6 +12,7 @@ rustc_errors = { path = "../rustc_errors" } rustc_lint = { path = "../rustc_lint" } rustc_macros = { path = "../rustc_macros" } rustc_metadata = { path = "../rustc_metadata" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_ast = { path = "../rustc_ast" } rustc_session = { path = "../rustc_session" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_plugin_impl/src/lib.rs b/compiler/rustc_plugin_impl/src/lib.rs index 672189e22cfc6..faa7495ef9fd1 100644 --- a/compiler/rustc_plugin_impl/src/lib.rs +++ b/compiler/rustc_plugin_impl/src/lib.rs @@ -12,8 +12,8 @@ #![deny(rustc::diagnostic_outside_of_impl)] use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_lint::LintStore; -use rustc_macros::fluent_messages; mod errors; pub mod load; diff --git a/compiler/rustc_privacy/Cargo.toml b/compiler/rustc_privacy/Cargo.toml index 744cb77dd00cd..08c4067705cbc 100644 --- a/compiler/rustc_privacy/Cargo.toml +++ b/compiler/rustc_privacy/Cargo.toml @@ -9,6 +9,7 @@ rustc_attr = { path = "../rustc_attr" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_macros = { path = "../rustc_macros" } rustc_middle = { path = "../rustc_middle" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index dcebfca08facf..9567329192d52 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -17,12 +17,12 @@ use rustc_attr as attr; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::intern::Interned; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir as hir; use rustc_hir::def::{DefKind, Res}; use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID}; use rustc_hir::intravisit::{self, Visitor}; use rustc_hir::{AssocItemKind, HirIdSet, ItemId, Node, PatKind}; -use rustc_macros::fluent_messages; use rustc_middle::bug; use rustc_middle::hir::nested_filter; use rustc_middle::middle::privacy::{EffectiveVisibilities, Level}; diff --git a/compiler/rustc_query_system/Cargo.toml b/compiler/rustc_query_system/Cargo.toml index 12b4a1143136b..34e576379762b 100644 --- a/compiler/rustc_query_system/Cargo.toml +++ b/compiler/rustc_query_system/Cargo.toml @@ -12,6 +12,7 @@ rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_query_system/src/lib.rs b/compiler/rustc_query_system/src/lib.rs index bb812b006e974..8c9e9cfad6024 100644 --- a/compiler/rustc_query_system/src/lib.rs +++ b/compiler/rustc_query_system/src/lib.rs @@ -16,7 +16,7 @@ extern crate rustc_data_structures; extern crate rustc_macros; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; pub mod cache; pub mod dep_graph; diff --git a/compiler/rustc_resolve/Cargo.toml b/compiler/rustc_resolve/Cargo.toml index 5c4ec44d2b874..1c16d85f1b9c2 100644 --- a/compiler/rustc_resolve/Cargo.toml +++ b/compiler/rustc_resolve/Cargo.toml @@ -16,6 +16,7 @@ rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_expand = { path = "../rustc_expand" } rustc_feature = { path = "../rustc_feature" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_hir = { path = "../rustc_hir" } rustc_index = { path = "../rustc_index" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs index b820d56b8afb1..282f12bd3c0d9 100644 --- a/compiler/rustc_resolve/src/lib.rs +++ b/compiler/rustc_resolve/src/lib.rs @@ -33,6 +33,7 @@ use rustc_errors::{ Applicability, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, SubdiagnosticMessage, }; use rustc_expand::base::{DeriveResolutions, SyntaxExtension, SyntaxExtensionKind}; +use rustc_fluent_macro::fluent_messages; use rustc_hir::def::Namespace::{self, *}; use rustc_hir::def::{self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, PartialRes, PerNS}; use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LocalDefIdMap, LocalDefIdSet}; @@ -40,7 +41,6 @@ use rustc_hir::def_id::{CRATE_DEF_ID, LOCAL_CRATE}; use rustc_hir::definitions::DefPathData; use rustc_hir::TraitCandidate; use rustc_index::vec::IndexVec; -use rustc_macros::fluent_messages; use rustc_metadata::creader::{CStore, CrateLoader}; use rustc_middle::metadata::ModChild; use rustc_middle::middle::privacy::EffectiveVisibilities; diff --git a/compiler/rustc_session/Cargo.toml b/compiler/rustc_session/Cargo.toml index 9e337dde99531..15dbfbfd3877b 100644 --- a/compiler/rustc_session/Cargo.toml +++ b/compiler/rustc_session/Cargo.toml @@ -10,6 +10,7 @@ tracing = "0.1" rustc_errors = { path = "../rustc_errors" } rustc_feature = { path = "../rustc_feature" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_target = { path = "../rustc_target" } rustc_serialize = { path = "../rustc_serialize" } rustc_data_structures = { path = "../rustc_data_structures" } diff --git a/compiler/rustc_session/src/lib.rs b/compiler/rustc_session/src/lib.rs index 968728905e7e5..590a68c660061 100644 --- a/compiler/rustc_session/src/lib.rs +++ b/compiler/rustc_session/src/lib.rs @@ -19,7 +19,7 @@ pub mod errors; extern crate tracing; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; pub mod cgu_reuse_tracker; pub mod utils; diff --git a/compiler/rustc_symbol_mangling/Cargo.toml b/compiler/rustc_symbol_mangling/Cargo.toml index 4e447eab02e7c..052ef8bb94c3e 100644 --- a/compiler/rustc_symbol_mangling/Cargo.toml +++ b/compiler/rustc_symbol_mangling/Cargo.toml @@ -15,6 +15,7 @@ twox-hash = "1.6.3" rustc_span = { path = "../rustc_span" } rustc_middle = { path = "../rustc_middle" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_target = { path = "../rustc_target" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_session = { path = "../rustc_session" } diff --git a/compiler/rustc_symbol_mangling/src/lib.rs b/compiler/rustc_symbol_mangling/src/lib.rs index c2fd3304f2b37..c97406868b6a7 100644 --- a/compiler/rustc_symbol_mangling/src/lib.rs +++ b/compiler/rustc_symbol_mangling/src/lib.rs @@ -101,9 +101,9 @@ extern crate rustc_middle; extern crate tracing; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_fluent_macro::fluent_messages; use rustc_hir::def::DefKind; use rustc_hir::def_id::{CrateNum, LOCAL_CRATE}; -use rustc_macros::fluent_messages; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs; use rustc_middle::mir::mono::{InstantiationMode, MonoItem}; diff --git a/compiler/rustc_trait_selection/Cargo.toml b/compiler/rustc_trait_selection/Cargo.toml index d3eba43b47e95..a81459317be6b 100644 --- a/compiler/rustc_trait_selection/Cargo.toml +++ b/compiler/rustc_trait_selection/Cargo.toml @@ -14,6 +14,7 @@ rustc_ast = { path = "../rustc_ast" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_index = { path = "../rustc_index" } rustc_infer = { path = "../rustc_infer" } rustc_macros = { path = "../rustc_macros" } diff --git a/compiler/rustc_trait_selection/src/lib.rs b/compiler/rustc_trait_selection/src/lib.rs index f866cb016e2a6..ed3994be98796 100644 --- a/compiler/rustc_trait_selection/src/lib.rs +++ b/compiler/rustc_trait_selection/src/lib.rs @@ -37,7 +37,7 @@ extern crate rustc_middle; extern crate smallvec; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; pub mod errors; pub mod infer; diff --git a/compiler/rustc_ty_utils/Cargo.toml b/compiler/rustc_ty_utils/Cargo.toml index 52fbd3ae04773..51885c9b47eb8 100644 --- a/compiler/rustc_ty_utils/Cargo.toml +++ b/compiler/rustc_ty_utils/Cargo.toml @@ -9,6 +9,7 @@ rustc_middle = { path = "../rustc_middle" } rustc_data_structures = { path = "../rustc_data_structures" } rustc_errors = { path = "../rustc_errors" } rustc_hir = { path = "../rustc_hir" } +rustc_fluent_macro = { path = "../rustc_fluent_macro" } rustc_infer = { path = "../rustc_infer" } rustc_macros = { path = "../rustc_macros" } rustc_span = { path = "../rustc_span" } diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index 2613445f39bec..9d5a72a73cd49 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -19,7 +19,7 @@ extern crate rustc_middle; extern crate tracing; use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::fluent_messages; +use rustc_fluent_macro::fluent_messages; use rustc_middle::ty::query::Providers; mod abi; diff --git a/tests/ui-fulldeps/fluent-messages/test.rs b/tests/ui-fulldeps/fluent-messages/test.rs index 6ba13387b0460..1dd6d211b3f0d 100644 --- a/tests/ui-fulldeps/fluent-messages/test.rs +++ b/tests/ui-fulldeps/fluent-messages/test.rs @@ -3,8 +3,8 @@ #![feature(rustc_private)] #![crate_type = "lib"] -extern crate rustc_macros; -use rustc_macros::fluent_messages; +extern crate rustc_fluent_macro; +use rustc_fluent_macro::fluent_messages; /// Copy of the relevant `DiagnosticMessage` variant constructed by `fluent_messages` as it /// expects `crate::DiagnosticMessage` to exist. diff --git a/tests/ui-fulldeps/internal-lints/diagnostics.rs b/tests/ui-fulldeps/internal-lints/diagnostics.rs index 3aa65d53d4eae..994fc26ba021e 100644 --- a/tests/ui-fulldeps/internal-lints/diagnostics.rs +++ b/tests/ui-fulldeps/internal-lints/diagnostics.rs @@ -7,15 +7,17 @@ #![deny(rustc::diagnostic_outside_of_impl)] extern crate rustc_errors; +extern crate rustc_fluent_macro; extern crate rustc_macros; extern crate rustc_session; extern crate rustc_span; use rustc_errors::{ - AddToDiagnostic, IntoDiagnostic, Diagnostic, DiagnosticBuilder, - ErrorGuaranteed, Handler, DiagnosticMessage, SubdiagnosticMessage, + AddToDiagnostic, Diagnostic, DiagnosticBuilder, DiagnosticMessage, ErrorGuaranteed, Handler, + IntoDiagnostic, SubdiagnosticMessage, }; -use rustc_macros::{fluent_messages, Diagnostic, Subdiagnostic}; +use rustc_fluent_macro::fluent_messages; +use rustc_macros::{Diagnostic, Subdiagnostic}; use rustc_span::Span; fluent_messages! { "./diagnostics.ftl" } diff --git a/tests/ui-fulldeps/internal-lints/diagnostics.stderr b/tests/ui-fulldeps/internal-lints/diagnostics.stderr index 6f797ebc2dde4..6e670c018520b 100644 --- a/tests/ui-fulldeps/internal-lints/diagnostics.stderr +++ b/tests/ui-fulldeps/internal-lints/diagnostics.stderr @@ -1,5 +1,5 @@ error: diagnostics should be created using translatable messages - --> $DIR/diagnostics.rs:41:17 + --> $DIR/diagnostics.rs:43:17 | LL | handler.struct_err("untranslatable diagnostic") | ^^^^^^^^^^ @@ -11,13 +11,13 @@ LL | #![deny(rustc::untranslatable_diagnostic)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostics should be created using translatable messages - --> $DIR/diagnostics.rs:61:14 + --> $DIR/diagnostics.rs:63:14 | LL | diag.note("untranslatable diagnostic"); | ^^^^ error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls - --> $DIR/diagnostics.rs:78:25 + --> $DIR/diagnostics.rs:80:25 | LL | let _diag = handler.struct_err(crate::fluent_generated::no_crate_example); | ^^^^^^^^^^ @@ -29,13 +29,13 @@ LL | #![deny(rustc::diagnostic_outside_of_impl)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostics should only be created in `IntoDiagnostic`/`AddToDiagnostic` impls - --> $DIR/diagnostics.rs:81:25 + --> $DIR/diagnostics.rs:83:25 | LL | let _diag = handler.struct_err("untranslatable diagnostic"); | ^^^^^^^^^^ error: diagnostics should be created using translatable messages - --> $DIR/diagnostics.rs:81:25 + --> $DIR/diagnostics.rs:83:25 | LL | let _diag = handler.struct_err("untranslatable diagnostic"); | ^^^^^^^^^^ diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs index 6cc7bab37266d..a50681aeaa792 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.rs @@ -16,8 +16,10 @@ extern crate rustc_span; use rustc_span::symbol::Ident; use rustc_span::Span; +extern crate rustc_fluent_macro; extern crate rustc_macros; -use rustc_macros::{fluent_messages, Diagnostic, LintDiagnostic, Subdiagnostic}; +use rustc_fluent_macro::fluent_messages; +use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; extern crate rustc_middle; use rustc_middle::ty::Ty; diff --git a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr index a2f3bb5277b55..ef6741980213d 100644 --- a/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/diagnostic-derive.stderr @@ -1,11 +1,11 @@ error: unsupported type attribute for diagnostic derive enum - --> $DIR/diagnostic-derive.rs:41:1 + --> $DIR/diagnostic-derive.rs:43:1 | LL | #[diag(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:44:5 + --> $DIR/diagnostic-derive.rs:46:5 | LL | Foo, | ^^^ @@ -13,7 +13,7 @@ LL | Foo, = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:46:5 + --> $DIR/diagnostic-derive.rs:48:5 | LL | Bar, | ^^^ @@ -21,19 +21,19 @@ LL | Bar, = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: expected parentheses: #[diag(...)] - --> $DIR/diagnostic-derive.rs:52:8 + --> $DIR/diagnostic-derive.rs:54:8 | LL | #[diag = "E0123"] | ^ error: `#[nonsense(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:57:1 + --> $DIR/diagnostic-derive.rs:59:1 | LL | #[nonsense(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:57:1 + --> $DIR/diagnostic-derive.rs:59:1 | LL | / #[nonsense(no_crate_example, code = "E0123")] LL | | @@ -45,7 +45,7 @@ LL | | struct InvalidStructAttr {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:64:1 + --> $DIR/diagnostic-derive.rs:66:1 | LL | / #[diag("E0123")] LL | | @@ -55,13 +55,13 @@ LL | | struct InvalidLitNestedAttr {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: diagnostic slug must be the first argument - --> $DIR/diagnostic-derive.rs:74:16 + --> $DIR/diagnostic-derive.rs:76:16 | LL | #[diag(nonsense("foo"), code = "E0123", slug = "foo")] | ^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:74:1 + --> $DIR/diagnostic-derive.rs:76:1 | LL | / #[diag(nonsense("foo"), code = "E0123", slug = "foo")] LL | | @@ -72,7 +72,7 @@ LL | | struct InvalidNestedStructAttr1 {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: unknown argument - --> $DIR/diagnostic-derive.rs:80:8 + --> $DIR/diagnostic-derive.rs:82:8 | LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")] | ^^^^^^^^ @@ -80,7 +80,7 @@ LL | #[diag(nonsense = "...", code = "E0123", slug = "foo")] = note: only the `code` parameter is valid after the slug error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:80:1 + --> $DIR/diagnostic-derive.rs:82:1 | LL | / #[diag(nonsense = "...", code = "E0123", slug = "foo")] LL | | @@ -91,7 +91,7 @@ LL | | struct InvalidNestedStructAttr2 {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: unknown argument - --> $DIR/diagnostic-derive.rs:86:8 + --> $DIR/diagnostic-derive.rs:88:8 | LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")] | ^^^^^^^^ @@ -99,7 +99,7 @@ LL | #[diag(nonsense = 4, code = "E0123", slug = "foo")] = note: only the `code` parameter is valid after the slug error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:86:1 + --> $DIR/diagnostic-derive.rs:88:1 | LL | / #[diag(nonsense = 4, code = "E0123", slug = "foo")] LL | | @@ -110,7 +110,7 @@ LL | | struct InvalidNestedStructAttr3 {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: unknown argument - --> $DIR/diagnostic-derive.rs:92:42 + --> $DIR/diagnostic-derive.rs:94:42 | LL | #[diag(no_crate_example, code = "E0123", slug = "foo")] | ^^^^ @@ -118,55 +118,55 @@ LL | #[diag(no_crate_example, code = "E0123", slug = "foo")] = note: only the `code` parameter is valid after the slug error: `#[suggestion = ...]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:99:5 + --> $DIR/diagnostic-derive.rs:101:5 | LL | #[suggestion = "bar"] | ^^^^^^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:106:8 + --> $DIR/diagnostic-derive.rs:108:8 | LL | #[diag(no_crate_example, code = "E0456")] | ^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:105:8 + --> $DIR/diagnostic-derive.rs:107:8 | LL | #[diag(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:106:26 + --> $DIR/diagnostic-derive.rs:108:26 | LL | #[diag(no_crate_example, code = "E0456")] | ^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:105:26 + --> $DIR/diagnostic-derive.rs:107:26 | LL | #[diag(no_crate_example, code = "E0123")] | ^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:112:42 + --> $DIR/diagnostic-derive.rs:114:42 | LL | #[diag(no_crate_example, code = "E0456", code = "E0457")] | ^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:112:26 + --> $DIR/diagnostic-derive.rs:114:26 | LL | #[diag(no_crate_example, code = "E0456", code = "E0457")] | ^^^^ error: diagnostic slug must be the first argument - --> $DIR/diagnostic-derive.rs:117:43 + --> $DIR/diagnostic-derive.rs:119:43 | LL | #[diag(no_crate_example, no_crate::example, code = "E0456")] | ^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:122:1 + --> $DIR/diagnostic-derive.rs:124:1 | LL | struct KindNotProvided {} | ^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -174,7 +174,7 @@ LL | struct KindNotProvided {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:125:1 + --> $DIR/diagnostic-derive.rs:127:1 | LL | / #[diag(code = "E0456")] LL | | @@ -184,31 +184,31 @@ LL | | struct SlugNotProvided {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/diagnostic-derive.rs:136:5 + --> $DIR/diagnostic-derive.rs:138:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ error: `#[nonsense]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:144:5 + --> $DIR/diagnostic-derive.rs:146:5 | LL | #[nonsense] | ^^^^^^^^^^^ error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/diagnostic-derive.rs:161:5 + --> $DIR/diagnostic-derive.rs:163:5 | LL | #[label(no_crate_label)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `name` doesn't refer to a field on this type - --> $DIR/diagnostic-derive.rs:169:46 + --> $DIR/diagnostic-derive.rs:171:46 | LL | #[suggestion(no_crate_suggestion, code = "{name}")] | ^^^^^^^^ error: invalid format string: expected `'}'` but string was terminated - --> $DIR/diagnostic-derive.rs:174:10 + --> $DIR/diagnostic-derive.rs:176:10 | LL | #[derive(Diagnostic)] | ^^^^^^^^^^ expected `'}'` in format string @@ -217,7 +217,7 @@ LL | #[derive(Diagnostic)] = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: invalid format string: unmatched `}` found - --> $DIR/diagnostic-derive.rs:184:10 + --> $DIR/diagnostic-derive.rs:186:10 | LL | #[derive(Diagnostic)] | ^^^^^^^^^^ unmatched `}` in format string @@ -226,19 +226,19 @@ LL | #[derive(Diagnostic)] = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error: the `#[label(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/diagnostic-derive.rs:204:5 + --> $DIR/diagnostic-derive.rs:206:5 | LL | #[label(no_crate_label)] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: suggestion without `code = "..."` - --> $DIR/diagnostic-derive.rs:223:5 + --> $DIR/diagnostic-derive.rs:225:5 | LL | #[suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: invalid nested attribute - --> $DIR/diagnostic-derive.rs:231:18 + --> $DIR/diagnostic-derive.rs:233:18 | LL | #[suggestion(nonsense = "bar")] | ^^^^^^^^ @@ -246,13 +246,13 @@ LL | #[suggestion(nonsense = "bar")] = help: only `style`, `code` and `applicability` are valid nested attributes error: suggestion without `code = "..."` - --> $DIR/diagnostic-derive.rs:231:5 + --> $DIR/diagnostic-derive.rs:233:5 | LL | #[suggestion(nonsense = "bar")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: invalid nested attribute - --> $DIR/diagnostic-derive.rs:240:18 + --> $DIR/diagnostic-derive.rs:242:18 | LL | #[suggestion(msg = "bar")] | ^^^ @@ -260,13 +260,13 @@ LL | #[suggestion(msg = "bar")] = help: only `style`, `code` and `applicability` are valid nested attributes error: suggestion without `code = "..."` - --> $DIR/diagnostic-derive.rs:240:5 + --> $DIR/diagnostic-derive.rs:242:5 | LL | #[suggestion(msg = "bar")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ error: wrong field type for suggestion - --> $DIR/diagnostic-derive.rs:263:5 + --> $DIR/diagnostic-derive.rs:265:5 | LL | / #[suggestion(no_crate_suggestion, code = "This is suggested code")] LL | | @@ -276,79 +276,79 @@ LL | | suggestion: Applicability, = help: `#[suggestion(...)]` should be applied to fields of type `Span` or `(Span, Applicability)` error: specified multiple times - --> $DIR/diagnostic-derive.rs:279:24 + --> $DIR/diagnostic-derive.rs:281:24 | LL | suggestion: (Span, Span, Applicability), | ^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:279:18 + --> $DIR/diagnostic-derive.rs:281:18 | LL | suggestion: (Span, Span, Applicability), | ^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:287:33 + --> $DIR/diagnostic-derive.rs:289:33 | LL | suggestion: (Applicability, Applicability, Span), | ^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:287:18 + --> $DIR/diagnostic-derive.rs:289:18 | LL | suggestion: (Applicability, Applicability, Span), | ^^^^^^^^^^^^^ error: `#[label = ...]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:294:5 + --> $DIR/diagnostic-derive.rs:296:5 | LL | #[label = "bar"] | ^^^^^^^^^^^^^^^^ error: specified multiple times - --> $DIR/diagnostic-derive.rs:445:5 + --> $DIR/diagnostic-derive.rs:447:5 | LL | #[suggestion(no_crate_suggestion, code = "...", applicability = "maybe-incorrect")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:447:24 + --> $DIR/diagnostic-derive.rs:449:24 | LL | suggestion: (Span, Applicability), | ^^^^^^^^^^^^^ error: invalid applicability - --> $DIR/diagnostic-derive.rs:453:69 + --> $DIR/diagnostic-derive.rs:455:69 | LL | #[suggestion(no_crate_suggestion, code = "...", applicability = "batman")] | ^^^^^^^^ error: the `#[help(...)]` attribute can only be applied to fields of type `Span`, `MultiSpan`, `bool` or `()` - --> $DIR/diagnostic-derive.rs:520:5 + --> $DIR/diagnostic-derive.rs:522:5 | LL | #[help(no_crate_help)] | ^^^^^^^^^^^^^^^^^^^^^^ error: a diagnostic slug must be the first argument to the attribute - --> $DIR/diagnostic-derive.rs:529:32 + --> $DIR/diagnostic-derive.rs:531:32 | LL | #[label(no_crate_label, foo)] | ^ error: invalid nested attribute - --> $DIR/diagnostic-derive.rs:537:29 + --> $DIR/diagnostic-derive.rs:539:29 | LL | #[label(no_crate_label, foo = "...")] | ^^^ error: invalid nested attribute - --> $DIR/diagnostic-derive.rs:545:29 + --> $DIR/diagnostic-derive.rs:547:29 | LL | #[label(no_crate_label, foo("..."))] | ^^^ error: `#[primary_span]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:557:5 + --> $DIR/diagnostic-derive.rs:559:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ @@ -356,13 +356,13 @@ LL | #[primary_span] = help: the `primary_span` field attribute is not valid for lint diagnostics error: `#[error(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:577:1 + --> $DIR/diagnostic-derive.rs:579:1 | LL | #[error(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:577:1 + --> $DIR/diagnostic-derive.rs:579:1 | LL | / #[error(no_crate_example, code = "E0123")] LL | | @@ -374,13 +374,13 @@ LL | | struct ErrorAttribute {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: `#[warn_(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:584:1 + --> $DIR/diagnostic-derive.rs:586:1 | LL | #[warn_(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:584:1 + --> $DIR/diagnostic-derive.rs:586:1 | LL | / #[warn_(no_crate_example, code = "E0123")] LL | | @@ -392,13 +392,13 @@ LL | | struct WarnAttribute {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: `#[lint(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:591:1 + --> $DIR/diagnostic-derive.rs:593:1 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:591:1 + --> $DIR/diagnostic-derive.rs:593:1 | LL | / #[lint(no_crate_example, code = "E0123")] LL | | @@ -410,19 +410,19 @@ LL | | struct LintAttributeOnSessionDiag {} = help: specify the slug as the first argument to the `#[diag(...)]` attribute, such as `#[diag(hir_analysis_example_error)]` error: `#[lint(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:598:1 + --> $DIR/diagnostic-derive.rs:600:1 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `#[lint(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:598:1 + --> $DIR/diagnostic-derive.rs:600:1 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: diagnostic slug not specified - --> $DIR/diagnostic-derive.rs:598:1 + --> $DIR/diagnostic-derive.rs:600:1 | LL | / #[lint(no_crate_example, code = "E0123")] LL | | @@ -435,19 +435,19 @@ LL | | struct LintAttributeOnLintDiag {} = help: specify the slug as the first argument to the attribute, such as `#[diag(compiletest_example)]` error: specified multiple times - --> $DIR/diagnostic-derive.rs:608:53 + --> $DIR/diagnostic-derive.rs:610:53 | LL | #[suggestion(no_crate_suggestion, code = "...", code = ",,,")] | ^^^^ | note: previously specified here - --> $DIR/diagnostic-derive.rs:608:39 + --> $DIR/diagnostic-derive.rs:610:39 | LL | #[suggestion(no_crate_suggestion, code = "...", code = ",,,")] | ^^^^ error: wrong types for suggestion - --> $DIR/diagnostic-derive.rs:617:24 + --> $DIR/diagnostic-derive.rs:619:24 | LL | suggestion: (Span, usize), | ^^^^^ @@ -455,7 +455,7 @@ LL | suggestion: (Span, usize), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: wrong types for suggestion - --> $DIR/diagnostic-derive.rs:625:17 + --> $DIR/diagnostic-derive.rs:627:17 | LL | suggestion: (Span,), | ^^^^^^^ @@ -463,13 +463,13 @@ LL | suggestion: (Span,), = help: `#[suggestion(...)]` on a tuple field must be applied to fields of type `(Span, Applicability)` error: suggestion without `code = "..."` - --> $DIR/diagnostic-derive.rs:632:5 + --> $DIR/diagnostic-derive.rs:634:5 | LL | #[suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:639:1 + --> $DIR/diagnostic-derive.rs:641:1 | LL | #[multipart_suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -477,7 +477,7 @@ LL | #[multipart_suggestion(no_crate_suggestion)] = help: consider creating a `Subdiagnostic` instead error: `#[multipart_suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:646:5 + --> $DIR/diagnostic-derive.rs:648:5 | LL | #[multipart_suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -485,13 +485,13 @@ LL | #[multipart_suggestion(no_crate_suggestion)] = help: consider creating a `Subdiagnostic` instead error: unexpected end of input, unexpected token in nested attribute, expected ident - --> $DIR/diagnostic-derive.rs:642:24 + --> $DIR/diagnostic-derive.rs:644:24 | LL | #[multipart_suggestion()] | ^ error: `#[suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:654:1 + --> $DIR/diagnostic-derive.rs:656:1 | LL | #[suggestion(no_crate_suggestion, code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -499,7 +499,7 @@ LL | #[suggestion(no_crate_suggestion, code = "...")] = help: `#[label]` and `#[suggestion]` can only be applied to fields error: `#[label]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:663:1 + --> $DIR/diagnostic-derive.rs:665:1 | LL | #[label] | ^^^^^^^^ @@ -507,31 +507,31 @@ LL | #[label] = help: `#[label]` and `#[suggestion]` can only be applied to fields error: `eager` is the only supported nested attribute for `subdiagnostic` - --> $DIR/diagnostic-derive.rs:697:7 + --> $DIR/diagnostic-derive.rs:699:7 | LL | #[subdiagnostic(bad)] | ^^^^^^^^^^^^^^^^^^ error: `#[subdiagnostic = ...]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:705:5 + --> $DIR/diagnostic-derive.rs:707:5 | LL | #[subdiagnostic = "bad"] | ^^^^^^^^^^^^^^^^^^^^^^^^ error: `eager` is the only supported nested attribute for `subdiagnostic` - --> $DIR/diagnostic-derive.rs:713:7 + --> $DIR/diagnostic-derive.rs:715:7 | LL | #[subdiagnostic(bad, bad)] | ^^^^^^^^^^^^^^^^^^^^^^^ error: `eager` is the only supported nested attribute for `subdiagnostic` - --> $DIR/diagnostic-derive.rs:721:7 + --> $DIR/diagnostic-derive.rs:723:7 | LL | #[subdiagnostic("bad")] | ^^^^^^^^^^^^^^^^^^^^ error: `#[subdiagnostic(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:729:5 + --> $DIR/diagnostic-derive.rs:731:5 | LL | #[subdiagnostic(eager)] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -539,31 +539,31 @@ LL | #[subdiagnostic(eager)] = help: eager subdiagnostics are not supported on lints error: expected at least one string literal for `code(...)` - --> $DIR/diagnostic-derive.rs:787:23 + --> $DIR/diagnostic-derive.rs:789:23 | LL | #[suggestion(code())] | ^ error: `code(...)` must contain only string literals - --> $DIR/diagnostic-derive.rs:795:23 + --> $DIR/diagnostic-derive.rs:797:23 | LL | #[suggestion(code(foo))] | ^^^ error: unexpected token - --> $DIR/diagnostic-derive.rs:795:23 + --> $DIR/diagnostic-derive.rs:797:23 | LL | #[suggestion(code(foo))] | ^^^ error: expected string literal - --> $DIR/diagnostic-derive.rs:804:25 + --> $DIR/diagnostic-derive.rs:806:25 | LL | #[suggestion(code = 3)] | ^ error: `#[suggestion(...)]` is not a valid attribute - --> $DIR/diagnostic-derive.rs:819:5 + --> $DIR/diagnostic-derive.rs:821:5 | LL | #[suggestion(no_crate_suggestion, code = "")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -573,67 +573,67 @@ LL | #[suggestion(no_crate_suggestion, code = "")] = help: to show a variable set of suggestions, use a `Vec` of `Subdiagnostic`s annotated with `#[suggestion(...)]` error: cannot find attribute `nonsense` in this scope - --> $DIR/diagnostic-derive.rs:57:3 + --> $DIR/diagnostic-derive.rs:59:3 | LL | #[nonsense(no_crate_example, code = "E0123")] | ^^^^^^^^ error: cannot find attribute `nonsense` in this scope - --> $DIR/diagnostic-derive.rs:144:7 + --> $DIR/diagnostic-derive.rs:146:7 | LL | #[nonsense] | ^^^^^^^^ error: cannot find attribute `error` in this scope - --> $DIR/diagnostic-derive.rs:577:3 + --> $DIR/diagnostic-derive.rs:579:3 | LL | #[error(no_crate_example, code = "E0123")] | ^^^^^ error: cannot find attribute `warn_` in this scope - --> $DIR/diagnostic-derive.rs:584:3 + --> $DIR/diagnostic-derive.rs:586:3 | LL | #[warn_(no_crate_example, code = "E0123")] | ^^^^^ help: a built-in attribute with a similar name exists: `warn` error: cannot find attribute `lint` in this scope - --> $DIR/diagnostic-derive.rs:591:3 + --> $DIR/diagnostic-derive.rs:593:3 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^ help: a built-in attribute with a similar name exists: `link` error: cannot find attribute `lint` in this scope - --> $DIR/diagnostic-derive.rs:598:3 + --> $DIR/diagnostic-derive.rs:600:3 | LL | #[lint(no_crate_example, code = "E0123")] | ^^^^ help: a built-in attribute with a similar name exists: `link` error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive.rs:639:3 + --> $DIR/diagnostic-derive.rs:641:3 | LL | #[multipart_suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^ error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive.rs:642:3 + --> $DIR/diagnostic-derive.rs:644:3 | LL | #[multipart_suggestion()] | ^^^^^^^^^^^^^^^^^^^^ error: cannot find attribute `multipart_suggestion` in this scope - --> $DIR/diagnostic-derive.rs:646:7 + --> $DIR/diagnostic-derive.rs:648:7 | LL | #[multipart_suggestion(no_crate_suggestion)] | ^^^^^^^^^^^^^^^^^^^^ error[E0425]: cannot find value `nonsense` in module `crate::fluent_generated` - --> $DIR/diagnostic-derive.rs:69:8 + --> $DIR/diagnostic-derive.rs:71:8 | LL | #[diag(nonsense, code = "E0123")] | ^^^^^^^^ not found in `crate::fluent_generated` error[E0425]: cannot find value `__code_34` in this scope - --> $DIR/diagnostic-derive.rs:801:10 + --> $DIR/diagnostic-derive.rs:803:10 | LL | #[derive(Diagnostic)] | ^^^^^^^^^^ not found in this scope @@ -641,7 +641,7 @@ LL | #[derive(Diagnostic)] = note: this error originates in the derive macro `Diagnostic` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `Hello: IntoDiagnosticArg` is not satisfied - --> $DIR/diagnostic-derive.rs:338:10 + --> $DIR/diagnostic-derive.rs:340:10 | LL | #[derive(Diagnostic)] | ^^^^^^^^^^ the trait `IntoDiagnosticArg` is not implemented for `Hello` diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs index 1d928ca93f9cb..d8d362ee69400 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.rs @@ -11,12 +11,14 @@ #![crate_type = "lib"] extern crate rustc_errors; +extern crate rustc_fluent_macro; extern crate rustc_macros; extern crate rustc_session; extern crate rustc_span; use rustc_errors::{Applicability, DiagnosticMessage, SubdiagnosticMessage}; -use rustc_macros::{fluent_messages, Subdiagnostic}; +use rustc_fluent_macro::fluent_messages; +use rustc_macros::Subdiagnostic; use rustc_span::Span; fluent_messages! { "./example.ftl" } diff --git a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr index 4211b91f04a0e..856b608b3a5d0 100644 --- a/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr +++ b/tests/ui-fulldeps/session-diagnostic/subdiagnostic-derive.stderr @@ -1,5 +1,5 @@ error: label without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:49:1 + --> $DIR/subdiagnostic-derive.rs:51:1 | LL | / #[label(no_crate_example)] LL | | @@ -9,133 +9,133 @@ LL | | } | |_^ error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:56:1 + --> $DIR/subdiagnostic-derive.rs:58:1 | LL | #[label] | ^^^^^^^^ error: `#[foo]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:65:1 + --> $DIR/subdiagnostic-derive.rs:67:1 | LL | #[foo] | ^^^^^^ error: `#[label = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:75:1 + --> $DIR/subdiagnostic-derive.rs:77:1 | LL | #[label = "..."] | ^^^^^^^^^^^^^^^^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:84:9 + --> $DIR/subdiagnostic-derive.rs:86:9 | LL | #[label(bug = "...")] | ^^^ error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:84:1 + --> $DIR/subdiagnostic-derive.rs:86:1 | LL | #[label(bug = "...")] | ^^^^^^^^^^^^^^^^^^^^^ error: unexpected literal in nested attribute, expected ident - --> $DIR/subdiagnostic-derive.rs:94:9 + --> $DIR/subdiagnostic-derive.rs:96:9 | LL | #[label("...")] | ^^^^^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:103:9 + --> $DIR/subdiagnostic-derive.rs:105:9 | LL | #[label(slug = 4)] | ^^^^ error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:103:1 + --> $DIR/subdiagnostic-derive.rs:105:1 | LL | #[label(slug = 4)] | ^^^^^^^^^^^^^^^^^^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:113:9 + --> $DIR/subdiagnostic-derive.rs:115:9 | LL | #[label(slug("..."))] | ^^^^ error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:113:1 + --> $DIR/subdiagnostic-derive.rs:115:1 | LL | #[label(slug("..."))] | ^^^^^^^^^^^^^^^^^^^^^ error: unexpected end of input, unexpected token in nested attribute, expected ident - --> $DIR/subdiagnostic-derive.rs:133:9 + --> $DIR/subdiagnostic-derive.rs:135:9 | LL | #[label()] | ^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:142:27 + --> $DIR/subdiagnostic-derive.rs:144:27 | LL | #[label(no_crate_example, code = "...")] | ^^^^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:151:27 + --> $DIR/subdiagnostic-derive.rs:153:27 | LL | #[label(no_crate_example, applicability = "machine-applicable")] | ^^^^^^^^^^^^^ error: unsupported type attribute for subdiagnostic enum - --> $DIR/subdiagnostic-derive.rs:160:1 + --> $DIR/subdiagnostic-derive.rs:162:1 | LL | #[foo] | ^^^^^^ error: `#[bar]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:174:5 + --> $DIR/subdiagnostic-derive.rs:176:5 | LL | #[bar] | ^^^^^^ error: `#[bar = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:186:5 + --> $DIR/subdiagnostic-derive.rs:188:5 | LL | #[bar = "..."] | ^^^^^^^^^^^^^^ error: `#[bar = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:198:5 + --> $DIR/subdiagnostic-derive.rs:200:5 | LL | #[bar = 4] | ^^^^^^^^^^ error: `#[bar(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:210:5 + --> $DIR/subdiagnostic-derive.rs:212:5 | LL | #[bar("...")] | ^^^^^^^^^^^^^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:222:13 + --> $DIR/subdiagnostic-derive.rs:224:13 | LL | #[label(code = "...")] | ^^^^ error: diagnostic slug must be first argument of a `#[label(...)]` attribute - --> $DIR/subdiagnostic-derive.rs:222:5 + --> $DIR/subdiagnostic-derive.rs:224:5 | LL | #[label(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^ error: the `#[primary_span]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive.rs:251:5 + --> $DIR/subdiagnostic-derive.rs:253:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ error: label without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:248:1 + --> $DIR/subdiagnostic-derive.rs:250:1 | LL | / #[label(no_crate_example)] LL | | @@ -147,13 +147,13 @@ LL | | } | |_^ error: `#[applicability]` is only valid on suggestions - --> $DIR/subdiagnostic-derive.rs:261:5 + --> $DIR/subdiagnostic-derive.rs:263:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: `#[bar]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:271:5 + --> $DIR/subdiagnostic-derive.rs:273:5 | LL | #[bar] | ^^^^^^ @@ -161,13 +161,13 @@ LL | #[bar] = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes error: `#[bar = ...]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:282:5 + --> $DIR/subdiagnostic-derive.rs:284:5 | LL | #[bar = "..."] | ^^^^^^^^^^^^^^ error: `#[bar(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:293:5 + --> $DIR/subdiagnostic-derive.rs:295:5 | LL | #[bar("...")] | ^^^^^^^^^^^^^ @@ -175,7 +175,7 @@ LL | #[bar("...")] = help: only `primary_span`, `applicability` and `skip_arg` are valid field attributes error: unexpected unsupported untagged union - --> $DIR/subdiagnostic-derive.rs:309:1 + --> $DIR/subdiagnostic-derive.rs:311:1 | LL | / union AC { LL | | @@ -185,73 +185,73 @@ LL | | } | |_^ error: a diagnostic slug must be the first argument to the attribute - --> $DIR/subdiagnostic-derive.rs:324:44 + --> $DIR/subdiagnostic-derive.rs:326:44 | LL | #[label(no_crate_example, no_crate::example)] | ^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:337:5 + --> $DIR/subdiagnostic-derive.rs:339:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:334:5 + --> $DIR/subdiagnostic-derive.rs:336:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ error: subdiagnostic kind not specified - --> $DIR/subdiagnostic-derive.rs:343:8 + --> $DIR/subdiagnostic-derive.rs:345:8 | LL | struct AG { | ^^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:380:46 + --> $DIR/subdiagnostic-derive.rs:382:46 | LL | #[suggestion(no_crate_example, code = "...", code = "...")] | ^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:380:32 + --> $DIR/subdiagnostic-derive.rs:382:32 | LL | #[suggestion(no_crate_example, code = "...", code = "...")] | ^^^^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:398:5 + --> $DIR/subdiagnostic-derive.rs:400:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:395:5 + --> $DIR/subdiagnostic-derive.rs:397:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: the `#[applicability]` attribute can only be applied to fields of type `Applicability` - --> $DIR/subdiagnostic-derive.rs:408:5 + --> $DIR/subdiagnostic-derive.rs:410:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: suggestion without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:421:1 + --> $DIR/subdiagnostic-derive.rs:423:1 | LL | #[suggestion(no_crate_example)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: invalid applicability - --> $DIR/subdiagnostic-derive.rs:431:62 + --> $DIR/subdiagnostic-derive.rs:433:62 | LL | #[suggestion(no_crate_example, code = "...", applicability = "foo")] | ^^^^^ error: suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:449:1 + --> $DIR/subdiagnostic-derive.rs:451:1 | LL | / #[suggestion(no_crate_example, code = "...")] LL | | @@ -261,25 +261,25 @@ LL | | } | |_^ error: unsupported type attribute for subdiagnostic enum - --> $DIR/subdiagnostic-derive.rs:463:1 + --> $DIR/subdiagnostic-derive.rs:465:1 | LL | #[label] | ^^^^^^^^ error: `var` doesn't refer to a field on this type - --> $DIR/subdiagnostic-derive.rs:483:39 + --> $DIR/subdiagnostic-derive.rs:485:39 | LL | #[suggestion(no_crate_example, code = "{var}", applicability = "machine-applicable")] | ^^^^^^^ error: `var` doesn't refer to a field on this type - --> $DIR/subdiagnostic-derive.rs:502:43 + --> $DIR/subdiagnostic-derive.rs:504:43 | LL | #[suggestion(no_crate_example, code = "{var}", applicability = "machine-applicable")] | ^^^^^^^ error: `#[suggestion_part]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:525:5 + --> $DIR/subdiagnostic-derive.rs:527:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ @@ -287,7 +287,7 @@ LL | #[suggestion_part] = help: `#[suggestion_part(...)]` is only valid in multipart suggestions, use `#[primary_span]` instead error: `#[suggestion_part(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:528:5 + --> $DIR/subdiagnostic-derive.rs:530:5 | LL | #[suggestion_part(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -295,7 +295,7 @@ LL | #[suggestion_part(code = "...")] = help: `#[suggestion_part(...)]` is only valid in multipart suggestions error: suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:522:1 + --> $DIR/subdiagnostic-derive.rs:524:1 | LL | / #[suggestion(no_crate_example, code = "...")] LL | | @@ -307,7 +307,7 @@ LL | | } | |_^ error: invalid nested attribute - --> $DIR/subdiagnostic-derive.rs:537:42 + --> $DIR/subdiagnostic-derive.rs:539:42 | LL | #[multipart_suggestion(no_crate_example, code = "...", applicability = "machine-applicable")] | ^^^^ @@ -315,7 +315,7 @@ LL | #[multipart_suggestion(no_crate_example, code = "...", applicability = "mac = help: only `style` and `applicability` are valid nested attributes error: multipart suggestion without any `#[suggestion_part(...)]` fields - --> $DIR/subdiagnostic-derive.rs:537:1 + --> $DIR/subdiagnostic-derive.rs:539:1 | LL | / #[multipart_suggestion(no_crate_example, code = "...", applicability = "machine-applicable")] LL | | @@ -326,19 +326,19 @@ LL | | } | |_^ error: `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:547:5 + --> $DIR/subdiagnostic-derive.rs:549:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ error: unexpected end of input, unexpected token in nested attribute, expected ident - --> $DIR/subdiagnostic-derive.rs:555:23 + --> $DIR/subdiagnostic-derive.rs:557:23 | LL | #[suggestion_part()] | ^ error: `#[primary_span]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:564:5 + --> $DIR/subdiagnostic-derive.rs:566:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ @@ -346,7 +346,7 @@ LL | #[primary_span] = help: multipart suggestions use one or more `#[suggestion_part]`s rather than one `#[primary_span]` error: multipart suggestion without any `#[suggestion_part(...)]` fields - --> $DIR/subdiagnostic-derive.rs:561:1 + --> $DIR/subdiagnostic-derive.rs:563:1 | LL | / #[multipart_suggestion(no_crate_example)] LL | | @@ -358,121 +358,121 @@ LL | | } | |_^ error: `#[suggestion_part(...)]` attribute without `code = "..."` - --> $DIR/subdiagnostic-derive.rs:572:5 + --> $DIR/subdiagnostic-derive.rs:574:5 | LL | #[suggestion_part] | ^^^^^^^^^^^^^^^^^^ error: `code` is the only valid nested attribute - --> $DIR/subdiagnostic-derive.rs:578:23 + --> $DIR/subdiagnostic-derive.rs:580:23 | LL | #[suggestion_part(foo = "bar")] | ^^^ error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive.rs:582:5 + --> $DIR/subdiagnostic-derive.rs:584:5 | LL | #[suggestion_part(code = "...")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: the `#[suggestion_part(...)]` attribute can only be applied to fields of type `Span` or `MultiSpan` - --> $DIR/subdiagnostic-derive.rs:585:5 + --> $DIR/subdiagnostic-derive.rs:587:5 | LL | #[suggestion_part()] | ^^^^^^^^^^^^^^^^^^^^ error: unexpected end of input, unexpected token in nested attribute, expected ident - --> $DIR/subdiagnostic-derive.rs:575:23 + --> $DIR/subdiagnostic-derive.rs:577:23 | LL | #[suggestion_part()] | ^ error: expected `,` - --> $DIR/subdiagnostic-derive.rs:578:27 + --> $DIR/subdiagnostic-derive.rs:580:27 | LL | #[suggestion_part(foo = "bar")] | ^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:593:37 + --> $DIR/subdiagnostic-derive.rs:595:37 | LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:593:23 + --> $DIR/subdiagnostic-derive.rs:595:23 | LL | #[suggestion_part(code = "...", code = ",,,")] | ^^^^ error: `#[applicability]` has no effect if all `#[suggestion]`/`#[multipart_suggestion]` attributes have a static `applicability = "..."` - --> $DIR/subdiagnostic-derive.rs:622:5 + --> $DIR/subdiagnostic-derive.rs:624:5 | LL | #[applicability] | ^^^^^^^^^^^^^^^^ error: expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive.rs:670:34 + --> $DIR/subdiagnostic-derive.rs:672:34 | LL | #[suggestion_part(code("foo"))] | ^ error: unexpected token - --> $DIR/subdiagnostic-derive.rs:670:28 + --> $DIR/subdiagnostic-derive.rs:672:28 | LL | #[suggestion_part(code("foo"))] | ^^^^^ error: expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive.rs:680:41 + --> $DIR/subdiagnostic-derive.rs:682:41 | LL | #[suggestion_part(code("foo", "bar"))] | ^ error: unexpected token - --> $DIR/subdiagnostic-derive.rs:680:28 + --> $DIR/subdiagnostic-derive.rs:682:28 | LL | #[suggestion_part(code("foo", "bar"))] | ^^^^^ error: expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive.rs:690:30 + --> $DIR/subdiagnostic-derive.rs:692:30 | LL | #[suggestion_part(code(3))] | ^ error: unexpected token - --> $DIR/subdiagnostic-derive.rs:690:28 + --> $DIR/subdiagnostic-derive.rs:692:28 | LL | #[suggestion_part(code(3))] | ^ error: expected exactly one string literal for `code = ...` - --> $DIR/subdiagnostic-derive.rs:700:29 + --> $DIR/subdiagnostic-derive.rs:702:29 | LL | #[suggestion_part(code())] | ^ error: expected string literal - --> $DIR/subdiagnostic-derive.rs:712:30 + --> $DIR/subdiagnostic-derive.rs:714:30 | LL | #[suggestion_part(code = 3)] | ^ error: specified multiple times - --> $DIR/subdiagnostic-derive.rs:754:1 + --> $DIR/subdiagnostic-derive.rs:756:1 | LL | #[suggestion(no_crate_example, code = "", style = "hidden", style = "normal")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | note: previously specified here - --> $DIR/subdiagnostic-derive.rs:754:1 + --> $DIR/subdiagnostic-derive.rs:756:1 | LL | #[suggestion(no_crate_example, code = "", style = "hidden", style = "normal")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: `#[suggestion_hidden(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:763:1 + --> $DIR/subdiagnostic-derive.rs:765:1 | LL | #[suggestion_hidden(no_crate_example, code = "")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -480,7 +480,7 @@ LL | #[suggestion_hidden(no_crate_example, code = "")] = help: Use `#[suggestion(..., style = "hidden")]` instead error: `#[suggestion_hidden(...)]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:771:1 + --> $DIR/subdiagnostic-derive.rs:773:1 | LL | #[suggestion_hidden(no_crate_example, code = "", style = "normal")] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -488,7 +488,7 @@ LL | #[suggestion_hidden(no_crate_example, code = "", style = "normal")] = help: Use `#[suggestion(..., style = "hidden")]` instead error: invalid suggestion style - --> $DIR/subdiagnostic-derive.rs:779:51 + --> $DIR/subdiagnostic-derive.rs:781:51 | LL | #[suggestion(no_crate_example, code = "", style = "foo")] | ^^^^^ @@ -496,31 +496,31 @@ LL | #[suggestion(no_crate_example, code = "", style = "foo")] = help: valid styles are `normal`, `short`, `hidden`, `verbose` and `tool-only` error: expected `= "xxx"` - --> $DIR/subdiagnostic-derive.rs:787:49 + --> $DIR/subdiagnostic-derive.rs:789:49 | LL | #[suggestion(no_crate_example, code = "", style = 42)] | ^ error: a diagnostic slug must be the first argument to the attribute - --> $DIR/subdiagnostic-derive.rs:795:48 + --> $DIR/subdiagnostic-derive.rs:797:48 | LL | #[suggestion(no_crate_example, code = "", style)] | ^ error: expected `= "xxx"` - --> $DIR/subdiagnostic-derive.rs:803:48 + --> $DIR/subdiagnostic-derive.rs:805:48 | LL | #[suggestion(no_crate_example, code = "", style("foo"))] | ^ error: expected `,` - --> $DIR/subdiagnostic-derive.rs:803:48 + --> $DIR/subdiagnostic-derive.rs:805:48 | LL | #[suggestion(no_crate_example, code = "", style("foo"))] | ^ error: `#[primary_span]` is not a valid attribute - --> $DIR/subdiagnostic-derive.rs:815:5 + --> $DIR/subdiagnostic-derive.rs:817:5 | LL | #[primary_span] | ^^^^^^^^^^^^^^^ @@ -529,7 +529,7 @@ LL | #[primary_span] = help: to create a suggestion with multiple spans, use `#[multipart_suggestion]` instead error: suggestion without `#[primary_span]` field - --> $DIR/subdiagnostic-derive.rs:812:1 + --> $DIR/subdiagnostic-derive.rs:814:1 | LL | / #[suggestion(no_crate_example, code = "")] LL | | @@ -541,67 +541,67 @@ LL | | } | |_^ error: cannot find attribute `foo` in this scope - --> $DIR/subdiagnostic-derive.rs:65:3 + --> $DIR/subdiagnostic-derive.rs:67:3 | LL | #[foo] | ^^^ error: cannot find attribute `foo` in this scope - --> $DIR/subdiagnostic-derive.rs:160:3 + --> $DIR/subdiagnostic-derive.rs:162:3 | LL | #[foo] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:174:7 + --> $DIR/subdiagnostic-derive.rs:176:7 | LL | #[bar] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:186:7 + --> $DIR/subdiagnostic-derive.rs:188:7 | LL | #[bar = "..."] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:198:7 + --> $DIR/subdiagnostic-derive.rs:200:7 | LL | #[bar = 4] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:210:7 + --> $DIR/subdiagnostic-derive.rs:212:7 | LL | #[bar("...")] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:271:7 + --> $DIR/subdiagnostic-derive.rs:273:7 | LL | #[bar] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:282:7 + --> $DIR/subdiagnostic-derive.rs:284:7 | LL | #[bar = "..."] | ^^^ error: cannot find attribute `bar` in this scope - --> $DIR/subdiagnostic-derive.rs:293:7 + --> $DIR/subdiagnostic-derive.rs:295:7 | LL | #[bar("...")] | ^^^ error[E0425]: cannot find value `slug` in module `crate::fluent_generated` - --> $DIR/subdiagnostic-derive.rs:123:9 + --> $DIR/subdiagnostic-derive.rs:125:9 | LL | #[label(slug)] | ^^^^ not found in `crate::fluent_generated` error[E0425]: cannot find value `__code_29` in this scope - --> $DIR/subdiagnostic-derive.rs:706:10 + --> $DIR/subdiagnostic-derive.rs:708:10 | LL | #[derive(Subdiagnostic)] | ^^^^^^^^^^^^^ not found in this scope From 4b981c26487ebe56de6b3000fcd98713804beefc Mon Sep 17 00:00:00 2001 From: Amanieu d'Antras Date: Thu, 23 Mar 2023 23:39:41 +0000 Subject: [PATCH 12/28] Rename -Zoom=panic to -Zoom=unwind --- compiler/rustc_interface/src/tests.rs | 2 +- compiler/rustc_session/src/config.rs | 6 +++--- compiler/rustc_session/src/options.rs | 2 +- library/alloc/src/alloc.rs | 4 ++-- tests/ui/oom_unwind.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 10dfd32d418a2..101967503c1e2 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -776,7 +776,7 @@ fn test_unstable_options_tracking_hash() { tracked!(no_link, true); tracked!(no_profiler_runtime, true); tracked!(no_unique_section_names, true); - tracked!(oom, OomStrategy::Panic); + tracked!(oom, OomStrategy::Unwind); tracked!(osx_rpath_install_name, true); tracked!(packed_bundled_libs, true); tracked!(panic_abort_tests, true); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 79eb31bb1050e..419b6afe7c68a 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -3048,9 +3048,9 @@ pub(crate) mod dep_tracking { #[derive(Clone, Copy, PartialEq, Hash, Debug, Encodable, Decodable, HashStable_Generic)] pub enum OomStrategy { /// Generate a panic that can be caught by `catch_unwind`. - Panic, + Unwind, - /// Abort the process immediately. + /// Calls the panic hook as normal but aborts instead of unwinding. Abort, } @@ -3059,7 +3059,7 @@ impl OomStrategy { pub fn should_panic(self) -> u8 { match self { - OomStrategy::Panic => 1, + OomStrategy::Unwind => 1, OomStrategy::Abort => 0, } } diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 631dd0a2146e8..46c992dfefd5f 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -662,7 +662,7 @@ mod parse { pub(crate) fn parse_oom_strategy(slot: &mut OomStrategy, v: Option<&str>) -> bool { match v { - Some("panic") => *slot = OomStrategy::Panic, + Some("unwind") => *slot = OomStrategy::Unwind, Some("abort") => *slot = OomStrategy::Abort, _ => return false, } diff --git a/library/alloc/src/alloc.rs b/library/alloc/src/alloc.rs index 97bedc604da82..0db23e55a8653 100644 --- a/library/alloc/src/alloc.rs +++ b/library/alloc/src/alloc.rs @@ -398,7 +398,7 @@ fn rust_oom(layout: Layout) -> ! { fn panic_impl(pi: &core::panic::PanicInfo<'_>) -> !; // This symbol is emitted by rustc . - // Its value depends on the -Zoom={panic,abort} compiler option. + // Its value depends on the -Zoom={unwind,abort} compiler option. static __rust_alloc_error_handler_should_panic: u8; } @@ -458,7 +458,7 @@ pub mod __alloc_error_handler { pub unsafe fn __rdl_oom(size: usize, _align: usize) -> ! { extern "Rust" { // This symbol is emitted by rustc next to __rust_alloc_error_handler. - // Its value depends on the -Zoom={panic,abort} compiler option. + // Its value depends on the -Zoom={unwind,abort} compiler option. static __rust_alloc_error_handler_should_panic: u8; } diff --git a/tests/ui/oom_unwind.rs b/tests/ui/oom_unwind.rs index 21a8fb2b22bee..704d6f8b810a9 100644 --- a/tests/ui/oom_unwind.rs +++ b/tests/ui/oom_unwind.rs @@ -1,4 +1,4 @@ -// compile-flags: -Z oom=panic +// compile-flags: -Z oom=unwind // run-pass // no-prefer-dynamic // needs-unwind From a091fd25cae34ebdc3f158e623743d51428952ff Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Apr 2023 12:07:30 +0200 Subject: [PATCH 13/28] Add list of supported disambiguators and suffixes for intra-doc links in the rustdoc book --- .../src/write-documentation/linking-to-items-by-name.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md b/src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md index eb2285ef90646..72157b5cd9bce 100644 --- a/src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md +++ b/src/doc/rustdoc/src/write-documentation/linking-to-items-by-name.md @@ -88,13 +88,16 @@ fn Foo() {} ``` These prefixes will be stripped when displayed in the documentation, so `[struct@Foo]` will be -rendered as `Foo`. +rendered as `Foo`. The following prefixes are available: `struct`, `enum`, `trait`, `union`, +`mod`, `module`, `const`, `constant`, `fn`, `function`, `method`, `derive`, `type`, `value`, +`macro`, `prim` or `primitive`. You can also disambiguate for functions by adding `()` after the function name, -or for macros by adding `!` after the macro name: +or for macros by adding `!` after the macro name. The macro `!` can be followed by `()`, `{}`, +or `[]`. Example: ```rust -/// This is different from [`foo!`] +/// This is different from [`foo!()`]. fn foo() {} /// This is different from [`foo()`] From 1531c95c5d3f4e9ef4cfc122c35947e7b9cca53e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 15 Apr 2023 15:52:27 +0200 Subject: [PATCH 14/28] Add code comment to remind contributors to update rustdoc book if they update the disambiguators list --- src/librustdoc/passes/collect_intra_doc_links.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 2cd9c8a878187..3b7226df65a3d 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -1419,6 +1419,7 @@ impl Disambiguator { if let Some(idx) = link.find('@') { let (prefix, rest) = link.split_at(idx); let d = match prefix { + // If you update this list, please also update the relevant rustdoc book section! "struct" => Kind(DefKind::Struct), "enum" => Kind(DefKind::Enum), "trait" => Kind(DefKind::Trait), @@ -1437,6 +1438,7 @@ impl Disambiguator { Ok(Some((d, &rest[1..], &rest[1..]))) } else { let suffixes = [ + // If you update this list, please also update the relevant rustdoc book section! ("!()", DefKind::Macro(MacroKind::Bang)), ("!{}", DefKind::Macro(MacroKind::Bang)), ("![]", DefKind::Macro(MacroKind::Bang)), From 6978147d478ffa55a7f2238ac84f9251f7a16102 Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 26 Mar 2023 12:25:08 +0200 Subject: [PATCH 15/28] Uplift clippy::drop_ref to rustc --- compiler/rustc_lint/messages.ftl | 3 + .../rustc_lint/src/drop_forget_useless.rs | 76 +++++++++ compiler/rustc_lint/src/lib.rs | 3 + compiler/rustc_lint/src/lints.rs | 9 ++ tests/ui/lint/drop_ref.rs | 99 ++++++++++++ tests/ui/lint/drop_ref.stderr | 151 ++++++++++++++++++ 6 files changed, 341 insertions(+) create mode 100644 compiler/rustc_lint/src/drop_forget_useless.rs create mode 100644 tests/ui/lint/drop_ref.rs create mode 100644 tests/ui/lint/drop_ref.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index db15b176df001..e9518f2dff93e 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -510,3 +510,6 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass .specifically = this associated type bound is unsatisfied for `{$proj_ty}` lint_opaque_hidden_inferred_bound_sugg = add this bound + +lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value + .note = argument has type `{$arg_ty}` diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs new file mode 100644 index 0000000000000..734a43af4a2d4 --- /dev/null +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -0,0 +1,76 @@ +use rustc_hir::{Arm, Expr, ExprKind, Node}; +use rustc_span::sym; + +use crate::{lints::DropRefDiag, LateContext, LateLintPass, LintContext}; + +declare_lint! { + /// The `drop_ref` lint checks for calls to `std::mem::drop` with a reference + /// instead of an owned value. + /// + /// ### Example + /// + /// ```rust + /// # fn operation_that_requires_mutex_to_be_unlocked() {} // just to make it compile + /// # let mutex = std::sync::Mutex::new(1); // just to make it compile + /// let mut lock_guard = mutex.lock(); + /// std::mem::drop(&lock_guard); // Should have been drop(lock_guard), mutex + /// // still locked + /// operation_that_requires_mutex_to_be_unlocked(); + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Calling `drop` on a reference will only drop the + /// reference itself, which is a no-op. It will not call the `drop` method (from + /// the `Drop` trait implementation) on the underlying referenced value, which + /// is likely what was intended. + pub DROP_REF, + Warn, + "calls to `std::mem::drop` with a reference instead of an owned value" +} + +declare_lint_pass!(DropForgetUseless => [DROP_REF]); + +impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { + fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { + if let ExprKind::Call(path, [arg]) = expr.kind + && let ExprKind::Path(ref qpath) = path.kind + && let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id() + && let Some(fn_name) = cx.tcx.get_diagnostic_name(def_id) + { + let arg_ty = cx.typeck_results().expr_ty(arg); + let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); + match fn_name { + sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => { + cx.emit_spanned_lint(DROP_REF, expr.span, DropRefDiag { arg_ty, note: arg.span }); + }, + _ => return, + }; + } + } +} + +// Dropping returned value of a function, as in the following snippet is considered idiomatic, see +// rust-lang/rust-clippy#9482 for examples. +// +// ``` +// match { +// => drop(fn_with_side_effect_and_returning_some_value()), +// .. +// } +// ``` +fn is_single_call_in_arm<'tcx>( + cx: &LateContext<'tcx>, + arg: &'tcx Expr<'_>, + drop_expr: &'tcx Expr<'_>, +) -> bool { + if matches!(arg.kind, ExprKind::Call(..) | ExprKind::MethodCall(..)) { + let parent_node = cx.tcx.hir().find_parent(drop_expr.hir_id); + if let Some(Node::Arm(Arm { body, .. })) = &parent_node { + return body.hir_id == drop_expr.hir_id; + } + } + false +} diff --git a/compiler/rustc_lint/src/lib.rs b/compiler/rustc_lint/src/lib.rs index b3578540516d0..48e5041d7e5a9 100644 --- a/compiler/rustc_lint/src/lib.rs +++ b/compiler/rustc_lint/src/lib.rs @@ -52,6 +52,7 @@ mod array_into_iter; pub mod builtin; mod context; mod deref_into_dyn_supertrait; +mod drop_forget_useless; mod early; mod enum_intrinsics_non_enums; mod errors; @@ -96,6 +97,7 @@ use rustc_span::Span; use array_into_iter::ArrayIntoIter; use builtin::*; use deref_into_dyn_supertrait::*; +use drop_forget_useless::*; use enum_intrinsics_non_enums::EnumIntrinsicsNonEnums; use for_loops_over_fallibles::*; use hidden_unicode_codepoints::*; @@ -201,6 +203,7 @@ late_lint_methods!( [ ForLoopsOverFallibles: ForLoopsOverFallibles, DerefIntoDynSupertrait: DerefIntoDynSupertrait, + DropForgetUseless: DropForgetUseless, HardwiredLints: HardwiredLints, ImproperCTypesDeclarations: ImproperCTypesDeclarations, ImproperCTypesDefinitions: ImproperCTypesDefinitions, diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 1d5e02369f528..4470aa5b15b9a 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -662,6 +662,15 @@ pub struct ForLoopsOverFalliblesSuggestion<'a> { pub end_span: Span, } +// drop_ref.rs +#[derive(LintDiagnostic)] +#[diag(lint_drop_ref)] +pub struct DropRefDiag<'a> { + pub arg_ty: Ty<'a>, + #[note] + pub note: Span, +} + // hidden_unicode_codepoints.rs #[derive(LintDiagnostic)] #[diag(lint_hidden_unicode_codepoints)] diff --git a/tests/ui/lint/drop_ref.rs b/tests/ui/lint/drop_ref.rs new file mode 100644 index 0000000000000..db4f7569f6fa3 --- /dev/null +++ b/tests/ui/lint/drop_ref.rs @@ -0,0 +1,99 @@ +// check-pass + +#![warn(drop_ref)] + +struct SomeStruct; + +fn main() { + drop(&SomeStruct); //~ WARN calls to `std::mem::drop` + + let mut owned1 = SomeStruct; + drop(&owned1); //~ WARN calls to `std::mem::drop` + drop(&&owned1); //~ WARN calls to `std::mem::drop` + drop(&mut owned1); //~ WARN calls to `std::mem::drop` + drop(owned1); + + let reference1 = &SomeStruct; + drop(reference1); //~ WARN calls to `std::mem::drop` + + let reference2 = &mut SomeStruct; + drop(reference2); //~ WARN calls to `std::mem::drop` + + let ref reference3 = SomeStruct; + drop(reference3); //~ WARN calls to `std::mem::drop` +} + +#[allow(dead_code)] +fn test_generic_fn_drop(val: T) { + drop(&val); //~ WARN calls to `std::mem::drop` + drop(val); +} + +#[allow(dead_code)] +fn test_similarly_named_function() { + fn drop(_val: T) {} + drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name + std::mem::drop(&SomeStruct); //~ WARN calls to `std::mem::drop` +} + +#[derive(Copy, Clone)] +pub struct Error; +fn produce_half_owl_error() -> Result<(), Error> { + Ok(()) +} + +fn produce_half_owl_ok() -> Result { + Ok(true) +} + +#[allow(dead_code)] +fn test_owl_result() -> Result<(), ()> { + produce_half_owl_error().map_err(|_| ())?; + produce_half_owl_ok().map(|_| ())?; + // the following should not be linted, + // we should not force users to use toilet closures + // to produce owl results when drop is more convenient + produce_half_owl_error().map_err(drop)?; + produce_half_owl_ok().map_err(drop)?; + Ok(()) +} + +#[allow(dead_code)] +fn test_owl_result_2() -> Result { + produce_half_owl_error().map_err(|_| ())?; + produce_half_owl_ok().map(|_| ())?; + // the following should not be linted, + // we should not force users to use toilet closures + // to produce owl results when drop is more convenient + produce_half_owl_error().map_err(drop)?; + produce_half_owl_ok().map(drop)?; + Ok(1) +} + +#[allow(unused)] +#[allow(clippy::unit_cmp)] +fn issue10122(x: u8) { + // This is a function which returns a reference and has a side-effect, which means + // that calling drop() on the function is considered an idiomatic way of achieving + // the side-effect in a match arm. + fn println_and(t: &T) -> &T { + println!("foo"); + t + } + + match x { + // Don't lint (copy type), we only care about side-effects + 0 => drop(println_and(&12)), + // Don't lint (no copy type), we only care about side-effects + 1 => drop(println_and(&String::new())), + 2 => { + // Lint, even if we only care about the side-effect, it's already in a block + drop(println_and(&13)); //~ WARN calls to `std::mem::drop` + }, + // Lint, idiomatic use is only in body of `Arm` + 3 if drop(println_and(&14)) == () => (), //~ WARN calls to `std::mem::drop` + // Lint, not a fn/method call + 4 => drop(&2), //~ WARN calls to `std::mem::drop` + _ => (), + } +} diff --git a/tests/ui/lint/drop_ref.stderr b/tests/ui/lint/drop_ref.stderr new file mode 100644 index 0000000000000..34e4050abcf6d --- /dev/null +++ b/tests/ui/lint/drop_ref.stderr @@ -0,0 +1,151 @@ +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:8:5 + | +LL | drop(&SomeStruct); + | ^^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_ref.rs:8:10 + | +LL | drop(&SomeStruct); + | ^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/drop_ref.rs:3:9 + | +LL | #![warn(drop_ref)] + | ^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:11:5 + | +LL | drop(&owned1); + | ^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_ref.rs:11:10 + | +LL | drop(&owned1); + | ^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:12:5 + | +LL | drop(&&owned1); + | ^^^^^^^^^^^^^^ + | +note: argument has type `&&SomeStruct` + --> $DIR/drop_ref.rs:12:10 + | +LL | drop(&&owned1); + | ^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:13:5 + | +LL | drop(&mut owned1); + | ^^^^^^^^^^^^^^^^^ + | +note: argument has type `&mut SomeStruct` + --> $DIR/drop_ref.rs:13:10 + | +LL | drop(&mut owned1); + | ^^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:17:5 + | +LL | drop(reference1); + | ^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_ref.rs:17:10 + | +LL | drop(reference1); + | ^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:20:5 + | +LL | drop(reference2); + | ^^^^^^^^^^^^^^^^ + | +note: argument has type `&mut SomeStruct` + --> $DIR/drop_ref.rs:20:10 + | +LL | drop(reference2); + | ^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:23:5 + | +LL | drop(reference3); + | ^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_ref.rs:23:10 + | +LL | drop(reference3); + | ^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:28:5 + | +LL | drop(&val); + | ^^^^^^^^^^ + | +note: argument has type `&T` + --> $DIR/drop_ref.rs:28:10 + | +LL | drop(&val); + | ^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:36:5 + | +LL | std::mem::drop(&SomeStruct); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_ref.rs:36:20 + | +LL | std::mem::drop(&SomeStruct); + | ^^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:91:13 + | +LL | drop(println_and(&13)); + | ^^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&i32` + --> $DIR/drop_ref.rs:91:18 + | +LL | drop(println_and(&13)); + | ^^^^^^^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:94:14 + | +LL | 3 if drop(println_and(&14)) == () => (), + | ^^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&i32` + --> $DIR/drop_ref.rs:94:19 + | +LL | 3 if drop(println_and(&14)) == () => (), + | ^^^^^^^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_ref.rs:96:14 + | +LL | 4 => drop(&2), + | ^^^^^^^^ + | +note: argument has type `&i32` + --> $DIR/drop_ref.rs:96:19 + | +LL | 4 => drop(&2), + | ^^ + +warning: 12 warnings emitted + From b33d6eac98a2badca95743da64be04b2fec4a1fd Mon Sep 17 00:00:00 2001 From: Urgau Date: Sun, 26 Mar 2023 16:18:43 +0200 Subject: [PATCH 16/28] Drop uplifted clippy::drop_ref --- .../clippy/clippy_lints/src/declared_lints.rs | 1 - .../clippy_lints/src/drop_forget_ref.rs | 30 +--- .../clippy/clippy_lints/src/renamed_lints.rs | 1 + src/tools/clippy/tests/ui/drop_forget_copy.rs | 2 +- .../clippy/tests/ui/drop_forget_copy.stderr | 50 +++++- src/tools/clippy/tests/ui/drop_ref.rs | 97 ------------ src/tools/clippy/tests/ui/drop_ref.stderr | 147 ------------------ src/tools/clippy/tests/ui/rename.fixed | 2 + src/tools/clippy/tests/ui/rename.rs | 2 + src/tools/clippy/tests/ui/rename.stderr | 92 ++++++----- 10 files changed, 106 insertions(+), 318 deletions(-) delete mode 100644 src/tools/clippy/tests/ui/drop_ref.rs delete mode 100644 src/tools/clippy/tests/ui/drop_ref.stderr diff --git a/src/tools/clippy/clippy_lints/src/declared_lints.rs b/src/tools/clippy/clippy_lints/src/declared_lints.rs index f24dab6278095..ac922d2024e4f 100644 --- a/src/tools/clippy/clippy_lints/src/declared_lints.rs +++ b/src/tools/clippy/clippy_lints/src/declared_lints.rs @@ -133,7 +133,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::double_parens::DOUBLE_PARENS_INFO, crate::drop_forget_ref::DROP_COPY_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, - crate::drop_forget_ref::DROP_REF_INFO, crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, crate::drop_forget_ref::FORGET_REF_INFO, diff --git a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs index 11e1bcdf12d1e..55d7c3247cddf 100644 --- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs +++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs @@ -7,30 +7,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::drop` with a reference - /// instead of an owned value. - /// - /// ### Why is this bad? - /// Calling `drop` on a reference will only drop the - /// reference itself, which is a no-op. It will not call the `drop` method (from - /// the `Drop` trait implementation) on the underlying referenced value, which - /// is likely what was intended. - /// - /// ### Example - /// ```ignore - /// let mut lock_guard = mutex.lock(); - /// std::mem::drop(&lock_guard) // Should have been drop(lock_guard), mutex - /// // still locked - /// operation_that_requires_mutex_to_be_unlocked(); - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DROP_REF, - correctness, - "calls to `std::mem::drop` with a reference instead of an owned value" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::forget` with a reference @@ -172,8 +148,6 @@ declare_clippy_lint! { "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" } -const DROP_REF_SUMMARY: &str = "calls to `std::mem::drop` with a reference instead of an owned value. \ - Dropping a reference does nothing"; const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ Forgetting a reference does nothing"; const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \ @@ -186,7 +160,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t Forgetting such a type is the same as dropping it"; declare_lint_pass!(DropForgetRef => [ - DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY, @@ -206,7 +179,8 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => (DROP_REF, DROP_REF_SUMMARY), + // early return for uplifted lints: drop_ref + sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY), sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY), sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs index 9f487dedb8cb6..8dac4ab8d378e 100644 --- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs +++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs @@ -31,6 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::to_string_in_display", "clippy::recursive_format_impl"), ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::drop_bounds", "drop_bounds"), + ("clippy::drop_ref", "drop_ref"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.rs b/src/tools/clippy/tests/ui/drop_forget_copy.rs index a7276dd59f434..04293eb16bb79 100644 --- a/src/tools/clippy/tests/ui/drop_forget_copy.rs +++ b/src/tools/clippy/tests/ui/drop_forget_copy.rs @@ -1,5 +1,5 @@ #![warn(clippy::drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, clippy::drop_ref, clippy::forget_ref, unused_mut)] +#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)] use std::mem::{drop, forget}; use std::vec::Vec; diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.stderr b/src/tools/clippy/tests/ui/drop_forget_copy.stderr index 90bef1c3c439f..df492d9b3d2ef 100644 --- a/src/tools/clippy/tests/ui/drop_forget_copy.stderr +++ b/src/tools/clippy/tests/ui/drop_forget_copy.stderr @@ -23,6 +23,18 @@ note: argument has type `SomeStruct` LL | drop(s2); | ^^ +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:35:5 + | +LL | drop(s3); + | ^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_forget_copy.rs:35:10 + | +LL | drop(s3); + | ^^ + error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact --> $DIR/drop_forget_copy.rs:36:5 | @@ -35,6 +47,18 @@ note: argument has type `SomeStruct` LL | drop(s4); | ^^ +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:37:5 + | +LL | drop(s5); + | ^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_forget_copy.rs:37:10 + | +LL | drop(s5); + | ^^ + error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact --> $DIR/drop_forget_copy.rs:39:5 | @@ -72,6 +96,30 @@ note: argument has type `SomeStruct` LL | forget(s4); | ^^ +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:55:5 + | +LL | drop(a2); + | ^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_forget_copy.rs:55:10 + | +LL | drop(a2); + | ^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:57:5 + | +LL | drop(a4); + | ^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_forget_copy.rs:57:10 + | +LL | drop(a4); + | ^^ + error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact --> $DIR/drop_forget_copy.rs:80:13 | @@ -108,5 +156,5 @@ note: argument has type `i32` LL | 4 => drop(2), // Lint, not a fn/method call | ^ -error: aborting due to 9 previous errors +error: aborting due to 13 previous errors diff --git a/src/tools/clippy/tests/ui/drop_ref.rs b/src/tools/clippy/tests/ui/drop_ref.rs deleted file mode 100644 index 10044e65f1156..0000000000000 --- a/src/tools/clippy/tests/ui/drop_ref.rs +++ /dev/null @@ -1,97 +0,0 @@ -#![warn(clippy::drop_ref)] -#![allow(clippy::toplevel_ref_arg)] -#![allow(clippy::map_err_ignore)] -#![allow(clippy::unnecessary_wraps, clippy::drop_non_drop)] - -use std::mem::drop; - -struct SomeStruct; - -fn main() { - drop(&SomeStruct); - - let mut owned1 = SomeStruct; - drop(&owned1); - drop(&&owned1); - drop(&mut owned1); - drop(owned1); //OK - - let reference1 = &SomeStruct; - drop(reference1); - - let reference2 = &mut SomeStruct; - drop(reference2); - - let ref reference3 = SomeStruct; - drop(reference3); -} - -#[allow(dead_code)] -fn test_generic_fn_drop(val: T) { - drop(&val); - drop(val); //OK -} - -#[allow(dead_code)] -fn test_similarly_named_function() { - fn drop(_val: T) {} - drop(&SomeStruct); //OK; call to unrelated function which happens to have the same name - std::mem::drop(&SomeStruct); -} - -#[derive(Copy, Clone)] -pub struct Error; -fn produce_half_owl_error() -> Result<(), Error> { - Ok(()) -} - -fn produce_half_owl_ok() -> Result { - Ok(true) -} - -#[allow(dead_code)] -fn test_owl_result() -> Result<(), ()> { - produce_half_owl_error().map_err(|_| ())?; - produce_half_owl_ok().map(|_| ())?; - // the following should not be linted, - // we should not force users to use toilet closures - // to produce owl results when drop is more convenient - produce_half_owl_error().map_err(drop)?; - produce_half_owl_ok().map_err(drop)?; - Ok(()) -} - -#[allow(dead_code)] -fn test_owl_result_2() -> Result { - produce_half_owl_error().map_err(|_| ())?; - produce_half_owl_ok().map(|_| ())?; - // the following should not be linted, - // we should not force users to use toilet closures - // to produce owl results when drop is more convenient - produce_half_owl_error().map_err(drop)?; - produce_half_owl_ok().map(drop)?; - Ok(1) -} - -#[allow(unused)] -#[allow(clippy::unit_cmp)] -fn issue10122(x: u8) { - // This is a function which returns a reference and has a side-effect, which means - // that calling drop() on the function is considered an idiomatic way of achieving the side-effect - // in a match arm. - fn println_and(t: &T) -> &T { - println!("foo"); - t - } - - match x { - 0 => drop(println_and(&12)), // Don't lint (copy type), we only care about side-effects - 1 => drop(println_and(&String::new())), // Don't lint (no copy type), we only care about side-effects - 2 => { - drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block - }, - 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - 4 => drop(&2), // Lint, not a fn/method call - _ => (), - } -} diff --git a/src/tools/clippy/tests/ui/drop_ref.stderr b/src/tools/clippy/tests/ui/drop_ref.stderr deleted file mode 100644 index 293b9f6de832d..0000000000000 --- a/src/tools/clippy/tests/ui/drop_ref.stderr +++ /dev/null @@ -1,147 +0,0 @@ -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:11:5 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:11:10 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^ - = note: `-D clippy::drop-ref` implied by `-D warnings` - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:14:5 - | -LL | drop(&owned1); - | ^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:14:10 - | -LL | drop(&owned1); - | ^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:15:5 - | -LL | drop(&&owned1); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/drop_ref.rs:15:10 - | -LL | drop(&&owned1); - | ^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:16:5 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:16:10 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:20:5 - | -LL | drop(reference1); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:20:10 - | -LL | drop(reference1); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:23:5 - | -LL | drop(reference2); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:23:10 - | -LL | drop(reference2); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:26:5 - | -LL | drop(reference3); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:26:10 - | -LL | drop(reference3); - | ^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:31:5 - | -LL | drop(&val); - | ^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/drop_ref.rs:31:10 - | -LL | drop(&val); - | ^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:39:5 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:39:20 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:91:13 - | -LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:91:18 - | -LL | drop(println_and(&13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:93:14 - | -LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:93:19 - | -LL | 3 if drop(println_and(&14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a reference instead of an owned value. Dropping a reference does nothing - --> $DIR/drop_ref.rs:94:14 - | -LL | 4 => drop(&2), // Lint, not a fn/method call - | ^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:94:19 - | -LL | 4 => drop(&2), // Lint, not a fn/method call - | ^^ - -error: aborting due to 12 previous errors - diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index 5076f61334d67..42429ec9f71db 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -28,6 +28,7 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] #![allow(drop_bounds)] +#![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -68,6 +69,7 @@ #![warn(clippy::recursive_format_impl)] #![warn(clippy::invisible_characters)] #![warn(drop_bounds)] +#![warn(drop_ref)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 64bc1ca7116c5..16a643bab2797 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -28,6 +28,7 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] #![allow(drop_bounds)] +#![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -68,6 +69,7 @@ #![warn(clippy::to_string_in_display)] #![warn(clippy::zero_width_space)] #![warn(clippy::drop_bounds)] +#![warn(clippy::drop_ref)] #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index 27a0263292ef1..a7fdb8812f062 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:42:9 + --> $DIR/rename.rs:43:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,250 +7,256 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:43:9 + --> $DIR/rename.rs:44:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:44:9 + --> $DIR/rename.rs:45:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` +error: lint `clippy::drop_ref` has been renamed to `drop_ref` + --> $DIR/rename.rs:72:9 + | +LL | #![warn(clippy::drop_ref)] + | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` + error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 42 previous errors +error: aborting due to 43 previous errors From 78ed1ef8b3acab4195adc1e84eeedc5beb60da06 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 27 Mar 2023 20:59:59 +0200 Subject: [PATCH 17/28] Uplift clippy::drop_copy to rustc --- compiler/rustc_lint/messages.ftl | 3 + .../rustc_lint/src/drop_forget_useless.rs | 32 ++++- compiler/rustc_lint/src/lints.rs | 8 ++ tests/ui/lint/drop_copy.rs | 79 +++++++++++ tests/ui/lint/drop_copy.stderr | 128 ++++++++++++++++++ 5 files changed, 248 insertions(+), 2 deletions(-) create mode 100644 tests/ui/lint/drop_copy.rs create mode 100644 tests/ui/lint/drop_copy.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index e9518f2dff93e..8c8c22ef3cc42 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -513,3 +513,6 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value .note = argument has type `{$arg_ty}` + +lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy`. + .note = argument has type `{$arg_ty}` diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs index 734a43af4a2d4..9b667a50fe1f6 100644 --- a/compiler/rustc_lint/src/drop_forget_useless.rs +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -1,7 +1,7 @@ use rustc_hir::{Arm, Expr, ExprKind, Node}; use rustc_span::sym; -use crate::{lints::DropRefDiag, LateContext, LateLintPass, LintContext}; +use crate::{lints::{DropRefDiag, DropCopyDiag}, LateContext, LateLintPass, LintContext}; declare_lint! { /// The `drop_ref` lint checks for calls to `std::mem::drop` with a reference @@ -31,7 +31,31 @@ declare_lint! { "calls to `std::mem::drop` with a reference instead of an owned value" } -declare_lint_pass!(DropForgetUseless => [DROP_REF]); +declare_lint! { + /// The `drop_copy` lint checks for calls to `std::mem::drop` with a value + /// that derives the Copy trait. + /// + /// ### Example + /// + /// ```rust + /// let x: i32 = 42; // i32 implements Copy + /// std::mem::drop(x); // A copy of x is passed to the function, leaving the + /// // original unaffected + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Calling `std::mem::drop` [does nothing for types that + /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the + /// value will be copied and moved into the function on invocation. + pub DROP_COPY, + Warn, + "calls to `std::mem::drop` with a value that implements Copy" +} + +declare_lint_pass!(DropForgetUseless => [DROP_REF, DROP_COPY]); impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { @@ -41,11 +65,15 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { && let Some(fn_name) = cx.tcx.get_diagnostic_name(def_id) { let arg_ty = cx.typeck_results().expr_ty(arg); + let is_copy = arg_ty.is_copy_modulo_regions(cx.tcx, cx.param_env); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); match fn_name { sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => { cx.emit_spanned_lint(DROP_REF, expr.span, DropRefDiag { arg_ty, note: arg.span }); }, + sym::mem_drop if is_copy && !drop_is_single_call_in_arm => { + cx.emit_spanned_lint(DROP_COPY, expr.span, DropCopyDiag { arg_ty, note: arg.span }); + } _ => return, }; } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 4470aa5b15b9a..fe24d25c76336 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -671,6 +671,14 @@ pub struct DropRefDiag<'a> { pub note: Span, } +#[derive(LintDiagnostic)] +#[diag(lint_drop_copy)] +pub struct DropCopyDiag<'a> { + pub arg_ty: Ty<'a>, + #[note] + pub note: Span, +} + // hidden_unicode_codepoints.rs #[derive(LintDiagnostic)] #[diag(lint_hidden_unicode_codepoints)] diff --git a/tests/ui/lint/drop_copy.rs b/tests/ui/lint/drop_copy.rs new file mode 100644 index 0000000000000..0adcd34505f0b --- /dev/null +++ b/tests/ui/lint/drop_copy.rs @@ -0,0 +1,79 @@ +// check-pass + +#![warn(drop_copy)] + +use std::mem::drop; +use std::vec::Vec; + +#[derive(Copy, Clone)] +struct SomeStruct; + +struct AnotherStruct { + x: u8, + y: u8, + z: Vec, +} + +impl Clone for AnotherStruct { + fn clone(&self) -> AnotherStruct { + AnotherStruct { + x: self.x, + y: self.y, + z: self.z.clone(), + } + } +} + +fn main() { + let s1 = SomeStruct {}; + let s2 = s1; + let s3 = &s1; + let mut s4 = s1; + let ref s5 = s1; + + drop(s1); //~ WARN calls to `std::mem::drop` + drop(s2); //~ WARN calls to `std::mem::drop` + drop(s3); //~ WARN calls to `std::mem::drop` + drop(s4); //~ WARN calls to `std::mem::drop` + drop(s5); //~ WARN calls to `std::mem::drop` + + let a1 = AnotherStruct { + x: 255, + y: 0, + z: vec![1, 2, 3], + }; + let a2 = &a1; + let mut a3 = a1.clone(); + let ref a4 = a1; + let a5 = a1.clone(); + + drop(a2); //~ WARN calls to `std::mem::drop` + drop(a3); + drop(a4); //~ WARN calls to `std::mem::drop` + drop(a5); +} + +#[allow(unused)] +#[allow(clippy::unit_cmp)] +fn issue9482(x: u8) { + fn println_and(t: T) -> T { + println!("foo"); + t + } + + match x { + // Don't lint (copy type), we only care about side-effects + 0 => drop(println_and(12)), + // Don't lint (no copy type), we only care about side-effects + 1 => drop(println_and(String::new())), + 2 => { + // Lint, even if we only care about the side-effect, it's already in a block + drop(println_and(13)); //~ WARN calls to `std::mem::drop` + }, + // Lint, idiomatic use is only in body of `Arm` + 3 if drop(println_and(14)) == () => (), //~ WARN calls to `std::mem::drop` + // Lint, not a fn/method call + 4 => drop(2),//~ WARN calls to `std::mem::drop` + _ => (), + } +} diff --git a/tests/ui/lint/drop_copy.stderr b/tests/ui/lint/drop_copy.stderr new file mode 100644 index 0000000000000..03d0b392e2b4b --- /dev/null +++ b/tests/ui/lint/drop_copy.stderr @@ -0,0 +1,128 @@ +warning: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_copy.rs:34:5 + | +LL | drop(s1); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_copy.rs:34:10 + | +LL | drop(s1); + | ^^ +note: the lint level is defined here + --> $DIR/drop_copy.rs:3:9 + | +LL | #![warn(drop_copy)] + | ^^^^^^^^^ + +warning: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_copy.rs:35:5 + | +LL | drop(s2); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_copy.rs:35:10 + | +LL | drop(s2); + | ^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_copy.rs:36:5 + | +LL | drop(s3); + | ^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_copy.rs:36:10 + | +LL | drop(s3); + | ^^ + = note: `#[warn(drop_ref)]` on by default + +warning: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_copy.rs:37:5 + | +LL | drop(s4); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_copy.rs:37:10 + | +LL | drop(s4); + | ^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_copy.rs:38:5 + | +LL | drop(s5); + | ^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_copy.rs:38:10 + | +LL | drop(s5); + | ^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_copy.rs:50:5 + | +LL | drop(a2); + | ^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_copy.rs:50:10 + | +LL | drop(a2); + | ^^ + +warning: calls to `std::mem::drop` with a reference instead of an owned value + --> $DIR/drop_copy.rs:52:5 + | +LL | drop(a4); + | ^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_copy.rs:52:10 + | +LL | drop(a4); + | ^^ + +warning: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_copy.rs:71:13 + | +LL | drop(println_and(13)); + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `i32` + --> $DIR/drop_copy.rs:71:18 + | +LL | drop(println_and(13)); + | ^^^^^^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_copy.rs:74:14 + | +LL | 3 if drop(println_and(14)) == () => (), + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `i32` + --> $DIR/drop_copy.rs:74:19 + | +LL | 3 if drop(println_and(14)) == () => (), + | ^^^^^^^^^^^^^^^ + +warning: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_copy.rs:76:14 + | +LL | 4 => drop(2), + | ^^^^^^^ + | +note: argument has type `i32` + --> $DIR/drop_copy.rs:76:19 + | +LL | 4 => drop(2), + | ^ + +warning: 10 warnings emitted + From e3d2a0a736cb0e73471ff33a725a3e50338eaa6f Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 27 Mar 2023 21:05:43 +0200 Subject: [PATCH 18/28] Drop uplifted clippy::drop_copy --- .../clippy/clippy_lints/src/declared_lints.rs | 1 - .../clippy_lints/src/drop_forget_ref.rs | 29 +----- .../clippy/clippy_lints/src/renamed_lints.rs | 1 + src/tools/clippy/tests/ui/drop_forget_copy.rs | 2 +- .../clippy/tests/ui/drop_forget_copy.stderr | 97 ++++++++++++++++--- .../tests/ui/multiple_unsafe_ops_per_block.rs | 2 +- src/tools/clippy/tests/ui/rename.fixed | 2 + src/tools/clippy/tests/ui/rename.rs | 2 + src/tools/clippy/tests/ui/rename.stderr | 94 +++++++++--------- .../tests/ui/unknown_clippy_lints.fixed | 2 +- .../tests/ui/unknown_clippy_lints.stderr | 2 +- 11 files changed, 146 insertions(+), 88 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/declared_lints.rs b/src/tools/clippy/clippy_lints/src/declared_lints.rs index ac922d2024e4f..9d0311ffadbc6 100644 --- a/src/tools/clippy/clippy_lints/src/declared_lints.rs +++ b/src/tools/clippy/clippy_lints/src/declared_lints.rs @@ -131,7 +131,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::doc::NEEDLESS_DOCTEST_MAIN_INFO, crate::doc::UNNECESSARY_SAFETY_DOC_INFO, crate::double_parens::DOUBLE_PARENS_INFO, - crate::drop_forget_ref::DROP_COPY_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, diff --git a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs index 55d7c3247cddf..9858243f3397b 100644 --- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs +++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs @@ -29,28 +29,6 @@ declare_clippy_lint! { "calls to `std::mem::forget` with a reference instead of an owned value" } -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::drop` with a value - /// that derives the Copy trait - /// - /// ### Why is this bad? - /// Calling `std::mem::drop` [does nothing for types that - /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html), since the - /// value will be copied and moved into the function on invocation. - /// - /// ### Example - /// ```rust - /// let x: i32 = 42; // i32 implements Copy - /// std::mem::drop(x) // A copy of x is passed to the function, leaving the - /// // original unaffected - /// ``` - #[clippy::version = "pre 1.29.0"] - pub DROP_COPY, - correctness, - "calls to `std::mem::drop` with a value that implements Copy" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::forget` with a value that @@ -150,8 +128,6 @@ declare_clippy_lint! { const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ Forgetting a reference does nothing"; -const DROP_COPY_SUMMARY: &str = "calls to `std::mem::drop` with a value that implements `Copy`. \ - Dropping a copy leaves the original intact"; const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ Forgetting a copy leaves the original intact"; const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ @@ -161,7 +137,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t declare_lint_pass!(DropForgetRef => [ FORGET_REF, - DROP_COPY, FORGET_COPY, DROP_NON_DROP, FORGET_NON_DROP, @@ -179,10 +154,10 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref + // early return for uplifted lints: drop_ref, drop_copy sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY), - sym::mem_drop if is_copy && !drop_is_single_call_in_arm => (DROP_COPY, DROP_COPY_SUMMARY), + sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { span_lint_and_help( diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs index 8dac4ab8d378e..bb6d68fe1c030 100644 --- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs +++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs @@ -31,6 +31,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::to_string_in_display", "clippy::recursive_format_impl"), ("clippy::zero_width_space", "clippy::invisible_characters"), ("clippy::drop_bounds", "drop_bounds"), + ("clippy::drop_copy", "drop_copy"), ("clippy::drop_ref", "drop_ref"), ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.rs b/src/tools/clippy/tests/ui/drop_forget_copy.rs index 04293eb16bb79..f723b03a979cf 100644 --- a/src/tools/clippy/tests/ui/drop_forget_copy.rs +++ b/src/tools/clippy/tests/ui/drop_forget_copy.rs @@ -1,4 +1,4 @@ -#![warn(clippy::drop_copy, clippy::forget_copy)] +#![warn(drop_copy, clippy::forget_copy)] #![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)] use std::mem::{drop, forget}; diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.stderr b/src/tools/clippy/tests/ui/drop_forget_copy.stderr index df492d9b3d2ef..4adb59bbd2576 100644 --- a/src/tools/clippy/tests/ui/drop_forget_copy.stderr +++ b/src/tools/clippy/tests/ui/drop_forget_copy.stderr @@ -1,4 +1,4 @@ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:33:5 | LL | drop(s1); @@ -9,9 +9,9 @@ note: argument has type `SomeStruct` | LL | drop(s1); | ^^ - = note: `-D clippy::drop-copy` implied by `-D warnings` + = note: `-D clippy::drop-non-drop` implied by `-D warnings` -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:34:5 | LL | drop(s2); @@ -23,7 +23,7 @@ note: argument has type `SomeStruct` LL | drop(s2); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:35:5 | LL | drop(s3); @@ -35,7 +35,7 @@ note: argument has type `&SomeStruct` LL | drop(s3); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:36:5 | LL | drop(s4); @@ -47,7 +47,7 @@ note: argument has type `SomeStruct` LL | drop(s4); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:37:5 | LL | drop(s5); @@ -96,7 +96,7 @@ note: argument has type `SomeStruct` LL | forget(s4); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:55:5 | LL | drop(a2); @@ -108,7 +108,7 @@ note: argument has type `&AnotherStruct` LL | drop(a2); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:57:5 | LL | drop(a4); @@ -120,7 +120,7 @@ note: argument has type `&AnotherStruct` LL | drop(a4); | ^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:80:13 | LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block @@ -132,7 +132,7 @@ note: argument has type `i32` LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block | ^^^^^^^^^^^^^^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:82:14 | LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` @@ -144,7 +144,7 @@ note: argument has type `i32` LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` | ^^^^^^^^^^^^^^^ -error: calls to `std::mem::drop` with a value that implements `Copy`. Dropping a copy leaves the original intact +error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:83:14 | LL | 4 => drop(2), // Lint, not a fn/method call @@ -156,5 +156,78 @@ note: argument has type `i32` LL | 4 => drop(2), // Lint, not a fn/method call | ^ -error: aborting due to 13 previous errors +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:33:5 + | +LL | drop(s1); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_forget_copy.rs:33:10 + | +LL | drop(s1); + | ^^ + = note: `-D drop-copy` implied by `-D warnings` + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:34:5 + | +LL | drop(s2); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_forget_copy.rs:34:10 + | +LL | drop(s2); + | ^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:36:5 + | +LL | drop(s4); + | ^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/drop_forget_copy.rs:36:10 + | +LL | drop(s4); + | ^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:80:13 + | +LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `i32` + --> $DIR/drop_forget_copy.rs:80:18 + | +LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block + | ^^^^^^^^^^^^^^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:82:14 + | +LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` + | ^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `i32` + --> $DIR/drop_forget_copy.rs:82:19 + | +LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` + | ^^^^^^^^^^^^^^^ + +error: calls to `std::mem::drop` with a value that implements `Copy`. + --> $DIR/drop_forget_copy.rs:83:14 + | +LL | 4 => drop(2), // Lint, not a fn/method call + | ^^^^^^^ + | +note: argument has type `i32` + --> $DIR/drop_forget_copy.rs:83:19 + | +LL | 4 => drop(2), // Lint, not a fn/method call + | ^ + +error: aborting due to 19 previous errors diff --git a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs index 9082f1675a875..43cfc0b2762eb 100644 --- a/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs +++ b/src/tools/clippy/tests/ui/multiple_unsafe_ops_per_block.rs @@ -2,7 +2,7 @@ #![allow(unused)] #![allow(deref_nullptr)] #![allow(clippy::unnecessary_operation)] -#![allow(clippy::drop_copy)] +#![allow(drop_copy)] #![warn(clippy::multiple_unsafe_ops_per_block)] extern crate proc_macros; diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index 42429ec9f71db..ac8beb81f96a4 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -28,6 +28,7 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] #![allow(drop_bounds)] +#![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] @@ -69,6 +70,7 @@ #![warn(clippy::recursive_format_impl)] #![warn(clippy::invisible_characters)] #![warn(drop_bounds)] +#![warn(drop_copy)] #![warn(drop_ref)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 16a643bab2797..c8be7c1b0622d 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -28,6 +28,7 @@ #![allow(clippy::recursive_format_impl)] #![allow(clippy::invisible_characters)] #![allow(drop_bounds)] +#![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] #![allow(array_into_iter)] @@ -69,6 +70,7 @@ #![warn(clippy::to_string_in_display)] #![warn(clippy::zero_width_space)] #![warn(clippy::drop_bounds)] +#![warn(clippy::drop_copy)] #![warn(clippy::drop_ref)] #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index a7fdb8812f062..21d632348a520 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:43:9 + --> $DIR/rename.rs:44:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,256 +7,262 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:44:9 + --> $DIR/rename.rs:45:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` +error: lint `clippy::drop_copy` has been renamed to `drop_copy` + --> $DIR/rename.rs:73:9 + | +LL | #![warn(clippy::drop_copy)] + | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` + error: lint `clippy::drop_ref` has been renamed to `drop_ref` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 43 previous errors +error: aborting due to 44 previous errors diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed index 4249ff8a958d1..6f7c5bdd0274c 100644 --- a/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed +++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.fixed @@ -10,7 +10,7 @@ #[warn(clippy::unnecessary_cast)] #[warn(clippy::useless_transmute)] // Shouldn't suggest rustc lint name(`dead_code`) -#[warn(clippy::drop_copy)] +#[warn(clippy::eq_op)] // Shouldn't suggest removed/deprecated clippy lint name(`unused_collect`) #[warn(clippy::unused_self)] // Shouldn't suggest renamed clippy lint name(`const_static_lifetime`) diff --git a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr index 421bf5ffa9a70..584c428932fee 100644 --- a/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr +++ b/src/tools/clippy/tests/ui/unknown_clippy_lints.stderr @@ -34,7 +34,7 @@ error: unknown lint: `clippy::dead_cod` --> $DIR/unknown_clippy_lints.rs:13:8 | LL | #[warn(clippy::dead_cod)] - | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::drop_copy` + | ^^^^^^^^^^^^^^^^ help: did you mean: `clippy::eq_op` error: unknown lint: `clippy::unused_colle` --> $DIR/unknown_clippy_lints.rs:15:8 From b91a4e9cba506b258e081be52259b8d3690fc47c Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 28 Mar 2023 18:31:21 +0200 Subject: [PATCH 19/28] Uplift clippy::forget_ref to rustc --- compiler/rustc_lint/messages.ftl | 3 + .../rustc_lint/src/drop_forget_useless.rs | 30 ++++- compiler/rustc_lint/src/lints.rs | 8 ++ tests/ui/lint/forget_ref.rs | 39 ++++++ tests/ui/lint/forget_ref.stderr | 115 ++++++++++++++++++ 5 files changed, 193 insertions(+), 2 deletions(-) create mode 100644 tests/ui/lint/forget_ref.rs create mode 100644 tests/ui/lint/forget_ref.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 8c8c22ef3cc42..aba647270885d 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -516,3 +516,6 @@ lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned v lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy`. .note = argument has type `{$arg_ty}` + +lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value + .note = argument has type `{$arg_ty}` diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs index 9b667a50fe1f6..32594178fe81f 100644 --- a/compiler/rustc_lint/src/drop_forget_useless.rs +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -1,7 +1,7 @@ use rustc_hir::{Arm, Expr, ExprKind, Node}; use rustc_span::sym; -use crate::{lints::{DropRefDiag, DropCopyDiag}, LateContext, LateLintPass, LintContext}; +use crate::{lints::{DropRefDiag, DropCopyDiag, ForgetRefDiag}, LateContext, LateLintPass, LintContext}; declare_lint! { /// The `drop_ref` lint checks for calls to `std::mem::drop` with a reference @@ -31,6 +31,29 @@ declare_lint! { "calls to `std::mem::drop` with a reference instead of an owned value" } +declare_lint! { + /// The `forget_ref` lint checks for calls to `std::mem::forget` with a reference + /// instead of an owned value. + /// + /// ### Example + /// + /// ```rust + /// let x = Box::new(1); + /// std::mem::forget(&x); // Should have been forget(x), x will still be dropped + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Calling `forget` on a reference will only forget the + /// reference itself, which is a no-op. It will not forget the underlying + /// referenced value, which is likely what was intended. + pub FORGET_REF, + Warn, + "calls to `std::mem::forget` with a reference instead of an owned value" +} + declare_lint! { /// The `drop_copy` lint checks for calls to `std::mem::drop` with a value /// that derives the Copy trait. @@ -55,7 +78,7 @@ declare_lint! { "calls to `std::mem::drop` with a value that implements Copy" } -declare_lint_pass!(DropForgetUseless => [DROP_REF, DROP_COPY]); +declare_lint_pass!(DropForgetUseless => [DROP_REF, FORGET_REF, DROP_COPY]); impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { @@ -71,6 +94,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => { cx.emit_spanned_lint(DROP_REF, expr.span, DropRefDiag { arg_ty, note: arg.span }); }, + sym::mem_forget if arg_ty.is_ref() => { + cx.emit_spanned_lint(FORGET_REF, expr.span, ForgetRefDiag { arg_ty, note: arg.span }); + }, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => { cx.emit_spanned_lint(DROP_COPY, expr.span, DropCopyDiag { arg_ty, note: arg.span }); } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index fe24d25c76336..d3702f5b21826 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -679,6 +679,14 @@ pub struct DropCopyDiag<'a> { pub note: Span, } +#[derive(LintDiagnostic)] +#[diag(lint_forget_ref)] +pub struct ForgetRefDiag<'a> { + pub arg_ty: Ty<'a>, + #[note] + pub note: Span, +} + // hidden_unicode_codepoints.rs #[derive(LintDiagnostic)] #[diag(lint_hidden_unicode_codepoints)] diff --git a/tests/ui/lint/forget_ref.rs b/tests/ui/lint/forget_ref.rs new file mode 100644 index 0000000000000..13f6d4be3d153 --- /dev/null +++ b/tests/ui/lint/forget_ref.rs @@ -0,0 +1,39 @@ +// check-pass + +#![warn(forget_ref)] + +use std::mem::forget; + +struct SomeStruct; + +fn main() { + forget(&SomeStruct); //~ WARN calls to `std::mem::forget` + + let mut owned = SomeStruct; + forget(&owned); //~ WARN calls to `std::mem::forget` + forget(&&owned); //~ WARN calls to `std::mem::forget` + forget(&mut owned); //~ WARN calls to `std::mem::forget` + forget(owned); + + let reference1 = &SomeStruct; + forget(&*reference1); //~ WARN calls to `std::mem::forget` + + let reference2 = &mut SomeStruct; + forget(reference2); //~ WARN calls to `std::mem::forget` + + let ref reference3 = SomeStruct; + forget(reference3); //~ WARN calls to `std::mem::forget` +} + +#[allow(dead_code)] +fn test_generic_fn_forget(val: T) { + forget(&val); //~ WARN calls to `std::mem::forget` + forget(val); +} + +#[allow(dead_code)] +fn test_similarly_named_function() { + fn forget(_val: T) {} + forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name + std::mem::forget(&SomeStruct); //~ WARN calls to `std::mem::forget` +} diff --git a/tests/ui/lint/forget_ref.stderr b/tests/ui/lint/forget_ref.stderr new file mode 100644 index 0000000000000..abb45443e4e9d --- /dev/null +++ b/tests/ui/lint/forget_ref.stderr @@ -0,0 +1,115 @@ +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:10:5 + | +LL | forget(&SomeStruct); + | ^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_ref.rs:10:12 + | +LL | forget(&SomeStruct); + | ^^^^^^^^^^^ +note: the lint level is defined here + --> $DIR/forget_ref.rs:3:9 + | +LL | #![warn(forget_ref)] + | ^^^^^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:13:5 + | +LL | forget(&owned); + | ^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_ref.rs:13:12 + | +LL | forget(&owned); + | ^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:14:5 + | +LL | forget(&&owned); + | ^^^^^^^^^^^^^^^ + | +note: argument has type `&&SomeStruct` + --> $DIR/forget_ref.rs:14:12 + | +LL | forget(&&owned); + | ^^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:15:5 + | +LL | forget(&mut owned); + | ^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&mut SomeStruct` + --> $DIR/forget_ref.rs:15:12 + | +LL | forget(&mut owned); + | ^^^^^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:19:5 + | +LL | forget(&*reference1); + | ^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_ref.rs:19:12 + | +LL | forget(&*reference1); + | ^^^^^^^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:22:5 + | +LL | forget(reference2); + | ^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&mut SomeStruct` + --> $DIR/forget_ref.rs:22:12 + | +LL | forget(reference2); + | ^^^^^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:25:5 + | +LL | forget(reference3); + | ^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_ref.rs:25:12 + | +LL | forget(reference3); + | ^^^^^^^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:30:5 + | +LL | forget(&val); + | ^^^^^^^^^^^^ + | +note: argument has type `&T` + --> $DIR/forget_ref.rs:30:12 + | +LL | forget(&val); + | ^^^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_ref.rs:38:5 + | +LL | std::mem::forget(&SomeStruct); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_ref.rs:38:22 + | +LL | std::mem::forget(&SomeStruct); + | ^^^^^^^^^^^ + +warning: 9 warnings emitted + From bc07f579050a6fb38bc7d0f232fa53ea1dd69f20 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 28 Mar 2023 18:40:54 +0200 Subject: [PATCH 20/28] Drop uplifted clippy::forget_ref --- .../clippy/clippy_lints/src/declared_lints.rs | 1 - .../clippy_lints/src/drop_forget_ref.rs | 29 +---- .../clippy/clippy_lints/src/renamed_lints.rs | 1 + src/tools/clippy/tests/ui/drop_forget_copy.rs | 2 +- .../clippy/tests/ui/drop_forget_copy.stderr | 62 +++++++++- src/tools/clippy/tests/ui/forget_ref.rs | 50 -------- src/tools/clippy/tests/ui/forget_ref.stderr | 111 ------------------ src/tools/clippy/tests/ui/rename.fixed | 2 + src/tools/clippy/tests/ui/rename.rs | 2 + src/tools/clippy/tests/ui/rename.stderr | 96 ++++++++------- 10 files changed, 120 insertions(+), 236 deletions(-) delete mode 100644 src/tools/clippy/tests/ui/forget_ref.rs delete mode 100644 src/tools/clippy/tests/ui/forget_ref.stderr diff --git a/src/tools/clippy/clippy_lints/src/declared_lints.rs b/src/tools/clippy/clippy_lints/src/declared_lints.rs index 9d0311ffadbc6..a69106871f0a3 100644 --- a/src/tools/clippy/clippy_lints/src/declared_lints.rs +++ b/src/tools/clippy/clippy_lints/src/declared_lints.rs @@ -134,7 +134,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::drop_forget_ref::DROP_NON_DROP_INFO, crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, - crate::drop_forget_ref::FORGET_REF_INFO, crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO, crate::duplicate_mod::DUPLICATE_MOD_INFO, crate::else_if_without_else::ELSE_IF_WITHOUT_ELSE_INFO, diff --git a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs index 9858243f3397b..23ec7f15aaa73 100644 --- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs +++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs @@ -7,28 +7,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::forget` with a reference - /// instead of an owned value. - /// - /// ### Why is this bad? - /// Calling `forget` on a reference will only forget the - /// reference itself, which is a no-op. It will not forget the underlying - /// referenced - /// value, which is likely what was intended. - /// - /// ### Example - /// ```rust - /// let x = Box::new(1); - /// std::mem::forget(&x) // Should have been forget(x), x will still be dropped - /// ``` - #[clippy::version = "pre 1.29.0"] - pub FORGET_REF, - correctness, - "calls to `std::mem::forget` with a reference instead of an owned value" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::forget` with a value that @@ -126,8 +104,6 @@ declare_clippy_lint! { "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" } -const FORGET_REF_SUMMARY: &str = "calls to `std::mem::forget` with a reference instead of an owned value. \ - Forgetting a reference does nothing"; const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ Forgetting a copy leaves the original intact"; const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ @@ -136,7 +112,6 @@ const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value t Forgetting such a type is the same as dropping it"; declare_lint_pass!(DropForgetRef => [ - FORGET_REF, FORGET_COPY, DROP_NON_DROP, FORGET_NON_DROP, @@ -154,9 +129,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, drop_copy + // early return for uplifted lints: drop_ref, drop_copy, forget_ref sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, - sym::mem_forget if arg_ty.is_ref() => (FORGET_REF, FORGET_REF_SUMMARY), + sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs index bb6d68fe1c030..839074ae5833f 100644 --- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs +++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs @@ -36,6 +36,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), + ("clippy::forget_ref", "forget_ref"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), ("clippy::invalid_ref", "invalid_value"), diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.rs b/src/tools/clippy/tests/ui/drop_forget_copy.rs index f723b03a979cf..ebe60ebbd304d 100644 --- a/src/tools/clippy/tests/ui/drop_forget_copy.rs +++ b/src/tools/clippy/tests/ui/drop_forget_copy.rs @@ -1,5 +1,5 @@ #![warn(drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, drop_ref, clippy::forget_ref, unused_mut)] +#![allow(clippy::toplevel_ref_arg, drop_ref, forget_ref, unused_mut)] use std::mem::{drop, forget}; use std::vec::Vec; diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.stderr b/src/tools/clippy/tests/ui/drop_forget_copy.stderr index 4adb59bbd2576..a24c4f0f0a5c6 100644 --- a/src/tools/clippy/tests/ui/drop_forget_copy.stderr +++ b/src/tools/clippy/tests/ui/drop_forget_copy.stderr @@ -84,6 +84,18 @@ note: argument has type `SomeStruct` LL | forget(s2); | ^^ +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:41:5 + | +LL | forget(s3); + | ^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_forget_copy.rs:41:12 + | +LL | forget(s3); + | ^^ + error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact --> $DIR/drop_forget_copy.rs:42:5 | @@ -96,6 +108,18 @@ note: argument has type `SomeStruct` LL | forget(s4); | ^^ +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:43:5 + | +LL | forget(s5); + | ^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/drop_forget_copy.rs:43:12 + | +LL | forget(s5); + | ^^ + error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:55:5 | @@ -120,6 +144,42 @@ note: argument has type `&AnotherStruct` LL | drop(a4); | ^^ +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:60:5 + | +LL | forget(a2); + | ^^^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_forget_copy.rs:60:12 + | +LL | forget(a2); + | ^^ + +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:62:5 + | +LL | forget(a3); + | ^^^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_forget_copy.rs:62:12 + | +LL | forget(a3); + | ^^ + +error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact + --> $DIR/drop_forget_copy.rs:63:5 + | +LL | forget(a4); + | ^^^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/drop_forget_copy.rs:63:12 + | +LL | forget(a4); + | ^^ + error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes --> $DIR/drop_forget_copy.rs:80:13 | @@ -229,5 +289,5 @@ note: argument has type `i32` LL | 4 => drop(2), // Lint, not a fn/method call | ^ -error: aborting due to 19 previous errors +error: aborting due to 24 previous errors diff --git a/src/tools/clippy/tests/ui/forget_ref.rs b/src/tools/clippy/tests/ui/forget_ref.rs deleted file mode 100644 index 031b415f56ff6..0000000000000 --- a/src/tools/clippy/tests/ui/forget_ref.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![warn(clippy::forget_ref)] -#![allow(clippy::toplevel_ref_arg)] -#![allow(clippy::unnecessary_wraps, clippy::forget_non_drop)] -#![allow(clippy::borrow_deref_ref)] - -use std::mem::forget; - -struct SomeStruct; - -fn main() { - forget(&SomeStruct); - - let mut owned = SomeStruct; - forget(&owned); - forget(&&owned); - forget(&mut owned); - forget(owned); //OK - - let reference1 = &SomeStruct; - forget(&*reference1); - - let reference2 = &mut SomeStruct; - forget(reference2); - - let ref reference3 = SomeStruct; - forget(reference3); -} - -#[allow(dead_code)] -fn test_generic_fn_forget(val: T) { - forget(&val); - forget(val); //OK -} - -#[allow(dead_code)] -fn test_similarly_named_function() { - fn forget(_val: T) {} - forget(&SomeStruct); //OK; call to unrelated function which happens to have the same name - std::mem::forget(&SomeStruct); -} - -#[derive(Copy, Clone)] -pub struct Error; -fn produce_half_owl_error() -> Result<(), Error> { - Ok(()) -} - -fn produce_half_owl_ok() -> Result { - Ok(true) -} diff --git a/src/tools/clippy/tests/ui/forget_ref.stderr b/src/tools/clippy/tests/ui/forget_ref.stderr deleted file mode 100644 index 011cdefc665f8..0000000000000 --- a/src/tools/clippy/tests/ui/forget_ref.stderr +++ /dev/null @@ -1,111 +0,0 @@ -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:11:5 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:11:12 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^ - = note: `-D clippy::forget-ref` implied by `-D warnings` - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:14:5 - | -LL | forget(&owned); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:14:12 - | -LL | forget(&owned); - | ^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:15:5 - | -LL | forget(&&owned); - | ^^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/forget_ref.rs:15:12 - | -LL | forget(&&owned); - | ^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:16:5 - | -LL | forget(&mut owned); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:16:12 - | -LL | forget(&mut owned); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:20:5 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:20:12 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:23:5 - | -LL | forget(reference2); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:23:12 - | -LL | forget(reference2); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:26:5 - | -LL | forget(reference3); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:26:12 - | -LL | forget(reference3); - | ^^^^^^^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:31:5 - | -LL | forget(&val); - | ^^^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/forget_ref.rs:31:12 - | -LL | forget(&val); - | ^^^^ - -error: calls to `std::mem::forget` with a reference instead of an owned value. Forgetting a reference does nothing - --> $DIR/forget_ref.rs:39:5 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:39:22 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^ - -error: aborting due to 9 previous errors - diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index ac8beb81f96a4..6e900d13a891c 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -31,6 +31,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -75,6 +76,7 @@ #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] +#![warn(forget_ref)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] #![warn(invalid_value)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index c8be7c1b0622d..4848cbfbea8dc 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -31,6 +31,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] #![allow(invalid_value)] @@ -75,6 +76,7 @@ #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] +#![warn(clippy::forget_ref)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] #![warn(clippy::invalid_ref)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index 21d632348a520..f1cb900cc04da 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:44:9 + --> $DIR/rename.rs:45:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,262 +7,268 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `drop_copy` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` error: lint `clippy::drop_ref` has been renamed to `drop_ref` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` +error: lint `clippy::forget_ref` has been renamed to `forget_ref` + --> $DIR/rename.rs:79:9 + | +LL | #![warn(clippy::forget_ref)] + | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_ref` + error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:80:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 44 previous errors +error: aborting due to 45 previous errors From 1e4f98ab142cf660dc60beaf29c3dc0d5be72059 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 28 Mar 2023 18:47:37 +0200 Subject: [PATCH 21/28] Uplift clippy::forget_copy to rustc --- compiler/rustc_lint/messages.ftl | 3 + .../rustc_lint/src/drop_forget_useless.rs | 38 ++++++- compiler/rustc_lint/src/lints.rs | 8 ++ tests/ui/lint/forget_copy.rs | 56 ++++++++++ tests/ui/lint/forget_copy.stderr | 104 ++++++++++++++++++ 5 files changed, 207 insertions(+), 2 deletions(-) create mode 100644 tests/ui/lint/forget_copy.rs create mode 100644 tests/ui/lint/forget_copy.stderr diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index aba647270885d..d0a4430db139f 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -519,3 +519,6 @@ lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy`. lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value .note = argument has type `{$arg_ty}` + +lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy`. + .note = argument has type `{$arg_ty}` diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs index 32594178fe81f..e72439439a4b5 100644 --- a/compiler/rustc_lint/src/drop_forget_useless.rs +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -1,7 +1,10 @@ use rustc_hir::{Arm, Expr, ExprKind, Node}; use rustc_span::sym; -use crate::{lints::{DropRefDiag, DropCopyDiag, ForgetRefDiag}, LateContext, LateLintPass, LintContext}; +use crate::{ + lints::{DropCopyDiag, DropRefDiag, ForgetCopyDiag, ForgetRefDiag}, + LateContext, LateLintPass, LintContext, +}; declare_lint! { /// The `drop_ref` lint checks for calls to `std::mem::drop` with a reference @@ -78,7 +81,35 @@ declare_lint! { "calls to `std::mem::drop` with a value that implements Copy" } -declare_lint_pass!(DropForgetUseless => [DROP_REF, FORGET_REF, DROP_COPY]); +declare_lint! { + /// The `forget_copy` lint checks for calls to `std::mem::forget` with a value + /// that derives the Copy trait. + /// + /// ### Example + /// + /// ```rust + /// let x: i32 = 42; // i32 implements Copy + /// std::mem::forget(x); // A copy of x is passed to the function, leaving the + /// // original unaffected + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Calling `std::mem::forget` [does nothing for types that + /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the + /// value will be copied and moved into the function on invocation. + /// + /// An alternative, but also valid, explanation is that Copy types do not + /// implement the Drop trait, which means they have no destructors. Without a + /// destructor, there is nothing for `std::mem::forget` to ignore. + pub FORGET_COPY, + Warn, + "calls to `std::mem::forget` with a value that implements Copy" +} + +declare_lint_pass!(DropForgetUseless => [DROP_REF, FORGET_REF, DROP_COPY, FORGET_COPY]); impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) { @@ -100,6 +131,9 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { sym::mem_drop if is_copy && !drop_is_single_call_in_arm => { cx.emit_spanned_lint(DROP_COPY, expr.span, DropCopyDiag { arg_ty, note: arg.span }); } + sym::mem_forget if is_copy => { + cx.emit_spanned_lint(FORGET_COPY, expr.span, ForgetCopyDiag { arg_ty, note: arg.span }); + } _ => return, }; } diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index d3702f5b21826..d6e10eb806878 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -687,6 +687,14 @@ pub struct ForgetRefDiag<'a> { pub note: Span, } +#[derive(LintDiagnostic)] +#[diag(lint_forget_copy)] +pub struct ForgetCopyDiag<'a> { + pub arg_ty: Ty<'a>, + #[note] + pub note: Span, +} + // hidden_unicode_codepoints.rs #[derive(LintDiagnostic)] #[diag(lint_hidden_unicode_codepoints)] diff --git a/tests/ui/lint/forget_copy.rs b/tests/ui/lint/forget_copy.rs new file mode 100644 index 0000000000000..a6b17b76971f2 --- /dev/null +++ b/tests/ui/lint/forget_copy.rs @@ -0,0 +1,56 @@ +// check-pass + +#![warn(forget_copy)] + +use std::mem::forget; +use std::vec::Vec; + +#[derive(Copy, Clone)] +struct SomeStruct; + +struct AnotherStruct { + x: u8, + y: u8, + z: Vec, +} + +impl Clone for AnotherStruct { + fn clone(&self) -> AnotherStruct { + AnotherStruct { + x: self.x, + y: self.y, + z: self.z.clone(), + } + } +} + +fn main() { + let s1 = SomeStruct {}; + let s2 = s1; + let s3 = &s1; + let mut s4 = s1; + let ref s5 = s1; + + forget(s1); //~ WARN calls to `std::mem::forget` + forget(s2); //~ WARN calls to `std::mem::forget` + forget(s3); //~ WARN calls to `std::mem::forget` + forget(s4); //~ WARN calls to `std::mem::forget` + forget(s5); //~ WARN calls to `std::mem::forget` + + let a1 = AnotherStruct { + x: 255, + y: 0, + z: vec![1, 2, 3], + }; + let a2 = &a1; + let mut a3 = a1.clone(); + let ref a4 = a1; + let a5 = a1.clone(); + + forget(a2); //~ WARN calls to `std::mem::forget` + let a3 = &a1; + forget(a3); //~ WARN calls to `std::mem::forget` + forget(a4); //~ WARN calls to `std::mem::forget` + let a5 = a1.clone(); + forget(a5); +} diff --git a/tests/ui/lint/forget_copy.stderr b/tests/ui/lint/forget_copy.stderr new file mode 100644 index 0000000000000..d33dfa0fd3d11 --- /dev/null +++ b/tests/ui/lint/forget_copy.stderr @@ -0,0 +1,104 @@ +warning: calls to `std::mem::forget` with a value that implements `Copy`. + --> $DIR/forget_copy.rs:34:5 + | +LL | forget(s1); + | ^^^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/forget_copy.rs:34:12 + | +LL | forget(s1); + | ^^ +note: the lint level is defined here + --> $DIR/forget_copy.rs:3:9 + | +LL | #![warn(forget_copy)] + | ^^^^^^^^^^^ + +warning: calls to `std::mem::forget` with a value that implements `Copy`. + --> $DIR/forget_copy.rs:35:5 + | +LL | forget(s2); + | ^^^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/forget_copy.rs:35:12 + | +LL | forget(s2); + | ^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_copy.rs:36:5 + | +LL | forget(s3); + | ^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_copy.rs:36:12 + | +LL | forget(s3); + | ^^ + = note: `#[warn(forget_ref)]` on by default + +warning: calls to `std::mem::forget` with a value that implements `Copy`. + --> $DIR/forget_copy.rs:37:5 + | +LL | forget(s4); + | ^^^^^^^^^^ + | +note: argument has type `SomeStruct` + --> $DIR/forget_copy.rs:37:12 + | +LL | forget(s4); + | ^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_copy.rs:38:5 + | +LL | forget(s5); + | ^^^^^^^^^^ + | +note: argument has type `&SomeStruct` + --> $DIR/forget_copy.rs:38:12 + | +LL | forget(s5); + | ^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_copy.rs:50:5 + | +LL | forget(a2); + | ^^^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/forget_copy.rs:50:12 + | +LL | forget(a2); + | ^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_copy.rs:52:5 + | +LL | forget(a3); + | ^^^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/forget_copy.rs:52:12 + | +LL | forget(a3); + | ^^ + +warning: calls to `std::mem::forget` with a reference instead of an owned value + --> $DIR/forget_copy.rs:53:5 + | +LL | forget(a4); + | ^^^^^^^^^^ + | +note: argument has type `&AnotherStruct` + --> $DIR/forget_copy.rs:53:12 + | +LL | forget(a4); + | ^^ + +warning: 8 warnings emitted + From d218a02d277e4b3c666ecca86a23d6a69c0414e4 Mon Sep 17 00:00:00 2001 From: Urgau Date: Tue, 28 Mar 2023 19:26:35 +0200 Subject: [PATCH 22/28] Drop uplifted clippy::forget_copy --- .../clippy/clippy_lints/src/declared_lints.rs | 1 - .../clippy_lints/src/drop_forget_ref.rs | 35 +-- .../clippy/clippy_lints/src/renamed_lints.rs | 1 + src/tools/clippy/tests/ui/drop_forget_copy.rs | 86 ----- .../clippy/tests/ui/drop_forget_copy.stderr | 293 ------------------ src/tools/clippy/tests/ui/mem_forget.rs | 2 +- src/tools/clippy/tests/ui/rename.fixed | 2 + src/tools/clippy/tests/ui/rename.rs | 2 + src/tools/clippy/tests/ui/rename.stderr | 98 +++--- 9 files changed, 60 insertions(+), 460 deletions(-) delete mode 100644 src/tools/clippy/tests/ui/drop_forget_copy.rs delete mode 100644 src/tools/clippy/tests/ui/drop_forget_copy.stderr diff --git a/src/tools/clippy/clippy_lints/src/declared_lints.rs b/src/tools/clippy/clippy_lints/src/declared_lints.rs index a69106871f0a3..a52fe749f2c49 100644 --- a/src/tools/clippy/clippy_lints/src/declared_lints.rs +++ b/src/tools/clippy/clippy_lints/src/declared_lints.rs @@ -132,7 +132,6 @@ pub(crate) static LINTS: &[&crate::LintInfo] = &[ crate::doc::UNNECESSARY_SAFETY_DOC_INFO, crate::double_parens::DOUBLE_PARENS_INFO, crate::drop_forget_ref::DROP_NON_DROP_INFO, - crate::drop_forget_ref::FORGET_COPY_INFO, crate::drop_forget_ref::FORGET_NON_DROP_INFO, crate::drop_forget_ref::UNDROPPED_MANUALLY_DROPS_INFO, crate::duplicate_mod::DUPLICATE_MOD_INFO, diff --git a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs index 23ec7f15aaa73..b2f7d026cc8b2 100644 --- a/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs +++ b/src/tools/clippy/clippy_lints/src/drop_forget_ref.rs @@ -7,34 +7,6 @@ use rustc_lint::{LateContext, LateLintPass}; use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_span::sym; -declare_clippy_lint! { - /// ### What it does - /// Checks for calls to `std::mem::forget` with a value that - /// derives the Copy trait - /// - /// ### Why is this bad? - /// Calling `std::mem::forget` [does nothing for types that - /// implement Copy](https://doc.rust-lang.org/std/mem/fn.drop.html) since the - /// value will be copied and moved into the function on invocation. - /// - /// An alternative, but also valid, explanation is that Copy types do not - /// implement - /// the Drop trait, which means they have no destructors. Without a destructor, - /// there - /// is nothing for `std::mem::forget` to ignore. - /// - /// ### Example - /// ```rust - /// let x: i32 = 42; // i32 implements Copy - /// std::mem::forget(x) // A copy of x is passed to the function, leaving the - /// // original unaffected - /// ``` - #[clippy::version = "pre 1.29.0"] - pub FORGET_COPY, - correctness, - "calls to `std::mem::forget` with a value that implements Copy" -} - declare_clippy_lint! { /// ### What it does /// Checks for calls to `std::mem::drop` with a value that does not implement `Drop`. @@ -104,15 +76,12 @@ declare_clippy_lint! { "use of safe `std::mem::drop` function to drop a std::mem::ManuallyDrop, which will not drop the inner value" } -const FORGET_COPY_SUMMARY: &str = "calls to `std::mem::forget` with a value that implements `Copy`. \ - Forgetting a copy leaves the original intact"; const DROP_NON_DROP_SUMMARY: &str = "call to `std::mem::drop` with a value that does not implement `Drop`. \ Dropping such a type only extends its contained lifetimes"; const FORGET_NON_DROP_SUMMARY: &str = "call to `std::mem::forget` with a value that does not implement `Drop`. \ Forgetting such a type is the same as dropping it"; declare_lint_pass!(DropForgetRef => [ - FORGET_COPY, DROP_NON_DROP, FORGET_NON_DROP, UNDROPPED_MANUALLY_DROPS @@ -129,11 +98,11 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetRef { let is_copy = is_copy(cx, arg_ty); let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); let (lint, msg) = match fn_name { - // early return for uplifted lints: drop_ref, drop_copy, forget_ref + // early return for uplifted lints: drop_ref, drop_copy, forget_ref, forget_copy sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => return, sym::mem_forget if arg_ty.is_ref() => return, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => return, - sym::mem_forget if is_copy => (FORGET_COPY, FORGET_COPY_SUMMARY), + sym::mem_forget if is_copy => return, sym::mem_drop if is_type_lang_item(cx, arg_ty, LangItem::ManuallyDrop) => { span_lint_and_help( cx, diff --git a/src/tools/clippy/clippy_lints/src/renamed_lints.rs b/src/tools/clippy/clippy_lints/src/renamed_lints.rs index 839074ae5833f..474768d03e259 100644 --- a/src/tools/clippy/clippy_lints/src/renamed_lints.rs +++ b/src/tools/clippy/clippy_lints/src/renamed_lints.rs @@ -36,6 +36,7 @@ pub static RENAMED_LINTS: &[(&str, &str)] = &[ ("clippy::for_loop_over_option", "for_loops_over_fallibles"), ("clippy::for_loop_over_result", "for_loops_over_fallibles"), ("clippy::for_loops_over_fallibles", "for_loops_over_fallibles"), + ("clippy::forget_copy", "forget_copy"), ("clippy::forget_ref", "forget_ref"), ("clippy::into_iter_on_array", "array_into_iter"), ("clippy::invalid_atomic_ordering", "invalid_atomic_ordering"), diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.rs b/src/tools/clippy/tests/ui/drop_forget_copy.rs deleted file mode 100644 index ebe60ebbd304d..0000000000000 --- a/src/tools/clippy/tests/ui/drop_forget_copy.rs +++ /dev/null @@ -1,86 +0,0 @@ -#![warn(drop_copy, clippy::forget_copy)] -#![allow(clippy::toplevel_ref_arg, drop_ref, forget_ref, unused_mut)] - -use std::mem::{drop, forget}; -use std::vec::Vec; - -#[derive(Copy, Clone)] -struct SomeStruct; - -struct AnotherStruct { - x: u8, - y: u8, - z: Vec, -} - -impl Clone for AnotherStruct { - fn clone(&self) -> AnotherStruct { - AnotherStruct { - x: self.x, - y: self.y, - z: self.z.clone(), - } - } -} - -fn main() { - let s1 = SomeStruct {}; - let s2 = s1; - let s3 = &s1; - let mut s4 = s1; - let ref s5 = s1; - - drop(s1); - drop(s2); - drop(s3); - drop(s4); - drop(s5); - - forget(s1); - forget(s2); - forget(s3); - forget(s4); - forget(s5); - - let a1 = AnotherStruct { - x: 255, - y: 0, - z: vec![1, 2, 3], - }; - let a2 = &a1; - let mut a3 = a1.clone(); - let ref a4 = a1; - let a5 = a1.clone(); - - drop(a2); - drop(a3); - drop(a4); - drop(a5); - - forget(a2); - let a3 = &a1; - forget(a3); - forget(a4); - let a5 = a1.clone(); - forget(a5); -} - -#[allow(unused)] -#[allow(clippy::unit_cmp)] -fn issue9482(x: u8) { - fn println_and(t: T) -> T { - println!("foo"); - t - } - - match x { - 0 => drop(println_and(12)), // Don't lint (copy type), we only care about side-effects - 1 => drop(println_and(String::new())), // Don't lint (no copy type), we only care about side-effects - 2 => { - drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - }, - 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - 4 => drop(2), // Lint, not a fn/method call - _ => (), - } -} diff --git a/src/tools/clippy/tests/ui/drop_forget_copy.stderr b/src/tools/clippy/tests/ui/drop_forget_copy.stderr deleted file mode 100644 index a24c4f0f0a5c6..0000000000000 --- a/src/tools/clippy/tests/ui/drop_forget_copy.stderr +++ /dev/null @@ -1,293 +0,0 @@ -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:33:5 - | -LL | drop(s1); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:33:10 - | -LL | drop(s1); - | ^^ - = note: `-D clippy::drop-non-drop` implied by `-D warnings` - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:34:5 - | -LL | drop(s2); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:34:10 - | -LL | drop(s2); - | ^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:35:5 - | -LL | drop(s3); - | ^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_forget_copy.rs:35:10 - | -LL | drop(s3); - | ^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:36:5 - | -LL | drop(s4); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:36:10 - | -LL | drop(s4); - | ^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:37:5 - | -LL | drop(s5); - | ^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_forget_copy.rs:37:10 - | -LL | drop(s5); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:39:5 - | -LL | forget(s1); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:39:12 - | -LL | forget(s1); - | ^^ - = note: `-D clippy::forget-copy` implied by `-D warnings` - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:40:5 - | -LL | forget(s2); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:40:12 - | -LL | forget(s2); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:41:5 - | -LL | forget(s3); - | ^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_forget_copy.rs:41:12 - | -LL | forget(s3); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:42:5 - | -LL | forget(s4); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:42:12 - | -LL | forget(s4); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:43:5 - | -LL | forget(s5); - | ^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_forget_copy.rs:43:12 - | -LL | forget(s5); - | ^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:55:5 - | -LL | drop(a2); - | ^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_forget_copy.rs:55:10 - | -LL | drop(a2); - | ^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:57:5 - | -LL | drop(a4); - | ^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_forget_copy.rs:57:10 - | -LL | drop(a4); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:60:5 - | -LL | forget(a2); - | ^^^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_forget_copy.rs:60:12 - | -LL | forget(a2); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:62:5 - | -LL | forget(a3); - | ^^^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_forget_copy.rs:62:12 - | -LL | forget(a3); - | ^^ - -error: calls to `std::mem::forget` with a value that implements `Copy`. Forgetting a copy leaves the original intact - --> $DIR/drop_forget_copy.rs:63:5 - | -LL | forget(a4); - | ^^^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_forget_copy.rs:63:12 - | -LL | forget(a4); - | ^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:80:13 - | -LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:80:18 - | -LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:82:14 - | -LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:82:19 - | -LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^ - -error: call to `std::mem::drop` with a value that does not implement `Drop`. Dropping such a type only extends its contained lifetimes - --> $DIR/drop_forget_copy.rs:83:14 - | -LL | 4 => drop(2), // Lint, not a fn/method call - | ^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:83:19 - | -LL | 4 => drop(2), // Lint, not a fn/method call - | ^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:33:5 - | -LL | drop(s1); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:33:10 - | -LL | drop(s1); - | ^^ - = note: `-D drop-copy` implied by `-D warnings` - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:34:5 - | -LL | drop(s2); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:34:10 - | -LL | drop(s2); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:36:5 - | -LL | drop(s4); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_forget_copy.rs:36:10 - | -LL | drop(s4); - | ^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:80:13 - | -LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:80:18 - | -LL | drop(println_and(13)); // Lint, even if we only care about the side-effect, it's already in a block - | ^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:82:14 - | -LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:82:19 - | -LL | 3 if drop(println_and(14)) == () => (), // Lint, idiomatic use is only in body of `Arm` - | ^^^^^^^^^^^^^^^ - -error: calls to `std::mem::drop` with a value that implements `Copy`. - --> $DIR/drop_forget_copy.rs:83:14 - | -LL | 4 => drop(2), // Lint, not a fn/method call - | ^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_forget_copy.rs:83:19 - | -LL | 4 => drop(2), // Lint, not a fn/method call - | ^ - -error: aborting due to 24 previous errors - diff --git a/src/tools/clippy/tests/ui/mem_forget.rs b/src/tools/clippy/tests/ui/mem_forget.rs index e5b35c098a239..5137448a6d4ba 100644 --- a/src/tools/clippy/tests/ui/mem_forget.rs +++ b/src/tools/clippy/tests/ui/mem_forget.rs @@ -5,7 +5,7 @@ use std::mem as memstuff; use std::mem::forget as forgetSomething; #[warn(clippy::mem_forget)] -#[allow(clippy::forget_copy)] +#[allow(forget_copy)] fn main() { let five: i32 = 5; forgetSomething(five); diff --git a/src/tools/clippy/tests/ui/rename.fixed b/src/tools/clippy/tests/ui/rename.fixed index 6e900d13a891c..13b4254b528dd 100644 --- a/src/tools/clippy/tests/ui/rename.fixed +++ b/src/tools/clippy/tests/ui/rename.fixed @@ -31,6 +31,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_copy)] #![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -76,6 +77,7 @@ #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] #![warn(for_loops_over_fallibles)] +#![warn(forget_copy)] #![warn(forget_ref)] #![warn(array_into_iter)] #![warn(invalid_atomic_ordering)] diff --git a/src/tools/clippy/tests/ui/rename.rs b/src/tools/clippy/tests/ui/rename.rs index 4848cbfbea8dc..6aaa550ae6d52 100644 --- a/src/tools/clippy/tests/ui/rename.rs +++ b/src/tools/clippy/tests/ui/rename.rs @@ -31,6 +31,7 @@ #![allow(drop_copy)] #![allow(drop_ref)] #![allow(for_loops_over_fallibles)] +#![allow(forget_copy)] #![allow(forget_ref)] #![allow(array_into_iter)] #![allow(invalid_atomic_ordering)] @@ -76,6 +77,7 @@ #![warn(clippy::for_loop_over_option)] #![warn(clippy::for_loop_over_result)] #![warn(clippy::for_loops_over_fallibles)] +#![warn(clippy::forget_copy)] #![warn(clippy::forget_ref)] #![warn(clippy::into_iter_on_array)] #![warn(clippy::invalid_atomic_ordering)] diff --git a/src/tools/clippy/tests/ui/rename.stderr b/src/tools/clippy/tests/ui/rename.stderr index f1cb900cc04da..a4b05756a2200 100644 --- a/src/tools/clippy/tests/ui/rename.stderr +++ b/src/tools/clippy/tests/ui/rename.stderr @@ -1,5 +1,5 @@ error: lint `clippy::almost_complete_letter_range` has been renamed to `clippy::almost_complete_range` - --> $DIR/rename.rs:45:9 + --> $DIR/rename.rs:46:9 | LL | #![warn(clippy::almost_complete_letter_range)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::almost_complete_range` @@ -7,268 +7,274 @@ LL | #![warn(clippy::almost_complete_letter_range)] = note: `-D renamed-and-removed-lints` implied by `-D warnings` error: lint `clippy::blacklisted_name` has been renamed to `clippy::disallowed_names` - --> $DIR/rename.rs:46:9 + --> $DIR/rename.rs:47:9 | LL | #![warn(clippy::blacklisted_name)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_names` error: lint `clippy::block_in_if_condition_expr` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:47:9 + --> $DIR/rename.rs:48:9 | LL | #![warn(clippy::block_in_if_condition_expr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::block_in_if_condition_stmt` has been renamed to `clippy::blocks_in_if_conditions` - --> $DIR/rename.rs:48:9 + --> $DIR/rename.rs:49:9 | LL | #![warn(clippy::block_in_if_condition_stmt)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::blocks_in_if_conditions` error: lint `clippy::box_vec` has been renamed to `clippy::box_collection` - --> $DIR/rename.rs:49:9 + --> $DIR/rename.rs:50:9 | LL | #![warn(clippy::box_vec)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::box_collection` error: lint `clippy::const_static_lifetime` has been renamed to `clippy::redundant_static_lifetimes` - --> $DIR/rename.rs:50:9 + --> $DIR/rename.rs:51:9 | LL | #![warn(clippy::const_static_lifetime)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::redundant_static_lifetimes` error: lint `clippy::cyclomatic_complexity` has been renamed to `clippy::cognitive_complexity` - --> $DIR/rename.rs:51:9 + --> $DIR/rename.rs:52:9 | LL | #![warn(clippy::cyclomatic_complexity)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::cognitive_complexity` error: lint `clippy::derive_hash_xor_eq` has been renamed to `clippy::derived_hash_with_manual_eq` - --> $DIR/rename.rs:52:9 + --> $DIR/rename.rs:53:9 | LL | #![warn(clippy::derive_hash_xor_eq)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::derived_hash_with_manual_eq` error: lint `clippy::disallowed_method` has been renamed to `clippy::disallowed_methods` - --> $DIR/rename.rs:53:9 + --> $DIR/rename.rs:54:9 | LL | #![warn(clippy::disallowed_method)] | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_methods` error: lint `clippy::disallowed_type` has been renamed to `clippy::disallowed_types` - --> $DIR/rename.rs:54:9 + --> $DIR/rename.rs:55:9 | LL | #![warn(clippy::disallowed_type)] | ^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::disallowed_types` error: lint `clippy::eval_order_dependence` has been renamed to `clippy::mixed_read_write_in_expression` - --> $DIR/rename.rs:55:9 + --> $DIR/rename.rs:56:9 | LL | #![warn(clippy::eval_order_dependence)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::mixed_read_write_in_expression` error: lint `clippy::identity_conversion` has been renamed to `clippy::useless_conversion` - --> $DIR/rename.rs:56:9 + --> $DIR/rename.rs:57:9 | LL | #![warn(clippy::identity_conversion)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::useless_conversion` error: lint `clippy::if_let_some_result` has been renamed to `clippy::match_result_ok` - --> $DIR/rename.rs:57:9 + --> $DIR/rename.rs:58:9 | LL | #![warn(clippy::if_let_some_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::match_result_ok` error: lint `clippy::logic_bug` has been renamed to `clippy::overly_complex_bool_expr` - --> $DIR/rename.rs:58:9 + --> $DIR/rename.rs:59:9 | LL | #![warn(clippy::logic_bug)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::overly_complex_bool_expr` error: lint `clippy::new_without_default_derive` has been renamed to `clippy::new_without_default` - --> $DIR/rename.rs:59:9 + --> $DIR/rename.rs:60:9 | LL | #![warn(clippy::new_without_default_derive)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::new_without_default` error: lint `clippy::option_and_then_some` has been renamed to `clippy::bind_instead_of_map` - --> $DIR/rename.rs:60:9 + --> $DIR/rename.rs:61:9 | LL | #![warn(clippy::option_and_then_some)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::bind_instead_of_map` error: lint `clippy::option_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:61:9 + --> $DIR/rename.rs:62:9 | LL | #![warn(clippy::option_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::option_map_unwrap_or` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:62:9 + --> $DIR/rename.rs:63:9 | LL | #![warn(clippy::option_map_unwrap_or)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:63:9 + --> $DIR/rename.rs:64:9 | LL | #![warn(clippy::option_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::option_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:64:9 + --> $DIR/rename.rs:65:9 | LL | #![warn(clippy::option_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::ref_in_deref` has been renamed to `clippy::needless_borrow` - --> $DIR/rename.rs:65:9 + --> $DIR/rename.rs:66:9 | LL | #![warn(clippy::ref_in_deref)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::needless_borrow` error: lint `clippy::result_expect_used` has been renamed to `clippy::expect_used` - --> $DIR/rename.rs:66:9 + --> $DIR/rename.rs:67:9 | LL | #![warn(clippy::result_expect_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::expect_used` error: lint `clippy::result_map_unwrap_or_else` has been renamed to `clippy::map_unwrap_or` - --> $DIR/rename.rs:67:9 + --> $DIR/rename.rs:68:9 | LL | #![warn(clippy::result_map_unwrap_or_else)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::map_unwrap_or` error: lint `clippy::result_unwrap_used` has been renamed to `clippy::unwrap_used` - --> $DIR/rename.rs:68:9 + --> $DIR/rename.rs:69:9 | LL | #![warn(clippy::result_unwrap_used)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::unwrap_used` error: lint `clippy::single_char_push_str` has been renamed to `clippy::single_char_add_str` - --> $DIR/rename.rs:69:9 + --> $DIR/rename.rs:70:9 | LL | #![warn(clippy::single_char_push_str)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::single_char_add_str` error: lint `clippy::stutter` has been renamed to `clippy::module_name_repetitions` - --> $DIR/rename.rs:70:9 + --> $DIR/rename.rs:71:9 | LL | #![warn(clippy::stutter)] | ^^^^^^^^^^^^^^^ help: use the new name: `clippy::module_name_repetitions` error: lint `clippy::to_string_in_display` has been renamed to `clippy::recursive_format_impl` - --> $DIR/rename.rs:71:9 + --> $DIR/rename.rs:72:9 | LL | #![warn(clippy::to_string_in_display)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::recursive_format_impl` error: lint `clippy::zero_width_space` has been renamed to `clippy::invisible_characters` - --> $DIR/rename.rs:72:9 + --> $DIR/rename.rs:73:9 | LL | #![warn(clippy::zero_width_space)] | ^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `clippy::invisible_characters` error: lint `clippy::drop_bounds` has been renamed to `drop_bounds` - --> $DIR/rename.rs:73:9 + --> $DIR/rename.rs:74:9 | LL | #![warn(clippy::drop_bounds)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `drop_bounds` error: lint `clippy::drop_copy` has been renamed to `drop_copy` - --> $DIR/rename.rs:74:9 + --> $DIR/rename.rs:75:9 | LL | #![warn(clippy::drop_copy)] | ^^^^^^^^^^^^^^^^^ help: use the new name: `drop_copy` error: lint `clippy::drop_ref` has been renamed to `drop_ref` - --> $DIR/rename.rs:75:9 + --> $DIR/rename.rs:76:9 | LL | #![warn(clippy::drop_ref)] | ^^^^^^^^^^^^^^^^ help: use the new name: `drop_ref` error: lint `clippy::for_loop_over_option` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:76:9 + --> $DIR/rename.rs:77:9 | LL | #![warn(clippy::for_loop_over_option)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loop_over_result` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:77:9 + --> $DIR/rename.rs:78:9 | LL | #![warn(clippy::for_loop_over_result)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` error: lint `clippy::for_loops_over_fallibles` has been renamed to `for_loops_over_fallibles` - --> $DIR/rename.rs:78:9 + --> $DIR/rename.rs:79:9 | LL | #![warn(clippy::for_loops_over_fallibles)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `for_loops_over_fallibles` +error: lint `clippy::forget_copy` has been renamed to `forget_copy` + --> $DIR/rename.rs:80:9 + | +LL | #![warn(clippy::forget_copy)] + | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_copy` + error: lint `clippy::forget_ref` has been renamed to `forget_ref` - --> $DIR/rename.rs:79:9 + --> $DIR/rename.rs:81:9 | LL | #![warn(clippy::forget_ref)] | ^^^^^^^^^^^^^^^^^^ help: use the new name: `forget_ref` error: lint `clippy::into_iter_on_array` has been renamed to `array_into_iter` - --> $DIR/rename.rs:80:9 + --> $DIR/rename.rs:82:9 | LL | #![warn(clippy::into_iter_on_array)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `array_into_iter` error: lint `clippy::invalid_atomic_ordering` has been renamed to `invalid_atomic_ordering` - --> $DIR/rename.rs:81:9 + --> $DIR/rename.rs:83:9 | LL | #![warn(clippy::invalid_atomic_ordering)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_atomic_ordering` error: lint `clippy::invalid_ref` has been renamed to `invalid_value` - --> $DIR/rename.rs:82:9 + --> $DIR/rename.rs:84:9 | LL | #![warn(clippy::invalid_ref)] | ^^^^^^^^^^^^^^^^^^^ help: use the new name: `invalid_value` error: lint `clippy::let_underscore_drop` has been renamed to `let_underscore_drop` - --> $DIR/rename.rs:83:9 + --> $DIR/rename.rs:85:9 | LL | #![warn(clippy::let_underscore_drop)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `let_underscore_drop` error: lint `clippy::mem_discriminant_non_enum` has been renamed to `enum_intrinsics_non_enums` - --> $DIR/rename.rs:84:9 + --> $DIR/rename.rs:86:9 | LL | #![warn(clippy::mem_discriminant_non_enum)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `enum_intrinsics_non_enums` error: lint `clippy::panic_params` has been renamed to `non_fmt_panics` - --> $DIR/rename.rs:85:9 + --> $DIR/rename.rs:87:9 | LL | #![warn(clippy::panic_params)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `non_fmt_panics` error: lint `clippy::positional_named_format_parameters` has been renamed to `named_arguments_used_positionally` - --> $DIR/rename.rs:86:9 + --> $DIR/rename.rs:88:9 | LL | #![warn(clippy::positional_named_format_parameters)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `named_arguments_used_positionally` error: lint `clippy::temporary_cstring_as_ptr` has been renamed to `temporary_cstring_as_ptr` - --> $DIR/rename.rs:87:9 + --> $DIR/rename.rs:89:9 | LL | #![warn(clippy::temporary_cstring_as_ptr)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `temporary_cstring_as_ptr` error: lint `clippy::unknown_clippy_lints` has been renamed to `unknown_lints` - --> $DIR/rename.rs:88:9 + --> $DIR/rename.rs:90:9 | LL | #![warn(clippy::unknown_clippy_lints)] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unknown_lints` error: lint `clippy::unused_label` has been renamed to `unused_labels` - --> $DIR/rename.rs:89:9 + --> $DIR/rename.rs:91:9 | LL | #![warn(clippy::unused_label)] | ^^^^^^^^^^^^^^^^^^^^ help: use the new name: `unused_labels` -error: aborting due to 45 previous errors +error: aborting due to 46 previous errors From 725537c18812deda525b595f63bf1b692ab74b5c Mon Sep 17 00:00:00 2001 From: Urgau Date: Wed, 29 Mar 2023 22:18:20 +0200 Subject: [PATCH 23/28] Adjust tests for new drop and forget lints --- .../fail/stacked_borrows/illegal_write2.rs | 2 + src/tools/miri/tests/fail/uninit_buffer.rs | 2 + .../fail/uninit_buffer_with_provenance.rs | 2 + .../zst-field-retagging-terminates.rs | 3 ++ .../multiple-lifetimes/partial-relation.rs | 2 +- .../borrowck-closures-slice-patterns-ok.rs | 1 + .../borrowck-field-sensitivity-rpass.rs | 1 + .../borrowck/borrowck-use-mut-borrow-rpass.rs | 2 + .../migrations/issue-78720.rs | 1 + .../migrations/issue-78720.stderr | 2 +- .../optimization/edge_case_run_pass.rs | 1 + .../run_pass/drop_then_use_fake_reads.rs | 2 + tests/ui/consts/const_forget.rs | 2 + tests/ui/consts/issue-104155.rs | 3 ++ tests/ui/crate-leading-sep.rs | 2 + tests/ui/drop/repeat-drop.rs | 2 + .../explicit-call-to-supertrait-dtor.fixed | 3 ++ .../explicit-call-to-supertrait-dtor.rs | 3 ++ .../explicit-call-to-supertrait-dtor.stderr | 2 +- .../feature-gate-unsafe_pin_internals.rs | 1 - tests/ui/generator/drop-env.rs | 1 + .../issue-57017.no_drop_tracking.stderr | 42 +++++++++---------- tests/ui/generator/issue-57017.rs | 1 + tests/ui/generator/non-static-is-unpin.rs | 1 + tests/ui/generator/resume-arg-size.rs | 1 + .../stdlib-prelude-from-opaque-late.rs | 1 + tests/ui/illegal-ufcs-drop.fixed | 3 ++ tests/ui/illegal-ufcs-drop.rs | 3 ++ tests/ui/illegal-ufcs-drop.stderr | 2 +- tests/ui/liveness/liveness-unused.rs | 2 +- .../ui/macros/parse-complex-macro-invoc-op.rs | 1 + tests/ui/never_type/never-assign-dead-code.rs | 1 + .../never_type/never-assign-dead-code.stderr | 8 ++-- tests/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs | 2 + tests/ui/nll/ty-outlives/projection-body.rs | 2 + .../or-patterns-default-binding-modes.rs | 2 + .../borrowck-pat-at-and-box-pass.rs | 3 ++ .../borrowck-pat-by-copy-bindings-in-at.rs | 2 + .../borrowck-move-ref-pattern-pass.rs | 2 + ...move-ref-patterns-closure-captures-pass.rs | 2 + tests/ui/print_type_sizes/async.rs | 2 + tests/ui/print_type_sizes/async.stdout | 8 ++-- .../generator_discr_placement.rs | 1 + .../generator_discr_placement.stdout | 2 +- ...pe-param-outlives-reempty-issue-74429-2.rs | 6 +-- ...type-param-outlives-reempty-issue-74429.rs | 2 + .../borrowck-exhaustive.rs | 2 + .../dbg-macro-expected-behavior.rs | 2 + .../dbg-macro-expected-behavior.run.stderr | 30 ++++++------- tests/ui/rust-2018/remove-extern-crate.fixed | 1 + tests/ui/rust-2018/remove-extern-crate.rs | 1 + tests/ui/rust-2018/remove-extern-crate.stderr | 6 +-- tests/ui/statics/issue-91050-1.rs | 2 + tests/ui/traits/copy-guessing.rs | 3 ++ tests/ui/traits/impl-evaluation-order.rs | 2 + .../auto-with-drop_tracking_mir.fail.stderr | 4 +- .../new-solver/auto-with-drop_tracking_mir.rs | 1 + .../traits/new-solver/temporary-ambiguity.rs | 2 +- .../trivial-bounds-inconsistent-copy.rs | 2 + .../trivial-bounds-inconsistent-copy.stderr | 8 ++-- 60 files changed, 144 insertions(+), 64 deletions(-) diff --git a/src/tools/miri/tests/fail/stacked_borrows/illegal_write2.rs b/src/tools/miri/tests/fail/stacked_borrows/illegal_write2.rs index 70c51e671fe84..bf4204c61fd72 100644 --- a/src/tools/miri/tests/fail/stacked_borrows/illegal_write2.rs +++ b/src/tools/miri/tests/fail/stacked_borrows/illegal_write2.rs @@ -1,3 +1,5 @@ +#![allow(drop_ref)] + fn main() { let target = &mut 42; let target2 = target as *mut _; diff --git a/src/tools/miri/tests/fail/uninit_buffer.rs b/src/tools/miri/tests/fail/uninit_buffer.rs index d21371225e571..c084dea20bd83 100644 --- a/src/tools/miri/tests/fail/uninit_buffer.rs +++ b/src/tools/miri/tests/fail/uninit_buffer.rs @@ -1,5 +1,7 @@ //@error-pattern: memory is uninitialized at [0x4..0x10] +#![allow(drop_copy)] + use std::alloc::{alloc, dealloc, Layout}; use std::slice::from_raw_parts; diff --git a/src/tools/miri/tests/fail/uninit_buffer_with_provenance.rs b/src/tools/miri/tests/fail/uninit_buffer_with_provenance.rs index 170bc6e1ed12b..1eccc48361247 100644 --- a/src/tools/miri/tests/fail/uninit_buffer_with_provenance.rs +++ b/src/tools/miri/tests/fail/uninit_buffer_with_provenance.rs @@ -2,6 +2,8 @@ //@normalize-stderr-test: "a[0-9]+" -> "ALLOC" #![feature(strict_provenance)] +#![allow(drop_copy)] + // Test printing allocations that contain single-byte provenance. use std::alloc::{alloc, dealloc, Layout}; diff --git a/src/tools/miri/tests/pass/stacked-borrows/zst-field-retagging-terminates.rs b/src/tools/miri/tests/pass/stacked-borrows/zst-field-retagging-terminates.rs index ce3c8b7d5f1a1..9f743f0b56656 100644 --- a/src/tools/miri/tests/pass/stacked-borrows/zst-field-retagging-terminates.rs +++ b/src/tools/miri/tests/pass/stacked-borrows/zst-field-retagging-terminates.rs @@ -1,5 +1,8 @@ //@compile-flags: -Zmiri-retag-fields // Checks that the test does not run forever (which relies on a fast path). + +#![allow(drop_copy)] + fn main() { let array = [(); usize::MAX]; drop(array); // Pass the array to a function, retagging its fields diff --git a/tests/ui/async-await/multiple-lifetimes/partial-relation.rs b/tests/ui/async-await/multiple-lifetimes/partial-relation.rs index 02b105999f5bb..7375cb6d3a0dd 100644 --- a/tests/ui/async-await/multiple-lifetimes/partial-relation.rs +++ b/tests/ui/async-await/multiple-lifetimes/partial-relation.rs @@ -4,7 +4,7 @@ async fn lotsa_lifetimes<'a, 'b, 'c>(a: &'a u32, b: &'b u32, c: &'c u32) -> (&'a u32, &'b u32) where 'b: 'a { - drop((a, c)); + let _ = (a, c); (b, b) } diff --git a/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs b/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs index 0229ca37a692a..9163c8ed6fb2c 100644 --- a/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs +++ b/tests/ui/borrowck/borrowck-closures-slice-patterns-ok.rs @@ -1,6 +1,7 @@ // Check that closure captures for slice patterns are inferred correctly #![allow(unused_variables)] +#![allow(drop_ref)] // run-pass diff --git a/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs b/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs index dd6708582c1b4..a88b323e0bf1e 100644 --- a/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs +++ b/tests/ui/borrowck/borrowck-field-sensitivity-rpass.rs @@ -1,6 +1,7 @@ // run-pass #![allow(unused_mut)] #![allow(unused_variables)] +#![allow(drop_copy)] // pretty-expanded FIXME #23616 struct A { a: isize, b: Box } diff --git a/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs b/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs index 1cf763f66fd20..40c6bfeeb434b 100644 --- a/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs +++ b/tests/ui/borrowck/borrowck-use-mut-borrow-rpass.rs @@ -1,6 +1,8 @@ // run-pass // pretty-expanded FIXME #23616 +#![allow(drop_copy)] + struct A { a: isize, b: Box } fn field_copy_after_field_borrow() { diff --git a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs index ff5d284614bf1..bc7295a0826f1 100644 --- a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs +++ b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.rs @@ -1,6 +1,7 @@ // run-pass #![warn(rust_2021_incompatible_closure_captures)] +#![allow(drop_ref, drop_copy)] fn main() { if let a = "" { diff --git a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr index 36a80e694e824..2609e2951ec54 100644 --- a/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr +++ b/tests/ui/closures/2229_closure_analysis/migrations/issue-78720.stderr @@ -1,5 +1,5 @@ warning: irrefutable `if let` pattern - --> $DIR/issue-78720.rs:6:8 + --> $DIR/issue-78720.rs:7:8 | LL | if let a = "" { | ^^^^^^^^^^ diff --git a/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs b/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs index 033fd6f17753a..0f15f664e757e 100644 --- a/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs +++ b/tests/ui/closures/2229_closure_analysis/optimization/edge_case_run_pass.rs @@ -3,6 +3,7 @@ #![allow(unused)] #![allow(dead_code)] +#![allow(drop_ref)] struct Int(i32); struct B<'a>(&'a i32); diff --git a/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs b/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs index 477fdd613f521..a097424a02172 100644 --- a/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs +++ b/tests/ui/closures/2229_closure_analysis/run_pass/drop_then_use_fake_reads.rs @@ -1,6 +1,8 @@ // edition:2021 // check-pass + #![feature(rustc_attrs)] +#![allow(drop_ref)] fn main() { let mut x = 1; diff --git a/tests/ui/consts/const_forget.rs b/tests/ui/consts/const_forget.rs index ec7dde8c9ecdc..acdd6a54cf4ec 100644 --- a/tests/ui/consts/const_forget.rs +++ b/tests/ui/consts/const_forget.rs @@ -1,5 +1,7 @@ // check-pass +#![allow(forget_copy)] + use std::mem::forget; const _: () = forget(0i32); diff --git a/tests/ui/consts/issue-104155.rs b/tests/ui/consts/issue-104155.rs index 1cc8f81b0d257..b3821f467b617 100644 --- a/tests/ui/consts/issue-104155.rs +++ b/tests/ui/consts/issue-104155.rs @@ -1,4 +1,7 @@ // check-pass + +#![allow(forget_copy)] + const _: () = core::mem::forget(Box::::default); const _: () = core::mem::forget(|| Box::::default()); diff --git a/tests/ui/crate-leading-sep.rs b/tests/ui/crate-leading-sep.rs index ca5905fab41ff..8d1d0b4fcdf02 100644 --- a/tests/ui/crate-leading-sep.rs +++ b/tests/ui/crate-leading-sep.rs @@ -1,6 +1,8 @@ // run-pass // pretty-expanded FIXME #23616 +#![allow(drop_copy)] + fn main() { use ::std::mem; mem::drop(2_usize); diff --git a/tests/ui/drop/repeat-drop.rs b/tests/ui/drop/repeat-drop.rs index 8fd46ecaf4420..659d35db6575a 100644 --- a/tests/ui/drop/repeat-drop.rs +++ b/tests/ui/drop/repeat-drop.rs @@ -1,6 +1,8 @@ // run-pass // needs-unwind +#![allow(drop_ref, drop_copy)] + static mut CHECK: usize = 0; struct DropChecker(usize); diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed b/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed index 47c4c9f67b692..0bc4feed329d3 100644 --- a/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed +++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.fixed @@ -1,4 +1,7 @@ // run-rustfix + +#![allow(drop_ref)] + struct Foo { x: isize } diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs b/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs index c698de50c75b8..26ae6698d669d 100644 --- a/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs +++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.rs @@ -1,4 +1,7 @@ // run-rustfix + +#![allow(drop_ref)] + struct Foo { x: isize } diff --git a/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr b/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr index 7f5106eb57e54..c70671173491e 100644 --- a/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr +++ b/tests/ui/explicit/explicit-call-to-supertrait-dtor.stderr @@ -1,5 +1,5 @@ error[E0040]: explicit use of destructor method - --> $DIR/explicit-call-to-supertrait-dtor.rs:19:14 + --> $DIR/explicit-call-to-supertrait-dtor.rs:22:14 | LL | self.drop(); | -----^^^^-- diff --git a/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs b/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs index 0680d23440304..dce94c9eab275 100644 --- a/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs +++ b/tests/ui/feature-gates/feature-gate-unsafe_pin_internals.rs @@ -13,5 +13,4 @@ fn non_unsafe_pin_new_unchecked(pointer: &mut T) -> Pin<&mut T> { fn main() { let mut self_referential = PhantomPinned; let _: Pin<&mut PhantomPinned> = non_unsafe_pin_new_unchecked(&mut self_referential); - core::mem::forget(self_referential); // move and disable drop glue! } diff --git a/tests/ui/generator/drop-env.rs b/tests/ui/generator/drop-env.rs index 66dfb8c2c0984..cb46953dac3c8 100644 --- a/tests/ui/generator/drop-env.rs +++ b/tests/ui/generator/drop-env.rs @@ -4,6 +4,7 @@ //[nomiropt]compile-flags: -Z mir-opt-level=0 #![feature(generators, generator_trait)] +#![allow(drop_copy)] use std::ops::Generator; use std::pin::Pin; diff --git a/tests/ui/generator/issue-57017.no_drop_tracking.stderr b/tests/ui/generator/issue-57017.no_drop_tracking.stderr index 06d2d23b9efb1..f7b8e198cc4bf 100644 --- a/tests/ui/generator/issue-57017.no_drop_tracking.stderr +++ b/tests/ui/generator/issue-57017.no_drop_tracking.stderr @@ -1,5 +1,5 @@ error: generator cannot be sent between threads safely - --> $DIR/issue-57017.rs:31:25 + --> $DIR/issue-57017.rs:32:25 | LL | assert_send(g); | ^ generator is not `Send` @@ -15,7 +15,7 @@ LL | | ); | = help: the trait `Sync` is not implemented for `copy::unsync::Client` note: generator is not `Send` as this value is used across a yield - --> $DIR/issue-57017.rs:29:28 + --> $DIR/issue-57017.rs:30:28 | LL | let g = move || match drop(&$name::unsync::Client::default()) { | --------------------------------- has type `©::unsync::Client` which is not `Send` @@ -33,14 +33,14 @@ LL | | } LL | | ); | |_____- in this macro invocation note: required by a bound in `assert_send` - --> $DIR/issue-57017.rs:51:19 + --> $DIR/issue-57017.rs:52:19 | LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) error: generator cannot be sent between threads safely - --> $DIR/issue-57017.rs:43:25 + --> $DIR/issue-57017.rs:44:25 | LL | assert_send(g); | ^ generator is not `Send` @@ -54,9 +54,9 @@ LL | | } LL | | ); | |_____- in this macro invocation | - = help: within `[generator@$DIR/issue-57017.rs:40:21: 40:28]`, the trait `Send` is not implemented for `copy::unsend::Client` + = help: within `[generator@$DIR/issue-57017.rs:41:21: 41:28]`, the trait `Send` is not implemented for `copy::unsend::Client` note: generator is not `Send` as this value is used across a yield - --> $DIR/issue-57017.rs:41:28 + --> $DIR/issue-57017.rs:42:28 | LL | let g = move || match drop($name::unsend::Client::default()) { | -------------------------------- has type `copy::unsend::Client` which is not `Send` @@ -74,14 +74,14 @@ LL | | } LL | | ); | |_____- in this macro invocation note: required by a bound in `assert_send` - --> $DIR/issue-57017.rs:51:19 + --> $DIR/issue-57017.rs:52:19 | LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) error: generator cannot be sent between threads safely - --> $DIR/issue-57017.rs:31:25 + --> $DIR/issue-57017.rs:32:25 | LL | assert_send(g); | ^ generator is not `Send` @@ -97,7 +97,7 @@ LL | | ); | = help: the trait `Sync` is not implemented for `derived_drop::unsync::Client` note: generator is not `Send` as this value is used across a yield - --> $DIR/issue-57017.rs:29:28 + --> $DIR/issue-57017.rs:30:28 | LL | let g = move || match drop(&$name::unsync::Client::default()) { | --------------------------------- has type `&derived_drop::unsync::Client` which is not `Send` @@ -115,14 +115,14 @@ LL | | } LL | | ); | |_____- in this macro invocation note: required by a bound in `assert_send` - --> $DIR/issue-57017.rs:51:19 + --> $DIR/issue-57017.rs:52:19 | LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) error: generator cannot be sent between threads safely - --> $DIR/issue-57017.rs:43:25 + --> $DIR/issue-57017.rs:44:25 | LL | assert_send(g); | ^ generator is not `Send` @@ -136,9 +136,9 @@ LL | | } LL | | ); | |_____- in this macro invocation | - = help: within `[generator@$DIR/issue-57017.rs:40:21: 40:28]`, the trait `Send` is not implemented for `derived_drop::unsend::Client` + = help: within `[generator@$DIR/issue-57017.rs:41:21: 41:28]`, the trait `Send` is not implemented for `derived_drop::unsend::Client` note: generator is not `Send` as this value is used across a yield - --> $DIR/issue-57017.rs:41:28 + --> $DIR/issue-57017.rs:42:28 | LL | let g = move || match drop($name::unsend::Client::default()) { | -------------------------------- has type `derived_drop::unsend::Client` which is not `Send` @@ -156,14 +156,14 @@ LL | | } LL | | ); | |_____- in this macro invocation note: required by a bound in `assert_send` - --> $DIR/issue-57017.rs:51:19 + --> $DIR/issue-57017.rs:52:19 | LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) error: generator cannot be sent between threads safely - --> $DIR/issue-57017.rs:31:25 + --> $DIR/issue-57017.rs:32:25 | LL | assert_send(g); | ^ generator is not `Send` @@ -179,7 +179,7 @@ LL | | ); | = help: the trait `Sync` is not implemented for `significant_drop::unsync::Client` note: generator is not `Send` as this value is used across a yield - --> $DIR/issue-57017.rs:29:28 + --> $DIR/issue-57017.rs:30:28 | LL | let g = move || match drop(&$name::unsync::Client::default()) { | --------------------------------- has type `&significant_drop::unsync::Client` which is not `Send` @@ -197,14 +197,14 @@ LL | | } LL | | ); | |_____- in this macro invocation note: required by a bound in `assert_send` - --> $DIR/issue-57017.rs:51:19 + --> $DIR/issue-57017.rs:52:19 | LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` = note: this error originates in the macro `type_combinations` (in Nightly builds, run with -Z macro-backtrace for more info) error: generator cannot be sent between threads safely - --> $DIR/issue-57017.rs:43:25 + --> $DIR/issue-57017.rs:44:25 | LL | assert_send(g); | ^ generator is not `Send` @@ -218,9 +218,9 @@ LL | | } LL | | ); | |_____- in this macro invocation | - = help: within `[generator@$DIR/issue-57017.rs:40:21: 40:28]`, the trait `Send` is not implemented for `significant_drop::unsend::Client` + = help: within `[generator@$DIR/issue-57017.rs:41:21: 41:28]`, the trait `Send` is not implemented for `significant_drop::unsend::Client` note: generator is not `Send` as this value is used across a yield - --> $DIR/issue-57017.rs:41:28 + --> $DIR/issue-57017.rs:42:28 | LL | let g = move || match drop($name::unsend::Client::default()) { | -------------------------------- has type `significant_drop::unsend::Client` which is not `Send` @@ -238,7 +238,7 @@ LL | | } LL | | ); | |_____- in this macro invocation note: required by a bound in `assert_send` - --> $DIR/issue-57017.rs:51:19 + --> $DIR/issue-57017.rs:52:19 | LL | fn assert_send(_thing: T) {} | ^^^^ required by this bound in `assert_send` diff --git a/tests/ui/generator/issue-57017.rs b/tests/ui/generator/issue-57017.rs index 03b00ac99ad22..918d233bf4ee6 100644 --- a/tests/ui/generator/issue-57017.rs +++ b/tests/ui/generator/issue-57017.rs @@ -5,6 +5,7 @@ // [drop_tracking_mir] build-pass #![feature(generators, negative_impls)] +#![allow(drop_ref, drop_copy)] macro_rules! type_combinations { ( diff --git a/tests/ui/generator/non-static-is-unpin.rs b/tests/ui/generator/non-static-is-unpin.rs index 17e23f5bcd2fa..adba800e25aeb 100644 --- a/tests/ui/generator/non-static-is-unpin.rs +++ b/tests/ui/generator/non-static-is-unpin.rs @@ -3,6 +3,7 @@ // run-pass #![feature(generators, generator_trait)] +#![allow(drop_copy)] use std::marker::{PhantomPinned, Unpin}; diff --git a/tests/ui/generator/resume-arg-size.rs b/tests/ui/generator/resume-arg-size.rs index b93dc54f7a97d..19618f8d0aa55 100644 --- a/tests/ui/generator/resume-arg-size.rs +++ b/tests/ui/generator/resume-arg-size.rs @@ -1,4 +1,5 @@ #![feature(generators)] +#![allow(drop_copy)] // run-pass diff --git a/tests/ui/hygiene/stdlib-prelude-from-opaque-late.rs b/tests/ui/hygiene/stdlib-prelude-from-opaque-late.rs index cf65de2bc2395..214267372bf87 100644 --- a/tests/ui/hygiene/stdlib-prelude-from-opaque-late.rs +++ b/tests/ui/hygiene/stdlib-prelude-from-opaque-late.rs @@ -1,6 +1,7 @@ // check-pass #![feature(decl_macro)] +#![allow(drop_copy)] macro mac() { mod m { diff --git a/tests/ui/illegal-ufcs-drop.fixed b/tests/ui/illegal-ufcs-drop.fixed index d73b391be0621..8783682dec47d 100644 --- a/tests/ui/illegal-ufcs-drop.fixed +++ b/tests/ui/illegal-ufcs-drop.fixed @@ -1,4 +1,7 @@ // run-rustfix + +#![allow(drop_ref)] + struct Foo; impl Drop for Foo { diff --git a/tests/ui/illegal-ufcs-drop.rs b/tests/ui/illegal-ufcs-drop.rs index 11411f55494c5..29774306ec6f5 100644 --- a/tests/ui/illegal-ufcs-drop.rs +++ b/tests/ui/illegal-ufcs-drop.rs @@ -1,4 +1,7 @@ // run-rustfix + +#![allow(drop_ref)] + struct Foo; impl Drop for Foo { diff --git a/tests/ui/illegal-ufcs-drop.stderr b/tests/ui/illegal-ufcs-drop.stderr index 91f47d5e456d3..7a5c0612c07eb 100644 --- a/tests/ui/illegal-ufcs-drop.stderr +++ b/tests/ui/illegal-ufcs-drop.stderr @@ -1,5 +1,5 @@ error[E0040]: explicit use of destructor method - --> $DIR/illegal-ufcs-drop.rs:9:5 + --> $DIR/illegal-ufcs-drop.rs:12:5 | LL | Drop::drop(&mut Foo) | ^^^^^^^^^^ diff --git a/tests/ui/liveness/liveness-unused.rs b/tests/ui/liveness/liveness-unused.rs index 9c7be15fcc84c..8ef6ab1b6ff45 100644 --- a/tests/ui/liveness/liveness-unused.rs +++ b/tests/ui/liveness/liveness-unused.rs @@ -1,7 +1,7 @@ #![warn(unused)] #![deny(unused_variables)] #![deny(unused_assignments)] -#![allow(dead_code, non_camel_case_types, trivial_numeric_casts)] +#![allow(dead_code, non_camel_case_types, trivial_numeric_casts, drop_copy)] use std::ops::AddAssign; diff --git a/tests/ui/macros/parse-complex-macro-invoc-op.rs b/tests/ui/macros/parse-complex-macro-invoc-op.rs index 8fef9b0ed877b..c50dfdf0116a2 100644 --- a/tests/ui/macros/parse-complex-macro-invoc-op.rs +++ b/tests/ui/macros/parse-complex-macro-invoc-op.rs @@ -4,6 +4,7 @@ #![allow(unused_assignments)] #![allow(unused_variables)] #![allow(stable_features)] +#![allow(drop_copy)] // Test parsing binary operators after macro invocations. diff --git a/tests/ui/never_type/never-assign-dead-code.rs b/tests/ui/never_type/never-assign-dead-code.rs index 7bb7c87097c50..e95a992d7804c 100644 --- a/tests/ui/never_type/never-assign-dead-code.rs +++ b/tests/ui/never_type/never-assign-dead-code.rs @@ -3,6 +3,7 @@ // check-pass #![feature(never_type)] +#![allow(drop_copy)] #![warn(unused)] fn main() { diff --git a/tests/ui/never_type/never-assign-dead-code.stderr b/tests/ui/never_type/never-assign-dead-code.stderr index 521b82023c93b..5660bde5c279b 100644 --- a/tests/ui/never_type/never-assign-dead-code.stderr +++ b/tests/ui/never_type/never-assign-dead-code.stderr @@ -1,5 +1,5 @@ warning: unreachable statement - --> $DIR/never-assign-dead-code.rs:10:5 + --> $DIR/never-assign-dead-code.rs:11:5 | LL | let x: ! = panic!("aah"); | ------------- any code following this expression is unreachable @@ -7,14 +7,14 @@ LL | drop(x); | ^^^^^^^^ unreachable statement | note: the lint level is defined here - --> $DIR/never-assign-dead-code.rs:6:9 + --> $DIR/never-assign-dead-code.rs:7:9 | LL | #![warn(unused)] | ^^^^^^ = note: `#[warn(unreachable_code)]` implied by `#[warn(unused)]` warning: unreachable call - --> $DIR/never-assign-dead-code.rs:10:5 + --> $DIR/never-assign-dead-code.rs:11:5 | LL | drop(x); | ^^^^ - any code following this expression is unreachable @@ -22,7 +22,7 @@ LL | drop(x); | unreachable call warning: unused variable: `x` - --> $DIR/never-assign-dead-code.rs:9:9 + --> $DIR/never-assign-dead-code.rs:10:9 | LL | let x: ! = panic!("aah"); | ^ help: if this is intentional, prefix it with an underscore: `_x` diff --git a/tests/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs b/tests/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs index 7cc0acf45f24b..73ceaeeb87572 100644 --- a/tests/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs +++ b/tests/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs @@ -5,6 +5,8 @@ // check-pass // compile-flags:-Zno-leak-check +#![allow(drop_copy)] + fn make_it() -> for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 { panic!() } diff --git a/tests/ui/nll/ty-outlives/projection-body.rs b/tests/ui/nll/ty-outlives/projection-body.rs index b03a539ebdbe9..bff9058a507b1 100644 --- a/tests/ui/nll/ty-outlives/projection-body.rs +++ b/tests/ui/nll/ty-outlives/projection-body.rs @@ -3,6 +3,8 @@ // // check-pass +#![allow(drop_ref)] + trait MyTrait<'a> { type Output; } diff --git a/tests/ui/or-patterns/or-patterns-default-binding-modes.rs b/tests/ui/or-patterns/or-patterns-default-binding-modes.rs index e56f9ffe23c63..c138d99d30328 100644 --- a/tests/ui/or-patterns/or-patterns-default-binding-modes.rs +++ b/tests/ui/or-patterns/or-patterns-default-binding-modes.rs @@ -3,6 +3,8 @@ // check-pass #![allow(irrefutable_let_patterns)] +#![allow(drop_copy)] +#![allow(drop_ref)] fn main() { // A regression test for a mistake we made at one point: diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs index fbdefd9d36c90..965204bf240e3 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-at-and-box-pass.rs @@ -2,6 +2,9 @@ // Test `@` patterns combined with `box` patterns. +#![allow(drop_ref)] +#![allow(drop_copy)] + #![feature(box_patterns)] #[derive(Copy, Clone)] diff --git a/tests/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs b/tests/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs index 0108861cfce3c..3eb5d2cbf5466 100644 --- a/tests/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs +++ b/tests/ui/pattern/bindings-after-at/borrowck-pat-by-copy-bindings-in-at.rs @@ -2,6 +2,8 @@ // Test `Copy` bindings in the rhs of `@` patterns. +#![allow(drop_copy)] + #[derive(Copy, Clone)] struct C; diff --git a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern-pass.rs b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern-pass.rs index 5445696fdff7d..0550238549ef3 100644 --- a/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern-pass.rs +++ b/tests/ui/pattern/move-ref-patterns/borrowck-move-ref-pattern-pass.rs @@ -1,5 +1,7 @@ // check-pass +#![allow(drop_ref)] + fn main() {} struct U; diff --git a/tests/ui/pattern/move-ref-patterns/move-ref-patterns-closure-captures-pass.rs b/tests/ui/pattern/move-ref-patterns/move-ref-patterns-closure-captures-pass.rs index 583f70f41aa70..788975d960aa9 100644 --- a/tests/ui/pattern/move-ref-patterns/move-ref-patterns-closure-captures-pass.rs +++ b/tests/ui/pattern/move-ref-patterns/move-ref-patterns-closure-captures-pass.rs @@ -1,5 +1,7 @@ // check-pass +#![allow(drop_ref)] + fn main() { struct U; fn accept_fn_once(_: impl FnOnce()) {} diff --git a/tests/ui/print_type_sizes/async.rs b/tests/ui/print_type_sizes/async.rs index 1598b0696913b..c73268dc46a72 100644 --- a/tests/ui/print_type_sizes/async.rs +++ b/tests/ui/print_type_sizes/async.rs @@ -3,6 +3,8 @@ // build-pass // ignore-pass +#![allow(drop_copy)] + async fn wait() {} pub async fn test(arg: [u8; 8192]) { diff --git a/tests/ui/print_type_sizes/async.stdout b/tests/ui/print_type_sizes/async.stdout index 8fe936efc8983..3974243980b50 100644 --- a/tests/ui/print_type_sizes/async.stdout +++ b/tests/ui/print_type_sizes/async.stdout @@ -1,4 +1,4 @@ -print-type-size type: `[async fn body@$DIR/async.rs:8:36: 11:2]`: 16386 bytes, alignment: 1 bytes +print-type-size type: `[async fn body@$DIR/async.rs:10:36: 13:2]`: 16386 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 8192 bytes print-type-size upvar `.arg`: 8192 bytes, offset: 0 bytes, alignment: 1 bytes @@ -16,14 +16,14 @@ print-type-size type: `std::mem::MaybeUninit<[u8; 8192]>`: 8192 bytes, alignment print-type-size variant `MaybeUninit`: 8192 bytes print-type-size field `.uninit`: 0 bytes print-type-size field `.value`: 8192 bytes -print-type-size type: `[async fn body@$DIR/async.rs:6:17: 6:19]`: 1 bytes, alignment: 1 bytes +print-type-size type: `[async fn body@$DIR/async.rs:8:17: 8:19]`: 1 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 0 bytes print-type-size variant `Returned`: 0 bytes print-type-size variant `Panicked`: 0 bytes -print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async.rs:6:17: 6:19]>`: 1 bytes, alignment: 1 bytes +print-type-size type: `std::mem::ManuallyDrop<[async fn body@$DIR/async.rs:8:17: 8:19]>`: 1 bytes, alignment: 1 bytes print-type-size field `.value`: 1 bytes -print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async.rs:6:17: 6:19]>`: 1 bytes, alignment: 1 bytes +print-type-size type: `std::mem::MaybeUninit<[async fn body@$DIR/async.rs:8:17: 8:19]>`: 1 bytes, alignment: 1 bytes print-type-size variant `MaybeUninit`: 1 bytes print-type-size field `.uninit`: 0 bytes print-type-size field `.value`: 1 bytes diff --git a/tests/ui/print_type_sizes/generator_discr_placement.rs b/tests/ui/print_type_sizes/generator_discr_placement.rs index 1a85fe95bb6f7..a77a03f0a8ae4 100644 --- a/tests/ui/print_type_sizes/generator_discr_placement.rs +++ b/tests/ui/print_type_sizes/generator_discr_placement.rs @@ -6,6 +6,7 @@ // Avoid emitting panic handlers, like the rest of these tests... #![feature(generators)] +#![allow(drop_copy)] pub fn foo() { let a = || { diff --git a/tests/ui/print_type_sizes/generator_discr_placement.stdout b/tests/ui/print_type_sizes/generator_discr_placement.stdout index f2a11c7a33bab..fe0022cf5f4c9 100644 --- a/tests/ui/print_type_sizes/generator_discr_placement.stdout +++ b/tests/ui/print_type_sizes/generator_discr_placement.stdout @@ -1,4 +1,4 @@ -print-type-size type: `[generator@$DIR/generator_discr_placement.rs:11:13: 11:15]`: 8 bytes, alignment: 4 bytes +print-type-size type: `[generator@$DIR/generator_discr_placement.rs:12:13: 12:15]`: 8 bytes, alignment: 4 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 0 bytes print-type-size variant `Suspend0`: 7 bytes diff --git a/tests/ui/regions/type-param-outlives-reempty-issue-74429-2.rs b/tests/ui/regions/type-param-outlives-reempty-issue-74429-2.rs index a65c17e0efc3c..5ae5ebb450e84 100644 --- a/tests/ui/regions/type-param-outlives-reempty-issue-74429-2.rs +++ b/tests/ui/regions/type-param-outlives-reempty-issue-74429-2.rs @@ -55,11 +55,11 @@ where } pub fn x(a: Array) { - // drop just avoids a must_use warning - drop((0..1).filter(|_| true)); + // _ just avoids a must_use warning + let _ = (0..1).filter(|_| true); let y = a.index_axis(); a.axis_iter().for_each(|_| { - drop(y); + let _ = y; }); } diff --git a/tests/ui/regions/type-param-outlives-reempty-issue-74429.rs b/tests/ui/regions/type-param-outlives-reempty-issue-74429.rs index d463f311c34e9..af2bb09805ac6 100644 --- a/tests/ui/regions/type-param-outlives-reempty-issue-74429.rs +++ b/tests/ui/regions/type-param-outlives-reempty-issue-74429.rs @@ -3,6 +3,8 @@ // check-pass +#![allow(drop_copy)] + use std::marker::PhantomData; fn apply(_: T, _: F) {} diff --git a/tests/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs b/tests/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs index be775b37f7b77..8f45b989f1363 100644 --- a/tests/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs +++ b/tests/ui/rfc-2008-non-exhaustive/borrowck-exhaustive.rs @@ -3,6 +3,8 @@ // check-pass +#![allow(drop_ref)] + // aux-build:monovariants.rs extern crate monovariants; diff --git a/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs b/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs index 04d924a9aed20..4c1562790d5f4 100644 --- a/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs +++ b/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.rs @@ -4,6 +4,8 @@ // Tests ensuring that `dbg!(expr)` has the expected run-time behavior. // as well as some compile time properties we expect. +#![allow(drop_copy)] + #[derive(Copy, Clone, Debug)] struct Unit; diff --git a/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr b/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr index 49d72158e92ba..a20a6062c13b6 100644 --- a/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr +++ b/tests/ui/rfc-2361-dbg-macro/dbg-macro-expected-behavior.run.stderr @@ -1,28 +1,28 @@ -[$DIR/dbg-macro-expected-behavior.rs:20] Unit = Unit -[$DIR/dbg-macro-expected-behavior.rs:21] a = Unit -[$DIR/dbg-macro-expected-behavior.rs:27] Point { x: 42, y: 24 } = Point { +[$DIR/dbg-macro-expected-behavior.rs:22] Unit = Unit +[$DIR/dbg-macro-expected-behavior.rs:23] a = Unit +[$DIR/dbg-macro-expected-behavior.rs:29] Point { x: 42, y: 24 } = Point { x: 42, y: 24, } -[$DIR/dbg-macro-expected-behavior.rs:28] b = Point { +[$DIR/dbg-macro-expected-behavior.rs:30] b = Point { x: 42, y: 24, } -[$DIR/dbg-macro-expected-behavior.rs:36] -[$DIR/dbg-macro-expected-behavior.rs:40] &a = NoCopy( +[$DIR/dbg-macro-expected-behavior.rs:38] +[$DIR/dbg-macro-expected-behavior.rs:42] &a = NoCopy( 1337, ) -[$DIR/dbg-macro-expected-behavior.rs:40] dbg!(& a) = NoCopy( +[$DIR/dbg-macro-expected-behavior.rs:42] dbg!(& a) = NoCopy( 1337, ) -[$DIR/dbg-macro-expected-behavior.rs:45] f(&42) = 42 +[$DIR/dbg-macro-expected-behavior.rs:47] f(&42) = 42 before -[$DIR/dbg-macro-expected-behavior.rs:50] { foo += 1; eprintln!("before"); 7331 } = 7331 -[$DIR/dbg-macro-expected-behavior.rs:58] ("Yeah",) = ( +[$DIR/dbg-macro-expected-behavior.rs:52] { foo += 1; eprintln!("before"); 7331 } = 7331 +[$DIR/dbg-macro-expected-behavior.rs:60] ("Yeah",) = ( "Yeah", ) -[$DIR/dbg-macro-expected-behavior.rs:61] 1 = 1 -[$DIR/dbg-macro-expected-behavior.rs:61] 2 = 2 -[$DIR/dbg-macro-expected-behavior.rs:65] 1u8 = 1 -[$DIR/dbg-macro-expected-behavior.rs:65] 2u32 = 2 -[$DIR/dbg-macro-expected-behavior.rs:65] "Yeah" = "Yeah" +[$DIR/dbg-macro-expected-behavior.rs:63] 1 = 1 +[$DIR/dbg-macro-expected-behavior.rs:63] 2 = 2 +[$DIR/dbg-macro-expected-behavior.rs:67] 1u8 = 1 +[$DIR/dbg-macro-expected-behavior.rs:67] 2u32 = 2 +[$DIR/dbg-macro-expected-behavior.rs:67] "Yeah" = "Yeah" diff --git a/tests/ui/rust-2018/remove-extern-crate.fixed b/tests/ui/rust-2018/remove-extern-crate.fixed index 15e0ccc5256a5..4ed4d610025fa 100644 --- a/tests/ui/rust-2018/remove-extern-crate.fixed +++ b/tests/ui/rust-2018/remove-extern-crate.fixed @@ -5,6 +5,7 @@ // compile-flags:--extern remove_extern_crate #![warn(rust_2018_idioms)] +#![allow(drop_copy)] //~ WARNING unused extern crate // Shouldn't suggest changing to `use`, as `another_name` diff --git a/tests/ui/rust-2018/remove-extern-crate.rs b/tests/ui/rust-2018/remove-extern-crate.rs index aec0bc7c37401..5dafdb2b7b774 100644 --- a/tests/ui/rust-2018/remove-extern-crate.rs +++ b/tests/ui/rust-2018/remove-extern-crate.rs @@ -5,6 +5,7 @@ // compile-flags:--extern remove_extern_crate #![warn(rust_2018_idioms)] +#![allow(drop_copy)] extern crate core; //~ WARNING unused extern crate // Shouldn't suggest changing to `use`, as `another_name` diff --git a/tests/ui/rust-2018/remove-extern-crate.stderr b/tests/ui/rust-2018/remove-extern-crate.stderr index d07358e471bb4..f752cac8ed630 100644 --- a/tests/ui/rust-2018/remove-extern-crate.stderr +++ b/tests/ui/rust-2018/remove-extern-crate.stderr @@ -1,5 +1,5 @@ warning: unused extern crate - --> $DIR/remove-extern-crate.rs:9:1 + --> $DIR/remove-extern-crate.rs:10:1 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ help: remove it @@ -12,7 +12,7 @@ LL | #![warn(rust_2018_idioms)] = note: `#[warn(unused_extern_crates)]` implied by `#[warn(rust_2018_idioms)]` warning: `extern crate` is not idiomatic in the new edition - --> $DIR/remove-extern-crate.rs:33:5 + --> $DIR/remove-extern-crate.rs:34:5 | LL | extern crate core; | ^^^^^^^^^^^^^^^^^^ @@ -23,7 +23,7 @@ LL | use core; | ~~~ warning: `extern crate` is not idiomatic in the new edition - --> $DIR/remove-extern-crate.rs:43:5 + --> $DIR/remove-extern-crate.rs:44:5 | LL | pub extern crate core; | ^^^^^^^^^^^^^^^^^^^^^^ diff --git a/tests/ui/statics/issue-91050-1.rs b/tests/ui/statics/issue-91050-1.rs index 403a41462ef18..f59bcf0b80339 100644 --- a/tests/ui/statics/issue-91050-1.rs +++ b/tests/ui/statics/issue-91050-1.rs @@ -12,6 +12,8 @@ // // In regular builds, the bad cast was UB, like "Invalid LLVMRustVisibility value!" +#![allow(drop_copy)] + pub mod before { #[no_mangle] pub static GLOBAL1: [u8; 1] = [1]; diff --git a/tests/ui/traits/copy-guessing.rs b/tests/ui/traits/copy-guessing.rs index f031dd9ca48f6..558303c2e40bc 100644 --- a/tests/ui/traits/copy-guessing.rs +++ b/tests/ui/traits/copy-guessing.rs @@ -1,5 +1,8 @@ // run-pass + #![allow(dead_code)] +#![allow(drop_copy)] + // "guessing" in trait selection can affect `copy_or_move`. Check that this // is correctly handled. I am not sure what is the "correct" behaviour, // but we should at least not ICE. diff --git a/tests/ui/traits/impl-evaluation-order.rs b/tests/ui/traits/impl-evaluation-order.rs index 57809d89aa64c..256ce992eefc4 100644 --- a/tests/ui/traits/impl-evaluation-order.rs +++ b/tests/ui/traits/impl-evaluation-order.rs @@ -6,6 +6,8 @@ // check-pass +#![allow(drop_copy)] + trait A { type B; } diff --git a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr index 6a926534e079b..4aefdd6bb0735 100644 --- a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr +++ b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.fail.stderr @@ -1,5 +1,5 @@ error[E0277]: `impl Future` cannot be sent between threads safely - --> $DIR/auto-with-drop_tracking_mir.rs:24:13 + --> $DIR/auto-with-drop_tracking_mir.rs:25:13 | LL | is_send(foo()); | ------- ^^^^^ `impl Future` cannot be sent between threads safely @@ -8,7 +8,7 @@ LL | is_send(foo()); | = help: the trait `Send` is not implemented for `impl Future` note: required by a bound in `is_send` - --> $DIR/auto-with-drop_tracking_mir.rs:23:24 + --> $DIR/auto-with-drop_tracking_mir.rs:24:24 | LL | fn is_send(_: impl Send) {} | ^^^^ required by this bound in `is_send` diff --git a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs index a5db7c4636b31..f115e1433182c 100644 --- a/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs +++ b/tests/ui/traits/new-solver/auto-with-drop_tracking_mir.rs @@ -14,6 +14,7 @@ async fn foo() { #[cfg(fail)] let x = &NotSync; bar().await; + #[allow(drop_ref)] drop(x); } diff --git a/tests/ui/traits/new-solver/temporary-ambiguity.rs b/tests/ui/traits/new-solver/temporary-ambiguity.rs index 18ee05457009b..c6c11a1a1de18 100644 --- a/tests/ui/traits/new-solver/temporary-ambiguity.rs +++ b/tests/ui/traits/new-solver/temporary-ambiguity.rs @@ -18,5 +18,5 @@ fn main() { let w = Wrapper(x); needs_foo(w); x = 1; - drop(x); + let _ = x; } diff --git a/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.rs b/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.rs index 3416503b851fb..6ed7667115a0d 100644 --- a/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.rs +++ b/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.rs @@ -1,6 +1,8 @@ // check-pass // Check tautalogically false `Copy` bounds + #![feature(trivial_bounds)] +#![allow(drop_ref, drop_copy)] fn copy_string(t: String) -> String where String: Copy { //~ WARNING trivial_bounds is_copy(&t); diff --git a/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.stderr b/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.stderr index 1e26623899bad..deeb352a2a851 100644 --- a/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.stderr +++ b/tests/ui/trivial-bounds/trivial-bounds-inconsistent-copy.stderr @@ -1,5 +1,5 @@ warning: trait bound String: Copy does not depend on any type or lifetime parameters - --> $DIR/trivial-bounds-inconsistent-copy.rs:5:51 + --> $DIR/trivial-bounds-inconsistent-copy.rs:7:51 | LL | fn copy_string(t: String) -> String where String: Copy { | ^^^^ @@ -7,19 +7,19 @@ LL | fn copy_string(t: String) -> String where String: Copy { = note: `#[warn(trivial_bounds)]` on by default warning: trait bound String: Copy does not depend on any type or lifetime parameters - --> $DIR/trivial-bounds-inconsistent-copy.rs:12:56 + --> $DIR/trivial-bounds-inconsistent-copy.rs:14:56 | LL | fn copy_out_string(t: &String) -> String where String: Copy { | ^^^^ warning: trait bound String: Copy does not depend on any type or lifetime parameters - --> $DIR/trivial-bounds-inconsistent-copy.rs:16:55 + --> $DIR/trivial-bounds-inconsistent-copy.rs:18:55 | LL | fn copy_string_with_param(x: String) where String: Copy { | ^^^^ warning: trait bound for<'b> &'b mut i32: Copy does not depend on any type or lifetime parameters - --> $DIR/trivial-bounds-inconsistent-copy.rs:22:76 + --> $DIR/trivial-bounds-inconsistent-copy.rs:24:76 | LL | fn copy_mut<'a>(t: &&'a mut i32) -> &'a mut i32 where for<'b> &'b mut i32: Copy { | ^^^^ From c93226d95685e363cb59835ff3331127cbff61cc Mon Sep 17 00:00:00 2001 From: Urgau Date: Thu, 30 Mar 2023 09:24:44 +0200 Subject: [PATCH 24/28] Allow the drop_copy lint in some library examples --- library/core/src/mem/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/core/src/mem/mod.rs b/library/core/src/mem/mod.rs index a67df7ed557a1..d0298fbd217e9 100644 --- a/library/core/src/mem/mod.rs +++ b/library/core/src/mem/mod.rs @@ -961,6 +961,7 @@ pub const fn replace(dest: &mut T, src: T) -> T { /// Integers and other types implementing [`Copy`] are unaffected by `drop`. /// /// ``` +/// # #![cfg_attr(not(bootstrap), allow(drop_copy))] /// #[derive(Copy, Clone)] /// struct Foo(u8); /// From 830fa9e294f156a8299fd96dcd4541b104c2a952 Mon Sep 17 00:00:00 2001 From: Urgau Date: Mon, 10 Apr 2023 11:55:37 +0200 Subject: [PATCH 25/28] Use label instead of note to be more consistent with other lints --- compiler/rustc_lint/messages.ftl | 8 +- .../rustc_lint/src/drop_forget_useless.rs | 8 +- compiler/rustc_lint/src/lints.rs | 16 +-- tests/ui/lint/drop_copy.stderr | 98 +++++---------- tests/ui/lint/drop_ref.stderr | 119 ++++++------------ tests/ui/lint/forget_copy.stderr | 78 ++++-------- tests/ui/lint/forget_ref.stderr | 89 ++++--------- 7 files changed, 133 insertions(+), 283 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index d0a4430db139f..517e85f67e73c 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -512,13 +512,13 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass lint_opaque_hidden_inferred_bound_sugg = add this bound lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value - .note = argument has type `{$arg_ty}` + .label = argument has type `{$arg_ty}` lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy`. - .note = argument has type `{$arg_ty}` + .label = argument has type `{$arg_ty}` lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value - .note = argument has type `{$arg_ty}` + .label = argument has type `{$arg_ty}` lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy`. - .note = argument has type `{$arg_ty}` + .label = argument has type `{$arg_ty}` diff --git a/compiler/rustc_lint/src/drop_forget_useless.rs b/compiler/rustc_lint/src/drop_forget_useless.rs index e72439439a4b5..259abc2af1129 100644 --- a/compiler/rustc_lint/src/drop_forget_useless.rs +++ b/compiler/rustc_lint/src/drop_forget_useless.rs @@ -123,16 +123,16 @@ impl<'tcx> LateLintPass<'tcx> for DropForgetUseless { let drop_is_single_call_in_arm = is_single_call_in_arm(cx, arg, expr); match fn_name { sym::mem_drop if arg_ty.is_ref() && !drop_is_single_call_in_arm => { - cx.emit_spanned_lint(DROP_REF, expr.span, DropRefDiag { arg_ty, note: arg.span }); + cx.emit_spanned_lint(DROP_REF, expr.span, DropRefDiag { arg_ty, label: arg.span }); }, sym::mem_forget if arg_ty.is_ref() => { - cx.emit_spanned_lint(FORGET_REF, expr.span, ForgetRefDiag { arg_ty, note: arg.span }); + cx.emit_spanned_lint(FORGET_REF, expr.span, ForgetRefDiag { arg_ty, label: arg.span }); }, sym::mem_drop if is_copy && !drop_is_single_call_in_arm => { - cx.emit_spanned_lint(DROP_COPY, expr.span, DropCopyDiag { arg_ty, note: arg.span }); + cx.emit_spanned_lint(DROP_COPY, expr.span, DropCopyDiag { arg_ty, label: arg.span }); } sym::mem_forget if is_copy => { - cx.emit_spanned_lint(FORGET_COPY, expr.span, ForgetCopyDiag { arg_ty, note: arg.span }); + cx.emit_spanned_lint(FORGET_COPY, expr.span, ForgetCopyDiag { arg_ty, label: arg.span }); } _ => return, }; diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index d6e10eb806878..2dcc5b81461dc 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -667,32 +667,32 @@ pub struct ForLoopsOverFalliblesSuggestion<'a> { #[diag(lint_drop_ref)] pub struct DropRefDiag<'a> { pub arg_ty: Ty<'a>, - #[note] - pub note: Span, + #[label] + pub label: Span, } #[derive(LintDiagnostic)] #[diag(lint_drop_copy)] pub struct DropCopyDiag<'a> { pub arg_ty: Ty<'a>, - #[note] - pub note: Span, + #[label] + pub label: Span, } #[derive(LintDiagnostic)] #[diag(lint_forget_ref)] pub struct ForgetRefDiag<'a> { pub arg_ty: Ty<'a>, - #[note] - pub note: Span, + #[label] + pub label: Span, } #[derive(LintDiagnostic)] #[diag(lint_forget_copy)] pub struct ForgetCopyDiag<'a> { pub arg_ty: Ty<'a>, - #[note] - pub note: Span, + #[label] + pub label: Span, } // hidden_unicode_codepoints.rs diff --git a/tests/ui/lint/drop_copy.stderr b/tests/ui/lint/drop_copy.stderr index 03d0b392e2b4b..a7a3b0e25ec76 100644 --- a/tests/ui/lint/drop_copy.stderr +++ b/tests/ui/lint/drop_copy.stderr @@ -2,13 +2,10 @@ warning: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_copy.rs:34:5 | LL | drop(s1); - | ^^^^^^^^ + | ^^^^^--^ + | | + | argument has type `SomeStruct` | -note: argument has type `SomeStruct` - --> $DIR/drop_copy.rs:34:10 - | -LL | drop(s1); - | ^^ note: the lint level is defined here --> $DIR/drop_copy.rs:3:9 | @@ -19,110 +16,75 @@ warning: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_copy.rs:35:5 | LL | drop(s2); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_copy.rs:35:10 - | -LL | drop(s2); - | ^^ + | ^^^^^--^ + | | + | argument has type `SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_copy.rs:36:5 | LL | drop(s3); - | ^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_copy.rs:36:10 + | ^^^^^--^ + | | + | argument has type `&SomeStruct` | -LL | drop(s3); - | ^^ = note: `#[warn(drop_ref)]` on by default warning: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_copy.rs:37:5 | LL | drop(s4); - | ^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/drop_copy.rs:37:10 - | -LL | drop(s4); - | ^^ + | ^^^^^--^ + | | + | argument has type `SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_copy.rs:38:5 | LL | drop(s5); - | ^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_copy.rs:38:10 - | -LL | drop(s5); - | ^^ + | ^^^^^--^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_copy.rs:50:5 | LL | drop(a2); - | ^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_copy.rs:50:10 - | -LL | drop(a2); - | ^^ + | ^^^^^--^ + | | + | argument has type `&AnotherStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_copy.rs:52:5 | LL | drop(a4); - | ^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/drop_copy.rs:52:10 - | -LL | drop(a4); - | ^^ + | ^^^^^--^ + | | + | argument has type `&AnotherStruct` warning: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_copy.rs:71:13 | LL | drop(println_and(13)); - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_copy.rs:71:18 - | -LL | drop(println_and(13)); - | ^^^^^^^^^^^^^^^ + | ^^^^^---------------^ + | | + | argument has type `i32` warning: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_copy.rs:74:14 | LL | 3 if drop(println_and(14)) == () => (), - | ^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_copy.rs:74:19 - | -LL | 3 if drop(println_and(14)) == () => (), - | ^^^^^^^^^^^^^^^ + | ^^^^^---------------^ + | | + | argument has type `i32` warning: calls to `std::mem::drop` with a value that implements `Copy`. --> $DIR/drop_copy.rs:76:14 | LL | 4 => drop(2), - | ^^^^^^^ - | -note: argument has type `i32` - --> $DIR/drop_copy.rs:76:19 - | -LL | 4 => drop(2), - | ^ + | ^^^^^-^ + | | + | argument has type `i32` warning: 10 warnings emitted diff --git a/tests/ui/lint/drop_ref.stderr b/tests/ui/lint/drop_ref.stderr index 34e4050abcf6d..c701f99fa9014 100644 --- a/tests/ui/lint/drop_ref.stderr +++ b/tests/ui/lint/drop_ref.stderr @@ -2,13 +2,10 @@ warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:8:5 | LL | drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^ + | ^^^^^-----------^ + | | + | argument has type `&SomeStruct` | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:8:10 - | -LL | drop(&SomeStruct); - | ^^^^^^^^^^^ note: the lint level is defined here --> $DIR/drop_ref.rs:3:9 | @@ -19,133 +16,89 @@ warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:11:5 | LL | drop(&owned1); - | ^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:11:10 - | -LL | drop(&owned1); - | ^^^^^^^ + | ^^^^^-------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:12:5 | LL | drop(&&owned1); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/drop_ref.rs:12:10 - | -LL | drop(&&owned1); - | ^^^^^^^^ + | ^^^^^--------^ + | | + | argument has type `&&SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:13:5 | LL | drop(&mut owned1); - | ^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:13:10 - | -LL | drop(&mut owned1); - | ^^^^^^^^^^^ + | ^^^^^-----------^ + | | + | argument has type `&mut SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:17:5 | LL | drop(reference1); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:17:10 - | -LL | drop(reference1); - | ^^^^^^^^^^ + | ^^^^^----------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:20:5 | LL | drop(reference2); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/drop_ref.rs:20:10 - | -LL | drop(reference2); - | ^^^^^^^^^^ + | ^^^^^----------^ + | | + | argument has type `&mut SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:23:5 | LL | drop(reference3); - | ^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:23:10 - | -LL | drop(reference3); - | ^^^^^^^^^^ + | ^^^^^----------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:28:5 | LL | drop(&val); - | ^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/drop_ref.rs:28:10 - | -LL | drop(&val); - | ^^^^ + | ^^^^^----^ + | | + | argument has type `&T` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:36:5 | LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/drop_ref.rs:36:20 - | -LL | std::mem::drop(&SomeStruct); - | ^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^-----------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:91:13 | LL | drop(println_and(&13)); - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:91:18 - | -LL | drop(println_and(&13)); - | ^^^^^^^^^^^^^^^^ + | ^^^^^----------------^ + | | + | argument has type `&i32` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:94:14 | LL | 3 if drop(println_and(&14)) == () => (), - | ^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:94:19 - | -LL | 3 if drop(println_and(&14)) == () => (), - | ^^^^^^^^^^^^^^^^ + | ^^^^^----------------^ + | | + | argument has type `&i32` warning: calls to `std::mem::drop` with a reference instead of an owned value --> $DIR/drop_ref.rs:96:14 | LL | 4 => drop(&2), - | ^^^^^^^^ - | -note: argument has type `&i32` - --> $DIR/drop_ref.rs:96:19 - | -LL | 4 => drop(&2), - | ^^ + | ^^^^^--^ + | | + | argument has type `&i32` warning: 12 warnings emitted diff --git a/tests/ui/lint/forget_copy.stderr b/tests/ui/lint/forget_copy.stderr index d33dfa0fd3d11..e2fc0f8af4fbe 100644 --- a/tests/ui/lint/forget_copy.stderr +++ b/tests/ui/lint/forget_copy.stderr @@ -2,13 +2,10 @@ warning: calls to `std::mem::forget` with a value that implements `Copy`. --> $DIR/forget_copy.rs:34:5 | LL | forget(s1); - | ^^^^^^^^^^ + | ^^^^^^^--^ + | | + | argument has type `SomeStruct` | -note: argument has type `SomeStruct` - --> $DIR/forget_copy.rs:34:12 - | -LL | forget(s1); - | ^^ note: the lint level is defined here --> $DIR/forget_copy.rs:3:9 | @@ -19,86 +16,59 @@ warning: calls to `std::mem::forget` with a value that implements `Copy`. --> $DIR/forget_copy.rs:35:5 | LL | forget(s2); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/forget_copy.rs:35:12 - | -LL | forget(s2); - | ^^ + | ^^^^^^^--^ + | | + | argument has type `SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_copy.rs:36:5 | LL | forget(s3); - | ^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_copy.rs:36:12 + | ^^^^^^^--^ + | | + | argument has type `&SomeStruct` | -LL | forget(s3); - | ^^ = note: `#[warn(forget_ref)]` on by default warning: calls to `std::mem::forget` with a value that implements `Copy`. --> $DIR/forget_copy.rs:37:5 | LL | forget(s4); - | ^^^^^^^^^^ - | -note: argument has type `SomeStruct` - --> $DIR/forget_copy.rs:37:12 - | -LL | forget(s4); - | ^^ + | ^^^^^^^--^ + | | + | argument has type `SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_copy.rs:38:5 | LL | forget(s5); - | ^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_copy.rs:38:12 - | -LL | forget(s5); - | ^^ + | ^^^^^^^--^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_copy.rs:50:5 | LL | forget(a2); - | ^^^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/forget_copy.rs:50:12 - | -LL | forget(a2); - | ^^ + | ^^^^^^^--^ + | | + | argument has type `&AnotherStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_copy.rs:52:5 | LL | forget(a3); - | ^^^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/forget_copy.rs:52:12 - | -LL | forget(a3); - | ^^ + | ^^^^^^^--^ + | | + | argument has type `&AnotherStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_copy.rs:53:5 | LL | forget(a4); - | ^^^^^^^^^^ - | -note: argument has type `&AnotherStruct` - --> $DIR/forget_copy.rs:53:12 - | -LL | forget(a4); - | ^^ + | ^^^^^^^--^ + | | + | argument has type `&AnotherStruct` warning: 8 warnings emitted diff --git a/tests/ui/lint/forget_ref.stderr b/tests/ui/lint/forget_ref.stderr index abb45443e4e9d..96fb217215aaa 100644 --- a/tests/ui/lint/forget_ref.stderr +++ b/tests/ui/lint/forget_ref.stderr @@ -2,13 +2,10 @@ warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:10:5 | LL | forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^-----------^ + | | + | argument has type `&SomeStruct` | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:10:12 - | -LL | forget(&SomeStruct); - | ^^^^^^^^^^^ note: the lint level is defined here --> $DIR/forget_ref.rs:3:9 | @@ -19,97 +16,65 @@ warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:13:5 | LL | forget(&owned); - | ^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:13:12 - | -LL | forget(&owned); - | ^^^^^^ + | ^^^^^^^------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:14:5 | LL | forget(&&owned); - | ^^^^^^^^^^^^^^^ - | -note: argument has type `&&SomeStruct` - --> $DIR/forget_ref.rs:14:12 - | -LL | forget(&&owned); - | ^^^^^^^ + | ^^^^^^^-------^ + | | + | argument has type `&&SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:15:5 | LL | forget(&mut owned); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:15:12 - | -LL | forget(&mut owned); - | ^^^^^^^^^^ + | ^^^^^^^----------^ + | | + | argument has type `&mut SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:19:5 | LL | forget(&*reference1); - | ^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:19:12 - | -LL | forget(&*reference1); - | ^^^^^^^^^^^^ + | ^^^^^^^------------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:22:5 | LL | forget(reference2); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&mut SomeStruct` - --> $DIR/forget_ref.rs:22:12 - | -LL | forget(reference2); - | ^^^^^^^^^^ + | ^^^^^^^----------^ + | | + | argument has type `&mut SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:25:5 | LL | forget(reference3); - | ^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:25:12 - | -LL | forget(reference3); - | ^^^^^^^^^^ + | ^^^^^^^----------^ + | | + | argument has type `&SomeStruct` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:30:5 | LL | forget(&val); - | ^^^^^^^^^^^^ - | -note: argument has type `&T` - --> $DIR/forget_ref.rs:30:12 - | -LL | forget(&val); - | ^^^^ + | ^^^^^^^----^ + | | + | argument has type `&T` warning: calls to `std::mem::forget` with a reference instead of an owned value --> $DIR/forget_ref.rs:38:5 | LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | -note: argument has type `&SomeStruct` - --> $DIR/forget_ref.rs:38:22 - | -LL | std::mem::forget(&SomeStruct); - | ^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^-----------^ + | | + | argument has type `&SomeStruct` warning: 9 warnings emitted From 6de2a74e68c5a3348bbb1ae292625a219be7e711 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 14 Apr 2023 21:49:05 +0200 Subject: [PATCH 26/28] Improve warning message by saying that it "does nothing" --- compiler/rustc_lint/messages.ftl | 8 ++++---- tests/ui/lint/drop_copy.stderr | 20 ++++++++++---------- tests/ui/lint/drop_ref.stderr | 24 ++++++++++++------------ tests/ui/lint/forget_copy.stderr | 16 ++++++++-------- tests/ui/lint/forget_ref.stderr | 18 +++++++++--------- 5 files changed, 43 insertions(+), 43 deletions(-) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 517e85f67e73c..3e6451b277a67 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -511,14 +511,14 @@ lint_opaque_hidden_inferred_bound = opaque type `{$ty}` does not satisfy its ass lint_opaque_hidden_inferred_bound_sugg = add this bound -lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value +lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value does nothing .label = argument has type `{$arg_ty}` -lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy`. +lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy` does nothing .label = argument has type `{$arg_ty}` -lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value +lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value does nothing .label = argument has type `{$arg_ty}` -lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy`. +lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy` does nothing .label = argument has type `{$arg_ty}` diff --git a/tests/ui/lint/drop_copy.stderr b/tests/ui/lint/drop_copy.stderr index a7a3b0e25ec76..2f122ad2aaa48 100644 --- a/tests/ui/lint/drop_copy.stderr +++ b/tests/ui/lint/drop_copy.stderr @@ -1,4 +1,4 @@ -warning: calls to `std::mem::drop` with a value that implements `Copy`. +warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:34:5 | LL | drop(s1); @@ -12,7 +12,7 @@ note: the lint level is defined here LL | #![warn(drop_copy)] | ^^^^^^^^^ -warning: calls to `std::mem::drop` with a value that implements `Copy`. +warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:35:5 | LL | drop(s2); @@ -20,7 +20,7 @@ LL | drop(s2); | | | argument has type `SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:36:5 | LL | drop(s3); @@ -30,7 +30,7 @@ LL | drop(s3); | = note: `#[warn(drop_ref)]` on by default -warning: calls to `std::mem::drop` with a value that implements `Copy`. +warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:37:5 | LL | drop(s4); @@ -38,7 +38,7 @@ LL | drop(s4); | | | argument has type `SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:38:5 | LL | drop(s5); @@ -46,7 +46,7 @@ LL | drop(s5); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:50:5 | LL | drop(a2); @@ -54,7 +54,7 @@ LL | drop(a2); | | | argument has type `&AnotherStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:52:5 | LL | drop(a4); @@ -62,7 +62,7 @@ LL | drop(a4); | | | argument has type `&AnotherStruct` -warning: calls to `std::mem::drop` with a value that implements `Copy`. +warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:71:13 | LL | drop(println_and(13)); @@ -70,7 +70,7 @@ LL | drop(println_and(13)); | | | argument has type `i32` -warning: calls to `std::mem::drop` with a value that implements `Copy`. +warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:74:14 | LL | 3 if drop(println_and(14)) == () => (), @@ -78,7 +78,7 @@ LL | 3 if drop(println_and(14)) == () => (), | | | argument has type `i32` -warning: calls to `std::mem::drop` with a value that implements `Copy`. +warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:76:14 | LL | 4 => drop(2), diff --git a/tests/ui/lint/drop_ref.stderr b/tests/ui/lint/drop_ref.stderr index c701f99fa9014..cd81f72d6e9b2 100644 --- a/tests/ui/lint/drop_ref.stderr +++ b/tests/ui/lint/drop_ref.stderr @@ -1,4 +1,4 @@ -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:8:5 | LL | drop(&SomeStruct); @@ -12,7 +12,7 @@ note: the lint level is defined here LL | #![warn(drop_ref)] | ^^^^^^^^ -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:11:5 | LL | drop(&owned1); @@ -20,7 +20,7 @@ LL | drop(&owned1); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:12:5 | LL | drop(&&owned1); @@ -28,7 +28,7 @@ LL | drop(&&owned1); | | | argument has type `&&SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:13:5 | LL | drop(&mut owned1); @@ -36,7 +36,7 @@ LL | drop(&mut owned1); | | | argument has type `&mut SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:17:5 | LL | drop(reference1); @@ -44,7 +44,7 @@ LL | drop(reference1); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:20:5 | LL | drop(reference2); @@ -52,7 +52,7 @@ LL | drop(reference2); | | | argument has type `&mut SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:23:5 | LL | drop(reference3); @@ -60,7 +60,7 @@ LL | drop(reference3); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:28:5 | LL | drop(&val); @@ -68,7 +68,7 @@ LL | drop(&val); | | | argument has type `&T` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:36:5 | LL | std::mem::drop(&SomeStruct); @@ -76,7 +76,7 @@ LL | std::mem::drop(&SomeStruct); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:91:13 | LL | drop(println_and(&13)); @@ -84,7 +84,7 @@ LL | drop(println_and(&13)); | | | argument has type `&i32` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:94:14 | LL | 3 if drop(println_and(&14)) == () => (), @@ -92,7 +92,7 @@ LL | 3 if drop(println_and(&14)) == () => (), | | | argument has type `&i32` -warning: calls to `std::mem::drop` with a reference instead of an owned value +warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:96:14 | LL | 4 => drop(&2), diff --git a/tests/ui/lint/forget_copy.stderr b/tests/ui/lint/forget_copy.stderr index e2fc0f8af4fbe..b5ce052d3796d 100644 --- a/tests/ui/lint/forget_copy.stderr +++ b/tests/ui/lint/forget_copy.stderr @@ -1,4 +1,4 @@ -warning: calls to `std::mem::forget` with a value that implements `Copy`. +warning: calls to `std::mem::forget` with a value that implements `Copy` does nothing --> $DIR/forget_copy.rs:34:5 | LL | forget(s1); @@ -12,7 +12,7 @@ note: the lint level is defined here LL | #![warn(forget_copy)] | ^^^^^^^^^^^ -warning: calls to `std::mem::forget` with a value that implements `Copy`. +warning: calls to `std::mem::forget` with a value that implements `Copy` does nothing --> $DIR/forget_copy.rs:35:5 | LL | forget(s2); @@ -20,7 +20,7 @@ LL | forget(s2); | | | argument has type `SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:36:5 | LL | forget(s3); @@ -30,7 +30,7 @@ LL | forget(s3); | = note: `#[warn(forget_ref)]` on by default -warning: calls to `std::mem::forget` with a value that implements `Copy`. +warning: calls to `std::mem::forget` with a value that implements `Copy` does nothing --> $DIR/forget_copy.rs:37:5 | LL | forget(s4); @@ -38,7 +38,7 @@ LL | forget(s4); | | | argument has type `SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:38:5 | LL | forget(s5); @@ -46,7 +46,7 @@ LL | forget(s5); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:50:5 | LL | forget(a2); @@ -54,7 +54,7 @@ LL | forget(a2); | | | argument has type `&AnotherStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:52:5 | LL | forget(a3); @@ -62,7 +62,7 @@ LL | forget(a3); | | | argument has type `&AnotherStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:53:5 | LL | forget(a4); diff --git a/tests/ui/lint/forget_ref.stderr b/tests/ui/lint/forget_ref.stderr index 96fb217215aaa..f20f5f54b25a1 100644 --- a/tests/ui/lint/forget_ref.stderr +++ b/tests/ui/lint/forget_ref.stderr @@ -1,4 +1,4 @@ -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:10:5 | LL | forget(&SomeStruct); @@ -12,7 +12,7 @@ note: the lint level is defined here LL | #![warn(forget_ref)] | ^^^^^^^^^^ -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:13:5 | LL | forget(&owned); @@ -20,7 +20,7 @@ LL | forget(&owned); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:14:5 | LL | forget(&&owned); @@ -28,7 +28,7 @@ LL | forget(&&owned); | | | argument has type `&&SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:15:5 | LL | forget(&mut owned); @@ -36,7 +36,7 @@ LL | forget(&mut owned); | | | argument has type `&mut SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:19:5 | LL | forget(&*reference1); @@ -44,7 +44,7 @@ LL | forget(&*reference1); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:22:5 | LL | forget(reference2); @@ -52,7 +52,7 @@ LL | forget(reference2); | | | argument has type `&mut SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:25:5 | LL | forget(reference3); @@ -60,7 +60,7 @@ LL | forget(reference3); | | | argument has type `&SomeStruct` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:30:5 | LL | forget(&val); @@ -68,7 +68,7 @@ LL | forget(&val); | | | argument has type `&T` -warning: calls to `std::mem::forget` with a reference instead of an owned value +warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:38:5 | LL | std::mem::forget(&SomeStruct); From af46d60a13588abd48f921141dbe485559d521e4 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 14 Apr 2023 22:20:27 +0200 Subject: [PATCH 27/28] Add note to suggest using `let _ = x` to ignore the value --- compiler/rustc_lint/messages.ftl | 4 ++++ compiler/rustc_lint/src/lints.rs | 4 ++++ tests/ui/lint/drop_copy.stderr | 18 ++++++++++++++++++ tests/ui/lint/drop_ref.stderr | 23 +++++++++++++++++++++++ tests/ui/lint/forget_copy.stderr | 14 ++++++++++++++ tests/ui/lint/forget_ref.stderr | 17 +++++++++++++++++ 6 files changed, 80 insertions(+) diff --git a/compiler/rustc_lint/messages.ftl b/compiler/rustc_lint/messages.ftl index 3e6451b277a67..775db4fba862b 100644 --- a/compiler/rustc_lint/messages.ftl +++ b/compiler/rustc_lint/messages.ftl @@ -513,12 +513,16 @@ lint_opaque_hidden_inferred_bound_sugg = add this bound lint_drop_ref = calls to `std::mem::drop` with a reference instead of an owned value does nothing .label = argument has type `{$arg_ty}` + .note = use `let _ = ...` to ignore the expression or result lint_drop_copy = calls to `std::mem::drop` with a value that implements `Copy` does nothing .label = argument has type `{$arg_ty}` + .note = use `let _ = ...` to ignore the expression or result lint_forget_ref = calls to `std::mem::forget` with a reference instead of an owned value does nothing .label = argument has type `{$arg_ty}` + .note = use `let _ = ...` to ignore the expression or result lint_forget_copy = calls to `std::mem::forget` with a value that implements `Copy` does nothing .label = argument has type `{$arg_ty}` + .note = use `let _ = ...` to ignore the expression or result diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 2dcc5b81461dc..0dc70e2e82f06 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -665,6 +665,7 @@ pub struct ForLoopsOverFalliblesSuggestion<'a> { // drop_ref.rs #[derive(LintDiagnostic)] #[diag(lint_drop_ref)] +#[note] pub struct DropRefDiag<'a> { pub arg_ty: Ty<'a>, #[label] @@ -673,6 +674,7 @@ pub struct DropRefDiag<'a> { #[derive(LintDiagnostic)] #[diag(lint_drop_copy)] +#[note] pub struct DropCopyDiag<'a> { pub arg_ty: Ty<'a>, #[label] @@ -681,6 +683,7 @@ pub struct DropCopyDiag<'a> { #[derive(LintDiagnostic)] #[diag(lint_forget_ref)] +#[note] pub struct ForgetRefDiag<'a> { pub arg_ty: Ty<'a>, #[label] @@ -689,6 +692,7 @@ pub struct ForgetRefDiag<'a> { #[derive(LintDiagnostic)] #[diag(lint_forget_copy)] +#[note] pub struct ForgetCopyDiag<'a> { pub arg_ty: Ty<'a>, #[label] diff --git a/tests/ui/lint/drop_copy.stderr b/tests/ui/lint/drop_copy.stderr index 2f122ad2aaa48..db8e89ad295b9 100644 --- a/tests/ui/lint/drop_copy.stderr +++ b/tests/ui/lint/drop_copy.stderr @@ -6,6 +6,7 @@ LL | drop(s1); | | | argument has type `SomeStruct` | + = note: use `let _ = ...` to ignore the expression or result note: the lint level is defined here --> $DIR/drop_copy.rs:3:9 | @@ -19,6 +20,8 @@ LL | drop(s2); | ^^^^^--^ | | | argument has type `SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:36:5 @@ -28,6 +31,7 @@ LL | drop(s3); | | | argument has type `&SomeStruct` | + = note: use `let _ = ...` to ignore the expression or result = note: `#[warn(drop_ref)]` on by default warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing @@ -37,6 +41,8 @@ LL | drop(s4); | ^^^^^--^ | | | argument has type `SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:38:5 @@ -45,6 +51,8 @@ LL | drop(s5); | ^^^^^--^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:50:5 @@ -53,6 +61,8 @@ LL | drop(a2); | ^^^^^--^ | | | argument has type `&AnotherStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_copy.rs:52:5 @@ -61,6 +71,8 @@ LL | drop(a4); | ^^^^^--^ | | | argument has type `&AnotherStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:71:13 @@ -69,6 +81,8 @@ LL | drop(println_and(13)); | ^^^^^---------------^ | | | argument has type `i32` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:74:14 @@ -77,6 +91,8 @@ LL | 3 if drop(println_and(14)) == () => (), | ^^^^^---------------^ | | | argument has type `i32` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a value that implements `Copy` does nothing --> $DIR/drop_copy.rs:76:14 @@ -85,6 +101,8 @@ LL | 4 => drop(2), | ^^^^^-^ | | | argument has type `i32` + | + = note: use `let _ = ...` to ignore the expression or result warning: 10 warnings emitted diff --git a/tests/ui/lint/drop_ref.stderr b/tests/ui/lint/drop_ref.stderr index cd81f72d6e9b2..04c988fe99da4 100644 --- a/tests/ui/lint/drop_ref.stderr +++ b/tests/ui/lint/drop_ref.stderr @@ -6,6 +6,7 @@ LL | drop(&SomeStruct); | | | argument has type `&SomeStruct` | + = note: use `let _ = ...` to ignore the expression or result note: the lint level is defined here --> $DIR/drop_ref.rs:3:9 | @@ -19,6 +20,8 @@ LL | drop(&owned1); | ^^^^^-------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:12:5 @@ -27,6 +30,8 @@ LL | drop(&&owned1); | ^^^^^--------^ | | | argument has type `&&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:13:5 @@ -35,6 +40,8 @@ LL | drop(&mut owned1); | ^^^^^-----------^ | | | argument has type `&mut SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:17:5 @@ -43,6 +50,8 @@ LL | drop(reference1); | ^^^^^----------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:20:5 @@ -51,6 +60,8 @@ LL | drop(reference2); | ^^^^^----------^ | | | argument has type `&mut SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:23:5 @@ -59,6 +70,8 @@ LL | drop(reference3); | ^^^^^----------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:28:5 @@ -67,6 +80,8 @@ LL | drop(&val); | ^^^^^----^ | | | argument has type `&T` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:36:5 @@ -75,6 +90,8 @@ LL | std::mem::drop(&SomeStruct); | ^^^^^^^^^^^^^^^-----------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:91:13 @@ -83,6 +100,8 @@ LL | drop(println_and(&13)); | ^^^^^----------------^ | | | argument has type `&i32` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:94:14 @@ -91,6 +110,8 @@ LL | 3 if drop(println_and(&14)) == () => (), | ^^^^^----------------^ | | | argument has type `&i32` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::drop` with a reference instead of an owned value does nothing --> $DIR/drop_ref.rs:96:14 @@ -99,6 +120,8 @@ LL | 4 => drop(&2), | ^^^^^--^ | | | argument has type `&i32` + | + = note: use `let _ = ...` to ignore the expression or result warning: 12 warnings emitted diff --git a/tests/ui/lint/forget_copy.stderr b/tests/ui/lint/forget_copy.stderr index b5ce052d3796d..37bc8a8854ee7 100644 --- a/tests/ui/lint/forget_copy.stderr +++ b/tests/ui/lint/forget_copy.stderr @@ -6,6 +6,7 @@ LL | forget(s1); | | | argument has type `SomeStruct` | + = note: use `let _ = ...` to ignore the expression or result note: the lint level is defined here --> $DIR/forget_copy.rs:3:9 | @@ -19,6 +20,8 @@ LL | forget(s2); | ^^^^^^^--^ | | | argument has type `SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:36:5 @@ -28,6 +31,7 @@ LL | forget(s3); | | | argument has type `&SomeStruct` | + = note: use `let _ = ...` to ignore the expression or result = note: `#[warn(forget_ref)]` on by default warning: calls to `std::mem::forget` with a value that implements `Copy` does nothing @@ -37,6 +41,8 @@ LL | forget(s4); | ^^^^^^^--^ | | | argument has type `SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:38:5 @@ -45,6 +51,8 @@ LL | forget(s5); | ^^^^^^^--^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:50:5 @@ -53,6 +61,8 @@ LL | forget(a2); | ^^^^^^^--^ | | | argument has type `&AnotherStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:52:5 @@ -61,6 +71,8 @@ LL | forget(a3); | ^^^^^^^--^ | | | argument has type `&AnotherStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_copy.rs:53:5 @@ -69,6 +81,8 @@ LL | forget(a4); | ^^^^^^^--^ | | | argument has type `&AnotherStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: 8 warnings emitted diff --git a/tests/ui/lint/forget_ref.stderr b/tests/ui/lint/forget_ref.stderr index f20f5f54b25a1..63fc779198007 100644 --- a/tests/ui/lint/forget_ref.stderr +++ b/tests/ui/lint/forget_ref.stderr @@ -6,6 +6,7 @@ LL | forget(&SomeStruct); | | | argument has type `&SomeStruct` | + = note: use `let _ = ...` to ignore the expression or result note: the lint level is defined here --> $DIR/forget_ref.rs:3:9 | @@ -19,6 +20,8 @@ LL | forget(&owned); | ^^^^^^^------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:14:5 @@ -27,6 +30,8 @@ LL | forget(&&owned); | ^^^^^^^-------^ | | | argument has type `&&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:15:5 @@ -35,6 +40,8 @@ LL | forget(&mut owned); | ^^^^^^^----------^ | | | argument has type `&mut SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:19:5 @@ -43,6 +50,8 @@ LL | forget(&*reference1); | ^^^^^^^------------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:22:5 @@ -51,6 +60,8 @@ LL | forget(reference2); | ^^^^^^^----------^ | | | argument has type `&mut SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:25:5 @@ -59,6 +70,8 @@ LL | forget(reference3); | ^^^^^^^----------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:30:5 @@ -67,6 +80,8 @@ LL | forget(&val); | ^^^^^^^----^ | | | argument has type `&T` + | + = note: use `let _ = ...` to ignore the expression or result warning: calls to `std::mem::forget` with a reference instead of an owned value does nothing --> $DIR/forget_ref.rs:38:5 @@ -75,6 +90,8 @@ LL | std::mem::forget(&SomeStruct); | ^^^^^^^^^^^^^^^^^-----------^ | | | argument has type `&SomeStruct` + | + = note: use `let _ = ...` to ignore the expression or result warning: 9 warnings emitted From 0a763c92f214501ccd0460fdddfbb49d21fe9b2e Mon Sep 17 00:00:00 2001 From: Erik Hofmayer Date: Mon, 17 Apr 2023 18:53:52 +0200 Subject: [PATCH 28/28] Make commit-date pattern more specific in test for issue 107094 --- tests/run-make/issue-107094/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/run-make/issue-107094/Makefile b/tests/run-make/issue-107094/Makefile index 7bbaf31a7771d..d614e3e1055c0 100644 --- a/tests/run-make/issue-107094/Makefile +++ b/tests/run-make/issue-107094/Makefile @@ -3,5 +3,5 @@ include ../tools.mk all: - $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" - $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9\-]+" + $(BARE_RUSTC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}" + $(BARE_RUSTDOC) --version --verbose | $(CGREP) -i -e "commit-hash: [0-9a-f]{40}" "commit-date: [0-9]{4}-[0-9]{2}-[0-9]{2}"