Skip to content

Commit 7ba7021

Browse files
committed
Fix bug in collecting trait and impl items with derives.
1 parent e2504cf commit 7ba7021

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/libsyntax/ext/expand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -744,15 +744,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
744744

745745
fn collect_attr(&mut self,
746746
attr: Option<ast::Attribute>,
747-
traits: Vec<Path>,
747+
mut traits: Vec<Path>,
748748
item: Annotatable,
749749
kind: ExpansionKind)
750750
-> Expansion {
751751
if !traits.is_empty() &&
752752
(kind == ExpansionKind::TraitItems || kind == ExpansionKind::ImplItems) {
753753
self.cx.span_err(traits[0].span, "`derive` can be only be applied to items");
754754
self.cx.trace_macros_diag();
755-
return kind.expect_from_annotatables(::std::iter::once(item));
755+
traits = Vec::new();
756756
}
757757
self.collect(kind, InvocationKind::Attr { attr: attr, traits: traits, item: item })
758758
}

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` can be only be applied to items
15+
fn f() {
16+
file!();
17+
}
18+
}
19+
20+
trait Tr1 {
21+
#[derive(Debug)] //~ ERROR `derive` can be only be applied to items
22+
fn f();
23+
}
24+
25+
trait Tr2 {
26+
#[derive(Debug)] //~ ERROR `derive` can be only be applied to items
27+
type F;
28+
}

0 commit comments

Comments
 (0)