Skip to content

Commit 43e9cc1

Browse files
estebankgitbot
authored and
gitbot
committed
Use #[derive(Default)] instead of manually implementing it
1 parent ac6d2c8 commit 43e9cc1

File tree

4 files changed

+7
-33
lines changed

4 files changed

+7
-33
lines changed

core/tests/hash/mod.rs

+3-12
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,11 @@ use std::hash::{BuildHasher, Hash, Hasher};
44
use std::ptr;
55
use std::rc::Rc;
66

7+
#[derive(Default)]
78
struct MyHasher {
89
hash: u64,
910
}
1011

11-
impl Default for MyHasher {
12-
fn default() -> MyHasher {
13-
MyHasher { hash: 0 }
14-
}
15-
}
16-
1712
impl Hasher for MyHasher {
1813
fn write(&mut self, buf: &[u8]) {
1914
for byte in buf {
@@ -107,6 +102,8 @@ fn test_writer_hasher() {
107102
struct Custom {
108103
hash: u64,
109104
}
105+
106+
#[derive(Default)]
110107
struct CustomHasher {
111108
output: u64,
112109
}
@@ -123,12 +120,6 @@ impl Hasher for CustomHasher {
123120
}
124121
}
125122

126-
impl Default for CustomHasher {
127-
fn default() -> CustomHasher {
128-
CustomHasher { output: 0 }
129-
}
130-
}
131-
132123
impl Hash for Custom {
133124
fn hash<H: Hasher>(&self, state: &mut H) {
134125
state.write_u64(self.hash);

proc_macro/src/bridge/fxhash.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
2222
/// out-performs an FNV-based hash within rustc itself -- the collision rate is
2323
/// similar or slightly worse than FNV, but the speed of the hash function
2424
/// itself is much higher because it works on up to 8 bytes at a time.
25+
#[derive(Default)]
2526
pub struct FxHasher {
2627
hash: usize,
2728
}
@@ -31,13 +32,6 @@ const K: usize = 0x9e3779b9;
3132
#[cfg(target_pointer_width = "64")]
3233
const K: usize = 0x517cc1b727220a95;
3334

34-
impl Default for FxHasher {
35-
#[inline]
36-
fn default() -> FxHasher {
37-
FxHasher { hash: 0 }
38-
}
39-
}
40-
4135
impl FxHasher {
4236
#[inline]
4337
fn add_to_hash(&mut self, i: usize) {

std/src/panicking.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ extern "C" fn __rust_foreign_exception() -> ! {
8181
rtabort!("Rust cannot catch foreign exceptions");
8282
}
8383

84+
#[derive(Default)]
8485
enum Hook {
86+
#[default]
8587
Default,
8688
Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>),
8789
}
@@ -96,13 +98,6 @@ impl Hook {
9698
}
9799
}
98100

99-
impl Default for Hook {
100-
#[inline]
101-
fn default() -> Hook {
102-
Hook::Default
103-
}
104-
}
105-
106101
static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
107102

108103
/// Registers a custom panic hook, replacing the previously registered hook.

std/src/sys_common/process.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,13 @@ use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes};
88
use crate::{env, fmt, io};
99

1010
// Stores a set of changes to an environment
11-
#[derive(Clone)]
11+
#[derive(Clone, Default)]
1212
pub struct CommandEnv {
1313
clear: bool,
1414
saw_path: bool,
1515
vars: BTreeMap<EnvKey, Option<OsString>>,
1616
}
1717

18-
impl Default for CommandEnv {
19-
fn default() -> Self {
20-
CommandEnv { clear: false, saw_path: false, vars: Default::default() }
21-
}
22-
}
23-
2418
impl fmt::Debug for CommandEnv {
2519
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2620
let mut debug_command_env = f.debug_struct("CommandEnv");

0 commit comments

Comments
 (0)