about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-17 08:34:08 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-17 11:50:25 -0800
commitbdb1146181e4c320255bec4a93af3d645d522d59 (patch)
tree243aa0f52b4ace1723d15a84da9deda982ee3bcd /src/libsyntax
parent823cd7a8d54166dab4c93ab9181071be8f45323e (diff)
parentab1bdde536668e752aaf4e9dbfa0acf058d0240b (diff)
downloadrust-bdb1146181e4c320255bec4a93af3d645d522d59.tar.gz
rust-bdb1146181e4c320255bec4a93af3d645d522d59.zip
rollup merge of #19831: luqmana/deriving-where
Fixes #19358.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ext/deriving/generic/mod.rs30
-rw-r--r--src/libsyntax/print/pprust.rs1
2 files changed, 26 insertions, 5 deletions
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs
index f40be823a1a..b31758e2d2a 100644
--- a/src/libsyntax/ext/deriving/generic/mod.rs
+++ b/src/libsyntax/ext/deriving/generic/mod.rs
@@ -388,7 +388,7 @@ impl<'a> TraitDef<'a> {
                            methods: Vec<P<ast::Method>>) -> P<ast::Item> {
         let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
 
-        let Generics { mut lifetimes, ty_params, where_clause: _ } =
+        let Generics { mut lifetimes, ty_params, mut where_clause } =
             self.generics.to_generics(cx, self.span, type_ident, generics);
         let mut ty_params = ty_params.into_vec();
 
@@ -420,13 +420,33 @@ impl<'a> TraitDef<'a> {
                        ty_param.unbound.clone(),
                        None)
         }));
+
+        // and similarly for where clauses
+        where_clause.predicates.extend(generics.where_clause.predicates.iter().map(|clause| {
+            match *clause {
+                ast::WherePredicate::BoundPredicate(ref wb) => {
+                    ast::WherePredicate::BoundPredicate(ast::WhereBoundPredicate {
+                        id: ast::DUMMY_NODE_ID,
+                        span: self.span,
+                        ident: wb.ident,
+                        bounds: OwnedSlice::from_vec(wb.bounds.iter().map(|b| b.clone()).collect())
+                    })
+                }
+                ast::WherePredicate::EqPredicate(ref we) => {
+                    ast::WherePredicate::EqPredicate(ast::WhereEqPredicate {
+                        id: ast::DUMMY_NODE_ID,
+                        span: self.span,
+                        path: we.path.clone(),
+                        ty: we.ty.clone()
+                    })
+                }
+            }
+        }));
+
         let trait_generics = Generics {
             lifetimes: lifetimes,
             ty_params: OwnedSlice::from_vec(ty_params),
-            where_clause: ast::WhereClause {
-                id: ast::DUMMY_NODE_ID,
-                predicates: Vec::new(),
-            },
+            where_clause: where_clause
         };
 
         // Create the reference to the trait.
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index b08cf1112fb..18793525e82 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -1062,6 +1062,7 @@ impl<'a> State<'a> {
                         span: codemap::Span) -> IoResult<()> {
         try!(self.print_ident(ident));
         try!(self.print_generics(generics));
+        try!(self.print_where_clause(generics));
         if ast_util::struct_def_is_tuple_like(struct_def) {
             if !struct_def.fields.is_empty() {
                 try!(self.popen());