Skip to content

Commit 96b09e0

Browse files
committed
Auto merge of #49982 - petrochenkov:noreex, r=alexcrichton
Remove unstable `macro_reexport` It's subsumed by `feature(use_extern_macros)` and `pub use` cc #35896 closes #29638 closes #38951
2 parents 1fd74eb + 730c722 commit 96b09e0

26 files changed

+290
-712
lines changed

src/librustc_resolve/build_reduced_graph.rs

+1-28
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ impl<'a> ToNameBinding<'a> for (Def, ty::Visibility, Span, Mark) {
7171
struct LegacyMacroImports {
7272
import_all: Option<Span>,
7373
imports: Vec<(Name, Span)>,
74-
reexports: Vec<(Name, Span)>,
7574
}
7675

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

624-
// `#[macro_use]` and `#[macro_reexport]` are only allowed at the crate root.
623+
// `#[macro_use]` is only allowed at the crate root.
625624
if self.current_module.parent.is_some() && used {
626625
span_err!(self.session, item.span, E0468,
627626
"an `extern crate` loading macros must be at the crate root");
@@ -669,17 +668,6 @@ impl<'a> Resolver<'a> {
669668
}
670669
}
671670
}
672-
for (name, span) in legacy_imports.reexports {
673-
self.cstore.export_macros_untracked(module.def_id().unwrap().krate);
674-
let ident = Ident::with_empty_ctxt(name);
675-
let result = self.resolve_ident_in_module(module, ident, MacroNS, false, false, span);
676-
if let Ok(binding) = result {
677-
let (def, vis) = (binding.def(), binding.vis);
678-
self.macro_exports.push(Export { ident, def, vis, span, is_import: true });
679-
} else {
680-
span_err!(self.session, span, E0470, "re-exported macro not found");
681-
}
682-
}
683671
used
684672
}
685673

@@ -721,21 +709,6 @@ impl<'a> Resolver<'a> {
721709
},
722710
None => imports.import_all = Some(attr.span),
723711
}
724-
} else if attr.check_name("macro_reexport") {
725-
let bad_macro_reexport = |this: &mut Self, span| {
726-
span_err!(this.session, span, E0467, "bad macro re-export");
727-
};
728-
if let Some(names) = attr.meta_item_list() {
729-
for attr in names {
730-
if let Some(word) = attr.word() {
731-
imports.reexports.push((word.ident.name, attr.span()));
732-
} else {
733-
bad_macro_reexport(self, attr.span());
734-
}
735-
}
736-
} else {
737-
bad_macro_reexport(self, attr.span());
738-
}
739712
}
740713
}
741714
imports

src/librustc_resolve/diagnostics.rs

+2-71
Original file line numberDiff line numberDiff line change
@@ -1395,35 +1395,6 @@ If you would like to import all exported macros, write `macro_use` with no
13951395
arguments.
13961396
"##,
13971397

