diff options
| author | bors <bors@rust-lang.org> | 2017-12-28 06:45:31 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-28 06:45:31 +0000 |
| commit | 5f7aeaf6e2b90e247a2d194d7bc0b642b287fc16 (patch) | |
| tree | 22dc195d1b7fbb49907dd10bbf5e333c8090b672 /src/test | |
| parent | 9a8c753d5e410b50e86f7a13d509760ee4ffe319 (diff) | |
| parent | d88269104679110dacab2aca32001352c2833ec5 (diff) | |
Auto merge of #47013 - topecongiro:issue-46655, r=petrochenkov
Do not expand a derive invocation when derive is not allowed Closes #46655. The first commit is what actually closes #46655. The second one is just a refactoring I have done while waiting on a test.
Diffstat (limited to 'src/test')
3 files changed, 28 insertions, 3 deletions
diff --git a/src/test/compile-fail/derive-on-trait-item-or-impl-item.rs b/src/test/compile-fail/derive-on-trait-item-or-impl-item.rs new file mode 100644 index 00000000000..9ff1c14f54c --- /dev/null +++ b/src/test/compile-fail/derive-on-trait-item-or-impl-item.rs @@ -0,0 +1,23 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +trait Foo { + #[derive(Clone)] + //~^ ERROR `derive` may only be applied to structs, enums and unions + type Bar; +} + +impl Bar { + #[derive(Clone)] + //~^ ERROR `derive` may only be applied to structs, enums and unions + fn bar(&self) {} +} + +fn main() {} diff --git a/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs b/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs index 1a9358f22bf..0f90cb3752c 100644 --- a/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs +++ b/src/test/run-pass-fulldeps/auxiliary/custom_derive_plugin_attr.rs @@ -21,6 +21,7 @@ extern crate rustc; extern crate rustc_plugin; use syntax::ast; +use syntax::attr; use syntax::ext::base::{MultiDecorator, ExtCtxt, Annotatable}; use syntax::ext::build::AstBuilder; use syntax::symbol::Symbol; @@ -80,7 +81,7 @@ fn totalsum_substructure(cx: &mut ExtCtxt, trait_span: Span, }; fields.iter().fold(cx.expr_isize(trait_span, 0), |acc, ref item| { - if item.attrs.iter().find(|a| a.check_name("ignore")).is_some() { + if attr::contains_name(&item.attrs, "ignore") { acc } else { cx.expr_binary(item.span, ast::BinOpKind::Add, acc, diff --git a/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs b/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs index 29b6cc012b3..0433b11f7c1 100644 --- a/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs +++ b/src/test/run-pass-fulldeps/proc-macro/auxiliary/issue-40001-plugin.rs @@ -17,6 +17,7 @@ extern crate rustc_plugin; extern crate syntax; use rustc_plugin::Registry; +use syntax::attr; use syntax::ext::base::*; use syntax::feature_gate::AttributeType::Whitelisted; use syntax::symbol::Symbol; @@ -59,9 +60,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for MissingWhitelistedAttrPass { _ => cx.tcx.hir.expect_item(cx.tcx.hir.get_parent(id)), }; - if !item.attrs.iter().any(|a| a.check_name("whitelisted_attr")) { + if !attr::contains_name(&item.attrs, "whitelisted_attr") { cx.span_lint(MISSING_WHITELISTED_ATTR, span, - "Missing 'whitelited_attr' attribute"); + "Missing 'whitelisted_attr' attribute"); } } } |
