Skip to content

Commit

Permalink
Auto merge of #49982 - petrochenkov:noreex, r=alexcrichton
Browse files Browse the repository at this point in the history
Remove unstable `macro_reexport`

It's subsumed by `feature(use_extern_macros)` and `pub use`

cc #35896
closes #29638
closes #38951
  • Loading branch information
bors committed May 1, 2018
2 parents 1fd74eb + 730c722 commit 96b09e0
Show file tree
Hide file tree
Showing 26 changed files with 290 additions and 712 deletions.
29 changes: 1 addition & 28 deletions src/librustc_resolve/build_reduced_graph.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
17 changes: 9 additions & 8 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
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,14 @@ 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};

#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
#[macro_use]
#[macro_reexport(vec, format)]
extern crate alloc as alloc_crate;
extern crate alloc_system;
#[doc(masked)]
Expand Down Expand Up @@ -450,6 +449,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
Loading

0 comments on commit 96b09e0

Please sign in to comment.