From e47384f720297cab759e4a10ae3b7173d66c5bf4 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Sat, 21 May 2016 01:15:29 -0400 Subject: [PATCH 1/2] enable macro visits in deriving --- src/libsyntax_ext/deriving/generic/mod.rs | 6 ++++- src/test/run-pass/derive-type-macros.rs | 28 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 src/test/run-pass/derive-type-macros.rs diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 20fb4bf32ccb7..2dd96c1f11f72 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -192,7 +192,7 @@ use std::collections::HashSet; use std::vec; use syntax::abi::Abi; -use syntax::ast::{self, EnumDef, Expr, Ident, Generics, VariantData, BinOpKind, PatKind}; +use syntax::ast::{self, EnumDef, Expr, Ident, Generics, Mac, VariantData, BinOpKind, PatKind}; use syntax::attr; use syntax::attr::AttrMetaMethods; use syntax::ext::base::{ExtCtxt, Annotatable}; @@ -371,6 +371,10 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. +// +// regression test for #32950 + +#![feature(type_macros)] + +macro_rules! passthru { + ($t:ty) => { $t } +} + +#[derive(Debug)] +struct Thing { + thing: passthru!(T) +} + +fn main() { + let t: passthru!(Thing) = Thing { thing: 42 }; + println!("{:?}", t); +} + From 1878bf9a139920e4b8967d3e6cbb84a43c5e0d70 Mon Sep 17 00:00:00 2001 From: Alex Burka Date: Sat, 21 May 2016 14:33:52 -0400 Subject: [PATCH 2/2] more robust test --- src/test/run-pass/derive-type-macros.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/test/run-pass/derive-type-macros.rs b/src/test/run-pass/derive-type-macros.rs index 898e8d9c33033..51d45d79542f8 100644 --- a/src/test/run-pass/derive-type-macros.rs +++ b/src/test/run-pass/derive-type-macros.rs @@ -16,13 +16,26 @@ macro_rules! passthru { ($t:ty) => { $t } } +macro_rules! useassoc { + ($t:ident, $assoc:ident) => { ($t, $t::$assoc) } +} + +trait HasAssoc { type Type; } + +impl HasAssoc for i32 { type Type = i32; } + +#[derive(Debug)] +struct Thing1 { + thing: useassoc!(T, Type) +} #[derive(Debug)] -struct Thing { - thing: passthru!(T) +struct Thing2 { + thing: (T, T::Type) } fn main() { - let t: passthru!(Thing) = Thing { thing: 42 }; - println!("{:?}", t); + let t1: passthru!(Thing1) = Thing1 { thing: (42, 42) }; + let t2: passthru!(Thing2) = Thing2 { thing: (42, 42) }; + println!("{:?} {:?}", t1, t2); }