Skip to content

Stabilize macros in some more positions #63931

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
merged 2 commits into from
Oct 1, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/librustc_macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![feature(proc_macro_hygiene)]
#![allow(rustc::default_hash_types)]

#![recursion_limit="128"]
23 changes: 6 additions & 17 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
@@ -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) => {
@@ -757,14 +749,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {

fn gate_proc_macro_expansion_kind(&self, span: Span, kind: AstFragmentKind) {
let kind = match kind {
AstFragmentKind::Expr => "expressions",
AstFragmentKind::Expr |
AstFragmentKind::OptExpr => "expressions",
AstFragmentKind::Pat => "patterns",
AstFragmentKind::Ty => "types",
AstFragmentKind::Stmts => "statements",
AstFragmentKind::Items => return,
AstFragmentKind::TraitItems => return,
AstFragmentKind::ImplItems => return,
AstFragmentKind::Ty |
AstFragmentKind::Items |
AstFragmentKind::TraitItems |
AstFragmentKind::ImplItems |
AstFragmentKind::ForeignItems => return,
AstFragmentKind::Arms
| AstFragmentKind::Fields
@@ -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)
}
2 changes: 2 additions & 0 deletions src/libsyntax/feature_gate/accepted.rs
Original file line number Diff line number Diff line change
@@ -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
3 changes: 0 additions & 3 deletions src/libsyntax/feature_gate/active.rs
Original file line number Diff line number Diff line change
@@ -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),

30 changes: 0 additions & 30 deletions src/test/ui/abi/macros/macros-in-extern.stderr

This file was deleted.

112 changes: 0 additions & 112 deletions src/test/ui/abi/proc-macro/auxiliary/test-macros.rs

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/ui/abi/proc-macro/macros-in-extern.stderr

This file was deleted.

27 changes: 0 additions & 27 deletions src/test/ui/feature-gates/feature-gate-macros_in_extern.rs

This file was deleted.

30 changes: 0 additions & 30 deletions src/test/ui/feature-gates/feature-gate-macros_in_extern.stderr

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/ui/macros/issue-54441.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![feature(macros_in_extern)]

macro_rules! m {
() => {
let //~ ERROR expected
2 changes: 1 addition & 1 deletion src/test/ui/macros/issue-54441.stderr
Original file line number Diff line number Diff line change
@@ -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
30 changes: 0 additions & 30 deletions src/test/ui/macros/macros-in-extern-rpass.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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!();
}
26 changes: 0 additions & 26 deletions src/test/ui/proc-macro/auxiliary/test-macros-rpass.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/test/ui/proc-macro/dollar-crate-issue-62325.rs
Original file line number Diff line number Diff line change
@@ -7,8 +7,6 @@
// normalize-stdout-test "bytes\([^0]\w*\.\.(\w+)\)" -> "bytes(LO..$1)"
// normalize-stdout-test "bytes\((\w+)\.\.[^0]\w*\)" -> "bytes($1..HI)"

#![feature(proc_macro_hygiene)]

#[macro_use]
extern crate test_macros;
extern crate dollar_crate_external;
2 changes: 0 additions & 2 deletions src/test/ui/proc-macro/lifetimes.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// aux-build:lifetimes.rs

#![feature(proc_macro_hygiene)]

extern crate lifetimes;

use lifetimes::*;
2 changes: 1 addition & 1 deletion src/test/ui/proc-macro/lifetimes.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: expected type, found `'`
--> $DIR/lifetimes.rs:9:10
--> $DIR/lifetimes.rs:7:10
|
LL | type A = single_quote_alone!();
| ^^^^^^^^^^^^^^^^^^^^^ this macro call doesn't expand to a type
6 changes: 6 additions & 0 deletions src/test/ui/proc-macro/macros-in-extern-derive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extern {
#[derive(Copy)] //~ ERROR `derive` may only be applied to structs, enums and unions
fn f();
}

fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/proc-macro/macros-in-extern-derive.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: `derive` may only be applied to structs, enums and unions
--> $DIR/macros-in-extern-derive.rs:2:5
|
LL | #[derive(Copy)]
| ^^^^^^^^^^^^^^^

error: aborting due to previous error

25 changes: 0 additions & 25 deletions src/test/ui/proc-macro/macros-in-extern-rpass.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
// run-pass
// aux-build:test-macros.rs
// ignore-wasm32

#[macro_use]
extern crate test_macros;

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) }, 0xDEADBEEF);
}

