Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Original file line number Diff line number Diff line change
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
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,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess since is the first version in which the feature would be removed (which would be 1.53) but I wasn't 100% sure, so please check this in particular when reviewing.

Some("removed due to being incomplete, in particular it does not work across crates")),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, always check my broken english :)


// -------------------------------------------------------------------------
// 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.