Skip to content

Commit 000c169

Browse files
committed
Make some manual impl Default derived
Some caught by the new lint introduced in the next commit. Others noticed manually.
1 parent 387b245 commit 000c169

File tree

6 files changed

+10
-40
lines changed

6 files changed

+10
-40
lines changed

compiler/rustc_ast/src/ast.rs

+3-16
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use rustc_data_structures::sync::Lrc;
3131
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
3232
pub use rustc_span::AttrId;
3333
use rustc_span::source_map::{Spanned, respan};
34-
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
34+
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
3535
use thin_vec::{ThinVec, thin_vec};
3636

3737
pub use crate::format::*;
@@ -387,22 +387,15 @@ impl GenericParam {
387387

388388
/// Represents lifetime, type and const parameters attached to a declaration of
389389
/// a function, enum, trait, etc.
390-
#[derive(Clone, Encodable, Decodable, Debug)]
390+
#[derive(Clone, Encodable, Decodable, Debug, Default)]
391391
pub struct Generics {
392392
pub params: ThinVec<GenericParam>,
393393
pub where_clause: WhereClause,
394394
pub span: Span,
395395
}
396396

397-
impl Default for Generics {
398-
/// Creates an instance of `Generics`.
399-
fn default() -> Generics {
400-
Generics { params: ThinVec::new(), where_clause: Default::default(), span: DUMMY_SP }
401-
}
402-
}
403-
404397
/// A where-clause in a definition.
405-
#[derive(Clone, Encodable, Decodable, Debug)]
398+
#[derive(Clone, Encodable, Decodable, Debug, Default)]
406399
pub struct WhereClause {
407400
/// `true` if we ate a `where` token.
408401
///
@@ -419,12 +412,6 @@ impl WhereClause {
419412
}
420413
}
421414

422-
impl Default for WhereClause {
423-
fn default() -> WhereClause {
424-
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }
425-
}
426-
}
427-
428415
/// A single predicate in a where-clause.
429416
#[derive(Clone, Encodable, Decodable, Debug)]
430417
pub struct WherePredicate {

compiler/rustc_lint/src/unused.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1023,19 +1023,14 @@ declare_lint! {
10231023
"`if`, `match`, `while` and `return` do not need parentheses"
10241024
}
10251025

1026+
#[derive(Default)]
10261027
pub(crate) struct UnusedParens {
10271028
with_self_ty_parens: bool,
10281029
/// `1 as (i32) < 2` parses to ExprKind::Lt
10291030
/// `1 as i32 < 2` parses to i32::<2[missing angle bracket]
10301031
parens_in_cast_in_lt: Vec<ast::NodeId>,
10311032
}
10321033

1033-
impl Default for UnusedParens {
1034-
fn default() -> Self {
1035-
Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() }
1036-
}
1037-
}
1038-
10391034
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
10401035

10411036
impl UnusedDelimLint for UnusedParens {

compiler/rustc_session/src/config.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,10 @@ pub struct CoverageOptions {
168168
}
169169

170170
/// Controls whether branch coverage or MC/DC coverage is enabled.
171-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
171+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
172172
pub enum CoverageLevel {
173173
/// Instrument for coverage at the MIR block level.
174+
#[default]
174175
Block,
175176
/// Also instrument branch points (includes block coverage).
176177
Branch,
@@ -195,12 +196,6 @@ pub enum CoverageLevel {
195196
Mcdc,
196197
}
197198

198-
impl Default for CoverageLevel {
199-
fn default() -> Self {
200-
Self::Block
201-
}
202-
}
203-
204199
/// Settings for `-Z instrument-xray` flag.
205200
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
206201
pub struct InstrumentXRay {

library/core/src/ascii/ascii_char.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,13 @@ use crate::{assert_unsafe_precondition, fmt};
5454
/// [chart]: https://www.unicode.org/charts/PDF/U0000.pdf
5555
/// [NIST FIPS 1-2]: https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub1-2-1977.pdf
5656
/// [NamesList]: https://www.unicode.org/Public/15.0.0/ucd/NamesList.txt
57-
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
57+
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Default)]
5858
#[unstable(feature = "ascii_char", issue = "110998")]
5959
#[repr(u8)]
6060
pub enum AsciiChar {
6161
/// U+0000 (The default variant)
6262
#[unstable(feature = "ascii_char_variants", issue = "110998")]
63+
#[default]
6364
Null = 0,
6465
/// U+0001
6566
#[unstable(feature = "ascii_char_variants", issue = "110998")]

library/core/src/default.rs

-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
33
#![stable(feature = "rust1", since = "1.0.0")]
44

5-
use crate::ascii::Char as AsciiChar;
6-
75
/// A trait for giving a type a useful default value.
86
///
97
/// Sometimes, you want to fall back to some kind of default value, and
@@ -163,7 +161,6 @@ macro_rules! default_impl {
163161
default_impl! { (), (), "Returns the default value of `()`" }
164162
default_impl! { bool, false, "Returns the default value of `false`" }
165163
default_impl! { char, '\x00', "Returns the default value of `\\x00`" }
166-
default_impl! { AsciiChar, AsciiChar::Null, "Returns the default value of `Null`" }
167164

168165
default_impl! { usize, 0, "Returns the default value of `0`" }
169166
default_impl! { u8, 0, "Returns the default value of `0`" }

library/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.

0 commit comments

Comments
 (0)