diff --git a/src/libsyntax_ext/deriving/generic/mod.rs b/src/libsyntax_ext/deriving/generic/mod.rs index 647e414a7fd27..e01f4ed1f9bd2 100644 --- a/src/libsyntax_ext/deriving/generic/mod.rs +++ b/src/libsyntax_ext/deriving/generic/mod.rs @@ -345,15 +345,18 @@ pub fn combine_substructure<'a>(f: CombineSubstructureFunc<'a>) /// This method helps to extract all the type parameters referenced from a /// type. For a type parameter ``, it looks for either a `TyPath` that /// is not global and starts with `T`, or a `TyQPath`. -fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec> { +fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name], span: Span, cx: &ExtCtxt) + -> Vec> { use syntax::visit; - struct Visitor<'a> { + struct Visitor<'a, 'b: 'a> { + cx: &'a ExtCtxt<'b>, + span: Span, ty_param_names: &'a [ast::Name], types: Vec>, } - impl<'a> visit::Visitor for Visitor<'a> { + impl<'a, 'b> visit::Visitor for Visitor<'a, 'b> { fn visit_ty(&mut self, ty: &ast::Ty) { match ty.node { ast::TyKind::Path(_, ref path) if !path.global => { @@ -371,11 +374,18 @@ fn find_type_parameters(ty: &ast::Ty, ty_param_names: &[ast::Name]) -> Vec TraitDef<'a> { let mut processed_field_types = HashSet::new(); for field_ty in field_tys { - let tys = find_type_parameters(&field_ty, &ty_param_names); + let tys = find_type_parameters(&field_ty, &ty_param_names, self.span, cx); for ty in tys { // if we have already handled this type, skip it diff --git a/src/test/compile-fail/issue-32950.rs b/src/test/compile-fail/issue-32950.rs index e47ebdd6a6938..e8ca1c1fa98ff 100644 --- a/src/test/compile-fail/issue-32950.rs +++ b/src/test/compile-fail/issue-32950.rs @@ -8,11 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(type_macros, concat_idents, rustc_attrs)] -#![allow(unused)] +#![feature(type_macros, concat_idents)] -#[derive(Debug)] struct FooBar; -#[derive(Debug)] struct Baz(T, concat_idents!(Foo, Bar)); +#[derive(Debug)] //~ NOTE in this expansion +struct Baz( + concat_idents!(Foo, Bar) //~ ERROR `derive` cannot be used on items with type macros +); -#[rustc_error] -fn main() {} //~ ERROR compilation successful +fn main() {}