Remove macro_reexport

It's subsumed by `feature(use_extern_macros)` and `pub use`
This commit is contained in:
Vadim Petrochenkov 2018-04-15 16:59:00 +03:00
parent a4a7947259
commit 300b6bb417
25 changed files with 252 additions and 677 deletions

View File

@ -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> {
@ -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");
@ -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
}
@ -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

View File

@ -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.
@ -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.
@ -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,

View File

@ -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>>>,
}
@ -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,
}
@ -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()`.
}
@ -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.

View File

@ -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)]
@ -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)]
@ -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)]
@ -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;

View File

@ -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),
@ -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! (
@ -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),
@ -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) => {

View File

@ -1,21 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that macro re-exports item are gated by `macro_reexport` feature gate.
// aux-build:macro_reexport_1.rs
// gate-test-macro_reexport
#![crate_type = "dylib"]
#[macro_reexport(reexported)]
//~^ ERROR macros re-exports are experimental and possibly buggy
#[macro_use] #[no_link]
extern crate macro_reexport_1;

View File

@ -1,19 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "dylib"]
// Since we load a serialized macro with all its attributes, accidentally
// re-exporting a `#[macro_export] macro_rules!` is something of a concern!
//
// We avoid it at the moment only because of the order in which we do things.
#[macro_use] #[no_link]
extern crate macro_reexport_1;

View File

@ -1,15 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "dylib"]
#[macro_export]
macro_rules! reexported {
() => ( 3 )
}

View File

@ -1,20 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:macro_reexport_1.rs
// aux-build:macro_non_reexport_2.rs
#[macro_use] #[no_link]
extern crate macro_non_reexport_2;
fn main() {
assert_eq!(reexported!(), 3);
//~^ ERROR cannot find macro `reexported!` in this scope
}

View File

@ -1,16 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![no_std]
#![feature(macro_reexport)]
#[allow(unused_extern_crates)]
#[macro_reexport] //~ ERROR bad macro re-export
extern crate std;

View File

@ -1,16 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![no_std]
#![feature(macro_reexport)]
#[allow(unused_extern_crates)]
#[macro_reexport="foo"] //~ ERROR bad macro re-export
extern crate std;

View File

@ -1,16 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![no_std]
#![feature(macro_reexport)]
#[allow(unused_extern_crates)]
#[macro_reexport(foo="bar")] //~ ERROR bad macro re-export
extern crate std;

View File

@ -1,22 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:macro_reexport_1.rs
#![feature(macro_reexport)]
#[macro_reexport(reexported)]
#[no_link]
extern crate macro_reexport_1;
fn main() {
assert_eq!(reexported!(), 3);
//~^ ERROR cannot find macro
}

View File

@ -1,16 +0,0 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// ignore-test not a test, auxiliary
#![feature(macro_reexport)]
#[macro_reexport(A)]
extern crate derive_a;

View File

@ -1,21 +0,0 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:derive-a.rs
// aux-build:derive-reexport.rs
// ignore-stage1
#[macro_use]
extern crate derive_reexport;
#[derive(Debug, PartialEq, A, Eq, Copy, Clone)]
struct A;
fn main() {}

View File

@ -1,15 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "dylib"]
#[macro_export]
macro_rules! reexported {
() => ( 3 )
}

View File

@ -1,16 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "dylib"]
#![feature(macro_reexport)]
#[macro_reexport(reexported)]
#[macro_use] #[no_link]
extern crate macro_reexport_1;

View File

@ -1,16 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![crate_type = "dylib"]
#![feature(macro_reexport)]
#[macro_reexport(reexported)]
#[no_link]
extern crate macro_reexport_1;

View File

@ -1,19 +0,0 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:macro_reexport_1.rs
// aux-build:macro_reexport_2_no_use.rs
#[macro_use] #[no_link]
extern crate macro_reexport_2_no_use;
fn main() {
assert_eq!(reexported!(), 3_usize);
}

View File

@ -1,19 +0,0 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// aux-build:macro_reexport_1.rs
// aux-build:macro_reexport_2.rs
#[macro_use] #[no_link]
extern crate macro_reexport_2;
fn main() {
assert_eq!(reexported!(), 3_usize);
}

View File

@ -10,14 +10,11 @@
// aux-build:pub-use-extern-macros.rs
#![feature(use_extern_macros, macro_reexport)]
#![feature(use_extern_macros)]
// @has pub_use_extern_macros/macro.foo.html
// @!has pub_use_extern_macros/index.html 'pub use macros::foo;'
#[macro_reexport(foo)] extern crate macros;
extern crate macros;
// @has pub_use_extern_macros/index.html 'pub use macros::bar;'
// @!has pub_use_extern_macros/macro.bar.html
// @has pub_use_extern_macros/macro.bar.html
pub use macros::bar;
// @has pub_use_extern_macros/macro.baz.html
@ -25,7 +22,7 @@ pub use macros::bar;
#[doc(inline)]
pub use macros::baz;
// @!has pub_use_extern_macros/macro.quux.html
// @has pub_use_extern_macros/macro.quux.html
// @!has pub_use_extern_macros/index.html 'pub use macros::quux;'
#[doc(hidden)]
pub use macros::quux;

View File

@ -50,7 +50,6 @@
#![allow (x5300)] //~ WARN unknown lint: `x5300`
#![forbid (x5200)] //~ WARN unknown lint: `x5200`
#![deny (x5100)] //~ WARN unknown lint: `x5100`
#![macro_reexport = "5000"] //~ WARN unused attribute
#![macro_use] // (allowed if no argument; see issue-43160-gating-of-macro_use.rs)
#![macro_export = "4800"] //~ WARN unused attribute
#![plugin_registrar = "4700"] //~ WARN unused attribute
@ -186,25 +185,6 @@ mod deny {
//~^ WARN unknown lint: `x5100`
}
#[macro_reexport = "5000"]
//~^ WARN unused attribute
mod macro_reexport {
mod inner { #![macro_reexport="5000"] }
//~^ WARN unused attribute
#[macro_reexport = "5000"] fn f() { }
//~^ WARN unused attribute
#[macro_reexport = "5000"] struct S;
//~^ WARN unused attribute
#[macro_reexport = "5000"] type T = S;
//~^ WARN unused attribute
#[macro_reexport = "5000"] impl S { }
//~^ WARN unused attribute
}
#[macro_use]
mod macro_use {
mod inner { #![macro_use] }

View File

@ -10,12 +10,9 @@
// aux-build:two_macros.rs
#![feature(macro_reexport)]
#![feature(macro_reexport)] //~ ERROR feature has been removed
#[macro_use(macro_two)]
#[macro_reexport(no_way)] //~ ERROR re-exported macro not found
#[macro_reexport(macro_one)] //~ ERROR attribute `macro_reexport` is currently unknown
extern crate two_macros;
pub fn main() {
macro_two!();
}
fn main() {}

View File

@ -0,0 +1,18 @@
error[E0557]: feature has been removed
--> $DIR/macro-reexport-removed.rs:13:12
|
LL | #![feature(macro_reexport)] //~ ERROR feature has been removed
| ^^^^^^^^^^^^^^
error[E0658]: The attribute `macro_reexport` is currently unknown to the compiler and may have meaning added to it in the future (see issue #29642)
--> $DIR/macro-reexport-removed.rs:15:1
|
LL | #[macro_reexport(macro_one)] //~ ERROR attribute `macro_reexport` is currently unknown
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add #![feature(custom_attribute)] to the crate attributes to enable
error: aborting due to 2 previous errors
Some errors occurred: E0557, E0658.
For more information about an error, try `rustc --explain E0557`.