1398-
E0467: r##"
1399-
Macro re-export declarations were empty or malformed.
1400-
1401-
Erroneous code examples:
1402-
1403-
```compile_fail,E0467
1404-
#[macro_reexport] // error: no macros listed for export
1405-
extern crate core as macros_for_good;
1406-
1407-
#[macro_reexport(fun_macro = "foo")] // error: not a macro identifier
1408-
extern crate core as other_macros_for_good;
1409-
```
1410-
1411-
This is a syntax error at the level of attribute declarations.
1412-
1413-
Currently, `macro_reexport` requires at least one macro name to be listed.
1414-
Unlike `macro_use`, listing no names does not re-export all macros from the
1415-
given crate.
1416-
1417-
Decide which macros you would like to export and list them properly.
1418-
1419-
These are proper re-export declarations:
1420-
1421-
```ignore (cannot-doctest-multicrate-project)
1422-
#[macro_reexport(some_macro, another_macro)]
1423-
extern crate macros_for_good;
1424-
```
1425-
"##,
1426-
14271398
E0468: r##"
14281399
A non-root module attempts to import macros from another crate.
14291400
@@ -1496,48 +1467,6 @@ extern crate some_crate; //ok!
14961467
```
14971468
"##,
14981469

1499-
E0470: r##"
1500-
A macro listed for re-export was not found.
1501-
1502-
Erroneous code example:
1503-
1504-
```compile_fail,E0470
1505-
#[macro_reexport(drink, be_merry)]
1506-
extern crate alloc;
1507-
1508-
fn main() {
1509-
// ...
1510-
}
1511-
```
1512-
1513-
Either the listed macro is not contained in the imported crate, or it is not
1514-
exported from the given crate.
1515-
1516-
This could be caused by a typo. Did you misspell the macro's name?
1517-
1518-
Double-check the names of the macros listed for re-export, and that the crate
1519-
in question exports them.
1520-
1521-
A working version:
1522-
1523-
```ignore (cannot-doctest-multicrate-project)
1524-
// In some_crate crate:
1525-
#[macro_export]
1526-
macro_rules! eat {
1527-
...
1528-
}
1529-
1530-
#[macro_export]
1531-
macro_rules! drink {
1532-
...
1533-
}
1534-
1535-
// In your_crate:
1536-
#[macro_reexport(eat, drink)]
1537-
extern crate some_crate;
1538-
```
1539-
"##,
1540-
15411470
E0530: r##"
15421471
A binding shadowed something it shouldn't.
15431472
@@ -1715,6 +1644,8 @@ register_diagnostics! {
17151644
// E0421, merged into 531
17161645
E0531, // unresolved pattern path kind `name`
17171646
// E0427, merged into 530
1647+
// E0467, removed
1648+
// E0470, removed
17181649
E0573,
17191650
E0574,
17201651
E0575,

src/librustdoc/visit_ast.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pub struct RustdocVisitor<'a, 'tcx: 'a, 'rcx: 'a> {
4949
inlining: bool,
5050
/// Is the current module and all of its parents public?
5151
inside_public_path: bool,
52-
reexported_macros: FxHashSet<DefId>,
5352
exact_paths: Option<FxHashMap<DefId, Vec<String>>>,
5453
}
5554

@@ -66,7 +65,6 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
6665
view_item_stack: stack,
6766
inlining: false,
6867
inside_public_path: true,
69-
reexported_macros: FxHashSet(),
7068
exact_paths: Some(FxHashMap()),
7169
cstore,
7270
}
@@ -221,7 +219,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> {
221219
if let Some(exports) = self.cx.tcx.module_exports(def_id) {
222220
for export in exports.iter().filter(|e| e.vis == Visibility::Public) {
223221
if let Def::Macro(def_id, ..) = export.def {
224-
if def_id.krate == LOCAL_CRATE || self.reexported_macros.contains(&def_id) {
222+
if def_id.krate == LOCAL_CRATE {
225223
continue // These are `krate.exported_macros`, handled in `self.visit()`.
226224
}
227225

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

301-
// Memoize the non-inlined `pub use`'d macros so we don't push an extra
302-
// declaration in `visit_mod_contents()`
303-
if !def_did.is_local() {
304-
if let Def::Macro(did, _) = def {
305-
if please_inline { return true }
306-
debug!("memoizing non-inlined macro export: {:?}", def);
307-
self.reexported_macros.insert(did);
308-
return false;
309-
}
310-
}
311-
312299
// For cross-crate impl inlining we need to know whether items are
313300
// reachable in documentation - a previously nonreachable item can be
314301
// made reachable by cross-crate inlining which we're checking here.

src/libstd/lib.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@
273273
#![feature(libc)]
274274
#![feature(link_args)]
275275
#![feature(linkage)]
276-
#![feature(macro_reexport)]
277276
#![feature(macro_vis_matcher)]
278277
#![feature(needs_panic_runtime)]
279278
#![feature(never_type)]
@@ -313,6 +312,7 @@
313312
#![feature(unboxed_closures)]
314313
#![feature(untagged_unions)]
315314
#![feature(unwind_attributes)]
315+
#![feature(use_extern_macros)]
316316
#![feature(vec_push_all)]
317317
#![feature(doc_cfg)]
318318
#![feature(doc_masked)]
@@ -347,15 +347,14 @@ use prelude::v1::*;
347347
#[cfg(test)] extern crate test;
348348
#[cfg(test)] extern crate rand;
349349

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

356+
#[allow(unused_imports)] // macros from `alloc` are not used on all platforms
357357
#[macro_use]
358-
#[macro_reexport(vec, format)]
359358
extern crate alloc as alloc_crate;
360359
extern crate alloc_system;
361360
#[doc(masked)]
@@ -450,6 +449,8 @@ pub use alloc_crate::borrow;
450449
#[stable(feature = "rust1", since = "1.0.0")]
451450
pub use alloc_crate::fmt;
452451
#[stable(feature = "rust1", since = "1.0.0")]
452+
pub use alloc_crate::format;
453+
#[stable(feature = "rust1", since = "1.0.0")]
453454
pub use alloc_crate::slice;
454455
#[stable(feature = "rust1", since = "1.0.0")]
455456
pub use alloc_crate::str;

0 commit comments

Comments
 (0)