Use #[derive(Default)]
instead of manually implementing it
This commit is contained in:
parent
e108481f74
commit
1f82b45b6a
8 changed files with 16 additions and 77 deletions
|
@ -31,7 +31,7 @@ use rustc_data_structures::sync::Lrc;
|
||||||
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
use rustc_macros::{Decodable, Encodable, HashStable_Generic};
|
||||||
pub use rustc_span::AttrId;
|
pub use rustc_span::AttrId;
|
||||||
use rustc_span::source_map::{Spanned, respan};
|
use rustc_span::source_map::{Spanned, respan};
|
||||||
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
|
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
|
||||||
use thin_vec::{ThinVec, thin_vec};
|
use thin_vec::{ThinVec, thin_vec};
|
||||||
|
|
||||||
pub use crate::format::*;
|
pub use crate::format::*;
|
||||||
|
@ -387,22 +387,15 @@ impl GenericParam {
|
||||||
|
|
||||||
/// Represents lifetime, type and const parameters attached to a declaration of
|
/// Represents lifetime, type and const parameters attached to a declaration of
|
||||||
/// a function, enum, trait, etc.
|
/// a function, enum, trait, etc.
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug, Default)]
|
||||||
pub struct Generics {
|
pub struct Generics {
|
||||||
pub params: ThinVec<GenericParam>,
|
pub params: ThinVec<GenericParam>,
|
||||||
pub where_clause: WhereClause,
|
pub where_clause: WhereClause,
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Generics {
|
|
||||||
/// Creates an instance of `Generics`.
|
|
||||||
fn default() -> Generics {
|
|
||||||
Generics { params: ThinVec::new(), where_clause: Default::default(), span: DUMMY_SP }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A where-clause in a definition.
|
/// A where-clause in a definition.
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug, Default)]
|
||||||
pub struct WhereClause {
|
pub struct WhereClause {
|
||||||
/// `true` if we ate a `where` token.
|
/// `true` if we ate a `where` token.
|
||||||
///
|
///
|
||||||
|
@ -419,12 +412,6 @@ impl WhereClause {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for WhereClause {
|
|
||||||
fn default() -> WhereClause {
|
|
||||||
WhereClause { has_where_token: false, predicates: ThinVec::new(), span: DUMMY_SP }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// A single predicate in a where-clause.
|
/// A single predicate in a where-clause.
|
||||||
#[derive(Clone, Encodable, Decodable, Debug)]
|
#[derive(Clone, Encodable, Decodable, Debug)]
|
||||||
pub struct WherePredicate {
|
pub struct WherePredicate {
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
use rustc_ast::Expr;
|
use rustc_ast::Expr;
|
||||||
use rustc_ast::util::{classify, parser};
|
use rustc_ast::util::{classify, parser};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
// The default amount of fixing is minimal fixing, so all fixups are set to `false` by `Default`.
|
||||||
|
// Fixups should be turned on in a targeted fashion where needed.
|
||||||
|
#[derive(Copy, Clone, Debug, Default)]
|
||||||
pub(crate) struct FixupContext {
|
pub(crate) struct FixupContext {
|
||||||
/// Print expression such that it can be parsed back as a statement
|
/// Print expression such that it can be parsed back as a statement
|
||||||
/// consisting of the original expression.
|
/// consisting of the original expression.
|
||||||
|
@ -93,20 +95,6 @@ pub(crate) struct FixupContext {
|
||||||
parenthesize_exterior_struct_lit: bool,
|
parenthesize_exterior_struct_lit: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The default amount of fixing is minimal fixing. Fixups should be turned on
|
|
||||||
/// in a targeted fashion where needed.
|
|
||||||
impl Default for FixupContext {
|
|
||||||
fn default() -> Self {
|
|
||||||
FixupContext {
|
|
||||||
stmt: false,
|
|
||||||
leftmost_subexpression_in_stmt: false,
|
|
||||||
match_arm: false,
|
|
||||||
leftmost_subexpression_in_match_arm: false,
|
|
||||||
parenthesize_exterior_struct_lit: false,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FixupContext {
|
impl FixupContext {
|
||||||
/// Create the initial fixup for printing an expression in statement
|
/// Create the initial fixup for printing an expression in statement
|
||||||
/// position.
|
/// position.
|
||||||
|
|
|
@ -1023,6 +1023,7 @@ declare_lint! {
|
||||||
"`if`, `match`, `while` and `return` do not need parentheses"
|
"`if`, `match`, `while` and `return` do not need parentheses"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub(crate) struct UnusedParens {
|
pub(crate) struct UnusedParens {
|
||||||
with_self_ty_parens: bool,
|
with_self_ty_parens: bool,
|
||||||
/// `1 as (i32) < 2` parses to ExprKind::Lt
|
/// `1 as (i32) < 2` parses to ExprKind::Lt
|
||||||
|
@ -1030,12 +1031,6 @@ pub(crate) struct UnusedParens {
|
||||||
parens_in_cast_in_lt: Vec<ast::NodeId>,
|
parens_in_cast_in_lt: Vec<ast::NodeId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for UnusedParens {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self { with_self_ty_parens: false, parens_in_cast_in_lt: Vec::new() }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
|
impl_lint_pass!(UnusedParens => [UNUSED_PARENS]);
|
||||||
|
|
||||||
impl UnusedDelimLint for UnusedParens {
|
impl UnusedDelimLint for UnusedParens {
|
||||||
|
|
|
@ -168,9 +168,10 @@ pub struct CoverageOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Controls whether branch coverage or MC/DC coverage is enabled.
|
/// Controls whether branch coverage or MC/DC coverage is enabled.
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Default)]
|
||||||
pub enum CoverageLevel {
|
pub enum CoverageLevel {
|
||||||
/// Instrument for coverage at the MIR block level.
|
/// Instrument for coverage at the MIR block level.
|
||||||
|
#[default]
|
||||||
Block,
|
Block,
|
||||||
/// Also instrument branch points (includes block coverage).
|
/// Also instrument branch points (includes block coverage).
|
||||||
Branch,
|
Branch,
|
||||||
|
@ -195,12 +196,6 @@ pub enum CoverageLevel {
|
||||||
Mcdc,
|
Mcdc,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CoverageLevel {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self::Block
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Settings for `-Z instrument-xray` flag.
|
/// Settings for `-Z instrument-xray` flag.
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
||||||
pub struct InstrumentXRay {
|
pub struct InstrumentXRay {
|
||||||
|
|
|
@ -4,16 +4,11 @@ use std::hash::{BuildHasher, Hash, Hasher};
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct MyHasher {
|
struct MyHasher {
|
||||||
hash: u64,
|
hash: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for MyHasher {
|
|
||||||
fn default() -> MyHasher {
|
|
||||||
MyHasher { hash: 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Hasher for MyHasher {
|
impl Hasher for MyHasher {
|
||||||
fn write(&mut self, buf: &[u8]) {
|
fn write(&mut self, buf: &[u8]) {
|
||||||
for byte in buf {
|
for byte in buf {
|
||||||
|
@ -107,6 +102,8 @@ fn test_writer_hasher() {
|
||||||
struct Custom {
|
struct Custom {
|
||||||
hash: u64,
|
hash: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
struct CustomHasher {
|
struct CustomHasher {
|
||||||
output: u64,
|
output: u64,
|
||||||
}
|
}
|
||||||
|
@ -123,12 +120,6 @@ impl Hasher for CustomHasher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for CustomHasher {
|
|
||||||
fn default() -> CustomHasher {
|
|
||||||
CustomHasher { output: 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Hash for Custom {
|
impl Hash for Custom {
|
||||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||||
state.write_u64(self.hash);
|
state.write_u64(self.hash);
|
||||||
|
|
|
@ -22,6 +22,7 @@ pub type FxHashMap<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;
|
||||||
/// out-performs an FNV-based hash within rustc itself -- the collision rate is
|
/// out-performs an FNV-based hash within rustc itself -- the collision rate is
|
||||||
/// similar or slightly worse than FNV, but the speed of the hash function
|
/// similar or slightly worse than FNV, but the speed of the hash function
|
||||||
/// itself is much higher because it works on up to 8 bytes at a time.
|
/// itself is much higher because it works on up to 8 bytes at a time.
|
||||||
|
#[derive(Default)]
|
||||||
pub struct FxHasher {
|
pub struct FxHasher {
|
||||||
hash: usize,
|
hash: usize,
|
||||||
}
|
}
|
||||||
|
@ -31,13 +32,6 @@ const K: usize = 0x9e3779b9;
|
||||||
#[cfg(target_pointer_width = "64")]
|
#[cfg(target_pointer_width = "64")]
|
||||||
const K: usize = 0x517cc1b727220a95;
|
const K: usize = 0x517cc1b727220a95;
|
||||||
|
|
||||||
impl Default for FxHasher {
|
|
||||||
#[inline]
|
|
||||||
fn default() -> FxHasher {
|
|
||||||
FxHasher { hash: 0 }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FxHasher {
|
impl FxHasher {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn add_to_hash(&mut self, i: usize) {
|
fn add_to_hash(&mut self, i: usize) {
|
||||||
|
|
|
@ -81,7 +81,9 @@ extern "C" fn __rust_foreign_exception() -> ! {
|
||||||
rtabort!("Rust cannot catch foreign exceptions");
|
rtabort!("Rust cannot catch foreign exceptions");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
enum Hook {
|
enum Hook {
|
||||||
|
#[default]
|
||||||
Default,
|
Default,
|
||||||
Custom(Box<dyn Fn(&PanicHookInfo<'_>) + 'static + Sync + Send>),
|
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);
|
static HOOK: RwLock<Hook> = RwLock::new(Hook::Default);
|
||||||
|
|
||||||
/// Registers a custom panic hook, replacing the previously registered hook.
|
/// Registers a custom panic hook, replacing the previously registered hook.
|
||||||
|
|
|
@ -8,19 +8,13 @@ use crate::sys::process::{EnvKey, ExitStatus, Process, StdioPipes};
|
||||||
use crate::{env, fmt, io};
|
use crate::{env, fmt, io};
|
||||||
|
|
||||||
// Stores a set of changes to an environment
|
// Stores a set of changes to an environment
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Default)]
|
||||||
pub struct CommandEnv {
|
pub struct CommandEnv {
|
||||||
clear: bool,
|
clear: bool,
|
||||||
saw_path: bool,
|
saw_path: bool,
|
||||||
vars: BTreeMap<EnvKey, Option<OsString>>,
|
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 {
|
impl fmt::Debug for CommandEnv {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
let mut debug_command_env = f.debug_struct("CommandEnv");
|
let mut debug_command_env = f.debug_struct("CommandEnv");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue