-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #44528 - tmnilsson:attr_proc_macro_cfg_process, r=jseyf…
…ried Apply attr proc macros before cfg processing Fixes #39336. r? @jseyfried
- Loading branch information
Showing
5 changed files
with
146 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,39 @@ | ||
// Copyright 2016 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. | ||
|
||
// aux-build:attr-cfg.rs | ||
// ignore-stage1 | ||
// revisions: foo bar | ||
|
||
#![feature(proc_macro)] | ||
|
||
extern crate attr_cfg; | ||
use attr_cfg::attr_cfg; | ||
|
||
#[attr_cfg] | ||
fn outer() -> u8 { | ||
#[cfg(foo)] | ||
fn inner() -> u8 { 1 } | ||
|
||
#[cfg(bar)] | ||
fn inner() -> u8 { 2 } | ||
|
||
inner() | ||
} | ||
|
||
#[cfg(foo)] | ||
fn main() { | ||
assert_eq!(outer(), 1); | ||
} | ||
|
||
#[cfg(bar)] | ||
fn main() { | ||
assert_eq!(outer(), 2); | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/run-pass-fulldeps/proc-macro/auxiliary/attr-cfg.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,32 @@ | ||
// Copyright 2016 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. | ||
|
||
// no-prefer-dynamic | ||
#![feature(proc_macro)] | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn attr_cfg(args: TokenStream, input: TokenStream) -> TokenStream { | ||
let input_str = input.to_string(); | ||
|
||
assert_eq!(input_str, "fn outer() -> u8 { | ||
#[cfg(foo)] | ||
fn inner() -> u8 { 1 } | ||
#[cfg(bar)] | ||
fn inner() -> u8 { 2 } | ||
inner() | ||
}"); | ||
|
||
input | ||
} |
23 changes: 23 additions & 0 deletions
23
src/test/run-pass-fulldeps/proc-macro/auxiliary/derive-attr-cfg.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,23 @@ | ||
// Copyright 2016 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. | ||
|
||
// no-prefer-dynamic | ||
#![feature(proc_macro)] | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_derive(Foo, attributes(foo))] | ||
pub fn derive(input: TokenStream) -> TokenStream { | ||
assert!(!input.to_string().contains("#[cfg(any())]")); | ||
"".parse().unwrap() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,27 @@ | ||
// Copyright 2016 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. | ||
|
||
// aux-build:derive-attr-cfg.rs | ||
// ignore-stage1 | ||
|
||
#![feature(proc_macro)] | ||
|
||
extern crate derive_attr_cfg; | ||
use derive_attr_cfg::Foo; | ||
|
||
#[derive(Foo)] | ||
#[foo] | ||
struct S { | ||
#[cfg(any())] | ||
x: i32 | ||
} | ||
|
||
fn main() { | ||
} |