Skip to content

Commit 827e57c

Browse files
committed
Auto merge of #53459 - petrochenkov:stabmore, r=nrc
Stabilize a few secondary macro features - `tool_attributes` - closes #44690 - `proc_macro_path_invoc` - this feature was created due to issues with tool attributes (#51277), those issues are now fixed (#52841) - partially `proc_macro_gen` - this feature was created due to issue #50504, the issue is now fixed (#51952), so proc macros can generate modules. They still can't generate `macro_rules` items though due to unclear hygiene interactions.
2 parents c648b0b + b34503e commit 827e57c

23 files changed

+27
-131
lines changed

src/doc/unstable-book/src/language-features/tool-attributes.md

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/librustc_resolve/macros.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
368368

369369
let def = def?;
370370

371-
if path.segments.len() > 1 {
372-
if kind != MacroKind::Bang {
373-
if def != Def::NonMacroAttr(NonMacroAttrKind::Tool) &&
374-
!self.session.features_untracked().proc_macro_path_invoc {
375-
let msg = format!("non-ident {} paths are unstable", kind.descr());
376-
emit_feature_err(&self.session.parse_sess, "proc_macro_path_invoc",
377-
path.span, GateIssue::Language, &msg);
378-
}
379-
}
380-
}
381-
382371
match def {
383372
Def::Macro(def_id, macro_kind) => {
384373
self.unused_macros.remove(&def_id);
@@ -391,10 +380,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
391380
Def::NonMacroAttr(attr_kind) => {
392381
if kind == MacroKind::Attr {
393382
let features = self.session.features_untracked();
394-
if attr_kind == NonMacroAttrKind::Tool && !features.tool_attributes {
395-
feature_err(&self.session.parse_sess, "tool_attributes", path.span,
396-
GateIssue::Language, "tool attributes are unstable").emit();
397-
}
398383
if attr_kind == NonMacroAttrKind::Custom {
399384
assert!(path.segments.len() == 1);
400385
let name = path.segments[0].ident.name.as_str();

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -666,30 +666,25 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
666666
None => return,
667667
};
668668

669-
fragment.visit_with(&mut DisallowModules {
669+
fragment.visit_with(&mut DisallowMacros {
670670
span,
671671
parse_sess: self.cx.parse_sess,
672672
});
673673

674-
struct DisallowModules<'a> {
674+
struct DisallowMacros<'a> {
675675
span: Span,
676676
parse_sess: &'a ParseSess,
677677
}
678678

679-
impl<'ast, 'a> Visitor<'ast> for DisallowModules<'a> {
679+
impl<'ast, 'a> Visitor<'ast> for DisallowMacros<'a> {
680680
fn visit_item(&mut self, i: &'ast ast::Item) {
681-
let name = match i.node {
682-
ast::ItemKind::Mod(_) => Some("modules"),
683-
ast::ItemKind::MacroDef(_) => Some("macro definitions"),
684-
_ => None,
685-
};
686-
if let Some(name) = name {
681+
if let ast::ItemKind::MacroDef(_) = i.node {
687682
emit_feature_err(
688683
self.parse_sess,
689684
"proc_macro_gen",
690685
self.span,
691686
GateIssue::Language,
692-
&format!("procedural macros cannot expand to {}", name),
687+
&format!("procedural macros cannot expand to macro definitions"),
693688
);
694689
}
695690
visit::walk_item(self, i);

src/libsyntax/feature_gate.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,9 +441,6 @@ declare_features! (
441441
(active, tbm_target_feature, "1.27.0", Some(44839), None),
442442
(active, wasm_target_feature, "1.30.0", Some(44839), None),
443443

444-
// Allows macro invocations of the form `#[foo::bar]`
445-
(active, proc_macro_path_invoc, "1.27.0", Some(38356), None),
446-
447444
// Allows macro invocations on modules expressions and statements and
448445
// procedural macros to expand to non-items.
449446
(active, proc_macro_mod, "1.27.0", Some(38356), None),
@@ -457,8 +454,6 @@ declare_features! (
457454
// Access to crate names passed via `--extern` through prelude
458455
(active, extern_prelude, "1.27.0", Some(44660), Some(Edition::Edition2018)),
459456

460-
// Scoped attributes
461-
(active, tool_attributes, "1.25.0", Some(44690), None),
462457
// Scoped lints
463458
(active, tool_lints, "1.28.0", Some(44690), None),
464459

@@ -655,6 +650,10 @@ declare_features! (
655650
(accepted, use_extern_macros, "1.30.0", Some(35896), None),
656651
// Allows keywords to be escaped for use as identifiers
657652
(accepted, raw_identifiers, "1.30.0", Some(48589), None),
653+
// Attributes scoped to tools
654+
(accepted, tool_attributes, "1.30.0", Some(44690), None),
655+
// Allows multi-segment paths in attributes and derives
656+
(accepted, proc_macro_path_invoc, "1.30.0", Some(38356), None),
658657
);
659658

660659
// If you change this, please modify src/doc/unstable-book as well. You must

src/test/compile-fail-fulldeps/proc-macro/auxiliary/more-gates.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ extern crate proc_macro;
1616

1717
use proc_macro::*;
1818

19-
#[proc_macro_attribute]
20-
pub fn attr2mod(_: TokenStream, _: TokenStream) -> TokenStream {
21-
"mod test {}".parse().unwrap()
22-
}
23-
2419
#[proc_macro_attribute]
2520
pub fn attr2mac1(_: TokenStream, _: TokenStream) -> TokenStream {
2621
"macro_rules! foo1 { (a) => (a) }".parse().unwrap()
@@ -31,11 +26,6 @@ pub fn attr2mac2(_: TokenStream, _: TokenStream) -> TokenStream {
3126
"macro foo2(a) { a }".parse().unwrap()
3227
}
3328

34-
#[proc_macro]
35-
pub fn mac2mod(_: TokenStream) -> TokenStream {
36-
"mod test2 {}".parse().unwrap()
37-
}
38-
3929
#[proc_macro]
4030
pub fn mac2mac1(_: TokenStream) -> TokenStream {
4131
"macro_rules! foo3 { (a) => (a) }".parse().unwrap()
@@ -49,7 +39,6 @@ pub fn mac2mac2(_: TokenStream) -> TokenStream {
4939
#[proc_macro]
5040
pub fn tricky(_: TokenStream) -> TokenStream {
5141
"fn foo() {
52-
mod test {}
5342
macro_rules! foo { (a) => (a) }
5443
}".parse().unwrap()
5544
}

src/test/compile-fail-fulldeps/proc-macro/more-gates.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,17 @@ extern crate more_gates as foo;
1414

1515
use foo::*;
1616

17-
#[attr2mod]
18-
//~^ ERROR: cannot expand to modules
19-
pub fn a() {}
2017
#[attr2mac1]
2118
//~^ ERROR: cannot expand to macro definitions
2219
pub fn a() {}
2320
#[attr2mac2]
2421
//~^ ERROR: cannot expand to macro definitions
2522
pub fn a() {}
2623

27-
mac2mod!(); //~ ERROR: cannot expand to modules
2824
mac2mac1!(); //~ ERROR: cannot expand to macro definitions
2925
mac2mac2!(); //~ ERROR: cannot expand to macro definitions
3026

3127
tricky!();
32-
//~^ ERROR: cannot expand to modules
33-
//~| ERROR: cannot expand to macro definitions
28+
//~^ ERROR: cannot expand to macro definitions
3429

3530
fn main() {}

src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
// aux-build:proc-macro-gates.rs
1212
// gate-test-proc_macro_non_items
13-
// gate-test-proc_macro_path_invoc
1413
// gate-test-proc_macro_mod line
1514
// gate-test-proc_macro_expr
1615
// gate-test-proc_macro_mod
@@ -22,20 +21,15 @@ extern crate proc_macro_gates as foo;
2221

2322
use foo::*;
2423

25-
#[foo::a] //~ ERROR: non-ident attribute macro paths are unstable
26-
fn _test() {}
27-
2824
fn _test_inner() {
2925
#![a] // OK
3026
}
3127

3228
#[a] //~ ERROR: custom attributes cannot be applied to modules
33-
//~| ERROR: procedural macros cannot expand to modules
3429
mod _test2 {}
3530

3631
mod _test2_inner {
3732
#![a] //~ ERROR: custom attributes cannot be applied to modules
38-
//~| ERROR: procedural macros cannot expand to modules
3933
}
4034

4135
#[a = y] //~ ERROR: must only be followed by a delimiter token

src/test/run-pass-fulldeps/proc-macro/derive-b.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:derive-b.rs
1212
// ignore-stage1
1313

14-
#![feature(proc_macro_path_invoc, unrestricted_attribute_tokens)]
14+
#![feature(unrestricted_attribute_tokens)]
1515

1616
extern crate derive_b;
1717

src/test/run-pass-fulldeps/proc-macro/issue-42708.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:issue-42708.rs
1212
// ignore-stage1
1313

14-
#![feature(decl_macro, proc_macro_path_invoc)]
14+
#![feature(decl_macro)]
1515
#![allow(unused)]
1616

1717
extern crate issue_42708;

src/test/run-pass-fulldeps/proc-macro/issue-50061.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:issue-50061.rs
1212
// ignore-stage1
1313

14-
#![feature(proc_macro_path_invoc, decl_macro)]
14+
#![feature(decl_macro)]
1515

1616
extern crate issue_50061;
1717

0 commit comments

Comments
 (0)