From fa0383f38d4b165ad2285efade1bbdbb780cdfe5 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sun, 14 Dec 2014 23:16:06 -0500 Subject: [PATCH] librustc_typeck: use `#[deriving(Copy)]` --- src/librustc_typeck/check/method/mod.rs | 4 +--- src/librustc_typeck/check/mod.rs | 11 +++-------- src/librustc_typeck/check/writeback.rs | 3 +-- src/librustc_typeck/collect.rs | 3 +-- src/librustc_typeck/rscope.rs | 3 +-- src/librustc_typeck/variance.rs | 14 ++++---------- 6 files changed, 11 insertions(+), 27 deletions(-) diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index ffaeceb3eed1..3b7eb22e56cc 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -46,14 +46,12 @@ pub enum MethodError { // A pared down enum describing just the places from which a method // candidate can arise. Used for error reporting only. -#[deriving(PartialOrd, Ord, PartialEq, Eq)] +#[deriving(Copy, PartialOrd, Ord, PartialEq, Eq)] pub enum CandidateSource { ImplSource(ast::DefId), TraitSource(/* trait id */ ast::DefId), } -impl Copy for CandidateSource {} - type MethodIndex = uint; // just for doc purposes /// Determines whether the type `self_ty` supports a method name `method_name` or not. diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 9e249cc449d0..bbc33826f355 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -166,6 +166,7 @@ pub struct Inherited<'a, 'tcx: 'a> { /// When type-checking an expression, we propagate downward /// whatever type hint we are able in the form of an `Expectation`. +#[deriving(Copy)] enum Expectation<'tcx> { /// We know nothing about what type this expression should have. NoExpectation, @@ -177,8 +178,6 @@ enum Expectation<'tcx> { ExpectCastableToType(Ty<'tcx>), } -impl<'tcx> Copy for Expectation<'tcx> {} - impl<'tcx> Expectation<'tcx> { // Disregard "castable to" expectations because they // can lead us astray. Consider for example `if cond @@ -1976,14 +1975,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } -#[deriving(Show)] +#[deriving(Copy, Show)] pub enum LvaluePreference { PreferMutLvalue, NoPreference } -impl Copy for LvaluePreference {} - /// Executes an autoderef loop for the type `t`. At each step, invokes `should_stop` to decide /// whether to terminate the loop. Returns the final type and number of derefs that it performed. /// @@ -2856,14 +2853,12 @@ pub fn lookup_tup_field_ty<'tcx>(tcx: &ty::ctxt<'tcx>, // Controls whether the arguments are automatically referenced. This is useful // for overloaded binary and unary operators. -#[deriving(PartialEq)] +#[deriving(Copy, PartialEq)] pub enum AutorefArgs { Yes, No, } -impl Copy for AutorefArgs {} - /// Controls whether the arguments are tupled. This is used for the call /// operator. /// diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index b73381966e8d..700d12116060 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -343,6 +343,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> { /////////////////////////////////////////////////////////////////////////// // Resolution reason. +#[deriving(Copy)] enum ResolveReason { ResolvingExpr(Span), ResolvingLocal(Span), @@ -351,8 +352,6 @@ enum ResolveReason { ResolvingUnboxedClosure(ast::DefId), } -impl Copy for ResolveReason {} - impl ResolveReason { fn span(&self, tcx: &ty::ctxt) -> Span { match *self { diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 280b42f0959d..4612acb04b2f 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -490,6 +490,7 @@ fn convert_associated_type<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>, } } +#[deriving(Copy)] enum ConvertMethodContext<'a> { /// Used when converting implementation methods. ImplConvertMethodContext, @@ -498,8 +499,6 @@ enum ConvertMethodContext<'a> { TraitConvertMethodContext(ast::DefId, &'a [ast::TraitItem]), } -impl<'a> Copy for ConvertMethodContext<'a> {} - fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>, convert_method_context: ConvertMethodContext, container: ImplOrTraitItemContainer, diff --git a/src/librustc_typeck/rscope.rs b/src/librustc_typeck/rscope.rs index 39c7a87837ca..f43e8579022e 100644 --- a/src/librustc_typeck/rscope.rs +++ b/src/librustc_typeck/rscope.rs @@ -36,10 +36,9 @@ pub trait RegionScope { // A scope in which all regions must be explicitly named. This is used // for types that appear in structs and so on. +#[deriving(Copy)] pub struct ExplicitRscope; -impl Copy for ExplicitRscope {} - impl RegionScope for ExplicitRscope { fn default_region_bound(&self, _span: Span) -> Option { None diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index 67478e0bfa77..ef0d1bc3859f 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -229,19 +229,16 @@ pub fn infer_variance(tcx: &ty::ctxt) { type VarianceTermPtr<'a> = &'a VarianceTerm<'a>; -#[deriving(Show)] +#[deriving(Copy, Show)] struct InferredIndex(uint); -impl Copy for InferredIndex {} - +#[deriving(Copy)] enum VarianceTerm<'a> { ConstantTerm(ty::Variance), TransformTerm(VarianceTermPtr<'a>, VarianceTermPtr<'a>), InferredTerm(InferredIndex), } -impl<'a> Copy for VarianceTerm<'a> {} - impl<'a> fmt::Show for VarianceTerm<'a> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { @@ -268,14 +265,12 @@ struct TermsContext<'a, 'tcx: 'a> { inferred_infos: Vec> , } -#[deriving(Show, PartialEq)] +#[deriving(Copy, Show, PartialEq)] enum ParamKind { TypeParam, RegionParam } -impl Copy for ParamKind {} - struct InferredInfo<'a> { item_id: ast::NodeId, kind: ParamKind, @@ -427,13 +422,12 @@ struct ConstraintContext<'a, 'tcx: 'a> { /// Declares that the variable `decl_id` appears in a location with /// variance `variance`. +#[deriving(Copy)] struct Constraint<'a> { inferred: InferredIndex, variance: &'a VarianceTerm<'a>, } -impl<'a> Copy for Constraint<'a> {} - fn add_constraints_from_crate<'a, 'tcx>(terms_cx: TermsContext<'a, 'tcx>, krate: &ast::Crate) -> ConstraintContext<'a, 'tcx> {