Skip to content

Commit 0e4d2fd

Browse files
committed
Revert "Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis"
This reverts commit e2561c5, reversing changes made to 2982ba5.
1 parent 5f1aeb5 commit 0e4d2fd

14 files changed

+35
-183
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

-1
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
691691
// involved, so we only emit errors where there are no other parsing errors.
692692
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
693693
}
694-
gate_all!(pub_macro_rules, "`pub` on `macro_rules` items is unstable");
695694

696695
// All uses of `gate_all!` below this point were added in #65742,
697696
// and subsequently disabled (with the non-early gating readded).

compiler/rustc_feature/src/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -624,9 +624,6 @@ declare_features! (
624624
/// Allows macro attributes to observe output of `#[derive]`.
625625
(active, macro_attributes_in_derive_output, "1.51.0", Some(81119), None),
626626

627-
/// Allows `pub` on `macro_rules` items.
628-
(active, pub_macro_rules, "1.52.0", Some(78855), None),
629-
630627
/// Allows the use of type alias impl trait in function return positions
631628
(active, min_type_alias_impl_trait, "1.52.0", Some(63063), None),
632629

compiler/rustc_parse/src/parser/item.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1478,7 +1478,15 @@ impl<'a> Parser<'a> {
14781478
let vstr = pprust::vis_to_string(vis);
14791479
let vstr = vstr.trim_end();
14801480
if macro_rules {
1481-
self.sess.gated_spans.gate(sym::pub_macro_rules, vis.span);
1481+
let msg = format!("can't qualify macro_rules invocation with `{}`", vstr);
1482+
self.struct_span_err(vis.span, &msg)
1483+
.span_suggestion(
1484+
vis.span,
1485+
"try exporting the macro",
1486+
"#[macro_export]".to_owned(),
1487+
Applicability::MaybeIncorrect, // speculative
1488+
)
1489+
.emit();
14821490
} else {
14831491
self.struct_span_err(vis.span, "can't qualify macro invocation with `pub`")
14841492
.span_suggestion(

compiler/rustc_resolve/src/build_reduced_graph.rs

+2-7
Original file line numberDiff line numberDiff line change
@@ -1230,13 +1230,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12301230
};
12311231

12321232
let res = Res::Def(DefKind::Macro(ext.macro_kind()), def_id.to_def_id());
1233-
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
12341233
self.r.macro_map.insert(def_id.to_def_id(), ext);
12351234
self.r.local_macro_def_scopes.insert(def_id, parent_scope.module);
12361235

1237-
if macro_rules && matches!(item.vis.kind, ast::VisibilityKind::Inherited) {
1236+
if macro_rules {
12381237
let ident = ident.normalize_to_macros_2_0();
12391238
self.r.macro_names.insert(ident);
1239+
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
12401240
let vis = if is_macro_export {
12411241
ty::Visibility::Public
12421242
} else {
@@ -1261,11 +1261,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12611261
}),
12621262
))
12631263
} else {
1264-
if is_macro_export {
1265-
let what = if macro_rules { "`macro_rules` with `pub`" } else { "`macro` items" };
1266-
let msg = format!("`#[macro_export]` cannot be used on {what}");
1267-
self.r.session.span_err(item.span, &msg);
1268-
}
12691264
let module = parent_scope.module;
12701265
let vis = match item.kind {
12711266
// Visibilities must not be resolved non-speculatively twice

compiler/rustc_span/src/symbol.rs

-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,6 @@ symbols! {
903903
ptr_null,
904904
ptr_null_mut,
905905
ptr_offset_from,
906-
pub_macro_rules,
907906
pub_restricted,
908907
pure,
909908
pushpop_unsafe,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#[macro_use] mod bleh {
2+
pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation
3+
($n:ident) => (
4+
fn $n () -> i32 {
5+
1
6+
}
7+
)
8+
}
9+
10+
}
11+
12+
foo!(meh);
13+
14+
fn main() {
15+
println!("{}", meh());
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: can't qualify macro_rules invocation with `pub`
2+
--> $DIR/pub-macro-rules.rs:2:5
3+
|
4+
LL | pub macro_rules! foo {
5+
| ^^^ help: try exporting the macro: `#[macro_export]`
6+
7+
error: aborting due to previous error
8+

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

-10
This file was deleted.

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

-39
This file was deleted.

src/test/ui/macros/macro-export-on-modularized-macros.rs

-11
This file was deleted.

src/test/ui/macros/macro-export-on-modularized-macros.stderr

-14
This file was deleted.

src/test/ui/macros/pub-macro-rules-fail.rs

-28
This file was deleted.

src/test/ui/macros/pub-macro-rules-fail.stderr

-48
This file was deleted.

src/test/ui/macros/pub-macro-rules.rs

-20
This file was deleted.

0 commit comments

Comments
 (0)