1
Fork 0

Remove TraitDef::generics.

Because it's always empty.
This commit is contained in:
Nicholas Nethercote 2022-11-14 15:43:10 +11:00
parent 96280b6a1d
commit 111db7d3a8
13 changed files with 32 additions and 46 deletions

View file

@ -392,15 +392,7 @@ pub struct Generics {
impl Default for Generics { impl Default for Generics {
/// Creates an instance of `Generics`. /// Creates an instance of `Generics`.
fn default() -> Generics { fn default() -> Generics {
Generics { Generics { params: Vec::new(), where_clause: Default::default(), span: DUMMY_SP }
params: Vec::new(),
where_clause: WhereClause {
has_where_token: false,
predicates: Vec::new(),
span: DUMMY_SP,
},
span: DUMMY_SP,
}
} }
} }
@ -415,6 +407,12 @@ pub struct WhereClause {
pub span: Span, pub span: Span,
} }
impl Default for WhereClause {
fn default() -> WhereClause {
WhereClause { has_where_token: false, predicates: Vec::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 enum WherePredicate { pub enum WherePredicate {

View file

@ -1,4 +1,3 @@
use crate::deriving::generic::ty::*;
use crate::deriving::generic::*; use crate::deriving::generic::*;
use crate::deriving::path_std; use crate::deriving::path_std;
@ -18,7 +17,6 @@ pub fn expand_deriving_copy(
path: path_std!(marker::Copy), path: path_std!(marker::Copy),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: true, supports_unions: true,
methods: Vec::new(), methods: Vec::new(),
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -74,7 +74,6 @@ pub fn expand_deriving_clone(
path: path_std!(clone::Clone), path: path_std!(clone::Clone),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: bounds, additional_bounds: bounds,
generics: Bounds::empty(),
supports_unions: true, supports_unions: true,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::clone, name: sym::clone,

View file

@ -27,7 +27,6 @@ pub fn expand_deriving_eq(
path: path_std!(cmp::Eq), path: path_std!(cmp::Eq),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: true, supports_unions: true,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::assert_receiver_is_total_eq, name: sym::assert_receiver_is_total_eq,

View file

@ -21,7 +21,6 @@ pub fn expand_deriving_ord(
path: path_std!(cmp::Ord), path: path_std!(cmp::Ord),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::cmp, name: sym::cmp,

View file

@ -85,7 +85,6 @@ pub fn expand_deriving_partial_eq(
path: path_std!(cmp::PartialEq), path: path_std!(cmp::PartialEq),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods, methods,
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -39,7 +39,6 @@ pub fn expand_deriving_partial_ord(
path: path_std!(cmp::PartialOrd), path: path_std!(cmp::PartialOrd),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: vec![], additional_bounds: vec![],
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![partial_cmp_def], methods: vec![partial_cmp_def],
associated_types: Vec::new(), associated_types: Vec::new(),

View file

@ -22,7 +22,6 @@ pub fn expand_deriving_debug(
path: path_std!(fmt::Debug), path: path_std!(fmt::Debug),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::fmt, name: sym::fmt,

View file

@ -25,7 +25,6 @@ pub fn expand_deriving_rustc_decodable(
path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global), path: Path::new_(vec![krate, sym::Decodable], vec![], PathKind::Global),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::decode, name: sym::decode,

View file

@ -26,7 +26,6 @@ pub fn expand_deriving_default(
path: Path::new(vec![kw::Default, sym::Default]), path: Path::new(vec![kw::Default, sym::Default]),
skip_path_as_bound: has_a_default_variant(item), skip_path_as_bound: has_a_default_variant(item),
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![MethodDef { methods: vec![MethodDef {
name: kw::Default, name: kw::Default,

View file

@ -109,7 +109,6 @@ pub fn expand_deriving_rustc_encodable(
path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global), path: Path::new_(vec![krate, sym::Encodable], vec![], PathKind::Global),
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::encode, name: sym::encode,

View file

@ -195,9 +195,6 @@ pub struct TraitDef<'a> {
/// other than the current trait /// other than the current trait
pub additional_bounds: Vec<Ty>, pub additional_bounds: Vec<Ty>,
/// Any extra lifetimes and/or bounds, e.g., `D: serialize::Decoder`
pub generics: Bounds,
/// Can this trait be derived for unions? /// Can this trait be derived for unions?
pub supports_unions: bool, pub supports_unions: bool,
@ -581,19 +578,21 @@ impl<'a> TraitDef<'a> {
}) })
}); });
let Generics { mut params, mut where_clause, .. } = let mut where_clause = ast::WhereClause::default();
self.generics.to_generics(cx, self.span, type_ident, generics);
where_clause.span = generics.where_clause.span; where_clause.span = generics.where_clause.span;
let ctxt = self.span.ctxt(); let ctxt = self.span.ctxt();
let span = generics.span.with_ctxt(ctxt); let span = generics.span.with_ctxt(ctxt);
// Create the generic parameters // Create the generic parameters
params.extend(generics.params.iter().map(|param| match &param.kind { let params: Vec<_> = generics
GenericParamKind::Lifetime { .. } => param.clone(), .params
GenericParamKind::Type { .. } => { .iter()
// I don't think this can be moved out of the loop, since .map(|param| match &param.kind {
// a GenericBound requires an ast id GenericParamKind::Lifetime { .. } => param.clone(),
let bounds: Vec<_> = GenericParamKind::Type { .. } => {
// I don't think this can be moved out of the loop, since
// a GenericBound requires an ast id
let bounds: Vec<_> =
// extra restrictions on the generics parameters to the // extra restrictions on the generics parameters to the
// type being derived upon // type being derived upon
self.additional_bounds.iter().map(|p| { self.additional_bounds.iter().map(|p| {
@ -606,21 +605,22 @@ impl<'a> TraitDef<'a> {
param.bounds.iter().cloned() param.bounds.iter().cloned()
).collect(); ).collect();
cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None) cx.typaram(param.ident.span.with_ctxt(ctxt), param.ident, bounds, None)
} }
GenericParamKind::Const { ty, kw_span, .. } => { GenericParamKind::Const { ty, kw_span, .. } => {
let const_nodefault_kind = GenericParamKind::Const { let const_nodefault_kind = GenericParamKind::Const {
ty: ty.clone(), ty: ty.clone(),
kw_span: kw_span.with_ctxt(ctxt), kw_span: kw_span.with_ctxt(ctxt),
// We can't have default values inside impl block // We can't have default values inside impl block
default: None, default: None,
}; };
let mut param_clone = param.clone(); let mut param_clone = param.clone();
param_clone.kind = const_nodefault_kind; param_clone.kind = const_nodefault_kind;
param_clone param_clone
} }
})); })
.collect();
// and similarly for where clauses // and similarly for where clauses
where_clause.predicates.extend(generics.where_clause.predicates.iter().map(|clause| { where_clause.predicates.extend(generics.where_clause.predicates.iter().map(|clause| {

View file

@ -24,7 +24,6 @@ pub fn expand_deriving_hash(
path, path,
skip_path_as_bound: false, skip_path_as_bound: false,
additional_bounds: Vec::new(), additional_bounds: Vec::new(),
generics: Bounds::empty(),
supports_unions: false, supports_unions: false,
methods: vec![MethodDef { methods: vec![MethodDef {
name: sym::hash, name: sym::hash,