Skip to content

Commit

Permalink
Auto merge of rust-lang#83713 - spastorino:revert-pub-macro-rules, r=…
Browse files Browse the repository at this point in the history
…nikomatsakis

Revert "Rollup merge of rust-lang#82296 - spastorino:pubrules, r=nikomatsakis"

This reverts commit e2561c5, reversing
changes made to 2982ba5.

As discussed in rust-lang#83641 this feature is not complete and in particular doesn't work cross macros and given that this is not going to be included in edition 2021 nobody seems to be trying to fix the underlying problem. When can add this again I guess, whenever somebody has the time to make it work cross crates.

r? `@nikomatsakis`
  • Loading branch information
bors committed Apr 28, 2021
2 parents 537544b + 83767d9 commit 855c2d1
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 182 deletions.
1 change: 0 additions & 1 deletion compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,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
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,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
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/removed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ declare_features! (
which is available from cargo build scripts with `cargo:rustc-link-arg` now")),
/// Allows using `#[main]` to replace the entrypoint `#[lang = "start"]` calls.
(removed, main, "1.53.0", Some(29634), None, None),
(removed, pub_macro_rules, "1.53.0", Some(78855), None,
Some("removed due to being incomplete, in particular it does not work across crates")),

// -------------------------------------------------------------------------
// feature-group-end: removed features
Expand Down
10 changes: 9 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
16 changes: 16 additions & 0 deletions src/test/ui/did_you_mean/pub-macro-rules.rs
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 855c2d1

Please sign in to comment.