Skip to content

Commit dd17de0

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 21fe748 commit dd17de0

File tree

6 files changed

+10
-40
lines changed

6 files changed

+10
-40
lines changed

compiler/rustc_ast/src/ast.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use rustc_macros::{Decodable, Encodable, HashStable_Generic};
3232
pub use rustc_span::AttrId;
3333
use rustc_span::source_map::{Spanned, respan};
3434
use rustc_span::symbol::{Ident, Symbol, kw, sym};
35-
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
35+
use rustc_span::{ErrorGuaranteed, Span};
3636
use thin_vec::{ThinVec, thin_vec};
3737

3838
pub use crate::format::*;
@@ -388,22 +388,15 @@ impl GenericParam {
388388

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

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

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

compiler/rustc_lint/src/unused.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,19 +1024,14 @@ declare_lint! {
10241024
"`if`, `match`, `while` and `return` do not need parentheses"
10251025
}
10261026

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

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

10421037
impl UnusedDelimLint for UnusedParens {

compiler/rustc_session/src/config.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ pub struct CoverageOptions {
162162
}
163163

164164
/// Controls whether branch coverage or MC/DC coverage is enabled.
165-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
165+
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
166166
pub enum CoverageLevel {
167167
/// Instrument for coverage at the MIR block level.
168+
#[default]
168169
Block,
169170
/// Also instrument branch points (includes block coverage).
170171
Branch,
@@ -189,12 +190,6 @@ pub enum CoverageLevel {
189190
Mcdc,
190191
}
191192

192-
impl Default for CoverageLevel {
193-
fn default() -> Self {
194-
Self::Block
195-
}
196-
}
197-
198193
/// Settings for `-Z instrument-xray` flag.
199194
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
200195
pub struct InstrumentXRay {

library/core/src/ascii/ascii_char.rs

Lines changed: 2 additions & 1 deletion
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 2 additions & 7 deletions
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)