Skip to content

Commit

Permalink
librustc: use #[deriving(Copy)]
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorge Aparicio committed Dec 19, 2014
1 parent f2ef2cd commit e64a007
Show file tree
Hide file tree
Showing 36 changed files with 159 additions and 426 deletions.
63 changes: 21 additions & 42 deletions src/librustc/lint/builtin.rs
Expand Up @@ -56,10 +56,9 @@ declare_lint! {
"suggest using `loop { }` instead of `while true { }`"
}

#[deriving(Copy)]
pub struct WhileTrue;

impl Copy for WhileTrue {}

impl LintPass for WhileTrue {
fn get_lints(&self) -> LintArray {
lint_array!(WHILE_TRUE)
Expand All @@ -83,10 +82,9 @@ declare_lint! {
"detects unnecessary type casts that can be removed"
}

#[deriving(Copy)]
pub struct UnusedCasts;

impl Copy for UnusedCasts {}

impl LintPass for UnusedCasts {
fn get_lints(&self) -> LintArray {
lint_array!(UNUSED_TYPECASTS)
Expand Down Expand Up @@ -126,13 +124,12 @@ declare_lint! {
"shift exceeds the type's number of bits"
}

#[deriving(Copy)]
pub struct TypeLimits {
/// Id of the last visited negated expression
negated_expr_id: ast::NodeId,
}

impl Copy for TypeLimits {}

impl TypeLimits {
pub fn new() -> TypeLimits {
TypeLimits {
Expand Down Expand Up @@ -442,10 +439,9 @@ impl<'a, 'tcx, 'v> Visitor<'v> for ImproperCTypesVisitor<'a, 'tcx> {
}
}

#[deriving(Copy)]
pub struct ImproperCTypes;

impl Copy for ImproperCTypes {}

impl LintPass for ImproperCTypes {
fn get_lints(&self) -> LintArray {
lint_array!(IMPROPER_CTYPES)
Expand Down Expand Up @@ -486,10 +482,9 @@ declare_lint! {
"use of owned (Box type) heap memory"
}

#[deriving(Copy)]
pub struct BoxPointers;

impl Copy for BoxPointers {}

impl BoxPointers {
fn check_heap_type<'a, 'tcx>(&self, cx: &Context<'a, 'tcx>,
span: Span, ty: Ty<'tcx>) {
Expand Down Expand Up @@ -627,10 +622,9 @@ declare_lint! {
"detects attributes that were not used by the compiler"
}

#[deriving(Copy)]
pub struct UnusedAttributes;

impl Copy for UnusedAttributes {}

impl LintPass for UnusedAttributes {
fn get_lints(&self) -> LintArray {
lint_array!(UNUSED_ATTRIBUTES)
Expand Down Expand Up @@ -711,10 +705,9 @@ declare_lint! {
"path statements with no effect"
}

#[deriving(Copy)]
pub struct PathStatements;

impl Copy for PathStatements {}

impl LintPass for PathStatements {
fn get_lints(&self) -> LintArray {
lint_array!(PATH_STATEMENTS)
Expand Down Expand Up @@ -746,10 +739,9 @@ declare_lint! {
"unused result of an expression in a statement"
}

#[deriving(Copy)]
pub struct UnusedResults;

impl Copy for UnusedResults {}

impl LintPass for UnusedResults {
fn get_lints(&self) -> LintArray {
lint_array!(UNUSED_MUST_USE, UNUSED_RESULTS)
Expand Down Expand Up @@ -815,10 +807,9 @@ declare_lint! {
"types, variants, traits and type parameters should have camel case names"
}

#[deriving(Copy)]
pub struct NonCamelCaseTypes;

impl Copy for NonCamelCaseTypes {}

impl NonCamelCaseTypes {
fn check_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
fn is_camel_case(ident: ast::Ident) -> bool {
Expand Down Expand Up @@ -939,10 +930,9 @@ declare_lint! {
"methods, functions, lifetime parameters and modules should have snake case names"
}

#[deriving(Copy)]
pub struct NonSnakeCase;

impl Copy for NonSnakeCase {}

impl NonSnakeCase {
fn check_snake_case(&self, cx: &Context, sort: &str, ident: ast::Ident, span: Span) {
fn is_snake_case(ident: ast::Ident) -> bool {
Expand Down Expand Up @@ -1053,10 +1043,9 @@ declare_lint! {
"static constants should have uppercase identifiers"
}

#[deriving(Copy)]
pub struct NonUpperCaseGlobals;

impl Copy for NonUpperCaseGlobals {}

impl LintPass for NonUpperCaseGlobals {
fn get_lints(&self) -> LintArray {
lint_array!(NON_UPPER_CASE_GLOBALS)
Expand Down Expand Up @@ -1107,10 +1096,9 @@ declare_lint! {
"`if`, `match`, `while` and `return` do not need parentheses"
}

#[deriving(Copy)]
pub struct UnusedParens;

impl Copy for UnusedParens {}

impl UnusedParens {
fn check_unused_parens_core(&self, cx: &Context, value: &ast::Expr, msg: &str,
struct_lit_needs_parens: bool) {
Expand Down Expand Up @@ -1202,10 +1190,9 @@ declare_lint! {
"unnecessary braces around an imported item"
}

#[deriving(Copy)]
pub struct UnusedImportBraces;

impl Copy for UnusedImportBraces {}

impl LintPass for UnusedImportBraces {
fn get_lints(&self) -> LintArray {
lint_array!(UNUSED_IMPORT_BRACES)
Expand Down Expand Up @@ -1242,10 +1229,9 @@ declare_lint! {
"using `Struct { x: x }` instead of `Struct { x }`"
}

#[deriving(Copy)]
pub struct NonShorthandFieldPatterns;

impl Copy for NonShorthandFieldPatterns {}

impl LintPass for NonShorthandFieldPatterns {
fn get_lints(&self) -> LintArray {
lint_array!(NON_SHORTHAND_FIELD_PATTERNS)
Expand Down Expand Up @@ -1276,10 +1262,9 @@ declare_lint! {
"unnecessary use of an `unsafe` block"
}

#[deriving(Copy)]
pub struct UnusedUnsafe;

impl Copy for UnusedUnsafe {}

impl LintPass for UnusedUnsafe {
fn get_lints(&self) -> LintArray {
lint_array!(UNUSED_UNSAFE)
Expand All @@ -1302,10 +1287,9 @@ declare_lint! {
"usage of an `unsafe` block"
}

#[deriving(Copy)]
pub struct UnsafeBlocks;

impl Copy for UnsafeBlocks {}

impl LintPass for UnsafeBlocks {
fn get_lints(&self) -> LintArray {
lint_array!(UNSAFE_BLOCKS)
Expand All @@ -1327,10 +1311,9 @@ declare_lint! {
"detect mut variables which don't need to be mutable"
}

#[deriving(Copy)]
pub struct UnusedMut;

impl Copy for UnusedMut {}

impl UnusedMut {
fn check_unused_mut_pat(&self, cx: &Context, pats: &[P<ast::Pat>]) {
// collect all mutable pattern and group their NodeIDs by their Identifier to
Expand Down Expand Up @@ -1397,10 +1380,9 @@ declare_lint! {
"detects unnecessary allocations that can be eliminated"
}

#[deriving(Copy)]
pub struct UnusedAllocation;

impl Copy for UnusedAllocation {}

impl LintPass for UnusedAllocation {
fn get_lints(&self) -> LintArray {
lint_array!(UNUSED_ALLOCATION)
Expand Down Expand Up @@ -1589,10 +1571,9 @@ impl LintPass for MissingDoc {
}
}

#[deriving(Copy)]
pub struct MissingCopyImplementations;

impl Copy for MissingCopyImplementations {}

impl LintPass for MissingCopyImplementations {
fn get_lints(&self) -> LintArray {
lint_array!(MISSING_COPY_IMPLEMENTATIONS)
Expand Down Expand Up @@ -1665,10 +1646,9 @@ declare_lint! {

/// Checks for use of items with `#[deprecated]`, `#[experimental]` and
/// `#[unstable]` attributes, or no stability attribute.
#[deriving(Copy)]
pub struct Stability;

impl Copy for Stability {}

impl Stability {
fn lint(&self, cx: &Context, id: ast::DefId, span: Span) {
let stability = stability::lookup(cx.tcx, id);
Expand Down Expand Up @@ -1903,10 +1883,9 @@ declare_lint!{

/// Does nothing as a lint pass, but registers some `Lint`s
/// which are used by other parts of the compiler.
#[deriving(Copy)]
pub struct HardwiredLints;

impl Copy for HardwiredLints {}

impl LintPass for HardwiredLints {
fn get_lints(&self) -> LintArray {
lint_array!(
Expand Down
15 changes: 4 additions & 11 deletions src/librustc/lint/mod.rs
Expand Up @@ -42,6 +42,7 @@ use syntax::ast;
pub use lint::context::{Context, LintStore, raw_emit_lint, check_crate, gather_attrs};

/// Specification of a single lint.
#[deriving(Copy)]
pub struct Lint {
/// A string identifier for the lint.
///
Expand All @@ -64,8 +65,6 @@ pub struct Lint {
pub desc: &'static str,
}

impl Copy for Lint {}

impl Lint {
/// Get the lint's name, with ASCII letters converted to lowercase.
pub fn name_lower(&self) -> String {
Expand Down Expand Up @@ -175,14 +174,12 @@ pub trait LintPass {
pub type LintPassObject = Box<LintPass + 'static>;

/// Identifies a lint known to the compiler.
#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct LintId {
// Identity is based on pointer equality of this field.
lint: &'static Lint,
}

impl Copy for LintId {}

impl PartialEq for LintId {
fn eq(&self, other: &LintId) -> bool {
(self.lint as *const Lint) == (other.lint as *const Lint)
Expand Down Expand Up @@ -213,13 +210,11 @@ impl LintId {
}

/// Setting for how to handle a lint.
#[deriving(Clone, PartialEq, PartialOrd, Eq, Ord)]
#[deriving(Clone, Copy, PartialEq, PartialOrd, Eq, Ord)]
pub enum Level {
Allow, Warn, Deny, Forbid
}

impl Copy for Level {}

impl Level {
/// Convert a level to a lower-case string.
pub fn as_str(self) -> &'static str {
Expand All @@ -244,7 +239,7 @@ impl Level {
}

/// How a lint level was set.
#[deriving(Clone, PartialEq, Eq)]
#[deriving(Clone, Copy, PartialEq, Eq)]
pub enum LintSource {
/// Lint is at the default level as declared
/// in rustc or a plugin.
Expand All @@ -257,8 +252,6 @@ pub enum LintSource {
CommandLine,
}

impl Copy for LintSource {}

pub type LevelSource = (Level, LintSource);

pub mod builtin;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/common.rs
Expand Up @@ -113,7 +113,7 @@ pub const tag_items_data_item_reexport_def_id: uint = 0x39;
pub const tag_items_data_item_reexport_name: uint = 0x3a;

// used to encode crate_ctxt side tables
#[deriving(PartialEq)]
#[deriving(Copy, PartialEq)]
#[repr(uint)]
pub enum astencode_tag { // Reserves 0x40 -- 0x5f
tag_ast = 0x40,
Expand Down Expand Up @@ -145,7 +145,6 @@ pub enum astencode_tag { // Reserves 0x40 -- 0x5f
tag_table_object_cast_map = 0x57,
}

impl Copy for astencode_tag {}
static first_astencode_tag: uint = tag_ast as uint;
static last_astencode_tag: uint = tag_table_object_cast_map as uint;
impl astencode_tag {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/metadata/csearch.rs
Expand Up @@ -33,14 +33,13 @@ use syntax::parse::token;

use std::collections::hash_map::HashMap;

#[deriving(Copy)]
pub struct MethodInfo {
pub name: ast::Name,
pub def_id: ast::DefId,
pub vis: ast::Visibility,
}

impl Copy for MethodInfo {}

pub fn get_symbol(cstore: &cstore::CStore, def: ast::DefId) -> String {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_symbol(cdata.data(), def.node)
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/metadata/cstore.rs
Expand Up @@ -48,23 +48,19 @@ pub struct crate_metadata {
pub span: Span,
}

#[deriving(Show, PartialEq, Clone)]
#[deriving(Copy, Show, PartialEq, Clone)]
pub enum LinkagePreference {
RequireDynamic,
RequireStatic,
}

impl Copy for LinkagePreference {}

#[deriving(Clone, PartialEq, FromPrimitive)]
#[deriving(Copy, Clone, PartialEq, FromPrimitive)]
pub enum NativeLibraryKind {
NativeStatic, // native static library (.a archive)
NativeFramework, // OSX-specific
NativeUnknown, // default way to specify a dynamic library
}

impl Copy for NativeLibraryKind {}

// Where a crate came from on the local filesystem. One of these two options
// must be non-None.
#[deriving(PartialEq, Clone)]
Expand Down
4 changes: 1 addition & 3 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -450,15 +450,13 @@ pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
}

// Something that a name can resolve to.
#[deriving(Clone,Show)]
#[deriving(Copy, Clone, Show)]
pub enum DefLike {
DlDef(def::Def),
DlImpl(ast::DefId),
DlField
}

impl Copy for DefLike {}

/// Iterates over the language items in the given crate.
pub fn each_lang_item<F>(cdata: Cmd, mut f: F) -> bool where
F: FnMut(ast::NodeId, uint) -> bool,
Expand Down

0 comments on commit e64a007

Please sign in to comment.