Skip to content

Commit fdfa6ab

Browse files
committed
Auto merge of #44757 - jseyfried:fix_bad_derive_collection, r=nrc
macros: fix bug in collecting trait and impl items with derives. Fixes #43023. r? @nrc
2 parents a83c3e7 + 7ba7021 commit fdfa6ab

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -770,15 +770,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
770770

771771
fn collect_attr(&mut self,
772772
attr: Option<ast::Attribute>,
773-
traits: Vec<Path>,
773+
mut traits: Vec<Path>,
774774
item: Annotatable,
775775
kind: ExpansionKind)
776776
-> Expansion {
777777
if !traits.is_empty() &&
778778
(kind == ExpansionKind::TraitItems || kind == ExpansionKind::ImplItems) {
779779
self.cx.span_err(traits[0].span, "`derive` can be only be applied to items");
780780
self.cx.trace_macros_diag();
781-
return kind.expect_from_annotatables(::std::iter::once(item));
781+
traits = Vec::new();
782782
}
783783
self.collect(kind, InvocationKind::Attr { attr: attr, traits: traits, item: item })
784784
}

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

Lines changed: 28 additions & 0 deletions
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)