Skip to content

Commit 7e08df5

Browse files
jseyfriednikomatsakis
authored andcommitted
Fix bug in collecting trait and impl items with derives.
1 parent 658134a commit 7e08df5

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/libsyntax/ext/expand.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -736,12 +736,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
736736
item: Annotatable,
737737
kind: ExpansionKind)
738738
-> Expansion {
739-
if !traits.is_empty() &&
740-
(kind == ExpansionKind::TraitItems || kind == ExpansionKind::ImplItems) {
741-
self.cx.span_err(traits[0].span, "`derive` can be only be applied to items");
742-
return kind.expect_from_annotatables(::std::iter::once(item));
743-
}
744-
self.collect(kind, InvocationKind::Attr { attr: attr, traits: traits, item: item })
739+
self.collect(kind, InvocationKind::Attr { attr, traits, item })
745740
}
746741

747742
// If `item` is an attr invocation, remove and return the macro attribute.

src/test/compile-fail/issue-43023.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct S;
12+
13+
impl S {
14+
#[derive(Debug)] //~ ERROR `derive` may only be applied to structs, enums and unions
15+
fn f() {
16+
file!();
17+
}
18+
}
19+
20+
trait Tr1 {
21+
#[derive(Debug)] //~ ERROR `derive` may only be applied to structs, enums and unions
22+
fn f();
23+
}
24+
25+
trait Tr2 {
26+
#[derive(Debug)] //~ ERROR `derive` may only be applied to structs, enums and unions
27+
type F;
28+
}

0 commit comments

Comments
 (0)