Skip to content
Permalink
Browse files

Stabilize macros in `extern` blocks

Add some tests for macros in extern blocks, remove duplicate tests
  • Loading branch information...
petrochenkov committed Aug 26, 2019
1 parent 22bc9e1 commit 349259d55f9b006fe871a26eaa2481b4103dc9d7
@@ -555,15 +555,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
}

fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
if fragment_kind == AstFragmentKind::ForeignItems && !self.cx.ecfg.macros_in_extern() {
if let SyntaxExtensionKind::NonMacroAttr { .. } = ext {} else {
emit_feature_err(&self.cx.parse_sess, sym::macros_in_extern,
span, GateIssue::Language,
"macro invocations in `extern {}` blocks are experimental");
}
}

if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
let expn_data = self.cx.current_expansion.id.expn_data();
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
@@ -578,6 +569,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
FatalError.raise();
}

let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
match invoc.kind {
InvocationKind::Bang { mac, .. } => match ext {
SyntaxExtensionKind::Bang(expander) => {
@@ -1578,9 +1570,6 @@ impl<'feat> ExpansionConfig<'feat> {
}
}

fn macros_in_extern(&self) -> bool {
self.features.map_or(false, |features| features.macros_in_extern)
}
fn proc_macro_hygiene(&self) -> bool {
self.features.map_or(false, |features| features.proc_macro_hygiene)
}
@@ -245,6 +245,8 @@ declare_features! (
(accepted, bind_by_move_pattern_guards, "1.39.0", Some(15287), None),
/// Allows attributes in formal function parameters.
(accepted, param_attrs, "1.39.0", Some(60406), None),
// Allows macro invocations in `extern {}` blocks.
(accepted, macros_in_extern, "1.40.0", Some(49476), None),

// -------------------------------------------------------------------------
// feature-group-end: accepted features
@@ -402,9 +402,6 @@ declare_features! (
/// Allows infering `'static` outlives requirements (RFC 2093).
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),

/// Allows macro invocations in `extern {}` blocks.
(active, macros_in_extern, "1.27.0", Some(49476), None),

/// Allows accessing fields of unions inside `const` functions.
(active, const_fn_union, "1.27.0", Some(51909), None),

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

@@ -1,5 +1,3 @@
#![feature(macros_in_extern)]

macro_rules! m {
() => {
let //~ ERROR expected
@@ -1,5 +1,5 @@
error: expected one of `crate`, `fn`, `pub`, `static`, or `type`, found `let`
--> $DIR/issue-54441.rs:5:9
--> $DIR/issue-54441.rs:3:9
|
LL | let
| ^^^ unexpected token

This file was deleted.

@@ -1,3 +1,4 @@
// run-pass
// ignore-wasm32

#![feature(decl_macro)]
@@ -16,17 +17,29 @@ macro_rules! emits_nothing(
() => ()
);

macro_rules! emits_multiple(
() => {
fn f1() -> u32;
fn f2() -> u32;
}
);

mod defs {
#[no_mangle] extern fn f1() -> u32 { 1 }
#[no_mangle] extern fn f2() -> u32 { 2 }
}

fn main() {
assert_eq!(unsafe { rust_get_test_int() }, 0isize);
assert_eq!(unsafe { rust_get_test_int() }, 1);
assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32);
assert_eq!(unsafe { f1() }, 1);
assert_eq!(unsafe { f2() }, 2);
}

#[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
emits_multiple!();
}

This file was deleted.

0 comments on commit 349259d

Please sign in to comment.
You can’t perform that action at this time.