-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Expand macros in extern {}
blocks
#49350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+544
−65
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
src/test/compile-fail-fulldeps/proc-macro/auxiliary/test-macros.rs
This file contains hidden or 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,36 @@ | ||
// Copyright 2018 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 | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(proc_macro)] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream { | ||
assert!(_attr.to_string().is_empty()); | ||
input | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream { | ||
assert!(_attr.to_string().is_empty()); | ||
assert!(!_input.to_string().is_empty()); | ||
"".parse().unwrap() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn emit_input(input: TokenStream) -> TokenStream { | ||
input | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/compile-fail-fulldeps/proc-macro/macros-in-extern.rs
This file contains hidden or 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,38 @@ | ||
// Copyright 2018 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:test-macros.rs | ||
// ignore-stage1 | ||
// ignore-wasm32 | ||
|
||
#![feature(proc_macro)] | ||
|
||
extern crate test_macros; | ||
|
||
use test_macros::{nop_attr, no_output, emit_input}; | ||
|
||
fn main() { | ||
assert_eq!(unsafe { rust_get_test_int() }, 0isize); | ||
assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF); | ||
} | ||
|
||
#[link(name = "rust_test_helpers", kind = "static")] | ||
extern { | ||
#[no_output] | ||
//~^ ERROR Macro and proc-macro invocations in `extern {}` blocks are experimental. | ||
fn some_definitely_unknown_symbol_which_should_be_removed(); | ||
|
||
#[nop_attr] | ||
//~^ ERROR Macro and proc-macro invocations in `extern {}` blocks are experimental. | ||
fn rust_get_test_int() -> isize; | ||
|
||
emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); | ||
//~^ ERROR Macro and proc-macro invocations in `extern {}` blocks are experimental. | ||
} |
This file contains hidden or 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,42 @@ | ||
// Copyright 2018 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. | ||
|
||
// ignore-wasm32 | ||
|
||
#![feature(decl_macro)] | ||
|
||
macro_rules! returns_isize( | ||
($ident:ident) => ( | ||
fn $ident() -> isize; | ||
) | ||
); | ||
|
||
macro takes_u32_returns_u32($ident:ident) { | ||
fn $ident (arg: u32) -> u32; | ||
} | ||
|
||
macro_rules! emits_nothing( | ||
() => () | ||
); | ||
|
||
fn main() { | ||
assert_eq!(unsafe { rust_get_test_int() }, 0isize); | ||
assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32); | ||
} | ||
|
||
#[link(name = "rust_test_helpers", kind = "static")] | ||
extern { | ||
returns_isize!(rust_get_test_int); | ||
//~^ ERROR Macro invocations in `extern {}` blocks are experimental. | ||
takes_u32_returns_u32!(rust_dbg_extern_identity_u32); | ||
//~^ ERROR Macro invocations in `extern {}` blocks are experimental. | ||
emits_nothing!(); | ||
//~^ ERROR Macro invocations in `extern {}` blocks are experimental. | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
src/test/run-pass-fulldeps/proc-macro/auxiliary/test-macros.rs
This file contains hidden or 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,36 @@ | ||
// Copyright 2018 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 | ||
|
||
#![crate_type = "proc-macro"] | ||
#![feature(proc_macro)] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn nop_attr(_attr: TokenStream, input: TokenStream) -> TokenStream { | ||
assert!(_attr.to_string().is_empty()); | ||
input | ||
} | ||
|
||
#[proc_macro_attribute] | ||
pub fn no_output(_attr: TokenStream, _input: TokenStream) -> TokenStream { | ||
assert!(_attr.to_string().is_empty()); | ||
assert!(!_input.to_string().is_empty()); | ||
"".parse().unwrap() | ||
} | ||
|
||
#[proc_macro] | ||
pub fn emit_input(input: TokenStream) -> TokenStream { | ||
input | ||
} |
This file contains hidden or 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,35 @@ | ||
// Copyright 2018 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:test-macros.rs | ||
// ignore-stage1 | ||
// ignore-wasm32 | ||
|
||
#![feature(proc_macro, macros_in_extern)] | ||
|
||
extern crate test_macros; | ||
|
||
use test_macros::{nop_attr, no_output, emit_input}; | ||
|
||
fn main() { | ||
assert_eq!(unsafe { rust_get_test_int() }, 1isize); | ||
assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEF); | ||
} | ||
|
||
#[link(name = "rust_test_helpers", kind = "static")] | ||
extern { | ||
#[no_output] | ||
fn some_definitely_unknown_symbol_which_should_be_removed(); | ||
|
||
#[nop_attr] | ||
fn rust_get_test_int() -> isize; | ||
|
||
emit_input!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;); | ||
} |
This file contains hidden or 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 2018 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. | ||
|
||
// ignore-wasm32 | ||
|
||
#![feature(decl_macro, macros_in_extern)] | ||
|
||
macro_rules! returns_isize( | ||
($ident:ident) => ( | ||
fn $ident() -> isize; | ||
) | ||
); | ||
|
||
macro takes_u32_returns_u32($ident:ident) { | ||
fn $ident (arg: u32) -> u32; | ||
} | ||
|
||
macro_rules! emits_nothing( | ||
() => () | ||
); | ||
|
||
fn main() { | ||
assert_eq!(unsafe { rust_get_test_int() }, 1isize); | ||
assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32); | ||
} | ||
|
||
#[link(name = "rust_test_helpers", kind = "static")] | ||
extern { | ||
returns_isize!(rust_get_test_int); | ||
takes_u32_returns_u32!(rust_dbg_extern_identity_u32); | ||
emits_nothing!(); | ||
} |
This file contains hidden or 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,35 @@ | ||
// Copyright 2018 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. | ||
|
||
#![feature(decl_macro)] | ||
|
||
macro_rules! returns_isize( | ||
($ident:ident) => ( | ||
fn $ident() -> isize; | ||
) | ||
); | ||
|
||
macro takes_u32_returns_u32($ident:ident) { | ||
fn $ident (arg: u32) -> u32; | ||
} | ||
|
||
macro_rules! emits_nothing( | ||
() => () | ||
); | ||
|
||
#[link(name = "rust_test_helpers", kind = "static")] | ||
extern { | ||
returns_isize!(rust_get_test_int); | ||
//~^ ERROR Macro invocations in `extern {}` blocks are experimental. | ||
takes_u32_returns_u32!(rust_dbg_extern_identity_u32); | ||
//~^ ERROR Macro invocations in `extern {}` blocks are experimental. | ||
emits_nothing!(); | ||
//~^ ERROR Macro invocations in `extern {}` blocks are experimental. | ||
} |
This file contains hidden or 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 @@ | ||
error[E0658]: Macro invocations in `extern {}` blocks are experimental. (see issue #49476) | ||
--> $DIR/feature-gate-macros_in_extern.rs:29:5 | ||
| | ||
LL | returns_isize!(rust_get_test_int); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(macros_in_extern)] to the crate attributes to enable | ||
|
||
error[E0658]: Macro invocations in `extern {}` blocks are experimental. (see issue #49476) | ||
--> $DIR/feature-gate-macros_in_extern.rs:31:5 | ||
| | ||
LL | takes_u32_returns_u32!(rust_dbg_extern_identity_u32); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(macros_in_extern)] to the crate attributes to enable | ||
|
||
error[E0658]: Macro invocations in `extern {}` blocks are experimental. (see issue #49476) | ||
--> $DIR/feature-gate-macros_in_extern.rs:33:5 | ||
| | ||
LL | emits_nothing!(); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add #![feature(macros_in_extern)] to the crate attributes to enable | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parser support for macros in foreign blocks is missing (the disambiguation is a bit tricky, but the approach can be copied from macros in traits/impls as well).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had covered this already but I lost a bunch of work somewhere.