Skip to content

Commit e54d7f8

Browse files
committed
Stabilize use_extern_macros
1 parent e5f6498 commit e54d7f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+51
-181
lines changed

src/doc/unstable-book/src/language-features/proc-macro.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ The two new procedural macro kinds are:
1717
* Attribute-like procedural macros which can be applied to any item which built-in attributes can
1818
be applied to, and which can take arguments in their invocation as well.
1919

20-
Additionally, this feature flag implicitly enables the [`use_extern_macros`](language-features/use-extern-macros.html) feature,
21-
which allows macros to be imported like any other item with `use` statements, as compared to
20+
Procedural macros can be imported like any other item with `use` statements, as compared to
2221
applying `#[macro_use]` to an `extern crate` declaration. It is important to note that procedural macros may
2322
**only** be imported in this manner, and will throw an error otherwise.
2423

src/librustc_resolve/build_reduced_graph.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -641,19 +641,12 @@ impl<'a> Resolver<'a> {
641641
-> bool {
642642
let allow_shadowing = expansion == Mark::root();
643643
let legacy_imports = self.legacy_macro_imports(&item.attrs);
644-
let mut used = legacy_imports != LegacyMacroImports::default();
644+
let used = legacy_imports != LegacyMacroImports::default();
645645

646646
// `#[macro_use]` is only allowed at the crate root.
647647
if self.current_module.parent.is_some() && used {
648648
span_err!(self.session, item.span, E0468,
649649
"an `extern crate` loading macros must be at the crate root");
650-
} else if !self.use_extern_macros && !used &&
651-
self.cstore.dep_kind_untracked(module.def_id().unwrap().krate)
652-
.macros_only() {
653-
let msg = "proc macro crates and `#[no_link]` crates have no effect without \
654-
`#[macro_use]`";
655-
self.session.span_warn(item.span, msg);
656-
used = true; // Avoid the normal unused extern crate warning
657650
}
658651

659652
let (graph_root, arenas) = (self.graph_root, self.arenas);

src/librustc_resolve/lib.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1380,13 +1380,10 @@ pub struct Resolver<'a> {
13801380
/// `use` injections for proc macros wrongly imported with #[macro_use]
13811381
proc_mac_errors: Vec<macros::ProcMacError>,
13821382

1383-
gated_errors: FxHashSet<Span>,
13841383
disallowed_shadowing: Vec<&'a LegacyBinding<'a>>,
13851384

13861385
arenas: &'a ResolverArenas<'a>,
13871386
dummy_binding: &'a NameBinding<'a>,
1388-
/// true if `#![feature(use_extern_macros)]`
1389-
use_extern_macros: bool,
13901387

13911388
crate_loader: &'a mut CrateLoader,
13921389
macro_names: FxHashSet<Ident>,
@@ -1698,7 +1695,6 @@ impl<'a> Resolver<'a> {
16981695
ambiguity_errors: Vec::new(),
16991696
use_injections: Vec::new(),
17001697
proc_mac_errors: Vec::new(),
1701-
gated_errors: FxHashSet(),
17021698
disallowed_shadowing: Vec::new(),
17031699

17041700
arenas,
@@ -1709,10 +1705,6 @@ impl<'a> Resolver<'a> {
17091705
vis: ty::Visibility::Public,
17101706
}),
17111707

1712-
// The `proc_macro` and `decl_macro` features imply `use_extern_macros`
1713-
use_extern_macros:
1714-
features.use_extern_macros || features.proc_macro || features.decl_macro,
1715-
17161708
crate_loader,
17171709
macro_names: FxHashSet(),
17181710
global_macros: FxHashMap(),
@@ -1753,9 +1745,7 @@ impl<'a> Resolver<'a> {
17531745
fn per_ns<F: FnMut(&mut Self, Namespace)>(&mut self, mut f: F) {
17541746
f(self, TypeNS);
17551747
f(self, ValueNS);
1756-
if self.use_extern_macros {
1757-
f(self, MacroNS);
1758-
}
1748+
f(self, MacroNS);
17591749
}
17601750

17611751
fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {

src/librustc_resolve/macros.rs

+2-27
Original file line numberDiff line numberDiff line change
@@ -458,21 +458,13 @@ impl<'a> Resolver<'a> {
458458
self.current_module = if module.is_trait() { module.parent.unwrap() } else { module };
459459

460460
// Possibly apply the macro helper hack
461-
if self.use_extern_macros && kind == MacroKind::Bang && path.len() == 1 &&
461+
if kind == MacroKind::Bang && path.len() == 1 &&
462462
path[0].span.ctxt().outer().expn_info().map_or(false, |info| info.local_inner_macros) {
463463
let root = Ident::new(keywords::DollarCrate.name(), path[0].span);
464464
path.insert(0, root);
465465
}
466466

467467
if path.len() > 1 {
468-
if !self.use_extern_macros && self.gated_errors.insert(span) {
469-
let msg = "non-ident macro paths are experimental";
470-
let feature = "use_extern_macros";
471-
emit_feature_err(&self.session.parse_sess, feature, span, GateIssue::Language, msg);
472-
self.found_unresolved_macro = true;
473-
return Err(Determinacy::Determined);
474-
}
475-
476468
let def = match self.resolve_path(&path, Some(MacroNS), false, span, CrateLint::No) {
477469
PathResult::NonModule(path_res) => match path_res.base_def() {
478470
Def::Err => Err(Determinacy::Determined),
@@ -588,7 +580,6 @@ impl<'a> Resolver<'a> {
588580
record_used: bool)
589581
-> Option<MacroBinding<'a>> {
590582
let ident = ident.modern();
591-
let mut possible_time_travel = None;
592583
let mut relative_depth: u32 = 0;
593584
let mut binding = None;
594585
loop {
@@ -598,9 +589,6 @@ impl<'a> Resolver<'a> {
598589
match invocation.expansion.get() {
599590
LegacyScope::Invocation(_) => scope.set(invocation.legacy_scope.get()),
600591
LegacyScope::Empty => {
601-
if possible_time_travel.is_none() {
602-
possible_time_travel = Some(scope);
603-
}
604592
scope = &invocation.legacy_scope;
605593
}
606594
_ => {
@@ -615,7 +603,7 @@ impl<'a> Resolver<'a> {
615603
}
616604
LegacyScope::Binding(potential_binding) => {
617605
if potential_binding.ident == ident {
618-
if (!self.use_extern_macros || record_used) && relative_depth > 0 {
606+
if record_used && relative_depth > 0 {
619607
self.disallowed_shadowing.push(potential_binding);
620608
}
621609
binding = Some(potential_binding);
@@ -629,21 +617,11 @@ impl<'a> Resolver<'a> {
629617
let binding = if let Some(binding) = binding {
630618
MacroBinding::Legacy(binding)
631619
} else if let Some(binding) = self.global_macros.get(&ident.name).cloned() {
632-
if !self.use_extern_macros {
633-
self.record_use(ident, MacroNS, binding, DUMMY_SP);
634-
}
635620
MacroBinding::Global(binding)
636621
} else {
637622
return None;
638623
};
639624

640-
if !self.use_extern_macros {
641-
if let Some(scope) = possible_time_travel {
642-
// Check for disallowed shadowing later
643-
self.lexical_macro_resolutions.push((ident, scope));
644-
}
645-
}
646-
647625
Some(binding)
648626
}
649627

@@ -749,9 +727,6 @@ impl<'a> Resolver<'a> {
749727
find_best_match_for_name(names, name, None)
750728
// Then check modules.
751729
}).or_else(|| {
752-
if !self.use_extern_macros {
753-
return None;
754-
}
755730
let is_macro = |def| {
756731
if let Def::Macro(_, def_kind) = def {
757732
def_kind == kind

src/librustc_resolve/resolve_imports.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,11 @@ impl<'a> Default for SingleImports<'a> {
131131
}
132132

133133
impl<'a> SingleImports<'a> {
134-
fn add_directive(&mut self, directive: &'a ImportDirective<'a>, use_extern_macros: bool) {
134+
fn add_directive(&mut self, directive: &'a ImportDirective<'a>) {
135135
match *self {
136136
SingleImports::None => *self = SingleImports::MaybeOne(directive),
137-
SingleImports::MaybeOne(directive_one) => *self = if use_extern_macros {
138-
SingleImports::MaybeTwo(directive_one, directive)
139-
} else {
140-
SingleImports::AtLeastOne
141-
},
137+
SingleImports::MaybeOne(directive_one) =>
138+
*self = SingleImports::MaybeTwo(directive_one, directive),
142139
// If three single imports can define the name in the namespace, we can assume that at
143140
// least one of them will define it since otherwise we'd get duplicate errors in one of
144141
// other namespaces.
@@ -348,7 +345,7 @@ impl<'a> Resolver<'a> {
348345
SingleImport { target, type_ns_only, .. } => {
349346
self.per_ns(|this, ns| if !type_ns_only || ns == TypeNS {
350347
let mut resolution = this.resolution(current_module, target, ns).borrow_mut();
351-
resolution.single_imports.add_directive(directive, this.use_extern_macros);
348+
resolution.single_imports.add_directive(directive);
352349
});
353350
}
354351
// We don't add prelude imports to the globs since they only affect lexical scopes,

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
#![feature(unboxed_closures)]
313313
#![feature(untagged_unions)]
314314
#![feature(unwind_attributes)]
315-
#![feature(use_extern_macros)]
315+
#![cfg_attr(stage0, feature(use_extern_macros))]
316316
#![feature(vec_push_all)]
317317
#![feature(doc_cfg)]
318318
#![feature(doc_masked)]

src/libsyntax/feature_gate.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,6 @@ declare_features! (
291291
// Allows #[link(..., cfg(..))]
292292
(active, link_cfg, "1.14.0", Some(37406), None),
293293

294-
(active, use_extern_macros, "1.15.0", Some(35896), None),
295-
296294
// `extern "ptx-*" fn()`
297295
(active, abi_ptx, "1.15.0", Some(38788), None),
298296

@@ -509,7 +507,7 @@ declare_features! (
509507
(removed, advanced_slice_patterns, "1.0.0", Some(23121), None,
510508
Some("merged into `#![feature(slice_patterns)]`")),
511509
(removed, macro_reexport, "1.0.0", Some(29638), None,
512-
Some("subsumed by `#![feature(use_extern_macros)]` and `pub use`")),
510+
Some("subsumed by `pub use`")),
513511
);
514512

515513
declare_features! (
@@ -624,6 +622,8 @@ declare_features! (
624622
(accepted, global_allocator, "1.28.0", Some(27389), None),
625623
// Allows `#[repr(transparent)]` attribute on newtype structs
626624
(accepted, repr_transparent, "1.28.0", Some(43036), None),
625+
// Allows importing and reexporting macros with `use`.
626+
(accepted, use_extern_macros, "1.29.0", Some(35896), None),
627627
);
628628

629629
// If you change this, please modify src/doc/unstable-book as well. You must

src/test/compile-fail-fulldeps/proc-macro/feature-gate-proc_macro.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// aux-build:attr_proc_macro.rs
12-
#![feature(use_extern_macros)]
1312

1413
extern crate attr_proc_macro;
1514
use attr_proc_macro::attr_proc_macro;

src/test/compile-fail-fulldeps/proc-macro/lints_in_proc_macros.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
// aux-build:bang_proc_macro2.rs
1212
// ignore-stage1
1313

14-
#![feature(use_extern_macros, proc_macro_non_items)]
15-
#![allow(unused_macros)]
14+
#![feature(proc_macro_non_items)]
1615

1716
extern crate bang_proc_macro2;
1817

src/test/compile-fail-fulldeps/proc-macro/no-macro-use-attr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
// aux-build:derive-a.rs
1212

1313
#![feature(rustc_attrs)]
14+
#![warn(unused_extern_crates)]
1415

1516
extern crate derive_a;
16-
//~^ WARN proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
17+
//~^ WARN unused extern crate
1718

1819
#[rustc_error]
1920
fn main() {} //~ ERROR compilation successful

src/test/compile-fail-fulldeps/proc-macro/proc-macro-gates2.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
// aux-build:proc-macro-gates.rs
1212

13-
#![feature(use_extern_macros, stmt_expr_attributes)]
13+
#![feature(stmt_expr_attributes)]
1414

1515
extern crate proc_macro_gates as foo;
1616

src/test/compile-fail/extern-macro.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// #41719
1212

13-
#![feature(use_extern_macros)]
14-
1513
fn main() {
1614
enum Foo {}
1715
let _ = Foo::bar!(); //~ ERROR fail to resolve non-ident macro path

src/test/compile-fail/macro-with-seps-err-msg.rs

-19
This file was deleted.

src/test/compile-fail/macros-nonfatal-errors.rs

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ fn main() {
2727
env!(foo, abr, baz); //~ ERROR
2828
env!("RUST_HOPEFULLY_THIS_DOESNT_EXIST"); //~ ERROR
2929

30-
foo::blah!(); //~ ERROR
31-
3230
format!(invalid); //~ ERROR
3331

3432
include!(invalid); //~ ERROR

src/test/compile-fail/no-link.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313
#[no_link]
1414
extern crate empty_struct;
15-
//~^ WARN proc macro crates and `#[no_link]` crates have no effect without `#[macro_use]`
1615

1716
fn main() {
1817
empty_struct::XEmpty1; //~ ERROR cannot find value `XEmpty1` in module `empty_struct`

src/test/run-pass-fulldeps/macro-quote-cond.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:cond_plugin.rs
1212
// ignore-stage1
1313

14-
#![feature(use_extern_macros, proc_macro_non_items)]
14+
#![feature(proc_macro_non_items)]
1515

1616
extern crate cond_plugin;
1717

src/test/run-pass-fulldeps/macro-quote-test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// aux-build:hello_macro.rs
1414
// ignore-stage1
1515

16-
#![feature(use_extern_macros, proc_macro_non_items, proc_macro_gen)]
16+
#![feature(proc_macro_non_items, proc_macro_gen)]
1717

1818
extern crate hello_macro;
1919

src/test/run-pass-fulldeps/proc-macro/auxiliary/hygiene_example.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
#![feature(use_extern_macros)]
12-
1311
extern crate hygiene_example_codegen;
1412

1513
pub use hygiene_example_codegen::hello;

src/test/run-pass-fulldeps/proc-macro/bang-macro.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:bang-macro.rs
1212
// ignore-stage1
1313

14-
#![feature(use_extern_macros, proc_macro_non_items)]
14+
#![feature(proc_macro_non_items)]
1515

1616
extern crate bang_macro;
1717
use bang_macro::rewrite;

src/test/run-pass-fulldeps/proc-macro/count_compound_ops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// aux-build:count_compound_ops.rs
1212
// ignore-stage1
1313

14-
#![feature(use_extern_macros, proc_macro_non_items)]
14+
#![feature(proc_macro_non_items)]
1515

1616
extern crate count_compound_ops;
1717
use count_compound_ops::count_compound_ops;

src/test/run-pass-fulldeps/proc-macro/derive-attr-cfg.rs

-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
// aux-build:derive-attr-cfg.rs
1212
// ignore-stage1
1313

14-
#![feature(use_extern_macros)]
15-
1614
extern crate derive_attr_cfg;
1715
use derive_attr_cfg::Foo;
1816

src/test/run-pass-fulldeps/proc-macro/hygiene_example.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// aux-build:hygiene_example.rs
1313
// ignore-stage1
1414

15-
#![feature(use_extern_macros, proc_macro_non_items)]
15+
#![feature(proc_macro_non_items)]
1616

1717
extern crate hygiene_example;
1818
use hygiene_example::hello;

src/test/run-pass-fulldeps/proc-macro/issue-39889.rs

-3
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@
1111
// aux-build:issue-39889.rs
1212
// ignore-stage1
1313

14-
#![feature(use_extern_macros)]
15-
#![allow(unused)]
16-
1714
extern crate issue_39889;
1815
use issue_39889::Issue39889;
1916

src/test/run-pass-fulldeps/proc-macro/span-api-tests.rs

-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
// ignore-pretty
1515

16-
#![feature(use_extern_macros)]
17-
1816
#[macro_use]
1917
extern crate span_test_macros;
2018

src/test/run-pass/paths-in-macro-invocations.rs

-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010

1111
// aux-build:two_macros.rs
1212

13-
#![feature(use_extern_macros)]
14-
1513
extern crate two_macros;
1614

1715
::two_macros::macro_one!();

0 commit comments

Comments
 (0)