diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-12-23 14:44:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-12-23 14:44:20 +0100 |
| commit | 95c33e303bf0ab031a9d4ab2d3fe37077d981164 (patch) | |
| tree | e87d37d7e65d2fbc5321f3e72bb2dc16ac8451ca /library/std/src | |
| parent | 85c39893a761fe4c050523278da4e7e45ab42b6e (diff) | |
| parent | 1f82b45b6a42eca19a9dc48402abdc02574f791d (diff) | |
Rollup merge of #134363 - estebank:derive-default, r=SparrowLii
Use `#[derive(Default)]` instead of manual `impl` when possible While working on #134175 I noticed a few manual `Default` `impl`s that could be `derive`d instead. These likely predate the existence of the `#[default]` attribute for `enum`s.
Diffstat (limited to 'library/std/src')
| -rw-r--r-- | library/std/src/panicking.rs | 9 | ||||
| -rw-r--r-- | library/std/src/sys_common/process.rs | 8 |
2 files changed, 3 insertions, 14 deletions
diff --git a/library/std/src/panicking.rs b/library/std/src/panicking.rs index dca5ccca0c4..e7ce5bc6140 100644 --- a/library/std/src/panicking.rs +++ b/library/std/src/panicking.rs @@ -81,7 +81,9 @@ extern "C" fn __rust_foreign_exception() -> ! { rtabort!("Rust cannot catch foreign exceptions"); } +#[derive(Default)] enum Hook { + #[default] Default, Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>), } @@ -96,13 +98,6 @@ impl Hook { } } -impl Default for Hook { - #[inline] - fn default() -> Hook { - Hook::Default - } -} - static HOOK: RwLock<Hook> = RwLock::new(Hook::Default); /// Registers a custom panic hook, replacing the previously registered hook. diff --git a/library/std/src/sys_common/process.rs b/library/std/src/sys_common/process.rs index 5333ee146f7..9f61d69d858 100644 --- a/library/std/src/sys_common/process.rs +++ b/library/std/src/sys_common/process.rs @@ -8,19 +8,13 @@ use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes}; use crate::{env, fmt, io}; // Stores a set of changes to an environment -#[derive(Clone)] +#[derive(Clone, Default)] pub struct CommandEnv { clear: bool, saw_path: bool, vars: BTreeMap<EnvKey, Option<OsString>>, } -impl Default for CommandEnv { - fn default() -> Self { - CommandEnv { clear: false, saw_path: false, vars: Default::default() } - } -} - impl fmt::Debug for CommandEnv { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let mut debug_command_env = f.debug_struct("CommandEnv"); |
