Skip to content

Commit 8bae91d

Browse files
authored
Rollup merge of rust-lang#63931 - petrochenkov:stabmac, r=Centril
Stabilize macros in some more positions - Fn-like macros and attribute macros in `extern` blocks - Fn-like procedural macros in type positions - ~Attribute macros on inline modules~ (moved to rust-lang#64273) Stabilization report: rust-lang#63931 (comment). Closes rust-lang#49476 cc rust-lang#54727
2 parents 3ca5804 + 5ae38bb commit 8bae91d

24 files changed

+60
-363
lines changed

src/librustc_macros/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(proc_macro_hygiene)]
21
#![allow(rustc::default_hash_types)]
32

43
#![recursion_limit="128"]

src/libsyntax/ext/expand.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -555,15 +555,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
555555
}
556556

557557
fn expand_invoc(&mut self, invoc: Invocation, ext: &SyntaxExtensionKind) -> AstFragment {
558-
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
559-
if fragment_kind == AstFragmentKind::ForeignItems && !self.cx.ecfg.macros_in_extern() {
560-
if let SyntaxExtensionKind::NonMacroAttr { .. } = ext {} else {
561-
emit_feature_err(&self.cx.parse_sess, sym::macros_in_extern,
562-
span, GateIssue::Language,
563-
"macro invocations in `extern {}` blocks are experimental");
564-
}
565-
}
566-
567558
if self.cx.current_expansion.depth > self.cx.ecfg.recursion_limit {
568559
let expn_data = self.cx.current_expansion.id.expn_data();
569560
let suggested_limit = self.cx.ecfg.recursion_limit * 2;
@@ -578,6 +569,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
578569
FatalError.raise();
579570
}
580571

572+
let (fragment_kind, span) = (invoc.fragment_kind, invoc.span());
581573
match invoc.kind {
582574
InvocationKind::Bang { mac, .. } => match ext {
583575
SyntaxExtensionKind::Bang(expander) => {
@@ -758,14 +750,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
758750

759751
fn gate_proc_macro_expansion_kind(&self, span: Span, kind: AstFragmentKind) {
760752
let kind = match kind {
761-
AstFragmentKind::Expr => "expressions",
753+
AstFragmentKind::Expr |
762754
AstFragmentKind::OptExpr => "expressions",
763755
AstFragmentKind::Pat => "patterns",
764-
AstFragmentKind::Ty => "types",
765756
AstFragmentKind::Stmts => "statements",
766-
AstFragmentKind::Items => return,
767-
AstFragmentKind::TraitItems => return,
768-
AstFragmentKind::ImplItems => return,
757+
AstFragmentKind::Ty |
758+
AstFragmentKind::Items |
759+
AstFragmentKind::TraitItems |
760+
AstFragmentKind::ImplItems |
769761
AstFragmentKind::ForeignItems => return,
770762
AstFragmentKind::Arms
771763
| AstFragmentKind::Fields
@@ -1578,9 +1570,6 @@ impl<'feat> ExpansionConfig<'feat> {
15781570
}
15791571
}
15801572

1581-
fn macros_in_extern(&self) -> bool {
1582-
self.features.map_or(false, |features| features.macros_in_extern)
1583-
}
15841573
fn proc_macro_hygiene(&self) -> bool {
15851574
self.features.map_or(false, |features| features.proc_macro_hygiene)
15861575
}

src/libsyntax/feature_gate/accepted.rs

+2
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ declare_features! (
245245
(accepted, bind_by_move_pattern_guards, "1.39.0", Some(15287), None),
246246
/// Allows attributes in formal function parameters.
247247
(accepted, param_attrs, "1.39.0", Some(60406), None),
248+
// Allows macro invocations in `extern {}` blocks.
249+
(accepted, macros_in_extern, "1.40.0", Some(49476), None),
248250

249251
// -------------------------------------------------------------------------
250252
// feature-group-end: accepted features

src/libsyntax/feature_gate/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -402,9 +402,6 @@ declare_features! (
402402
/// Allows infering `'static` outlives requirements (RFC 2093).
403403
(active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
404404

405-
/// Allows macro invocations in `extern {}` blocks.
406-
(active, macros_in_extern, "1.27.0", Some(49476), None),
407-
408405
/// Allows accessing fields of unions inside `const` functions.
409406
(active, const_fn_union, "1.27.0", Some(51909), None),
410407

src/test/ui/abi/macros/macros-in-extern.stderr

-30
This file was deleted.

src/test/ui/abi/proc-macro/auxiliary/test-macros.rs

-112
This file was deleted.

src/test/ui/abi/proc-macro/macros-in-extern.stderr

-30
This file was deleted.

src/test/ui/feature-gates/feature-gate-macros_in_extern.rs

-27
This file was deleted.

src/test/ui/feature-gates/feature-gate-macros_in_extern.stderr

-30
This file was deleted.

src/test/ui/macros/issue-54441.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(macros_in_extern)]
2-
31
macro_rules! m {
42
() => {
53
let //~ ERROR expected

src/test/ui/macros/issue-54441.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected one of `crate`, `fn`, `pub`, `static`, or `type`, found `let`
2-
--> $DIR/issue-54441.rs:5:9
2+
--> $DIR/issue-54441.rs:3:9
33
|
44
LL | let
55
| ^^^ unexpected token

src/test/ui/macros/macros-in-extern-rpass.rs

-30
This file was deleted.

src/test/ui/abi/macros/macros-in-extern.rs src/test/ui/macros/macros-in-extern.rs

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// run-pass
12
// ignore-wasm32
23

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

20+
macro_rules! emits_multiple(
21+
() => {
22+
fn f1() -> u32;
23+
fn f2() -> u32;
24+
}
25+
);
26+
27+
mod defs {
28+
#[no_mangle] extern fn f1() -> u32 { 1 }
29+
#[no_mangle] extern fn f2() -> u32 { 2 }
30+
}
31+
1932
fn main() {
20-
assert_eq!(unsafe { rust_get_test_int() }, 0isize);
33+
assert_eq!(unsafe { rust_get_test_int() }, 1);
2134
assert_eq!(unsafe { rust_dbg_extern_identity_u32(0xDEADBEEF) }, 0xDEADBEEFu32);
35+
assert_eq!(unsafe { f1() }, 1);
36+
assert_eq!(unsafe { f2() }, 2);
2237
}
2338

2439
#[link(name = "rust_test_helpers", kind = "static")]
2540
extern {
2641
returns_isize!(rust_get_test_int);
27-
//~^ ERROR macro invocations in `extern {}` blocks are experimental
2842
takes_u32_returns_u32!(rust_dbg_extern_identity_u32);
29-
//~^ ERROR macro invocations in `extern {}` blocks are experimental
3043
emits_nothing!();
31-
//~^ ERROR macro invocations in `extern {}` blocks are experimental
44+
emits_multiple!();
3245
}

0 commit comments

Comments
 (0)