#[link(name = "rust_test_helpers", kind = "static")]
extern {
#[empty_attr]
//~^ ERROR macro invocations in `extern {}` blocks are experimental
fn some_definitely_unknown_symbol_which_should_be_removed();

#[identity_attr]
//~^ ERROR macro invocations in `extern {}` blocks are experimental
fn rust_get_test_int() -> isize;

identity!(fn rust_dbg_extern_identity_u32(arg: u32) -> u32;);
//~^ ERROR macro invocations in `extern {}` blocks are experimental
}
11 changes: 11 additions & 0 deletions src/test/ui/proc-macro/macros-in-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// check-pass
// aux-build:test-macros.rs

#[macro_use]
extern crate test_macros;

const C: identity!(u8) = 10;

fn main() {
let c: u8 = C;
}
1 change: 0 additions & 1 deletion src/test/ui/proc-macro/proc-macro-gates.rs
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@ fn attrs() {
}

fn main() {
let _x: identity!(u32) = 3; //~ ERROR: procedural macros cannot be expanded to types
if let identity!(Some(_x)) = Some(3) {}
//~^ ERROR: procedural macros cannot be expanded to patterns

21 changes: 6 additions & 15 deletions src/test/ui/proc-macro/proc-macro-gates.stderr
Original file line number Diff line number Diff line change
@@ -94,17 +94,8 @@ LL | let _x = #[identity_attr] println!();
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to types
--> $DIR/proc-macro-gates.rs:53:13
|
LL | let _x: identity!(u32) = 3;
| ^^^^^^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to patterns
--> $DIR/proc-macro-gates.rs:54:12
--> $DIR/proc-macro-gates.rs:53:12
|
LL | if let identity!(Some(_x)) = Some(3) {}
| ^^^^^^^^^^^^^^^^^^^
@@ -113,7 +104,7 @@ LL | if let identity!(Some(_x)) = Some(3) {}
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to statements
--> $DIR/proc-macro-gates.rs:57:5
--> $DIR/proc-macro-gates.rs:56:5
|
LL | empty!(struct S;);
| ^^^^^^^^^^^^^^^^^^
@@ -122,7 +113,7 @@ LL | empty!(struct S;);
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to statements
--> $DIR/proc-macro-gates.rs:58:5
--> $DIR/proc-macro-gates.rs:57:5
|
LL | empty!(let _x = 3;);
| ^^^^^^^^^^^^^^^^^^^^
@@ -131,7 +122,7 @@ LL | empty!(let _x = 3;);
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to expressions
--> $DIR/proc-macro-gates.rs:60:14
--> $DIR/proc-macro-gates.rs:59:14
|
LL | let _x = identity!(3);
| ^^^^^^^^^^^^
@@ -140,14 +131,14 @@ LL | let _x = identity!(3);
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error[E0658]: procedural macros cannot be expanded to expressions
--> $DIR/proc-macro-gates.rs:61:15
--> $DIR/proc-macro-gates.rs:60:15
|
LL | let _x = [empty!(3)];
| ^^^^^^^^^
|
= note: for more information, see https://github.com/rust-lang/rust/issues/54727
= help: add `#![feature(proc_macro_hygiene)]` to the crate attributes to enable

error: aborting due to 17 previous errors
error: aborting due to 16 previous errors

For more information about this error, try `rustc --explain E0658`.