From e0637766029752d6d9a2aaf088edbc469b4f66a0 Mon Sep 17 00:00:00 2001 From: Guillaume Date: Wed, 4 Mar 2026 01:00:11 +0100 Subject: [PATCH 01/13] Fix LegacyKeyValueFormat report from docker build: powerpc --- src/ci/docker/host-x86_64/dist-powerpc-linux/Dockerfile | 4 ++-- .../docker/host-x86_64/dist-powerpc64-linux-gnu/Dockerfile | 4 ++-- .../host-x86_64/dist-powerpc64-linux-musl/Dockerfile | 7 +++---- .../host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile | 7 +++---- .../host-x86_64/dist-powerpc64le-linux-musl/Dockerfile | 7 +++---- 5 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/ci/docker/host-x86_64/dist-powerpc-linux/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc-linux/Dockerfile index 7081d9527f060..825392414671d 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc-linux/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-powerpc-linux/Dockerfile @@ -26,5 +26,5 @@ ENV \ ENV HOSTS=powerpc-unknown-linux-gnu -ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --disable-docs -ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS +ENV RUST_CONFIGURE_ARGS="--enable-extended --enable-profiler --disable-docs" +ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS" diff --git a/src/ci/docker/host-x86_64/dist-powerpc64-linux-gnu/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc64-linux-gnu/Dockerfile index 046406224c347..ad0e210190170 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64-linux-gnu/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-powerpc64-linux-gnu/Dockerfile @@ -26,5 +26,5 @@ ENV \ ENV HOSTS=powerpc64-unknown-linux-gnu -ENV RUST_CONFIGURE_ARGS --enable-extended --enable-profiler --disable-docs -ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS +ENV RUST_CONFIGURE_ARGS="--enable-extended --enable-profiler --disable-docs" +ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS" diff --git a/src/ci/docker/host-x86_64/dist-powerpc64-linux-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc64-linux-musl/Dockerfile index 7c8a1e657ac2e..17783b9c73588 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64-linux-musl/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-powerpc64-linux-musl/Dockerfile @@ -27,13 +27,12 @@ ENV \ ENV HOSTS=powerpc64-unknown-linux-musl -ENV RUST_CONFIGURE_ARGS \ - --enable-extended \ +ENV RUST_CONFIGURE_ARGS="--enable-extended \ --enable-full-tools \ --enable-profiler \ --enable-sanitizers \ --disable-docs \ --set target.powerpc64-unknown-linux-musl.crt-static=false \ - --musl-root-powerpc64=/x-tools/powerpc64-unknown-linux-musl/powerpc64-unknown-linux-musl/sysroot/usr + --musl-root-powerpc64=/x-tools/powerpc64-unknown-linux-musl/powerpc64-unknown-linux-musl/sysroot/usr" -ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS +ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS" diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile index e3ba51e8ffce0..6a9573cb4231c 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-gnu/Dockerfile @@ -27,11 +27,10 @@ ENV \ ENV HOSTS=powerpc64le-unknown-linux-gnu -ENV RUST_CONFIGURE_ARGS \ - --enable-extended \ +ENV RUST_CONFIGURE_ARGS="--enable-extended \ --enable-full-tools \ --enable-profiler \ --enable-sanitizers \ - --disable-docs + --disable-docs" -ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS +ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS" diff --git a/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/Dockerfile b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/Dockerfile index 601c8e905858e..be16966fbe1b4 100644 --- a/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/Dockerfile +++ b/src/ci/docker/host-x86_64/dist-powerpc64le-linux-musl/Dockerfile @@ -27,13 +27,12 @@ ENV \ ENV HOSTS=powerpc64le-unknown-linux-musl -ENV RUST_CONFIGURE_ARGS \ - --enable-extended \ +ENV RUST_CONFIGURE_ARGS="--enable-extended \ --enable-full-tools \ --enable-profiler \ --enable-sanitizers \ --disable-docs \ --set target.powerpc64le-unknown-linux-musl.crt-static=false \ - --musl-root-powerpc64le=/x-tools/powerpc64le-unknown-linux-musl/powerpc64le-unknown-linux-musl/sysroot/usr + --musl-root-powerpc64le=/x-tools/powerpc64le-unknown-linux-musl/powerpc64le-unknown-linux-musl/sysroot/usr" -ENV SCRIPT python3 ../x.py dist --host $HOSTS --target $HOSTS +ENV SCRIPT="python3 ../x.py dist --host $HOSTS --target $HOSTS" From 2e657348a9522c1d54570e4914fbf6d44f0a7be3 Mon Sep 17 00:00:00 2001 From: may Date: Tue, 24 Mar 2026 16:23:09 +0100 Subject: [PATCH 02/13] feat: reimplement `hash_map!` macro Co-authored-by: stifskere --- library/std/src/lib.rs | 2 ++ library/std/src/macros.rs | 76 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c8c8a6c897142..3f4ac35674f66 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -337,6 +337,8 @@ #![feature(formatting_options)] #![feature(funnel_shifts)] #![feature(generic_atomic)] +#![feature(hash_map_internals)] +#![feature(hash_map_macro)] #![feature(hasher_prefixfree_extras)] #![feature(hashmap_internals)] #![feature(hint_must_use)] diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index 0bb14552432d5..cc000274ea8d6 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -414,3 +414,79 @@ pub macro dbg_internal { } }, } + +#[doc(hidden)] +#[macro_export] +#[allow_internal_unstable(hash_map_internals)] +#[unstable(feature = "hash_map_internals", issue = "none")] +macro_rules! repetition_utils { + (@count $($tokens:tt),*) => {{ + [$($crate::repetition_utils!(@replace $tokens => ())),*].len() + }}; + + (@replace $x:tt => $y:tt) => { $y } +} + +/// Creates a [`HashMap`] containing the arguments. +/// +/// `hash_map!` allows specifying the entries that make +/// up the [`HashMap`] where the key and value are separated by a `=>`. +/// +/// The entries are separated by commas with a trailing comma being allowed. +/// +/// It is semantically equivalent to using repeated [`HashMap::insert`] +/// on a newly created hashmap. +/// +/// `hash_map!` will attempt to avoid repeated reallocations by +/// using [`HashMap::with_capacity`]. +/// +/// # Examples +/// +/// ```rust +/// #![feature(hash_map_macro)] +/// use std::hash_map; +/// +/// let map = hash_map! { +/// "key" => "value", +/// "key1" => "value1" +/// }; +/// +/// assert_eq!(map.get("key"), Some(&"value")); +/// assert_eq!(map.get("key1"), Some(&"value1")); +/// assert!(map.get("brrrrrrooooommm").is_none()); +/// ``` +/// +/// And with a trailing comma +/// +///```rust +/// #![feature(hash_map_macro)] +/// use std::hash_map; +/// +/// let map = hash_map! { +/// "key" => "value", // notice the , +/// }; +/// +/// assert_eq!(map.get("key"), Some(&"value")); +/// ``` +/// +/// The key and value are moved into the HashMap. +/// +/// [`HashMap`]: crate::collections::HashMap +/// [`HashMap::insert`]: crate::collections::HashMap::insert +/// [`HashMap::with_capacity`]: crate::collections::HashMap::with_capacity +#[macro_export] +#[allow_internal_unstable(hash_map_internals)] +#[unstable(feature = "hash_map_macro", issue = "144032")] +macro_rules! hash_map { + () => {{ + $crate::collections::HashMap::new() + }}; + + ( $( $key:expr => $value:expr ),* $(,)? ) => {{ + let mut map = $crate::collections::HashMap::with_capacity( + const { $crate::repetition_utils!(@count $($key),*) } + ); + $( map.insert($key, $value); )* + map + }} +} From eee01dd21138c376b1f64e49f7f76b9f6121c5ec Mon Sep 17 00:00:00 2001 From: Vincent Whitchurch Date: Thu, 26 Mar 2026 09:38:27 +0000 Subject: [PATCH 03/13] Add `IoSplit` diagnostic item for `std::io::Split` Similar to the existing `IoLines` item. It will be used in Clippy to detect uses of `Split` leading to infinite loops similar to the existing lint for `Lines`. --- library/std/src/io/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 623c34c6d2910..cba578cd3a6fa 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -3348,6 +3348,7 @@ impl SizeHint for &[u8] { /// [`split`]: BufRead::split #[stable(feature = "rust1", since = "1.0.0")] #[derive(Debug)] +#[cfg_attr(not(test), rustc_diagnostic_item = "IoSplit")] pub struct Split { buf: B, delim: u8, From 1f1785712384f90b52a01e966ac70883efc8b9d3 Mon Sep 17 00:00:00 2001 From: Laine Taffin Altman Date: Fri, 27 Mar 2026 17:24:27 -0700 Subject: [PATCH 04/13] std_detect on AArch64 Darwin: Detect FEAT_SVE_B16B16 This is now exposed via `sysctl` as of macOS "Tahoe" 26.4 (or possibly earlier). --- library/std_detect/src/detect/os/darwin/aarch64.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/library/std_detect/src/detect/os/darwin/aarch64.rs b/library/std_detect/src/detect/os/darwin/aarch64.rs index a23d65a23d811..5805d5cc36460 100644 --- a/library/std_detect/src/detect/os/darwin/aarch64.rs +++ b/library/std_detect/src/detect/os/darwin/aarch64.rs @@ -81,6 +81,7 @@ pub(crate) fn detect_features() -> cache::Initializer { let sme_f64f64 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_F64F64"); let sme_i16i64 = _sysctlbyname(c"hw.optional.arm.FEAT_SME_I16I64"); let ssbs = _sysctlbyname(c"hw.optional.arm.FEAT_SSBS"); + let sve_b16b16 = _sysctlbyname(c"hw.optional.arm.FEAT_SVE_B16B16"); let wfxt = _sysctlbyname(c"hw.optional.arm.FEAT_WFxT"); // The following features are not exposed by `is_aarch64_feature_detected`, @@ -160,6 +161,7 @@ pub(crate) fn detect_features() -> cache::Initializer { enable_feature(Feature::sme_f64f64, sme_f64f64); enable_feature(Feature::sme_i16i64, sme_i16i64); enable_feature(Feature::ssbs, ssbs); + enable_feature(Feature::sve_b16b16, sve_b16b16); enable_feature(Feature::wfxt, wfxt); value From 024acdd4b6e04efde74559f9a9416558d89aa165 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sat, 28 Mar 2026 10:51:02 -0400 Subject: [PATCH 05/13] Fix ambiguous parsing in bootstrap.py --- src/bootstrap/bootstrap.py | 7 ++++++- src/bootstrap/src/utils/change_tracker.rs | 5 +++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 105e41ca45f63..b893bb3f58213 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -1259,7 +1259,12 @@ def check_vendored_status(self): def parse_args(args): """Parse the command line arguments that the python script needs.""" - parser = argparse.ArgumentParser(add_help=False) + + # Pass allow_abbrev=False to remove support for inexact matches (e.g., + # `--json` turning on `--json-output`). The argument list here is partial, + # most flags are matched in the Rust bootstrap code. This prevents the the + # default ambiguity checks in argparse from functioning correctly. + parser = argparse.ArgumentParser(add_help=False, allow_abbrev=False) parser.add_argument("-h", "--help", action="store_true") parser.add_argument("--config") parser.add_argument("--build-dir") diff --git a/src/bootstrap/src/utils/change_tracker.rs b/src/bootstrap/src/utils/change_tracker.rs index f8af8f3bec031..3ae2373e1da21 100644 --- a/src/bootstrap/src/utils/change_tracker.rs +++ b/src/bootstrap/src/utils/change_tracker.rs @@ -616,4 +616,9 @@ pub const CONFIG_CHANGE_HISTORY: &[ChangeInfo] = &[ severity: ChangeSeverity::Warning, summary: "`x.py test --no-doc` is renamed to `--all-targets`. Additionally `--tests` is added which only executes unit and integration tests.", }, + ChangeInfo { + change_id: 154508, + severity: ChangeSeverity::Info, + summary: "`x.py` stopped accepting partial argument names. Use full names to avoid errors.", + }, ]; From 27242aa3196c1aa7b58fa744231f76362b0ecf2c Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Sat, 28 Mar 2026 21:00:03 +0000 Subject: [PATCH 06/13] Panic in Hermit clock_gettime --- library/std/src/sys/time/hermit.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/sys/time/hermit.rs b/library/std/src/sys/time/hermit.rs index 8e8a656ab61ee..4e8e5dfe21c8a 100644 --- a/library/std/src/sys/time/hermit.rs +++ b/library/std/src/sys/time/hermit.rs @@ -6,7 +6,7 @@ use crate::time::Duration; fn clock_gettime(clock: hermit_abi::clockid_t) -> Timespec { let mut t = hermit_abi::timespec { tv_sec: 0, tv_nsec: 0 }; - let _ = unsafe { hermit_abi::clock_gettime(clock, &raw mut t) }; + unsafe { hermit_abi::clock_gettime(clock, &raw mut t) }.unwrap(); Timespec::new(t.tv_sec, t.tv_nsec.into()).unwrap() } From 64ee85d511782d70d39626c5b9514108a0998295 Mon Sep 17 00:00:00 2001 From: Deadbeef Date: Sun, 29 Mar 2026 01:02:48 -0400 Subject: [PATCH 07/13] update zulip link in `std` documentation #docs doesn't seem to exist anymore, so point people to `t-libs`. Also include direct link to topic since Zulip is world-viewable now. --- library/std/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index c8c8a6c897142..e831d7b466531 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -94,8 +94,8 @@ //! pull-requests for your suggested changes. //! //! Contributions are appreciated! If you see a part of the docs that can be -//! improved, submit a PR, or chat with us first on [Zulip][rust-zulip] -//! #docs. +//! improved, submit a PR, or chat with us first on [Zulip][t-libs-zulip] +//! #t-libs. //! //! # A Tour of The Rust Standard Library //! @@ -209,7 +209,7 @@ //! [multithreading]: thread //! [other]: #what-is-in-the-standard-library-documentation //! [primitive types]: ../book/ch03-02-data-types.html -//! [rust-zulip]: https://rust-lang.zulipchat.com/ +//! [t-libs-zulip]: https://rust-lang.zulipchat.com/#narrow/channel/219381-t-libs/ //! [array]: prim@array //! [slice]: prim@slice From 69b6d26d05006dca7556abc555fb0e029ecf1f4e Mon Sep 17 00:00:00 2001 From: yukang Date: Sun, 29 Mar 2026 16:23:14 +0800 Subject: [PATCH 08/13] fix invalid type suggestion for item nested in function --- .../rustc_hir_analysis/src/collect/type_of.rs | 4 ++-- compiler/rustc_middle/src/ty/print/mod.rs | 17 +++++++++++++++-- compiler/rustc_middle/src/ty/print/pretty.rs | 13 +++++++++++++ ...ocal-item-type-suggestion-issue-146786.fixed | 11 +++++++++++ ...n-local-item-type-suggestion-issue-146786.rs | 11 +++++++++++ ...cal-item-type-suggestion-issue-146786.stderr | 8 ++++++++ 6 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.fixed create mode 100644 tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.rs create mode 100644 tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.stderr diff --git a/compiler/rustc_hir_analysis/src/collect/type_of.rs b/compiler/rustc_hir_analysis/src/collect/type_of.rs index f2ae5c1f928d0..e65efd6880b85 100644 --- a/compiler/rustc_hir_analysis/src/collect/type_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/type_of.rs @@ -4,7 +4,7 @@ use rustc_errors::{Applicability, StashKey, Suggestions}; use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::intravisit::VisitorExt; use rustc_hir::{self as hir, AmbigArg, HirId}; -use rustc_middle::ty::print::with_forced_trimmed_paths; +use rustc_middle::ty::print::{with_forced_trimmed_paths, with_types_for_suggestion}; use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::{self, DefiningScopeKind, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::{bug, span_bug}; @@ -451,7 +451,7 @@ fn infer_placeholder_type<'tcx>( err.span_suggestion( ty_span, format!("provide a type for the {kind}"), - format!("{colon} {ty}"), + with_types_for_suggestion!(format!("{colon} {ty}")), Applicability::MachineApplicable, ); } else { diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index 0fd68e74e0441..20e40dd6b2fe4 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -133,8 +133,15 @@ pub trait Printer<'tcx>: Sized { self.print_path_with_generic_args(|p| p.print_def_path(def_id, parent_args), &[kind.into()]) } - // Defaults (should not be overridden): + fn reset_path(&mut self) -> Result<(), PrintError> { + Ok(()) + } + fn should_omit_parent_def_path(&self, _parent_def_id: DefId) -> bool { + false + } + + // Defaults (should not be overridden): #[instrument(skip(self), level = "debug")] fn default_print_def_path( &mut self, @@ -210,9 +217,15 @@ pub trait Printer<'tcx>: Sized { && self.tcx().generics_of(parent_def_id).parent_count == 0; } + let omit_parent = matches!(key.disambiguated_data.data, DefPathData::TypeNs(..)) + && self.should_omit_parent_def_path(parent_def_id); + self.print_path_with_simple( |p: &mut Self| { - if trait_qualify_parent { + if omit_parent { + p.reset_path()?; + Ok(()) + } else if trait_qualify_parent { let trait_ref = ty::TraitRef::new( p.tcx(), parent_def_id, diff --git a/compiler/rustc_middle/src/ty/print/pretty.rs b/compiler/rustc_middle/src/ty/print/pretty.rs index 2c14c37609d41..b196327763f05 100644 --- a/compiler/rustc_middle/src/ty/print/pretty.rs +++ b/compiler/rustc_middle/src/ty/print/pretty.rs @@ -2224,6 +2224,19 @@ impl<'tcx> Printer<'tcx> for FmtPrinter<'_, 'tcx> { self.tcx } + fn reset_path(&mut self) -> Result<(), PrintError> { + self.empty_path = true; + Ok(()) + } + + fn should_omit_parent_def_path(&self, parent_def_id: DefId) -> bool { + RTN_MODE.with(|mode| mode.get()) == RtnMode::ForSuggestion + && matches!( + self.tcx().def_key(parent_def_id).disambiguated_data.data, + DefPathData::ValueNs(..) | DefPathData::Closure | DefPathData::AnonConst + ) + } + fn print_def_path( &mut self, def_id: DefId, diff --git a/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.fixed b/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.fixed new file mode 100644 index 0000000000000..50beced2940bb --- /dev/null +++ b/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.fixed @@ -0,0 +1,11 @@ +//@ run-rustfix +#![allow(dead_code)] + +fn main() { + struct Error; + + const ERROR: Error = Error; + //~^ ERROR missing type for `const` item + //~| HELP provide a type for the constant + //~| SUGGESTION : Error +} diff --git a/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.rs b/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.rs new file mode 100644 index 0000000000000..f3c4aed435da0 --- /dev/null +++ b/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.rs @@ -0,0 +1,11 @@ +//@ run-rustfix +#![allow(dead_code)] + +fn main() { + struct Error; + + const ERROR = Error; + //~^ ERROR missing type for `const` item + //~| HELP provide a type for the constant + //~| SUGGESTION : Error +} diff --git a/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.stderr b/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.stderr new file mode 100644 index 0000000000000..4111f9d35306c --- /dev/null +++ b/tests/ui/suggestions/function-local-item-type-suggestion-issue-146786.stderr @@ -0,0 +1,8 @@ +error: missing type for `const` item + --> $DIR/function-local-item-type-suggestion-issue-146786.rs:7:16 + | +LL | const ERROR = Error; + | ^ help: provide a type for the constant: `: Error` + +error: aborting due to 1 previous error + From 51816efcc02d36d6f4c1a9149f655869ee6bc58d Mon Sep 17 00:00:00 2001 From: dianne Date: Wed, 18 Mar 2026 20:06:02 -0700 Subject: [PATCH 09/13] don't drop arguments' temporaries in `dbg!` --- library/std/src/macros.rs | 82 ++++++++++--------- library/std/src/macros/tests.rs | 13 +++ .../clippy/clippy_lints/src/dbg_macro.rs | 47 ++--------- .../dangling_primitive.stderr | 2 +- .../return_pointer_on_unwind.stderr | 2 +- tests/ui/borrowck/dbg-issue-120327.stderr | 40 ++++----- tests/ui/liveness/liveness-upvars.rs | 2 +- tests/ui/liveness/liveness-upvars.stderr | 10 ++- .../dbg-macro-move-semantics.stderr | 16 ++-- 9 files changed, 103 insertions(+), 111 deletions(-) create mode 100644 library/std/src/macros/tests.rs diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index 0bb14552432d5..5f9b383c2da37 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -5,6 +5,9 @@ //! library. // ignore-tidy-dbg +#[cfg(test)] +mod tests; + #[doc = include_str!("../../core/src/macros/panic.md")] #[macro_export] #[rustc_builtin_macro(std_panic)] @@ -359,19 +362,16 @@ macro_rules! dbg { }; } -/// Internal macro that processes a list of expressions and produces a chain of -/// nested `match`es, one for each expression, before finally calling `eprint!` -/// with the collected information and returning all the evaluated expressions -/// in a tuple. +/// Internal macro that processes a list of expressions, binds their results +/// with `match`, calls `eprint!` with the collected information, and returns +/// all the evaluated expressions in a tuple. /// /// E.g. `dbg_internal!(() () (1, 2))` expands into /// ```rust, ignore -/// match 1 { -/// tmp_1 => match 2 { -/// tmp_2 => { -/// eprint!("...", &tmp_1, &tmp_2, /* some other arguments */); -/// (tmp_1, tmp_2) -/// } +/// match (1, 2) { +/// (tmp_1, tmp_2) => { +/// eprint!("...", &tmp_1, &tmp_2, /* some other arguments */); +/// (tmp_1, tmp_2) /// } /// } /// ``` @@ -380,37 +380,41 @@ macro_rules! dbg { #[doc(hidden)] #[rustc_macro_transparency = "semiopaque"] pub macro dbg_internal { - (($($piece:literal),+) ($($processed:expr => $bound:expr),+) ()) => {{ - $crate::eprint!( - $crate::concat!($($piece),+), - $( - $crate::stringify!($processed), - // The `&T: Debug` check happens here (not in the format literal desugaring) - // to avoid format literal related messages and suggestions. - &&$bound as &dyn $crate::fmt::Debug - ),+, - // The location returned here is that of the macro invocation, so - // it will be the same for all expressions. Thus, label these - // arguments so that they can be reused in every piece of the - // formatting template. - file=$crate::file!(), - line=$crate::line!(), - column=$crate::column!() - ); - // Comma separate the variables only when necessary so that this will - // not yield a tuple for a single expression, but rather just parenthesize - // the expression. - ($($bound),+) - }}, - (($($piece:literal),*) ($($processed:expr => $bound:expr),*) ($val:expr $(,$rest:expr)*)) => { + (($($piece:literal),+) ($($processed:expr => $bound:ident),+) ()) => { // Use of `match` here is intentional because it affects the lifetimes // of temporaries - https://stackoverflow.com/a/48732525/1063961 - match $val { - tmp => $crate::macros::dbg_internal!( - ($($piece,)* "[{file}:{line}:{column}] {} = {:#?}\n") - ($($processed => $bound,)* $val => tmp) - ($($rest),*) - ), + // Always put the arguments in a tuple to avoid an unused parens lint on the pattern. + match ($($processed,)+) { + ($($bound,)+) => { + $crate::eprint!( + $crate::concat!($($piece),+), + $( + $crate::stringify!($processed), + // The `&T: Debug` check happens here (not in the format literal desugaring) + // to avoid format literal related messages and suggestions. + &&$bound as &dyn $crate::fmt::Debug + ),+, + // The location returned here is that of the macro invocation, so + // it will be the same for all expressions. Thus, label these + // arguments so that they can be reused in every piece of the + // formatting template. + file=$crate::file!(), + line=$crate::line!(), + column=$crate::column!() + ); + // Comma separate the variables only when necessary so that this will + // not yield a tuple for a single expression, but rather just parenthesize + // the expression. + ($($bound),+) + + } } }, + (($($piece:literal),*) ($($processed:expr => $bound:ident),*) ($val:expr $(,$rest:expr)*)) => { + $crate::macros::dbg_internal!( + ($($piece,)* "[{file}:{line}:{column}] {} = {:#?}\n") + ($($processed => $bound,)* $val => tmp) + ($($rest),*) + ) + }, } diff --git a/library/std/src/macros/tests.rs b/library/std/src/macros/tests.rs new file mode 100644 index 0000000000000..db2be925ff30a --- /dev/null +++ b/library/std/src/macros/tests.rs @@ -0,0 +1,13 @@ +// ignore-tidy-dbg + +/// Test for : +/// `dbg!` shouldn't drop arguments' temporaries. +#[test] +fn no_dropping_temps() { + fn temp() {} + + *dbg!(&temp()); + *dbg!(&temp(), 1).0; + *dbg!(0, &temp()).1; + *dbg!(0, &temp(), 2).1; +} diff --git a/src/tools/clippy/clippy_lints/src/dbg_macro.rs b/src/tools/clippy/clippy_lints/src/dbg_macro.rs index eb14ef18c03da..63968a8b5e04e 100644 --- a/src/tools/clippy/clippy_lints/src/dbg_macro.rs +++ b/src/tools/clippy/clippy_lints/src/dbg_macro.rs @@ -5,7 +5,7 @@ use clippy_utils::source::snippet_with_applicability; use clippy_utils::{is_in_test, sym}; use rustc_data_structures::fx::FxHashSet; use rustc_errors::Applicability; -use rustc_hir::{Arm, Closure, ClosureKind, CoroutineKind, Expr, ExprKind, LetStmt, LocalSource, Node, Stmt, StmtKind}; +use rustc_hir::{Closure, ClosureKind, CoroutineKind, Expr, ExprKind, LetStmt, LocalSource, Node, Stmt, StmtKind}; use rustc_lint::{LateContext, LateLintPass, LintContext}; use rustc_session::impl_lint_pass; use rustc_span::{Span, SyntaxContext}; @@ -92,16 +92,15 @@ impl LateLintPass<'_> for DbgMacro { (macro_call.span, String::from("()")) } }, - ExprKind::Match(first, arms, _) => { - let vals = collect_vals(first, arms); - let suggestion = match *vals.as_slice() { + ExprKind::Match(args, _, _) => { + let suggestion = match args.kind { // dbg!(1) => 1 - [val] => { + ExprKind::Tup([val]) => { snippet_with_applicability(cx, val.span.source_callsite(), "..", &mut applicability) .to_string() }, // dbg!(2, 3) => (2, 3) - [first, .., last] => { + ExprKind::Tup([first, .., last]) => { let snippet = snippet_with_applicability( cx, first.span.source_callsite().to(last.span.source_callsite()), @@ -165,39 +164,3 @@ fn is_async_move_desugar<'tcx>(expr: &'tcx Expr<'tcx>) -> Option<&'tcx Expr<'tcx fn first_dbg_macro_in_expansion(cx: &LateContext<'_>, span: Span) -> Option { macro_backtrace(span).find(|mc| cx.tcx.is_diagnostic_item(sym::dbg_macro, mc.def_id)) } - -/// Extracts all value expressions from the `match`-tree generated by `dbg!`. -/// -/// E.g. from -/// ```rust, ignore -/// match 1 { -/// tmp_1 => match 2 { -/// tmp_2 => { -/// /* printing */ -/// (tmp_1, tmp_2) -/// } -/// } -/// } -/// ``` -/// this extracts `1` and `2`. -fn collect_vals<'hir>(first: &'hir Expr<'hir>, mut arms: &'hir [Arm<'hir>]) -> Vec<&'hir Expr<'hir>> { - let mut vals = vec![first]; - loop { - let [arm] = arms else { - unreachable!("dbg! macro expansion only has single-arm matches") - }; - - match is_async_move_desugar(arm.body) - .unwrap_or(arm.body) - .peel_drop_temps() - .kind - { - ExprKind::Block(..) => return vals, - ExprKind::Match(val, a, _) => { - vals.push(val); - arms = a; - }, - _ => unreachable!("dbg! macro expansion only results in block or match expressions"), - } - } -} diff --git a/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr b/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr index afc2cb214842e..4f06a1afa50fe 100644 --- a/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr +++ b/src/tools/miri/tests/fail/dangling_pointers/dangling_primitive.stderr @@ -2,7 +2,7 @@ error: Undefined Behavior: memory access failed: ALLOC has been freed, so this p --> tests/fail/dangling_pointers/dangling_primitive.rs:LL:CC | LL | dbg!(*ptr); - | ^^^^^^^^^^ Undefined Behavior occurred here + | ^^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr b/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr index 364a4b4a74418..88d5694c4736d 100644 --- a/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr +++ b/src/tools/miri/tests/fail/function_calls/return_pointer_on_unwind.stderr @@ -7,7 +7,7 @@ error: Undefined Behavior: reading memory at ALLOC[0x0..0x4], but memory is unin --> tests/fail/function_calls/return_pointer_on_unwind.rs:LL:CC | LL | dbg!(x.0); - | ^^^^^^^^^ Undefined Behavior occurred here + | ^^^ Undefined Behavior occurred here | = help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior = help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information diff --git a/tests/ui/borrowck/dbg-issue-120327.stderr b/tests/ui/borrowck/dbg-issue-120327.stderr index efacc0c3f1341..685a530a1fe5b 100644 --- a/tests/ui/borrowck/dbg-issue-120327.stderr +++ b/tests/ui/borrowck/dbg-issue-120327.stderr @@ -4,14 +4,14 @@ error[E0382]: use of moved value: `a` LL | let a = String::new(); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait LL | dbg!(a); - | ------- value moved here + | - value moved here LL | return a; | ^ value used here after move | -help: consider borrowing instead of transferring ownership +help: consider cloning the value if the performance cost is acceptable | -LL | dbg!(&a); - | + +LL | dbg!(a.clone()); + | ++++++++ error[E0382]: use of moved value: `a` --> $DIR/dbg-issue-120327.rs:10:12 @@ -19,14 +19,14 @@ error[E0382]: use of moved value: `a` LL | let a = String::new(); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait LL | dbg!(1, 2, a, 1, 2); - | ------------------- value moved here + | - value moved here LL | return a; | ^ value used here after move | -help: consider borrowing instead of transferring ownership +help: consider cloning the value if the performance cost is acceptable | -LL | dbg!(1, 2, &a, 1, 2); - | + +LL | dbg!(1, 2, a.clone(), 1, 2); + | ++++++++ error[E0382]: use of moved value: `b` --> $DIR/dbg-issue-120327.rs:16:12 @@ -34,14 +34,14 @@ error[E0382]: use of moved value: `b` LL | let b: String = "".to_string(); | - move occurs because `b` has type `String`, which does not implement the `Copy` trait LL | dbg!(a, b); - | ---------- value moved here + | - value moved here LL | return b; | ^ value used here after move | -help: consider borrowing instead of transferring ownership +help: consider cloning the value if the performance cost is acceptable | -LL | dbg!(a, &b); - | + +LL | dbg!(a, b.clone()); + | ++++++++ error[E0382]: use of moved value: `a` --> $DIR/dbg-issue-120327.rs:22:12 @@ -50,14 +50,14 @@ LL | fn x(a: String) -> String { | - move occurs because `a` has type `String`, which does not implement the `Copy` trait LL | let b: String = "".to_string(); LL | dbg!(a, b); - | ---------- value moved here + | - value moved here LL | return a; | ^ value used here after move | -help: consider borrowing instead of transferring ownership +help: consider cloning the value if the performance cost is acceptable | -LL | dbg!(&a, b); - | + +LL | dbg!(a.clone(), b); + | ++++++++ error[E0382]: use of moved value: `b` --> $DIR/dbg-issue-120327.rs:46:12 @@ -103,14 +103,14 @@ error[E0382]: borrow of moved value: `a` LL | let a: String = "".to_string(); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait LL | let _res = get_expr(dbg!(a)); - | ------- value moved here + | - value moved here LL | let _l = a.len(); | ^ value borrowed here after move | -help: consider borrowing instead of transferring ownership +help: consider cloning the value if the performance cost is acceptable | -LL | let _res = get_expr(dbg!(&a)); - | + +LL | let _res = get_expr(dbg!(a.clone())); + | ++++++++ error: aborting due to 7 previous errors diff --git a/tests/ui/liveness/liveness-upvars.rs b/tests/ui/liveness/liveness-upvars.rs index be58b48a40576..0e198f1dea10b 100644 --- a/tests/ui/liveness/liveness-upvars.rs +++ b/tests/ui/liveness/liveness-upvars.rs @@ -98,7 +98,7 @@ pub fn g(mut v: T) { } pub fn h() { - let mut z = T::default(); + let mut z = T::default(); //~ WARN unused variable: `z` let _ = move |b| { loop { if b { diff --git a/tests/ui/liveness/liveness-upvars.stderr b/tests/ui/liveness/liveness-upvars.stderr index cfed2830164ad..0bb5786ab3e2e 100644 --- a/tests/ui/liveness/liveness-upvars.stderr +++ b/tests/ui/liveness/liveness-upvars.stderr @@ -156,6 +156,14 @@ LL | z = T::default(); | = help: maybe it is overwritten before being read? +warning: unused variable: `z` + --> $DIR/liveness-upvars.rs:101:9 + | +LL | let mut z = T::default(); + | ^^^^^ help: if this is intentional, prefix it with an underscore: `_z` + | + = note: `#[warn(unused_variables)]` implied by `#[warn(unused)]` + warning: value captured by `state` is never read --> $DIR/liveness-upvars.rs:131:9 | @@ -196,5 +204,5 @@ LL | s = yield (); | = help: maybe it is overwritten before being read? -warning: 24 warnings emitted +warning: 25 warnings emitted diff --git a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr index f8ef315b9cc78..76b2d1be27795 100644 --- a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr +++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr @@ -1,17 +1,21 @@ error[E0382]: use of moved value: `a` - --> $DIR/dbg-macro-move-semantics.rs:9:13 + --> $DIR/dbg-macro-move-semantics.rs:9:18 | LL | let a = NoCopy(0); | - move occurs because `a` has type `NoCopy`, which does not implement the `Copy` trait LL | let _ = dbg!(a); - | ------- value moved here + | - value moved here LL | let _ = dbg!(a); - | ^^^^^^^ value used here after move + | ^ value used here after move | -help: consider borrowing instead of transferring ownership +note: if `NoCopy` implemented `Clone`, you could clone the value + --> $DIR/dbg-macro-move-semantics.rs:4:1 | -LL | let _ = dbg!(&a); - | + +LL | struct NoCopy(usize); + | ^^^^^^^^^^^^^ consider implementing `Clone` for this type +... +LL | let _ = dbg!(a); + | - you could clone this value error: aborting due to 1 previous error From 9fd2c9ef01d859ac3eaa04d68804140a988d75ae Mon Sep 17 00:00:00 2001 From: Jean IBARZ Date: Sun, 29 Mar 2026 14:15:57 +0200 Subject: [PATCH 10/13] Add regression test for recursive lazy type alias normalization ICE Exercises a self-referencing type alias with lazy_type_alias and min_generic_const_args, which previously caused an ICE during normalization. --- .../recursive-lazy-type-alias-ice-152633.rs | 14 ++++++++++++++ .../recursive-lazy-type-alias-ice-152633.stderr | 11 +++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs create mode 100644 tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr diff --git a/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs new file mode 100644 index 0000000000000..4b3633653133c --- /dev/null +++ b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.rs @@ -0,0 +1,14 @@ +//! Ensure a self-referencing lazy type alias with `min_generic_const_args` +//! doesn't ICE during normalization. +//! +//! Regression test for . + +#![feature(lazy_type_alias)] +#![feature(min_generic_const_args)] + +trait Trait { + type const ASSOC: (); +} +type Arr2 = [usize; ::ASSOC]; //~ ERROR E0275 + +fn main() {} diff --git a/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr new file mode 100644 index 0000000000000..a8e68a05253b9 --- /dev/null +++ b/tests/ui/type-alias/recursive-lazy-type-alias-ice-152633.stderr @@ -0,0 +1,11 @@ +error[E0275]: overflow normalizing the type alias `Arr2` + --> $DIR/recursive-lazy-type-alias-ice-152633.rs:12:1 + | +LL | type Arr2 = [usize; ::ASSOC]; + | ^^^^^^^^^ + | + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`. From c67380d6fe272b985bc8fdb4a54abfca5d51bf97 Mon Sep 17 00:00:00 2001 From: Sasha Pourcelot Date: Thu, 19 Mar 2026 21:35:58 +0000 Subject: [PATCH 11/13] rustdoc: add test showing cfg pretty-printing of all targets --- tests/rustdoc-html/doc-cfg/all-targets.rs | 144 ++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/rustdoc-html/doc-cfg/all-targets.rs diff --git a/tests/rustdoc-html/doc-cfg/all-targets.rs b/tests/rustdoc-html/doc-cfg/all-targets.rs new file mode 100644 index 0000000000000..ab6e6c216eefa --- /dev/null +++ b/tests/rustdoc-html/doc-cfg/all-targets.rs @@ -0,0 +1,144 @@ +#![feature(doc_cfg)] + +//@ has all_targets/fn.foo.html \ +// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ +// 'Available on GNU or target_env=macabi or target_env=mlibc or MSVC or musl or \ +// Newlib or target_env=nto70 or target_env=nto71 or target_env=nto71_iosock or \ +// target_env=nto80 or target_env=ohos or target_env=relibc or SGX or \ +// target_env=sim or target_env=p1 or target_env=p2 or target_env=p3 or uClibc or \ +// target_env=v5 or target_env=fake_env only.' +#[doc(cfg(any( + target_env = "gnu", + target_env = "macabi", + target_env = "mlibc", + target_env = "msvc", + target_env = "musl", + target_env = "newlib", + target_env = "nto70", + target_env = "nto71", + target_env = "nto71_iosock", + target_env = "nto80", + target_env = "ohos", + target_env = "relibc", + target_env = "sgx", + target_env = "sim", + target_env = "p1", + target_env = "p2", + target_env = "p3", + target_env = "uclibc", + target_env = "v5", + target_env = "fake_env", +)))] +pub fn foo() {} + +//@ has all_targets/fn.bar.html \ +// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ +// 'Available on AArch64 or target_arch=amdgpu or ARM or target_arch=arm64ec or \ +// target_arch=avr or target_arch=bpf or CSKY or target_arch=hexagon or LoongArch \ +// LA32 or LoongArch LA64 or M68k or MIPS or MIPS Release 6 or MIPS-64 or MIPS-64 \ +// Release 6 or MSP430 or target_arch=nvptx64 or PowerPC or PowerPC-64 or RISC-V \ +// RV32 or RISC-V RV64 or s390x or target_arch=sparc or SPARC64 or \ +// target_arch=spirv or WebAssembly or WebAssembly or x86 or x86-64 or \ +// target_arch=xtensa or target_arch=fake_arch only.' +#[doc(cfg(any( + target_arch = "aarch64", + target_arch = "amdgpu", + target_arch = "arm", + target_arch = "arm64ec", + target_arch = "avr", + target_arch = "bpf", + target_arch = "csky", + target_arch = "hexagon", + target_arch = "loongarch32", + target_arch = "loongarch64", + target_arch = "m68k", + target_arch = "mips", + target_arch = "mips32r6", + target_arch = "mips64", + target_arch = "mips64r6", + target_arch = "msp430", + target_arch = "nvptx64", + target_arch = "powerpc", + target_arch = "powerpc64", + target_arch = "riscv32", + target_arch = "riscv64", + target_arch = "s390x", + target_arch = "sparc", + target_arch = "sparc64", + target_arch = "spirv", + target_arch = "wasm32", + target_arch = "wasm64", + target_arch = "x86", + target_arch = "x86_64", + target_arch = "xtensa", + target_arch = "fake_arch", +)))] +pub fn bar() {} + +//@ has all_targets/fn.baz.html \ +// '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ +// 'Available on target_os=aix and target_os=amdhsa and Android and target_os=cuda \ +// and Cygwin and DragonFly BSD and Emscripten and target_os=espidf and FreeBSD \ +// and Fuchsia and Haiku and target_os=helenos and Hermit and target_os=horizon \ +// and target_os=hurd and illumos and iOS and L4Re and Linux and \ +// target_os=lynxos178 and macOS and target_os=managarm and target_os=motor and \ +// NetBSD and target_os=none and target_os=nto and target_os=nuttx and OpenBSD and \ +// target_os=psp and target_os=psx and target_os=qurt and Redox and \ +// target_os=rtems and Solaris and target_os=solid_asp3 and target_os=teeos and \ +// target_os=trusty and tvOS and target_os=uefi and target_os=vexos and visionOS \ +// and target_os=vita and target_os=vxworks and WASI and watchOS and Windows and \ +// target_os=xous and target_os=zkvm and target_os=unknown and target_os=fake_os \ +// only.' +#[doc(cfg(all( + target_os = "aix", + target_os = "amdhsa", + target_os = "android", + target_os = "cuda", + target_os = "cygwin", + target_os = "dragonfly", + target_os = "emscripten", + target_os = "espidf", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "haiku", + target_os = "helenos", + target_os = "hermit", + target_os = "horizon", + target_os = "hurd", + target_os = "illumos", + target_os = "ios", + target_os = "l4re", + target_os = "linux", + target_os = "lynxos178", + target_os = "macos", + target_os = "managarm", + target_os = "motor", + target_os = "netbsd", + target_os = "none", + target_os = "nto", + target_os = "nuttx", + target_os = "openbsd", + target_os = "psp", + target_os = "psx", + target_os = "qurt", + target_os = "redox", + target_os = "rtems", + target_os = "solaris", + target_os = "solid_asp3", + target_os = "teeos", + target_os = "trusty", + target_os = "tvos", + target_os = "uefi", + target_os = "vexos", + target_os = "visionos", + target_os = "vita", + target_os = "vxworks", + target_os = "wasi", + target_os = "watchos", + target_os = "windows", + target_os = "xous", + target_os = "zkvm", + target_os = "unknown", + target_os = "fake_os", +)))] +pub fn baz() {} From 9f0944832b62279adba24c702e5d6f7a94880485 Mon Sep 17 00:00:00 2001 From: Sasha Pourcelot Date: Thu, 19 Mar 2026 21:35:58 +0000 Subject: [PATCH 12/13] rustdoc: add missing target_{os,arch,env} values for cfg pretty printer --- src/librustdoc/clean/cfg.rs | 195 +++++++++++++++------- tests/rustdoc-gui/item-info-overflow.goml | 4 +- tests/rustdoc-html/doc-cfg/all-targets.rs | 43 +++-- 3 files changed, 159 insertions(+), 83 deletions(-) diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index 3ec2bc3af8d42..ee03431d036b0 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -3,6 +3,7 @@ // FIXME: Once the portability lint RFC is implemented (see tracking issue #41619), // switch to use those structures instead. +use std::str::FromStr; use std::sync::Arc; use std::{fmt, mem, ops}; @@ -15,6 +16,7 @@ use rustc_hir::attrs::{self, AttributeKind, CfgEntry, CfgHideShow, HideOrShow}; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::{Symbol, sym}; use rustc_span::{DUMMY_SP, Span}; +use rustc_target::spec; use crate::display::{Joined as _, MaybeDisplay, Wrapped}; use crate::html::escape::Escape; @@ -421,54 +423,10 @@ impl fmt::Display for Display<'_> { (sym::unix, None) => "Unix", (sym::windows, None) => "Windows", (sym::debug_assertions, None) => "debug-assertions enabled", - (sym::target_os, Some(os)) => match os.as_str() { - "android" => "Android", - "cygwin" => "Cygwin", - "dragonfly" => "DragonFly BSD", - "emscripten" => "Emscripten", - "freebsd" => "FreeBSD", - "fuchsia" => "Fuchsia", - "haiku" => "Haiku", - "hermit" => "Hermit", - "illumos" => "illumos", - "ios" => "iOS", - "l4re" => "L4Re", - "linux" => "Linux", - "macos" => "macOS", - "netbsd" => "NetBSD", - "openbsd" => "OpenBSD", - "redox" => "Redox", - "solaris" => "Solaris", - "tvos" => "tvOS", - "wasi" => "WASI", - "watchos" => "watchOS", - "windows" => "Windows", - "visionos" => "visionOS", - _ => "", - }, - (sym::target_arch, Some(arch)) => match arch.as_str() { - "aarch64" => "AArch64", - "arm" => "ARM", - "loongarch32" => "LoongArch LA32", - "loongarch64" => "LoongArch LA64", - "m68k" => "M68k", - "csky" => "CSKY", - "mips" => "MIPS", - "mips32r6" => "MIPS Release 6", - "mips64" => "MIPS-64", - "mips64r6" => "MIPS-64 Release 6", - "msp430" => "MSP430", - "powerpc" => "PowerPC", - "powerpc64" => "PowerPC-64", - "riscv32" => "RISC-V RV32", - "riscv64" => "RISC-V RV64", - "s390x" => "s390x", - "sparc64" => "SPARC64", - "wasm32" | "wasm64" => "WebAssembly", - "x86" => "x86", - "x86_64" => "x86-64", - _ => "", - }, + (sym::target_os, Some(os)) => human_readable_target_os(*os).unwrap_or_default(), + (sym::target_arch, Some(arch)) => { + human_readable_target_arch(*arch).unwrap_or_default() + } (sym::target_vendor, Some(vendor)) => match vendor.as_str() { "apple" => "Apple", "pc" => "PC", @@ -476,15 +434,9 @@ impl fmt::Display for Display<'_> { "fortanix" => "Fortanix", _ => "", }, - (sym::target_env, Some(env)) => match env.as_str() { - "gnu" => "GNU", - "msvc" => "MSVC", - "musl" => "musl", - "newlib" => "Newlib", - "uclibc" => "uClibc", - "sgx" => "SGX", - _ => "", - }, + (sym::target_env, Some(env)) => { + human_readable_target_env(*env).unwrap_or_default() + } (sym::target_endian, Some(endian)) => { return write!(fmt, "{endian}-endian"); } @@ -527,6 +479,135 @@ impl fmt::Display for Display<'_> { } } +fn human_readable_target_os(os: Symbol) -> Option<&'static str> { + let os = spec::Os::from_str(os.as_str()).ok()?; + + use spec::Os::*; + Some(match os { + // tidy-alphabetical-start + Aix => "AIX", + AmdHsa => "AMD HSA", + Android => "Android", + Cuda => "CUDA", + Cygwin => "Cygwin", + Dragonfly => "DragonFly BSD", + Emscripten => "Emscripten", + EspIdf => "ESP-IDF", + FreeBsd => "FreeBSD", + Fuchsia => "Fuchsia", + Haiku => "Haiku", + HelenOs => "HelenOS", + Hermit => "Hermit", + Horizon => "Horizon", + Hurd => "GNU/Hurd", + IOs => "iOS", + Illumos => "illumos", + L4Re => "L4Re", + Linux => "Linux", + LynxOs178 => "LynxOS-178", + MacOs => "macOS", + Managarm => "Managarm", + Motor => "Motor OS", + NetBsd => "NetBSD", + None => "bare-metal", // FIXME(scrabsha): is this appropriate? + Nto => "QNX Neutrino", + NuttX => "NuttX", + OpenBsd => "OpenBSD", + Psp => "Play Station Portable", + Psx => "Play Station 1", + Qurt => "QuRT", + Redox => "Redox OS", + Rtems => "RTEMS OS", + Solaris => "Solaris", + SolidAsp3 => "SOLID ASP3", + TeeOs => "TEEOS", + Trusty => "Trusty", + TvOs => "tvOS", + Uefi => "UEFI", + VexOs => "VEXos", + VisionOs => "visionOS", + Vita => "Play Station Vita", + VxWorks => "VxWorks", + Wasi => "WASI", + WatchOs => "watchOS", + Windows => "Windows", + Xous => "Xous", + Zkvm => "zero knowledge Virtual Machine", + // tidy-alphabetical-end + Unknown | Other(_) => return Option::None, + }) +} + +fn human_readable_target_arch(os: Symbol) -> Option<&'static str> { + let arch = spec::Arch::from_str(os.as_str()).ok()?; + + use spec::Arch::*; + Some(match arch { + // tidy-alphabetical-start + AArch64 => "AArch64", + AmdGpu => "AMG GPU", + Arm => "ARM", + Arm64EC => "ARM64EC", + Avr => "AVR", + Bpf => "BPF", + CSky => "C-SKY", + Hexagon => "Hexagon", + LoongArch32 => "LoongArch64", + LoongArch64 => "LoongArch32", + M68k => "Motorola 680x0", + Mips => "MIPS", + Mips32r6 => "MIPS release 6", + Mips64 => "MIPS-64", + Mips64r6 => "MIPS-64 release 6", + Msp430 => "MSP430", + Nvptx64 => "NVidia GPU", + PowerPC => "PowerPC", + PowerPC64 => "PowerPC64", + RiscV32 => "RISC-V RV32", + RiscV64 => "RISC-V RV64", + S390x => "s390x", + Sparc => "SPARC", + Sparc64 => "SPARC-64", + SpirV => "SPIR-V", + Wasm32 | Wasm64 => "WebAssembly", + X86 => "x86", + X86_64 => "x86-64", + Xtensa => "Xtensa", + // tidy-alphabetical-end + Other(_) => return None, + }) +} + +fn human_readable_target_env(env: Symbol) -> Option<&'static str> { + let env = spec::Env::from_str(env.as_str()).ok()?; + + use spec::Env::*; + Some(match env { + // tidy-alphabetical-start + Gnu => "GNU", + MacAbi => "Catalyst", + Mlibc => "mac ABI", + Msvc => "MSVC", + Musl => "musl", + Newlib => "Newlib", + Nto70 => "Neutrino 7.0", + Nto71 => "Neutrino 7.1", + Nto71IoSock => "Neutrino 7.1 with io-sock", + Nto80 => "Neutrino 8.0", + Ohos => "OpenHarmony", + P1 => "WASIp1", + P2 => "WASIp2", + P3 => "WASIp3", + Relibc => "relibc", + Sgx => "SGX", + Sim => "Simulator", + Uclibc => "uClibc", + V5 => "V5", + // tidy-alphabetical-end + Unspecified | Other(_) => return None, + }) +} + #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] struct NameValueCfg { name: Symbol, diff --git a/tests/rustdoc-gui/item-info-overflow.goml b/tests/rustdoc-gui/item-info-overflow.goml index 2c4e06e297c7d..b53ffb00f1c36 100644 --- a/tests/rustdoc-gui/item-info-overflow.goml +++ b/tests/rustdoc-gui/item-info-overflow.goml @@ -8,7 +8,7 @@ assert-property: (".item-info", {"scrollWidth": "940"}) // Just to be sure we're comparing the correct "item-info": assert-text: ( ".item-info", - "Available on Android or Linux or Emscripten or DragonFly BSD", + "Available on Android or Linux or Emscripten or DragonFly BSD or FreeBSD or NetBSD or OpenBSD", STARTS_WITH, ) @@ -26,6 +26,6 @@ assert-property: ( // Just to be sure we're comparing the correct "item-info": assert-text: ( "#impl-SimpleTrait-for-LongItemInfo2 .item-info", - "Available on Android or Linux or Emscripten or DragonFly BSD", + "Available on Android or Linux or Emscripten or DragonFly BSD or FreeBSD or NetBSD or OpenBSD", STARTS_WITH, ) diff --git a/tests/rustdoc-html/doc-cfg/all-targets.rs b/tests/rustdoc-html/doc-cfg/all-targets.rs index ab6e6c216eefa..4db41e1f83448 100644 --- a/tests/rustdoc-html/doc-cfg/all-targets.rs +++ b/tests/rustdoc-html/doc-cfg/all-targets.rs @@ -2,11 +2,10 @@ //@ has all_targets/fn.foo.html \ // '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ -// 'Available on GNU or target_env=macabi or target_env=mlibc or MSVC or musl or \ -// Newlib or target_env=nto70 or target_env=nto71 or target_env=nto71_iosock or \ -// target_env=nto80 or target_env=ohos or target_env=relibc or SGX or \ -// target_env=sim or target_env=p1 or target_env=p2 or target_env=p3 or uClibc or \ -// target_env=v5 or target_env=fake_env only.' +// 'Available on GNU or Catalyst or mac ABI or MSVC or musl or Newlib or \ +// Neutrino 7.0 or Neutrino 7.1 or Neutrino 7.1 with io-sock or Neutrino 8.0 or \ +// OpenHarmony or relibc or SGX or Simulator or WASIp1 or WASIp2 or WASIp3 or \ +// uClibc or V5 or target_env=fake_env only.' #[doc(cfg(any( target_env = "gnu", target_env = "macabi", @@ -33,13 +32,12 @@ pub fn foo() {} //@ has all_targets/fn.bar.html \ // '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ -// 'Available on AArch64 or target_arch=amdgpu or ARM or target_arch=arm64ec or \ -// target_arch=avr or target_arch=bpf or CSKY or target_arch=hexagon or LoongArch \ -// LA32 or LoongArch LA64 or M68k or MIPS or MIPS Release 6 or MIPS-64 or MIPS-64 \ -// Release 6 or MSP430 or target_arch=nvptx64 or PowerPC or PowerPC-64 or RISC-V \ -// RV32 or RISC-V RV64 or s390x or target_arch=sparc or SPARC64 or \ -// target_arch=spirv or WebAssembly or WebAssembly or x86 or x86-64 or \ -// target_arch=xtensa or target_arch=fake_arch only.' +// 'Available on AArch64 or AMG GPU or ARM or ARM64EC or AVR or BPF or C-SKY or \ +// Hexagon or LoongArch64 or LoongArch32 or Motorola 680x0 or MIPS or MIPS release \ +// 6 or MIPS-64 or MIPS-64 release 6 or MSP430 or NVidia GPU or PowerPC or \ +// PowerPC64 or RISC-V RV32 or RISC-V RV64 or s390x or SPARC or SPARC-64 or SPIR-V \ +// or WebAssembly or WebAssembly or x86 or x86-64 or Xtensa or \ +// target_arch=fake_arch only.' #[doc(cfg(any( target_arch = "aarch64", target_arch = "amdgpu", @@ -77,18 +75,15 @@ pub fn bar() {} //@ has all_targets/fn.baz.html \ // '//*[@id="main-content"]/*[@class="item-info"]/*[@class="stab portability"]' \ -// 'Available on target_os=aix and target_os=amdhsa and Android and target_os=cuda \ -// and Cygwin and DragonFly BSD and Emscripten and target_os=espidf and FreeBSD \ -// and Fuchsia and Haiku and target_os=helenos and Hermit and target_os=horizon \ -// and target_os=hurd and illumos and iOS and L4Re and Linux and \ -// target_os=lynxos178 and macOS and target_os=managarm and target_os=motor and \ -// NetBSD and target_os=none and target_os=nto and target_os=nuttx and OpenBSD and \ -// target_os=psp and target_os=psx and target_os=qurt and Redox and \ -// target_os=rtems and Solaris and target_os=solid_asp3 and target_os=teeos and \ -// target_os=trusty and tvOS and target_os=uefi and target_os=vexos and visionOS \ -// and target_os=vita and target_os=vxworks and WASI and watchOS and Windows and \ -// target_os=xous and target_os=zkvm and target_os=unknown and target_os=fake_os \ -// only.' +// 'Available on AIX and AMD HSA and Android and CUDA and Cygwin and DragonFly \ +// BSD and Emscripten and ESP-IDF and FreeBSD and Fuchsia and Haiku and HelenOS \ +// and Hermit and Horizon and GNU/Hurd and illumos and iOS and L4Re and Linux \ +// and LynxOS-178 and macOS and Managarm and Motor OS and NetBSD and bare-metal \ +// and QNX Neutrino and NuttX and OpenBSD and Play Station Portable and Play \ +// Station 1 and QuRT and Redox OS and RTEMS OS and Solaris and SOLID ASP3 and \ +// TEEOS and Trusty and tvOS and UEFI and VEXos and visionOS and Play Station \ +// Vita and VxWorks and WASI and watchOS and Windows and Xous and zero knowledge \ +// Virtual Machine and target_os=unknown and target_os=fake_os only.' #[doc(cfg(all( target_os = "aix", target_os = "amdhsa", From 7d1b41cbb386fef7763885f738f7f89b48de10e2 Mon Sep 17 00:00:00 2001 From: dianne Date: Sun, 29 Mar 2026 08:08:51 -0700 Subject: [PATCH 13/13] update diagnostic for variables moved by `dbg!` --- .../src/diagnostics/conflict_errors.rs | 40 +++++---- compiler/rustc_span/src/symbol.rs | 1 + src/tools/clippy/clippy_utils/src/sym.rs | 1 - tests/ui/borrowck/dbg-issue-120327.rs | 53 ++++-------- tests/ui/borrowck/dbg-issue-120327.stderr | 81 ++++++++++++------- .../dbg-macro-move-semantics.stderr | 4 + 6 files changed, 96 insertions(+), 84 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 641121597848c..56facbb70e64f 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -545,8 +545,6 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { } // for dbg!(x) which may take ownership, suggest dbg!(&x) instead - // but here we actually do not check whether the macro name is `dbg!` - // so that we may extend the scope a bit larger to cover more cases fn suggest_ref_for_dbg_args( &self, body: &hir::Expr<'_>, @@ -560,29 +558,41 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> { }); let Some(var_info) = var_info else { return }; let arg_name = var_info.name; - struct MatchArgFinder { - expr_span: Span, - match_arg_span: Option, + struct MatchArgFinder<'tcx> { + tcx: TyCtxt<'tcx>, + move_span: Span, arg_name: Symbol, + match_arg_span: Option = None, } - impl Visitor<'_> for MatchArgFinder { + impl Visitor<'_> for MatchArgFinder<'_> { fn visit_expr(&mut self, e: &hir::Expr<'_>) { // dbg! is expanded into a match pattern, we need to find the right argument span - if let hir::ExprKind::Match(expr, ..) = &e.kind - && let hir::ExprKind::Path(hir::QPath::Resolved( - _, - path @ Path { segments: [seg], .. }, - )) = &expr.kind - && seg.ident.name == self.arg_name - && self.expr_span.source_callsite().contains(expr.span) + if let hir::ExprKind::Match(scrutinee, ..) = &e.kind + && let hir::ExprKind::Tup(args) = scrutinee.kind + && e.span.macro_backtrace().any(|expn| { + expn.macro_def_id.is_some_and(|macro_def_id| { + self.tcx.is_diagnostic_item(sym::dbg_macro, macro_def_id) + }) + }) { - self.match_arg_span = Some(path.span); + for arg in args { + if let hir::ExprKind::Path(hir::QPath::Resolved( + _, + path @ Path { segments: [seg], .. }, + )) = &arg.kind + && seg.ident.name == self.arg_name + && self.move_span.source_equal(arg.span) + { + self.match_arg_span = Some(path.span); + return; + } + } } hir::intravisit::walk_expr(self, e); } } - let mut finder = MatchArgFinder { expr_span: move_span, match_arg_span: None, arg_name }; + let mut finder = MatchArgFinder { tcx: self.infcx.tcx, move_span, arg_name, .. }; finder.visit_expr(body); if let Some(macro_arg_span) = finder.match_arg_span { err.span_suggestion_verbose( diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 286fea7d90505..e6658fc0eec1c 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -746,6 +746,7 @@ symbols! { custom_mir, custom_test_frameworks, d32, + dbg_macro, dead_code, dealloc, debug, diff --git a/src/tools/clippy/clippy_utils/src/sym.rs b/src/tools/clippy/clippy_utils/src/sym.rs index d6ba678434bc7..909dc3956d5f7 100644 --- a/src/tools/clippy/clippy_utils/src/sym.rs +++ b/src/tools/clippy/clippy_utils/src/sym.rs @@ -199,7 +199,6 @@ generate! { cx, cycle, cyclomatic_complexity, - dbg_macro, de, debug_struct, deprecated_in_future, diff --git a/tests/ui/borrowck/dbg-issue-120327.rs b/tests/ui/borrowck/dbg-issue-120327.rs index 2de43f634877a..45605acc34334 100644 --- a/tests/ui/borrowck/dbg-issue-120327.rs +++ b/tests/ui/borrowck/dbg-issue-120327.rs @@ -1,67 +1,44 @@ +//! Diagnostic test for : suggest borrowing +//! variables passed to `dbg!` that are later used. +//@ dont-require-annotations: HELP + fn s() -> String { let a = String::new(); - dbg!(a); + dbg!(a); //~ HELP consider borrowing instead of transferring ownership return a; //~ ERROR use of moved value: } fn m() -> String { let a = String::new(); - dbg!(1, 2, a, 1, 2); + dbg!(1, 2, a, 1, 2); //~ HELP consider borrowing instead of transferring ownership return a; //~ ERROR use of moved value: } fn t(a: String) -> String { let b: String = "".to_string(); - dbg!(a, b); + dbg!(a, b); //~ HELP consider borrowing instead of transferring ownership return b; //~ ERROR use of moved value: } fn x(a: String) -> String { let b: String = "".to_string(); - dbg!(a, b); + dbg!(a, b); //~ HELP consider borrowing instead of transferring ownership return a; //~ ERROR use of moved value: } -macro_rules! my_dbg { - () => { - eprintln!("[{}:{}:{}]", file!(), line!(), column!()) - }; - ($val:expr $(,)?) => { - match $val { - tmp => { - eprintln!("[{}:{}:{}] {} = {:#?}", - file!(), line!(), column!(), stringify!($val), &tmp); - tmp - } - } - }; - ($($val:expr),+ $(,)?) => { - ($(my_dbg!($val)),+,) - }; -} - -fn test_my_dbg() -> String { - let b: String = "".to_string(); - my_dbg!(b, 1); - return b; //~ ERROR use of moved value: -} - -fn test_not_macro() -> String { - let a = String::new(); - let _b = match a { - tmp => { - eprintln!("dbg: {}", tmp); - tmp - } - }; - return a; //~ ERROR use of moved value: +fn two_of_them(a: String) -> String { + dbg!(a, a); //~ ERROR use of moved value + //~| HELP consider borrowing instead of transferring ownership + //~| HELP consider borrowing instead of transferring ownership + return a; //~ ERROR use of moved value } fn get_expr(_s: String) {} +// The suggestion is purely syntactic; applying it here will result in a type error. fn test() { let a: String = "".to_string(); - let _res = get_expr(dbg!(a)); + let _res = get_expr(dbg!(a)); //~ HELP consider borrowing instead of transferring ownership let _l = a.len(); //~ ERROR borrow of moved value } diff --git a/tests/ui/borrowck/dbg-issue-120327.stderr b/tests/ui/borrowck/dbg-issue-120327.stderr index 685a530a1fe5b..e7a7151e541dd 100644 --- a/tests/ui/borrowck/dbg-issue-120327.stderr +++ b/tests/ui/borrowck/dbg-issue-120327.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `a` - --> $DIR/dbg-issue-120327.rs:4:12 + --> $DIR/dbg-issue-120327.rs:8:12 | LL | let a = String::new(); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait @@ -12,9 +12,13 @@ help: consider cloning the value if the performance cost is acceptable | LL | dbg!(a.clone()); | ++++++++ +help: consider borrowing instead of transferring ownership + | +LL | dbg!(&a); + | + error[E0382]: use of moved value: `a` - --> $DIR/dbg-issue-120327.rs:10:12 + --> $DIR/dbg-issue-120327.rs:14:12 | LL | let a = String::new(); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait @@ -27,9 +31,13 @@ help: consider cloning the value if the performance cost is acceptable | LL | dbg!(1, 2, a.clone(), 1, 2); | ++++++++ +help: consider borrowing instead of transferring ownership + | +LL | dbg!(1, 2, &a, 1, 2); + | + error[E0382]: use of moved value: `b` - --> $DIR/dbg-issue-120327.rs:16:12 + --> $DIR/dbg-issue-120327.rs:20:12 | LL | let b: String = "".to_string(); | - move occurs because `b` has type `String`, which does not implement the `Copy` trait @@ -42,9 +50,13 @@ help: consider cloning the value if the performance cost is acceptable | LL | dbg!(a, b.clone()); | ++++++++ +help: consider borrowing instead of transferring ownership + | +LL | dbg!(a, &b); + | + error[E0382]: use of moved value: `a` - --> $DIR/dbg-issue-120327.rs:22:12 + --> $DIR/dbg-issue-120327.rs:26:12 | LL | fn x(a: String) -> String { | - move occurs because `a` has type `String`, which does not implement the `Copy` trait @@ -58,47 +70,52 @@ help: consider cloning the value if the performance cost is acceptable | LL | dbg!(a.clone(), b); | ++++++++ +help: consider borrowing instead of transferring ownership + | +LL | dbg!(&a, b); + | + -error[E0382]: use of moved value: `b` - --> $DIR/dbg-issue-120327.rs:46:12 +error[E0382]: use of moved value: `a` + --> $DIR/dbg-issue-120327.rs:30:13 | -LL | tmp => { - | --- value moved here -... -LL | let b: String = "".to_string(); - | - move occurs because `b` has type `String`, which does not implement the `Copy` trait -LL | my_dbg!(b, 1); -LL | return b; - | ^ value used here after move +LL | fn two_of_them(a: String) -> String { + | - move occurs because `a` has type `String`, which does not implement the `Copy` trait +LL | dbg!(a, a); + | - ^ value used here after move + | | + | value moved here | -help: consider borrowing instead of transferring ownership +help: consider cloning the value if the performance cost is acceptable | -LL | my_dbg!(&b, 1); - | + -help: borrow this binding in the pattern to avoid moving the value +LL | dbg!(a.clone(), a); + | ++++++++ +help: consider borrowing instead of transferring ownership | -LL | ref tmp => { - | +++ +LL | dbg!(&a, a); + | + error[E0382]: use of moved value: `a` - --> $DIR/dbg-issue-120327.rs:57:12 + --> $DIR/dbg-issue-120327.rs:33:12 | -LL | let a = String::new(); - | - move occurs because `a` has type `String`, which does not implement the `Copy` trait -LL | let _b = match a { -LL | tmp => { - | --- value moved here +LL | fn two_of_them(a: String) -> String { + | - move occurs because `a` has type `String`, which does not implement the `Copy` trait +LL | dbg!(a, a); + | - value moved here ... LL | return a; | ^ value used here after move | -help: borrow this binding in the pattern to avoid moving the value +help: consider cloning the value if the performance cost is acceptable + | +LL | dbg!(a, a.clone()); + | ++++++++ +help: consider borrowing instead of transferring ownership | -LL | ref tmp => { - | +++ +LL | dbg!(a, &a); + | + error[E0382]: borrow of moved value: `a` - --> $DIR/dbg-issue-120327.rs:65:14 + --> $DIR/dbg-issue-120327.rs:42:14 | LL | let a: String = "".to_string(); | - move occurs because `a` has type `String`, which does not implement the `Copy` trait @@ -111,6 +128,10 @@ help: consider cloning the value if the performance cost is acceptable | LL | let _res = get_expr(dbg!(a.clone())); | ++++++++ +help: consider borrowing instead of transferring ownership + | +LL | let _res = get_expr(dbg!(&a)); + | + error: aborting due to 7 previous errors diff --git a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr index 76b2d1be27795..7ce5ebf81e310 100644 --- a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr +++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-move-semantics.stderr @@ -16,6 +16,10 @@ LL | struct NoCopy(usize); ... LL | let _ = dbg!(a); | - you could clone this value +help: consider borrowing instead of transferring ownership + | +LL | let _ = dbg!(&a); + | + error: aborting due to 1 previous error