Skip to content

Commit 5943351

Browse files
committed
Auto merge of #68717 - petrochenkov:stabexpat, r=varkor
Stabilize fn-like proc macros in expression, pattern and statement positions I.e. all the positions in which stable `macro_rules` macros are supported. Depends on #68716 ("Stabilize `Span::mixed_site`"). cc #54727 cc #54727 (comment) Stabilization report: #68717 (comment).
2 parents 89988fe + 5c6f7b3 commit 5943351

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+73
-202
lines changed

src/librustc_expand/expand.rs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
679679
ExpandResult::Ready(match invoc.kind {
680680
InvocationKind::Bang { mac, .. } => match ext {
681681
SyntaxExtensionKind::Bang(expander) => {
682-
self.gate_proc_macro_expansion_kind(span, fragment_kind);
683682
let tok_result = match expander.expand(self.cx, span, mac.args.inner_tokens()) {
684683
Err(_) => return ExpandResult::Ready(fragment_kind.dummy(span)),
685684
Ok(ts) => ts,
@@ -846,36 +845,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
846845
}
847846
}
848847

849-
fn gate_proc_macro_expansion_kind(&self, span: Span, kind: AstFragmentKind) {
850-
let kind = match kind {
851-
AstFragmentKind::Expr | AstFragmentKind::OptExpr => "expressions",
852-
AstFragmentKind::Pat => "patterns",
853-
AstFragmentKind::Stmts => "statements",
854-
AstFragmentKind::Ty
855-
| AstFragmentKind::Items
856-
| AstFragmentKind::TraitItems
857-
| AstFragmentKind::ImplItems
858-
| AstFragmentKind::ForeignItems => return,
859-
AstFragmentKind::Arms
860-
| AstFragmentKind::Fields
861-
| AstFragmentKind::FieldPats
862-
| AstFragmentKind::GenericParams
863-
| AstFragmentKind::Params
864-
| AstFragmentKind::StructFields
865-
| AstFragmentKind::Variants => panic!("unexpected AST fragment kind"),
866-
};
867-
if self.cx.ecfg.proc_macro_hygiene() {
868-
return;
869-
}
870-
feature_err(
871-
self.cx.parse_sess,
872-
sym::proc_macro_hygiene,
873-
span,
874-
&format!("procedural macros cannot be expanded to {}", kind),
875-
)
876-
.emit();
877-
}
878-
879848
fn parse_ast_fragment(
880849
&mut self,
881850
toks: TokenStream,

src/librustc_feature/active.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,8 +430,7 @@ declare_features! (
430430
/// Allows `#[marker]` on certain traits allowing overlapping implementations.
431431
(active, marker_trait_attr, "1.30.0", Some(29864), None),
432432

433-
/// Allows macro invocations on modules expressions and statements and
434-
/// procedural macros to expand to non-items.
433+
/// Allows macro attributes on expressions, statements and non-inline modules.
435434
(active, proc_macro_hygiene, "1.30.0", Some(54727), None),
436435

437436
/// Allows unsized rvalues at arguments and parameters.

src/test/ui/auxiliary/cond_plugin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// no-prefer-dynamic
33

44
#![crate_type = "proc-macro"]
5-
#![feature(proc_macro_hygiene)]
65
#![feature(proc_macro_quote)]
76

87
extern crate proc_macro;

src/test/ui/auxiliary/hello_macro.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// no-prefer-dynamic
33

44
#![crate_type = "proc-macro"]
5-
#![feature(proc_macro_hygiene, proc_macro_quote)]
5+
#![feature(proc_macro_quote)]
66

77
extern crate proc_macro;
88

src/test/ui/auxiliary/proc_macro_def.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// no-prefer-dynamic
33

44
#![crate_type = "proc-macro"]
5-
#![feature(proc_macro_hygiene)]
65
#![feature(proc_macro_quote)]
76

87
extern crate proc_macro;

src/test/ui/macro-quote-cond.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
// run-pass
2-
3-
#![allow(unused_parens)]
42
// aux-build:cond_plugin.rs
53

6-
#![feature(proc_macro_hygiene)]
4+
#![allow(unused_parens)]
75

86
extern crate cond_plugin;
97

src/test/ui/macro-quote-test.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
// run-pass
21
// Test that a macro can emit delimiters with nothing inside - `()`, `{}`
32

3+
// run-pass
44
// aux-build:hello_macro.rs
55

6-
#![feature(proc_macro_hygiene)]
7-
86
extern crate hello_macro;
97

108
fn main() {

src/test/ui/macros/auxiliary/proc_macro_sequence.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// no-prefer-dynamic
33

44
#![crate_type = "proc-macro"]
5-
#![feature(proc_macro_span, proc_macro_hygiene, proc_macro_quote)]
5+
#![feature(proc_macro_span, proc_macro_quote)]
66

77
extern crate proc_macro;
88

src/test/ui/proc-macro/attr-invalid-exprs.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
// aux-build:attr-stmt-expr.rs
2-
31
//! Attributes producing expressions in invalid locations
42
5-
#![feature(stmt_expr_attributes, proc_macro_hygiene)]
3+
// aux-build:attr-stmt-expr.rs
4+
5+
#![feature(proc_macro_hygiene)]
6+
#![feature(stmt_expr_attributes)]
67

78
extern crate attr_stmt_expr;
89
use attr_stmt_expr::{duplicate, no_output};

src/test/ui/proc-macro/attr-invalid-exprs.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
error: expected expression, found end of macro arguments
2-
--> $DIR/attr-invalid-exprs.rs:11:13
2+
--> $DIR/attr-invalid-exprs.rs:12:13
33
|
44
LL | let _ = #[no_output] "Hello, world!";
55
| ^^^^^^^^^^^^
66

77
error: macro expansion ignores token `,` and any following
8-
--> $DIR/attr-invalid-exprs.rs:14:13
8+
--> $DIR/attr-invalid-exprs.rs:15:13
99
|
1010
LL | let _ = #[duplicate] "Hello, world!";
1111
| ^^^^^^^^^^^^- help: you might be missing a semicolon here: `;`
@@ -15,7 +15,7 @@ LL | let _ = #[duplicate] "Hello, world!";
1515
= note: the usage of `duplicate!` is likely invalid in expression context
1616

1717
error: macro expansion ignores token `,` and any following
18-
--> $DIR/attr-invalid-exprs.rs:23:9
18+
--> $DIR/attr-invalid-exprs.rs:24:9
1919
|
2020
LL | #[duplicate]
2121
| ^^^^^^^^^^^^- help: you might be missing a semicolon here: `;`

0 commit comments

Comments
 (0)