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()`).
This commit is contained in:
Seiichi Uchida 2017-12-26 16:47:32 +09:00
parent 0cd67581e7
commit 18da3c671b
3 changed files with 126 additions and 79 deletions

View file

@ -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() {}