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:
parent
0cd67581e7
commit
18da3c671b
3 changed files with 126 additions and 79 deletions
23
src/test/compile-fail/derive-on-trait-item-or-impl-item.rs
Normal file
23
src/test/compile-fail/derive-on-trait-item-or-impl-item.rs
Normal 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() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue