Skip to content

Commit

Permalink
Revert "Rollup merge of #82296 - spastorino:pubrules, r=nikomatsakis"
Browse files Browse the repository at this point in the history
This reverts commit e2561c5, reversing
changes made to 2982ba5.
  • Loading branch information
spastorino committed Apr 23, 2021
1 parent 5f1aeb5 commit 0e4d2fd
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 183 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Expand Up @@ -691,7 +691,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session) {
// involved, so we only emit errors where there are no other parsing errors.
gate_all!(destructuring_assignment, "destructuring assignments are unstable");
}
gate_all!(pub_macro_rules, "`pub` on `macro_rules` items is unstable");

// All uses of `gate_all!` below this point were added in #65742,
// and subsequently disabled (with the non-early gating readded).
Expand Down
3 changes: 0 additions & 3 deletions compiler/rustc_feature/src/active.rs
Expand Up @@ -624,9 +624,6 @@ declare_features! (
/// Allows macro attributes to observe output of `#[derive]`.
(active, macro_attributes_in_derive_output, "1.51.0", Some(81119), None),

/// Allows `pub` on `macro_rules` items.
(active, pub_macro_rules, "1.52.0", Some(78855), None),

/// Allows the use of type alias impl trait in function return positions
(active, min_type_alias_impl_trait, "1.52.0", Some(63063), None),

Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Expand Up @@ -1478,7 +1478,15 @@ impl<'a> Parser<'a> {
let vstr = pprust::vis_to_string(vis);
let vstr = vstr.trim_end();
if macro_rules {
self.sess.gated_spans.gate(sym::pub_macro_rules, vis.span);
let msg = format!("can't qualify macro_rules invocation with `{}`", vstr);
self.struct_span_err(vis.span, &msg)
.span_suggestion(
vis.span,
"try exporting the macro",
"#[macro_export]".to_owned(),
Applicability::MaybeIncorrect, // speculative
)
.emit();
} else {
self.struct_span_err(vis.span, "can't qualify macro invocation with `pub`")
.span_suggestion(
Expand Down
9 changes: 2 additions & 7 deletions compiler/rustc_resolve/src/build_reduced_graph.rs
Expand Up @@ -1230,13 +1230,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
};

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

if macro_rules && matches!(item.vis.kind, ast::VisibilityKind::Inherited) {
if macro_rules {
let ident = ident.normalize_to_macros_2_0();
self.r.macro_names.insert(ident);
let is_macro_export = self.r.session.contains_name(&item.attrs, sym::macro_export);
let vis = if is_macro_export {
ty::Visibility::Public
} else {
Expand All @@ -1261,11 +1261,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}),
))
} else {
if is_macro_export {
let what = if macro_rules { "`macro_rules` with `pub`" } else { "`macro` items" };
let msg = format!("`#[macro_export]` cannot be used on {what}");
self.r.session.span_err(item.span, &msg);
}
let module = parent_scope.module;
let vis = match item.kind {
// Visibilities must not be resolved non-speculatively twice
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_span/src/symbol.rs
Expand Up @@ -903,7 +903,6 @@ symbols! {
ptr_null,
ptr_null_mut,
ptr_offset_from,
pub_macro_rules,
pub_restricted,
pure,
pushpop_unsafe,
Expand Down
16 changes: 16 additions & 0 deletions src/test/ui/did_you_mean/pub-macro-rules.rs
@@ -0,0 +1,16 @@
#[macro_use] mod bleh {
pub macro_rules! foo { //~ ERROR can't qualify macro_rules invocation
($n:ident) => (
fn $n () -> i32 {
1
}
)
}

}

foo!(meh);

fn main() {
println!("{}", meh());
}
8 changes: 8 additions & 0 deletions src/test/ui/did_you_mean/pub-macro-rules.stderr
@@ -0,0 +1,8 @@
error: can't qualify macro_rules invocation with `pub`
--> $DIR/pub-macro-rules.rs:2:5
|
LL | pub macro_rules! foo {
| ^^^ help: try exporting the macro: `#[macro_export]`

error: aborting due to previous error

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

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions src/test/ui/macros/macro-export-on-modularized-macros.rs

This file was deleted.

14 changes: 0 additions & 14 deletions src/test/ui/macros/macro-export-on-modularized-macros.stderr

This file was deleted.

28 changes: 0 additions & 28 deletions src/test/ui/macros/pub-macro-rules-fail.rs

This file was deleted.

48 changes: 0 additions & 48 deletions src/test/ui/macros/pub-macro-rules-fail.stderr

This file was deleted.

20 changes: 0 additions & 20 deletions src/test/ui/macros/pub-macro-rules.rs

This file was deleted.

0 comments on commit 0e4d2fd

Please sign in to comment.