Skip to content

Commit

Permalink
Remove macro_reexport
Browse files Browse the repository at this point in the history
It's subsumed by `feature(use_extern_macros)` and `pub use`
  • Loading branch information
petrochenkov committed May 1, 2018
1 parent a4a7947 commit 300b6bb
Show file tree
Hide file tree
Showing 25 changed files with 252 additions and 677 deletions.
29 changes: 1 addition & 28 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -71,7 +71,6 @@ impl<'a> ToNameBinding<'a> for (Def, ty::Visibility, Span, Mark) {
struct LegacyMacroImports {
import_all: Option<Span>,
imports: Vec<(Name, Span)>,
reexports: Vec<(Name, Span)>,
}

impl<'a> Resolver<'a> {
Expand Down Expand Up @@ -621,7 +620,7 @@ impl<'a> Resolver<'a> {
let legacy_imports = self.legacy_macro_imports(&item.attrs);
let mut used = legacy_imports != LegacyMacroImports::default();

// `#[macro_use]` and `#[macro_reexport]` are only allowed at the crate root.
// `#[macro_use]` is only allowed at the crate root.
if self.current_module.parent.is_some() && used {
span_err!(self.session, item.span, E0468,
"an `extern crate` loading macros must be at the crate root");
Expand Down Expand Up @@ -669,17 +668,6 @@ impl<'a> Resolver<'a> {
}
}
}
for (name, span) in legacy_imports.reexports {
self.cstore.export_macros_untracked(module.def_id().unwrap().krate);
let ident = Ident::with_empty_ctxt(name);
let result = self.resolve_ident_in_module(module, ident, MacroNS, false, false, span);
if let Ok(binding) = result {
let (def, vis) = (binding.def(), binding.vis);
self.macro_exports.push(Export { ident, def, vis, span, is_import: true });
} else {
span_err!(self.session, span, E0470, "re-exported macro not found");
}
}
used
}

Expand Down Expand Up @@ -721,21 +709,6 @@ impl<'a> Resolver<'a> {
},
None => imports.import_all = Some(attr.span),
}
} else if attr.check_name("macro_reexport") {
let bad_macro_reexport = |this: &mut Self, span| {
span_err!(this.session, span, E0467, "bad macro re-export");
};
if let Some(names) = attr.meta_item_list() {
for attr in names {
if let Some(word) = attr.word() {
imports.reexports.push((word.ident.name, attr.span()));
} else {
bad_macro_reexport(self, attr.span());
}
}
} else {
bad_macro_reexport(self, attr.span());
}
}
}
imports
Expand Down
73 changes: 2 additions & 71 deletions src/librustc_resolve/diagnostics.rs
Expand Up @@ -1395,35 +1395,6 @@ If you would like to import all exported macros, write `macro_use` with no
arguments.
"##,

E0467: r##"
Macro re-export declarations were empty or malformed.
Erroneous code examples:
```compile_fail,E0467
#[macro_reexport] // error: no macros listed for export
extern crate core as macros_for_good;
#[macro_reexport(fun_macro = "foo")] // error: not a macro identifier
extern crate core as other_macros_for_good;
```
This is a syntax error at the level of attribute declarations.
Currently, `macro_reexport` requires at least one macro name to be listed.
Unlike `macro_use`, listing no names does not re-export all macros from the
given crate.
Decide which macros you would like to export and list them properly.
These are proper re-export declarations:
```ignore (cannot-doctest-multicrate-project)
#[macro_reexport(some_macro, another_macro)]
extern crate macros_for_good;
```
"##,

