Skip to content

Commit d4da744

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 930d3b1 + 375332c commit d4da744

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

src/libsyntax/ext/expand.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -774,13 +774,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
774774
item: Annotatable,
775775
kind: ExpansionKind)
776776
-> Expansion {
777-
if !traits.is_empty() &&
778-
(kind == ExpansionKind::TraitItems || kind == ExpansionKind::ImplItems) {
779-
self.cx.span_err(traits[0].span, "`derive` can be only be applied to items");
780-
self.cx.trace_macros_diag();
781-
return kind.expect_from_annotatables(::std::iter::once(item));
782-
}
783-
self.collect(kind, InvocationKind::Attr { attr: attr, traits: traits, item: item })
777+
self.collect(kind, InvocationKind::Attr { attr, traits, item })
784778
}
785779

786780
// 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)