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

-31
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

+1-2
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

-1
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

+1-1
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

-1
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

+1-3
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

+1-3
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

+1-1
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

+4-3
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

+3-3
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: `;`

src/test/ui/proc-macro/auxiliary/count_compound_ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// force-host
22
// no-prefer-dynamic
33

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

77
extern crate proc_macro;

src/test/ui/proc-macro/auxiliary/generate-dollar-ident.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// force-host
22
// no-prefer-dynamic
33

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

src/test/ui/proc-macro/auxiliary/hygiene_example_codegen.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// force-host
22
// no-prefer-dynamic
33

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

77
extern crate proc_macro as proc_macro_renamed; // This does not break `quote!`

src/test/ui/proc-macro/auxiliary/mixed-site-span.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// force-host
22
// no-prefer-dynamic
33

4-
#![feature(proc_macro_hygiene)]
54
#![feature(proc_macro_quote)]
65

76
#![crate_type = "proc-macro"]

src/test/ui/proc-macro/auxiliary/resolved-located-at.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#![feature(proc_macro_def_site)]
55
#![feature(proc_macro_diagnostic)]
6-
#![feature(proc_macro_hygiene)]
76
#![feature(proc_macro_quote)]
87
#![crate_type = "proc-macro"]
98

src/test/ui/proc-macro/bang-macro.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// run-pass
22
// aux-build:bang-macro.rs
33

4-
#![feature(proc_macro_hygiene)]
5-
64
extern crate bang_macro;
75
use bang_macro::rewrite;
86

src/test/ui/proc-macro/call-site.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
1-
// run-pass
2-
3-
#![allow(unused_variables)]
4-
#![allow(unused_imports)]
1+
// check-pass
52
// aux-build:call-site.rs
63

7-
#![feature(proc_macro_hygiene)]
8-
94
extern crate call_site;
10-
use call_site::*;
115

126
fn main() {
137
let x1 = 10;

src/test/ui/proc-macro/count_compound_ops.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// run-pass
22
// aux-build:count_compound_ops.rs
33

4-
#![feature(proc_macro_hygiene)]
5-
64
extern crate count_compound_ops;
75
use count_compound_ops::count_compound_ops;
86

src/test/ui/proc-macro/hygiene_example.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
// run-pass
2-
3-
#![allow(unused_macros)]
1+
// check-pass
42
// aux-build:hygiene_example_codegen.rs
53
// aux-build:hygiene_example.rs
64

7-
#![feature(proc_macro_hygiene)]
8-
95
extern crate hygiene_example;
106
use hygiene_example::hello;
117

src/test/ui/proc-macro/is-available.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// run-pass
22

3-
#![feature(proc_macro_hygiene, proc_macro_is_available)]
3+
#![feature(proc_macro_is_available)]
44

55
extern crate proc_macro;
66

src/test/ui/proc-macro/lints_in_proc_macros.rs

-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// aux-build:bang_proc_macro2.rs
22

3-
#![feature(proc_macro_hygiene)]
4-
#![allow(unused_macros)]
5-
63
extern crate bang_proc_macro2;
74

85
use bang_proc_macro2::bang_proc_macro2;

src/test/ui/proc-macro/lints_in_proc_macros.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find value `foobar2` in this scope
2-
--> $DIR/lints_in_proc_macros.rs:12:5
2+
--> $DIR/lints_in_proc_macros.rs:9:5
33
|
44
LL | bang_proc_macro2!();
55
| ^^^^^^^^^^^^^^^^^^^^ help: a local variable with a similar name exists: `foobar`

src/test/ui/proc-macro/macro-use-bang.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// build-pass (FIXME(62277): could be check-pass?)
22
// aux-build:test-macros.rs
33

4-
#![feature(proc_macro_hygiene)]
5-
64
#[macro_use]
75
extern crate test_macros;
86

src/test/ui/proc-macro/mixed-site-span.rs

-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
// aux-build:mixed-site-span.rs
44

5-
#![feature(proc_macro_hygiene)]
6-
75
#[macro_use]
86
extern crate mixed_site_span;
97

src/test/ui/proc-macro/mixed-site-span.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
error[E0426]: use of undeclared label `'label_use`
2-
--> $DIR/mixed-site-span.rs:15:9
2+
--> $DIR/mixed-site-span.rs:13:9
33
|
44
LL | proc_macro_rules!();
55
| ^^^^^^^^^^^^^^^^^^^^ undeclared label `'label_use`
66
|
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error[E0425]: cannot find value `local_use` in this scope
10-
--> $DIR/mixed-site-span.rs:15:9
10+
--> $DIR/mixed-site-span.rs:13:9
1111
|
1212
LL | proc_macro_rules!();
1313
| ^^^^^^^^^^^^^^^^^^^^ not found in this scope
1414
|
1515
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1616

1717
error[E0425]: cannot find value `local_def` in this scope
18-
--> $DIR/mixed-site-span.rs:19:9
18+
--> $DIR/mixed-site-span.rs:17:9
1919
|
2020
LL | local_def;
2121
| ^^^^^^^^^ not found in this scope
2222

2323
error[E0412]: cannot find type `ItemUse` in crate `$crate`
24-
--> $DIR/mixed-site-span.rs:26:1
24+
--> $DIR/mixed-site-span.rs:24:1
2525
|
2626
LL | pass_dollar_crate!();
2727
| ^^^^^^^^^^^^^^^^^^^^^ not found in `$crate`

src/test/ui/proc-macro/multispan.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// aux-build:multispan.rs
22

3-
#![feature(proc_macro_hygiene)]
4-
53
extern crate multispan;
64

75
use multispan::hello;

0 commit comments

Comments
 (0)