about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorSeiichi Uchida <seuchida@gmail.com>2017-12-26 16:47:32 +0900
committerSeiichi Uchida <seuchida@gmail.com>2017-12-26 16:47:32 +0900
commit18da3c671b8147fb8d4e206d487f0ee4e4c3ba11 (patch)
tree44008e34c1ca92a795595088ecf7e3dd171bb335 /src/test
parent0cd67581e7d048810874903dc589e5b855f47e7d (diff)
downloadrust-18da3c671b8147fb8d4e206d487f0ee4e4c3ba11.tar.gz
rust-18da3c671b8147fb8d4e206d487f0ee4e4c3ba11.zip
Do not expand a derive invocation when derive is not allowed
1. Change the return type of `expand_invoc()` and its subroutines to
   `Option<Expansion>` from `Expansion`.
2. Return `None` when expanding a derive invocation if the item cannot
   have derive on it (in `expand_derive_invoc()`).
Diffstat (limited to 'src/test')
-rw-r--r--src/test/compile-fail/derive-on-trait-item-or-impl-item.rs23
1 files changed, 23 insertions, 0 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() {}