From 89d401f6aba9166246e329b1aa18bd5f32fbed7e Mon Sep 17 00:00:00 2001 From: Jared Roesch Date: Sat, 1 Aug 2015 14:35:46 -0700 Subject: [PATCH] Address nits --- src/libsyntax/ext/expand.rs | 1 - src/test/run-pass/type-macros.rs | 84 -------------------------------- 2 files changed, 85 deletions(-) delete mode 100644 src/test/run-pass/type-macros.rs diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index aadc3cfbafe0..b80551c99727 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -1567,7 +1567,6 @@ pub fn expand_type(t: P, fld: &mut MacroExpander) -> P { }; // Keep going, outside-in. - // let fully_expanded = fld.fold_ty(expanded_ty); fld.cx.bt_pop(); diff --git a/src/test/run-pass/type-macros.rs b/src/test/run-pass/type-macros.rs deleted file mode 100644 index a5eb37b8cc3c..000000000000 --- a/src/test/run-pass/type-macros.rs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use std::ops::*; - -#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] -struct Nil; // empty HList -#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)] -struct Cons(H, T); // cons cell of HList - -// trait to classify valid HLists -trait HList {} -impl HList for Nil {} -impl HList for Cons {} - -// term-level macro for HLists -macro_rules! hlist { - {} => { Nil }; - { $head:expr } => { Cons($head, Nil) }; - { $head:expr, $($tail:expr),* } => { Cons($head, hlist!($($tail),*)) }; -} - -// type-level macro for HLists -macro_rules! HList { - {} => { Nil }; - { $head:ty } => { Cons<$head, Nil> }; - { $head:ty, $($tail:ty),* } => { Cons<$head, HList!($($tail),*)> }; -} - -// nil case for HList append -impl Add for Nil { - type Output = Ys; - - fn add(self, rhs: Ys) -> Ys { - rhs - } -} - -// cons case for HList append -impl Add for Cons where - Xs: Add, -{ - type Output = Cons; - - fn add(self, rhs: Ys) -> Cons { - Cons(self.0, self.1 + rhs) - } -} - -// type macro Expr allows us to expand the + operator appropriately -macro_rules! Expr { - { ( $($LHS:tt)+ ) } => { Expr!($($LHS)+) }; - { HList ! [ $($LHS:tt)* ] + $($RHS:tt)+ } => { - >::Output - }; - { $LHS:tt + $($RHS:tt)+ } => { >::Output }; - { $LHS:ty } => { $LHS }; -} - -// test demonstrating term level `xs + ys` and type level `Expr!(Xs + Ys)` -fn main() { - fn aux(xs: Xs, ys: Ys) -> Expr!(Xs + Ys) - where Xs: Add { - xs + ys - } - - let xs: HList![&str, bool, Vec] = hlist!["foo", false, vec![]]; - let ys: HList![u64, [u8; 3], ()] = hlist![0, [0, 1, 2], ()]; - - // demonstrate recursive expansion of Expr! - let zs: Expr!((HList![&str] + HList![bool] + HList![Vec]) + - (HList![u64] + HList![[u8; 3], ()]) + - HList![]) - = aux(xs, ys); - assert_eq!(zs, hlist!["foo", false, vec![], 0, [0, 1, 2], ()]) -} -