diff options
| author | bors <bors@rust-lang.org> | 2016-04-06 05:04:15 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-04-06 05:04:15 -0700 |
| commit | 943ec3bdfc9ba28e94b6d00a2b53fb2cd8b21655 (patch) | |
| tree | 30b2cefa099bea233f2e257116c5ec99589aaa63 /src/libsyntax_ext | |
| parent | 772c600d4d6f39daa6d07d1a60ee0df3d3426978 (diff) | |
| parent | 552af51ffb9f4ae08a7ee3bf27b0e8309006ca6f (diff) | |
| download | rust-943ec3bdfc9ba28e94b6d00a2b53fb2cd8b21655.tar.gz rust-943ec3bdfc9ba28e94b6d00a2b53fb2cd8b21655.zip | |
Auto merge of #32767 - Manishearth:breakingbatch, r=eddyb
Batch up all plugin breaking changes https://github.com/rust-lang/rust/pull/32688 already landed so we should get this into the same nightly. cc https://github.com/rust-lang/rust/issues/31645
Diffstat (limited to 'src/libsyntax_ext')
| -rw-r--r-- | src/libsyntax_ext/deriving/generic/mod.rs | 63 |
1 files changed, 14 insertions, 49 deletions
diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 7d452b14dae..b8ba1a58f21 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -186,7 +186,6 @@ pub use self::StaticFields::*; pub use self::SubstructureFields::*; -use self::StructType::*; use std::cell::RefCell; use std::collections::HashSet; @@ -194,7 +193,6 @@ use std::vec; use syntax::abi::Abi; use syntax::ast::{self, EnumDef, Expr, Ident, Generics, VariantData, BinOpKind, PatKind}; -use syntax::ast_util; use syntax::attr; use syntax::attr::AttrMetaMethods; use syntax::ext::base::{ExtCtxt, Annotatable}; @@ -620,7 +618,6 @@ impl<'a> TraitDef<'a> { // Just mark it now since we know that it'll end up used downstream attr::mark_used(&attr); let opt_trait_ref = Some(trait_ref); - let ident = ast_util::impl_pretty_name(&opt_trait_ref, Some(&self_type)); let unused_qual = cx.attribute( self.span, cx.meta_list(self.span, @@ -638,7 +635,7 @@ impl<'a> TraitDef<'a> { cx.item( self.span, - ident, + special_idents::invalid, a, ast::ItemKind::Impl(unsafety, ast::ImplPolarity::Positive, @@ -654,7 +651,7 @@ impl<'a> TraitDef<'a> { type_ident: Ident, generics: &Generics) -> P<ast::Item> { let field_tys: Vec<P<ast::Ty>> = struct_def.fields().iter() - .map(|field| field.node.ty.clone()) + .map(|field| field.ty.clone()) .collect(); let methods = self.methods.iter().map(|method_def| { @@ -702,7 +699,7 @@ impl<'a> TraitDef<'a> { for variant in &enum_def.variants { field_tys.extend(variant.node.data.fields().iter() - .map(|field| field.node.ty.clone())); + .map(|field| field.ty.clone())); } let methods = self.methods.iter().map(|method_def| { @@ -1409,11 +1406,6 @@ impl<'a> MethodDef<'a> { } } -#[derive(PartialEq)] // dogfooding! -enum StructType { - Unknown, Record, Tuple -} - // general helper methods. impl<'a> TraitDef<'a> { fn set_expn_info(&self, @@ -1441,9 +1433,9 @@ impl<'a> TraitDef<'a> { let mut just_spans = Vec::new(); for field in struct_def.fields(){ let sp = self.set_expn_info(cx, field.span); - match field.node.kind { - ast::NamedField(ident, _) => named_idents.push((ident, sp)), - ast::UnnamedField(..) => just_spans.push(sp), + match field.ident { + Some(ident) => named_idents.push((ident, sp)), + _ => just_spans.push(sp), } } @@ -1479,53 +1471,26 @@ impl<'a> TraitDef<'a> { -> (P<ast::Pat>, Vec<(Span, Option<Ident>, P<Expr>, &'a [ast::Attribute])>) { - if struct_def.fields().is_empty() { - if struct_def.is_struct() { - return (cx.pat_struct(self.span, struct_path, vec![]), vec![]); - } else { - return (cx.pat_enum(self.span, struct_path, vec![]), vec![]); - } - } - let mut paths = Vec::new(); - let mut ident_expr = Vec::new(); - let mut struct_type = Unknown; - + let mut ident_exprs = Vec::new(); for (i, struct_field) in struct_def.fields().iter().enumerate() { let sp = self.set_expn_info(cx, struct_field.span); - let opt_id = match struct_field.node.kind { - ast::NamedField(ident, _) if (struct_type == Unknown || - struct_type == Record) => { - struct_type = Record; - Some(ident) - } - ast::UnnamedField(..) if (struct_type == Unknown || - struct_type == Tuple) => { - struct_type = Tuple; - None - } - _ => { - cx.span_bug(sp, "a struct with named and unnamed fields in `derive`"); - } - }; let ident = cx.ident_of(&format!("{}_{}", prefix, i)); paths.push(codemap::Spanned{span: sp, node: ident}); let val = cx.expr_deref(sp, cx.expr_path(cx.path_ident(sp,ident))); let val = cx.expr(sp, ast::ExprKind::Paren(val)); - ident_expr.push((sp, opt_id, val, &struct_field.node.attrs[..])); + ident_exprs.push((sp, struct_field.ident, val, &struct_field.attrs[..])); } let subpats = self.create_subpatterns(cx, paths, mutbl); - - // struct_type is definitely not Unknown, since struct_def.fields - // must be nonempty to reach here let pattern = if struct_def.is_struct() { - let field_pats = subpats.into_iter().zip(&ident_expr) - .map(|(pat, &(_, id, _, _))| { - // id is guaranteed to be Some + let field_pats = subpats.into_iter().zip(&ident_exprs).map(|(pat, &(sp, ident, _, _))| { + if ident.is_none() { + cx.span_bug(sp, "a braced struct with unnamed fields in `derive`"); + } codemap::Spanned { span: pat.span, - node: ast::FieldPat { ident: id.unwrap(), pat: pat, is_shorthand: false }, + node: ast::FieldPat { ident: ident.unwrap(), pat: pat, is_shorthand: false }, } }).collect(); cx.pat_struct(self.span, struct_path, field_pats) @@ -1533,7 +1498,7 @@ impl<'a> TraitDef<'a> { cx.pat_enum(self.span, struct_path, subpats) }; - (pattern, ident_expr) + (pattern, ident_exprs) } fn create_enum_variant_pattern(&self, |