E0468: r##"
A non-root module attempts to import macros from another crate.
Expand Down Expand Up @@ -1496,48 +1467,6 @@ extern crate some_crate; //ok!
```
"##,

E0470: r##"
A macro listed for re-export was not found.
Erroneous code example:
```compile_fail,E0470
#[macro_reexport(drink, be_merry)]
extern crate alloc;
fn main() {
// ...
}
```
Either the listed macro is not contained in the imported crate, or it is not
exported from the given crate.
This could be caused by a typo. Did you misspell the macro's name?
Double-check the names of the macros listed for re-export, and that the crate
in question exports them.
A working version:
```ignore (cannot-doctest-multicrate-project)
// In some_crate crate:
#[macro_export]
macro_rules! eat {
...
}
#[macro_export]
macro_rules! drink {
...
}
// In your_crate:
#[macro_reexport(eat, drink)]
extern crate some_crate;
```
"##,

E0530: r##"
A binding shadowed something it shouldn't.
Expand Down Expand Up @@ -1715,6 +1644,8 @@ register_diagnostics! {
// E0421, merged into 531
E0531, // unresolved pattern path kind `name`
// E0427, merged into 530
// E0467, removed
// E0470, removed
E0573,
E0574,
E0575,
Expand Down
15 changes: 1 addition & 14 deletions src/librustdoc/visit_ast.rs
Expand Up @@ -49,7 +49,6 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
inlining: bool,
/// Is the current module and all of its parents public?
inside_public_path: bool,
reexported_macros: FxHashSet<DefId>,
exact_paths: Option<FxHashMap<DefId, Vec<String>>>,
}

Expand All @@ -66,7 +65,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
view_item_stack: stack,
inlining: false,
inside_public_path: true,
reexported_macros: FxHashSet(),
exact_paths: Some(FxHashMap()),
cstore,
}
Expand Down Expand Up @@ -221,7 +219,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
if let Some(exports) = self.cx.tcx.module_exports(def_id) {
for export in exports.iter().filter(|e| e.vis == Visibility::Public) {
if let Def::Macro(def_id, ..) = export.def {
if def_id.krate == LOCAL_CRATE || self.reexported_macros.contains(&def_id) {
if def_id.krate == LOCAL_CRATE {
continue // These are `krate.exported_macros`, handled in `self.visit()`.
}

Expand Down Expand Up @@ -298,17 +296,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
let is_no_inline = use_attrs.lists("doc").has_word("no_inline") ||
use_attrs.lists("doc").has_word("hidden");

// Memoize the non-inlined `pub use`'d macros so we don't push an extra
// declaration in `visit_mod_contents()`
if !def_did.is_local() {
if let Def::Macro(did, _) = def {
if please_inline { return true }
debug!("memoizing non-inlined macro export: {:?}", def);
self.reexported_macros.insert(did);
return false;
}
}

// For cross-crate impl inlining we need to know whether items are
// reachable in documentation - a previously nonreachable item can be
// made reachable by cross-crate inlining which we're checking here.
Expand Down
16 changes: 8 additions & 8 deletions src/libstd/lib.rs
Expand Up @@ -273,7 +273,6 @@
#![feature(libc)]
#![feature(link_args)]
#![feature(linkage)]
#![feature(macro_reexport)]
#![feature(macro_vis_matcher)]
#![feature(needs_panic_runtime)]
#![feature(never_type)]
Expand Down Expand Up @@ -313,6 +312,7 @@
#![feature(unboxed_closures)]
#![feature(untagged_unions)]
#![feature(unwind_attributes)]
#![feature(use_extern_macros)]
#![feature(vec_push_all)]
#![feature(doc_cfg)]
#![feature(doc_masked)]
Expand Down Expand Up @@ -347,15 +347,13 @@ use prelude::v1::*;
#[cfg(test)] extern crate test;
#[cfg(test)] extern crate rand;

// We want to re-export a few macros from core but libcore has already been
// imported by the compiler (via our #[no_std] attribute) In this case we just
// add a new crate name so we can attach the re-exports to it.
#[macro_reexport(assert_eq, assert_ne, debug_assert, debug_assert_eq,
debug_assert_ne, unreachable, unimplemented, write, writeln, try)]
extern crate core as __core;
// Re-export a few macros from core
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::{assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne};
#[stable(feature = "rust1", since = "1.0.0")]
pub use core::{unreachable, unimplemented, write, writeln, try};

#[macro_use]
#[macro_reexport(vec, format)]
extern crate alloc as alloc_crate;
extern crate alloc_system;
#[doc(masked)]
Expand Down Expand Up @@ -450,6 +448,8 @@ pub use alloc_crate::borrow;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::fmt;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::format;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::slice;
#[stable(feature = "rust1", since = "1.0.0")]
pub use alloc_crate::str;
Expand Down
11 changes: 2 additions & 9 deletions src/libsyntax/feature_gate.rs
Expand Up @@ -162,9 +162,6 @@ declare_features! (
// OIBIT specific features
(active, optin_builtin_traits, "1.0.0", Some(13231), None),

// macro re-export needs more discussion and stabilization
(active, macro_reexport, "1.0.0", Some(29638), None),

// Allows use of #[staged_api]
// rustc internal
(active, staged_api, "1.0.0", None, None),
Expand Down Expand Up @@ -484,6 +481,8 @@ declare_features! (
(removed, simd, "1.0.0", Some(27731), None),
// Merged into `slice_patterns`
(removed, advanced_slice_patterns, "1.0.0", Some(23121), None),
// Subsumed by `use`
(removed, macro_reexport, "1.0.0", Some(29638), None),
);

declare_features! (
Expand Down Expand Up @@ -673,7 +672,6 @@ pub const BUILTIN_ATTRIBUTES: &'static [(&'static str, AttributeType, AttributeG
("forbid", Normal, Ungated),
("deny", Normal, Ungated),

("macro_reexport", Normal, Ungated),
("macro_use", Normal, Ungated),
("macro_export", Normal, Ungated),
("plugin_registrar", Normal, Ungated),
Expand Down Expand Up @@ -1516,11 +1514,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
gate_feature_post!(&self, underscore_imports, i.span,
"renaming extern crates with `_` is unstable");
}
if let Some(attr) = attr::find_by_name(&i.attrs[..], "macro_reexport") {
gate_feature_post!(&self, macro_reexport, attr.span,
"macros re-exports are experimental \
and possibly buggy");
}
}

ast::ItemKind::ForeignMod(ref foreign_module) => {
Expand Down
21 changes: 0 additions & 21 deletions src/test/compile-fail-fulldeps/gated-macro-reexports.rs

This file was deleted.

19 changes: 0 additions & 19 deletions src/test/compile-fail/auxiliary/macro_non_reexport_2.rs

This file was deleted.

15 changes: 0 additions & 15 deletions src/test/compile-fail/auxiliary/macro_reexport_1.rs

This file was deleted.

20 changes: 0 additions & 20 deletions src/test/compile-fail/macro-no-implicit-reexport.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/compile-fail/macro-reexport-malformed-1.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/test/compile-fail/macro-reexport-malformed-2.rs

This file was deleted.

0 comments on commit 300b6bb

Please sign in to comment.