Skip to content

Commit 111db7d

Browse files
committed
Remove TraitDef::generics.
Because it's always empty.
1 parent 96280b6 commit 111db7d

File tree

13 files changed

+33
-47
lines changed

13 files changed

+33
-47
lines changed

compiler/rustc_ast/src/ast.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -392,15 +392,7 @@ pub struct Generics {
392392
impl Default for Generics {
393393
/// Creates an instance of `Generics`.
394394
fn default() -> Generics {
395-
Generics {
396-
params: Vec::new(),
397-
where_clause: WhereClause {
398-
has_where_token: false,
399-
predicates: Vec::new(),
400-
span: DUMMY_SP,
401-
},
402-
span: DUMMY_SP,
403-
}
395+
Generics { params: Vec::new(), where_clause: Default::default(), span: DUMMY_SP }
404396
}
405397
}
406398

@@ -415,6 +407,12 @@ pub struct WhereClause {
415407
pub span: Span,
416408
}
417409

410+
impl Default for WhereClause {
411+
fn default() -> WhereClause {
412+
WhereClause { has_where_token: false, predicates: Vec::new(), span: DUMMY_SP }
413+
}
414+
}
415+
418416
/// A single predicate in a where-clause.
419417
#[derive(Clone, Encodable, Decodable, Debug)]
420418
pub enum WherePredicate {

compiler/rustc_builtin_macros/src/deriving/bounds.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use crate::deriving::generic::ty::*;
21
use crate::deriving::generic::*;
32
use crate::deriving::path_std;
43

@@ -18,7 +17,6 @@ pub fn expand_deriving_copy(
1817
path: path_std!(marker::Copy),
1918
skip_path_as_bound: false,
2019
additional_bounds: Vec::new(),
21-
generics: Bounds::empty(),
2220
supports_unions: true,
2321
methods: Vec::new(),
2422
associated_types: Vec::new(),

compiler/rustc_builtin_macros/src/deriving/clone.rs

-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ pub fn expand_deriving_clone(
7474
path: path_std!(clone::Clone),
7575
skip_path_as_bound: false,
7676
additional_bounds: bounds,
77-
generics: Bounds::empty(),
7877
supports_unions: true,
7978
methods: vec![MethodDef {
8079
name: sym::clone,

compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ pub fn expand_deriving_eq(
2727
path: path_std!(cmp::Eq),
2828
skip_path_as_bound: false,
2929
additional_bounds: Vec::new(),
30-
generics: Bounds::empty(),
3130
supports_unions: true,
3231
methods: vec![MethodDef {
3332
name: sym::assert_receiver_is_total_eq,

compiler/rustc_builtin_macros/src/deriving/cmp/ord.rs

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ pub fn expand_deriving_ord(
2121
path: path_std!(cmp::Ord),
2222
skip_path_as_bound: false,
2323
additional_bounds: Vec::new(),
24-
generics: Bounds::empty(),
2524
supports_unions: false,
2625
methods: vec![MethodDef {
2726
name: sym::cmp,

compiler/rustc_builtin_macros/src/deriving/cmp/partial_eq.rs

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ pub fn expand_deriving_partial_eq(
8585
path: path_std!(cmp::PartialEq),
8686
skip_path_as_bound: false,
8787
additional_bounds: Vec::new(),
88-
generics: Bounds::empty(),
8988
supports_unions: false,
9089
methods,
9190
associated_types: Vec::new(),

compiler/rustc_builtin_macros/src/deriving/cmp/partial_ord.rs

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ pub fn expand_deriving_partial_ord(
3939
path: path_std!(cmp::PartialOrd),
4040
skip_path_as_bound: false,
4141
additional_bounds: vec![],
42-
generics: Bounds::empty(),
4342
supports_unions: false,
4443
methods: vec![partial_cmp_def],
4544
associated_types: Vec::new(),

compiler/rustc_builtin_macros/src/deriving/debug.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub fn expand_deriving_debug(
2222
path: path_std!(fmt::Debug),
2323
skip_path_as_bound: false,
2424
additional_bounds: Vec::new(),
25-
generics: Bounds::empty(),
2625
supports_unions: false,
2726
methods: vec![MethodDef {
2827
name: sym::fmt,

compiler/rustc_builtin_macros/src/deriving/decodable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub fn expand_deriving_rustc_decodable(
2525
path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
2626
skip_path_as_bound: false,
2727
additional_bounds: Vec::new(),
28-
generics: Bounds::empty(),
2928
supports_unions: false,
3029
methods: vec![MethodDef {
3130
name: sym::decode,

compiler/rustc_builtin_macros/src/deriving/default.rs

-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub fn expand_deriving_default(
2626
path: Path::new(vec![kw::Default, sym::Default]),
2727
skip_path_as_bound: has_a_default_variant(item),
2828
additional_bounds: Vec::new(),
29-
generics: Bounds::empty(),
3029
supports_unions: false,
3130
methods: vec![MethodDef {
3231
name: kw::Default,

compiler/rustc_builtin_macros/src/deriving/encodable.rs

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ pub fn expand_deriving_rustc_encodable(
109109
path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global),
110110
skip_path_as_bound: false,
111111
additional_bounds: Vec::new(),
112-
generics: Bounds::empty(),
113112
supports_unions: false,
114113
methods: vec![MethodDef {
115114
name: sym::encode,

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,6 @@ pub struct TraitDef<'a> {
195195
/// other than the current trait
196196
pub additional_bounds: Vec<Ty>,
197197

198-
/// Any extra lifetimes and/or bounds, e.g., `D: serialize::Decoder`
199-
pub generics: Bounds,
200-
201198
/// Can this trait be derived for unions?
202199
pub supports_unions: bool,
203200

@@ -581,19 +578,21 @@ impl<'a> TraitDef<'a> {
581578
})
582579
});
583580

584-
let Generics { mut params, mut where_clause, .. } =
585-
self.generics.to_generics(cx, self.span, type_ident, generics);
581+
let mut where_clause = ast::WhereClause::default();
586582
where_clause.span = generics.where_clause.span;
587583
let ctxt = self.span.ctxt();
588584
let span = generics.span.with_ctxt(ctxt);
589585

590586
// Create the generic parameters
591-
params.extend(generics.params.iter().map(|param| match &param.kind {
592-
GenericParamKind::Lifetime { .. } => param.clone(),
593-
GenericParamKind::Type { .. } => {
594-
// I don't think this can be moved out of the loop, since
595-
// a GenericBound requires an ast id
596-
let bounds: Vec<_> =
587+
let params: Vec<_> = generics
588+
.params
589+
.iter()
590+
.map(|param| match &param.kind {
591+
GenericParamKind::Lifetime { .. } => param.clone(),
592+
GenericParamKind::Type { .. } => {
593+
// I don't think this can be moved out of the loop, since
594+
// a GenericBound requires an ast id
595+
let bounds: Vec<_> =
597596
// extra restrictions on the generics parameters to the
598597
// type being derived upon
599598
self.additional_bounds.iter().map(|p| {
@@ -606,21 +605,22 @@ impl<'a> TraitDef<'a> {
606605
param.bounds.iter().cloned()
607606
).collect();
608607

609-
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
610-
}
611-
GenericParamKind::Const { ty, kw_span, .. } => {
612-
let const_nodefault_kind = GenericParamKind::Const {
613-
ty: ty.clone(),
614-
kw_span: kw_span.with_ctxt(ctxt),
615-
616-
// We can't have default values inside impl block
617-
default: None,
618-
};
619-
let mut param_clone = param.clone();
620-
param_clone.kind = const_nodefault_kind;
621-
param_clone
622-
}
623-
}));
608+
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
609+
}
610+
GenericParamKind::Const { ty, kw_span, .. } => {
611+
let const_nodefault_kind = GenericParamKind::Const {
612+
ty: ty.clone(),
613+
kw_span: kw_span.with_ctxt(ctxt),
614+
615+
// We can't have default values inside impl block
616+
default: None,
617+
};
618+
let mut param_clone = param.clone();
619+
param_clone.kind = const_nodefault_kind;
620+
param_clone
621+
}
622+
})
623+
.collect();
624624

625625
// and similarly for where clauses
626626
where_clause.predicates.extend(generics.where_clause.predicates.iter().map(|clause| {

compiler/rustc_builtin_macros/src/deriving/hash.rs

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ pub fn expand_deriving_hash(
2424
path,
2525
skip_path_as_bound: false,
2626
additional_bounds: Vec::new(),
27-
generics: Bounds::empty(),
2827
supports_unions: false,
2928
methods: vec![MethodDef {
3029
name: sym::hash,

0 commit comments

Comments
 (0)