Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable macro visits in deriving #33769

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/libsyntax_ext/deriving/generic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -371,6 +371,10 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec<P<ast

visit::walk_ty(self, ty)
}

fn visit_mac(&mut self, mac: &'a Mac) {
visit::walk_mac(self, mac)
}
}

let mut visitor = Visitor {
Expand Down
41 changes: 41 additions & 0 deletions src/test/run-pass/derive-type-macros.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2016 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 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 }
}

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<T: HasAssoc> {
thing: useassoc!(T, Type)
}
#[derive(Debug)]
struct Thing2<T: HasAssoc> {
thing: (T, T::Type)
}

fn main() {
let t1: passthru!(Thing1<passthru!(i32)>) = Thing1 { thing: (42, 42) };
let t2: passthru!(Thing2<passthru!(i32)>) = Thing2 { thing: (42, 42) };
println!("{:?} {:?}", t1, t2);
}