Skip to content

Commit c8c587f

Browse files
committed
Auto merge of #50911 - petrochenkov:macuse, r=alexcrichton
Stabilize `use_extern_macros` Closes #35896
2 parents de21ea8 + 674a5db commit c8c587f

File tree

87 files changed

+164
-524
lines changed

Some content is hidden

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

87 files changed

+164
-524
lines changed

src/librustc_resolve/build_reduced_graph.rs

+1-8
Original file line numberDiff line numberDiff line change
@@ -833,19 +833,12 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
833833
-> bool {
834834
let allow_shadowing = expansion == Mark::root();
835835
let legacy_imports = self.legacy_macro_imports(&item.attrs);
836-
let mut used = legacy_imports != LegacyMacroImports::default();
836+
let used = legacy_imports != LegacyMacroImports::default();
837837

838838
// `#[macro_use]` is only allowed at the crate root.
839839
if self.current_module.parent.is_some() && used {
840840
span_err!(self.session, item.span, E0468,
841841
"an `extern crate` loading macros must be at the crate root");
842-
} else if !self.use_extern_macros && !used &&
843-
self.cstore.dep_kind_untracked(module.def_id().unwrap().krate)
844-
.macros_only() {
845-
let msg = "proc macro crates and `#[no_link]` crates have no effect without \
846-
`#[macro_use]`";
847-
self.session.span_warn(item.span, msg);
848-
used = true; // Avoid the normal unused extern crate warning
849842
}
850843

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

src/librustc_resolve/check_unused.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) {
131131
directive.vis.get() == ty::Visibility::Public ||
132132
directive.span.is_dummy() => {
133133
if let ImportDirectiveSubclass::MacroUse = directive.subclass {
134-
if resolver.use_extern_macros && !directive.span.is_dummy() {
134+
if !directive.span.is_dummy() {
135135
resolver.session.buffer_lint(
136136
lint::builtin::MACRO_USE_EXTERN_CRATE,
137137
directive.id,

src/librustc_resolve/lib.rs

+2-56
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use std::mem::replace;
8080
use rustc_data_structures::sync::Lrc;
8181

8282
use resolve_imports::{ImportDirective, ImportDirectiveSubclass, NameResolution, ImportResolver};
83-
use macros::{InvocationData, LegacyBinding, LegacyScope, MacroBinding};
83+
use macros::{InvocationData, LegacyBinding, MacroBinding};
8484

8585
// NB: This module needs to be declared first so diagnostics are
8686
// registered before they are used.
@@ -1399,23 +1399,18 @@ pub struct Resolver<'a, 'b: 'a> {
13991399
/// crate-local macro expanded `macro_export` referred to by a module-relative path
14001400
macro_expanded_macro_export_errors: BTreeSet<(Span, Span)>,
14011401

1402-
gated_errors: FxHashSet<Span>,
14031402
disallowed_shadowing: Vec<&'a LegacyBinding<'a>>,
14041403

14051404
arenas: &'a ResolverArenas<'a>,
14061405
dummy_binding: &'a NameBinding<'a>,
1407-
/// true if `#![feature(use_extern_macros)]`
1408-
use_extern_macros: bool,
14091406

14101407
crate_loader: &'a mut CrateLoader<'b>,
14111408
macro_names: FxHashSet<Ident>,
14121409
macro_prelude: FxHashMap<Name, &'a NameBinding<'a>>,
14131410
pub all_macros: FxHashMap<Name, Def>,
1414-
lexical_macro_resolutions: Vec<(Ident, &'a Cell<LegacyScope<'a>>)>,
14151411
macro_map: FxHashMap<DefId, Lrc<SyntaxExtension>>,
14161412
macro_defs: FxHashMap<Mark, DefId>,
14171413
local_macro_def_scopes: FxHashMap<NodeId, Module<'a>>,
1418-
macro_exports: Vec<Export>, // FIXME: Remove when `use_extern_macros` is stabilized
14191414
pub whitelisted_legacy_custom_derives: Vec<Name>,
14201415
pub found_unresolved_macro: bool,
14211416

@@ -1657,8 +1652,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
16571652
invocations.insert(Mark::root(),
16581653
arenas.alloc_invocation_data(InvocationData::root(graph_root)));
16591654

1660-
let features = session.features_untracked();
1661-
16621655
let mut macro_defs = FxHashMap();
16631656
macro_defs.insert(Mark::root(), root_def_id);
16641657

@@ -1717,7 +1710,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
17171710
ambiguity_errors: Vec::new(),
17181711
use_injections: Vec::new(),
17191712
proc_mac_errors: Vec::new(),
1720-
gated_errors: FxHashSet(),
17211713
disallowed_shadowing: Vec::new(),
17221714
macro_expanded_macro_export_errors: BTreeSet::new(),
17231715

@@ -1729,15 +1721,11 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
17291721
vis: ty::Visibility::Public,
17301722
}),
17311723

1732-
use_extern_macros: features.use_extern_macros(),
1733-
17341724
crate_loader,
17351725
macro_names: FxHashSet(),
17361726
macro_prelude: FxHashMap(),
17371727
all_macros: FxHashMap(),
1738-
lexical_macro_resolutions: Vec::new(),
17391728
macro_map: FxHashMap(),
1740-
macro_exports: Vec::new(),
17411729
invocations,
17421730
macro_defs,
17431731
local_macro_def_scopes: FxHashMap(),
@@ -1770,9 +1758,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
17701758
fn per_ns<F: FnMut(&mut Self, Namespace)>(&mut self, mut f: F) {
17711759
f(self, TypeNS);
17721760
f(self, ValueNS);
1773-
if self.use_extern_macros {
1774-
f(self, MacroNS);
1775-
}
1761+
f(self, MacroNS);
17761762
}
17771763

17781764
fn macro_def(&self, mut ctxt: SyntaxContext) -> DefId {
@@ -2186,11 +2172,8 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
21862172

21872173
fn resolve_item(&mut self, item: &Item) {
21882174
let name = item.ident.name;
2189-
21902175
debug!("(resolving item) resolving {}", name);
21912176

2192-
self.check_proc_macro_attrs(&item.attrs);
2193-
21942177
match item.node {
21952178
ItemKind::Enum(_, ref generics) |
21962179
ItemKind::Ty(_, ref generics) |
@@ -2218,8 +2201,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
22182201
walk_list!(this, visit_param_bound, bounds);
22192202

22202203
for trait_item in trait_items {
2221-
this.check_proc_macro_attrs(&trait_item.attrs);
2222-
22232204
let type_parameters = HasTypeParameters(&trait_item.generics,
22242205
TraitOrImplItemRibKind);
22252206
this.with_type_parameter_rib(type_parameters, |this| {
@@ -2498,7 +2479,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
24982479
this.visit_generics(generics);
24992480
this.with_current_self_type(self_type, |this| {
25002481
for impl_item in impl_items {
2501-
this.check_proc_macro_attrs(&impl_item.attrs);
25022482
this.resolve_visibility(&impl_item.vis);
25032483

25042484
// We also need a new scope for the impl item type parameters.
@@ -4488,10 +4468,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
44884468
}
44894469

44904470
fn report_shadowing_errors(&mut self) {
4491-
for (ident, scope) in replace(&mut self.lexical_macro_resolutions, Vec::new()) {
4492-
self.resolve_legacy_scope(scope, ident, true);
4493-
}
4494-
44954471
let mut reported_errors = FxHashSet();
44964472
for binding in replace(&mut self.disallowed_shadowing, Vec::new()) {
44974473
if self.resolve_legacy_scope(&binding.parent, binding.ident, false).is_some() &&
@@ -4612,36 +4588,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
46124588
err.emit();
46134589
self.name_already_seen.insert(name, span);
46144590
}
4615-
4616-
fn check_proc_macro_attrs(&mut self, attrs: &[ast::Attribute]) {
4617-
if self.use_extern_macros { return; }
4618-
4619-
for attr in attrs {
4620-
if attr.path.segments.len() > 1 {
4621-
continue
4622-
}
4623-
let ident = attr.path.segments[0].ident;
4624-
let result = self.resolve_lexical_macro_path_segment(ident,
4625-
MacroNS,
4626-
false,
4627-
false,
4628-
true,
4629-
attr.path.span);
4630-
if let Ok(binding) = result {
4631-
if let SyntaxExtension::AttrProcMacro(..) = *binding.binding().get_macro(self) {
4632-
attr::mark_known(attr);
4633-
4634-
let msg = "attribute procedural macros are experimental";
4635-
let feature = "use_extern_macros";
4636-
4637-
feature_err(&self.session.parse_sess, feature,
4638-
attr.span, GateIssue::Language, msg)
4639-
.span_label(binding.span(), "procedural macro imported here")
4640-
.emit();
4641-
}
4642-
}
4643-
}
4644-
}
46454591
}
46464592

46474593
fn is_self_type(path: &[Ident], namespace: Namespace) -> bool {

src/librustc_resolve/macros.rs

+7-41
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use build_reduced_graph::{BuildReducedGraphVisitor, IsMacroExport};
1616
use resolve_imports::ImportResolver;
1717
use rustc::hir::def_id::{DefId, BUILTIN_MACROS_CRATE, CRATE_DEF_INDEX, DefIndex,
1818
DefIndexAddressSpace};
19-
use rustc::hir::def::{Def, Export, NonMacroAttrKind};
19+
use rustc::hir::def::{Def, NonMacroAttrKind};
2020
use rustc::hir::map::{self, DefCollector};
2121
use rustc::{ty, lint};
2222
use rustc::middle::cstore::CrateStore;
@@ -524,21 +524,13 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
524524
self.current_module = if module.is_trait() { module.parent.unwrap() } else { module };
525525

526526
// Possibly apply the macro helper hack
527-
if self.use_extern_macros && kind == MacroKind::Bang && path.len() == 1 &&
527+
if kind == MacroKind::Bang && path.len() == 1 &&
528528
path[0].span.ctxt().outer().expn_info().map_or(false, |info| info.local_inner_macros) {
529529
let root = Ident::new(keywords::DollarCrate.name(), path[0].span);
530530
path.insert(0, root);
531531
}
532532

533533
if path.len() > 1 {
534-
if !self.use_extern_macros && self.gated_errors.insert(span) {
535-
let msg = "non-ident macro paths are experimental";
536-
let feature = "use_extern_macros";
537-
emit_feature_err(&self.session.parse_sess, feature, span, GateIssue::Language, msg);
538-
self.found_unresolved_macro = true;
539-
return Err(Determinacy::Determined);
540-
}
541-
542534
let res = self.resolve_path(None, &path, Some(MacroNS), false, span, CrateLint::No);
543535
let def = match res {
544536
PathResult::NonModule(path_res) => match path_res.base_def() {
@@ -843,7 +835,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
843835
record_used: bool)
844836
-> Option<MacroBinding<'a>> {
845837
let ident = ident.modern();
846-
let mut possible_time_travel = None;
847838
let mut relative_depth: u32 = 0;
848839
let mut binding = None;
849840
loop {
@@ -853,9 +844,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
853844
match invocation.expansion.get() {
854845
LegacyScope::Invocation(_) => scope.set(invocation.legacy_scope.get()),
855846
LegacyScope::Empty => {
856-
if possible_time_travel.is_none() {
857-
possible_time_travel = Some(scope);
858-
}
859847
scope = &invocation.legacy_scope;
860848
}
861849
_ => {
@@ -870,7 +858,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
870858
}
871859
LegacyScope::Binding(potential_binding) => {
872860
if potential_binding.ident == ident {
873-
if (!self.use_extern_macros || record_used) && relative_depth > 0 {
861+
if record_used && relative_depth > 0 {
874862
self.disallowed_shadowing.push(potential_binding);
875863
}
876864
binding = Some(potential_binding);
@@ -884,21 +872,11 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
884872
let binding = if let Some(binding) = binding {
885873
MacroBinding::Legacy(binding)
886874
} else if let Some(binding) = self.macro_prelude.get(&ident.name).cloned() {
887-
if !self.use_extern_macros {
888-
self.record_use(ident, MacroNS, binding, DUMMY_SP);
889-
}
890875
MacroBinding::Global(binding)
891876
} else {
892877
return None;
893878
};
894879

895-
if !self.use_extern_macros {
896-
if let Some(scope) = possible_time_travel {
897-
// Check for disallowed shadowing later
898-
self.lexical_macro_resolutions.push((ident, scope));
899-
}
900-
}
901-
902880
Some(binding)
903881
}
904882

@@ -1008,9 +986,6 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
1008986
find_best_match_for_name(names, name, None)
1009987
// Then check modules.
1010988
}).or_else(|| {
1011-
if !self.use_extern_macros {
1012-
return None;
1013-
}
1014989
let is_macro = |def| {
1015990
if let Def::Macro(_, def_kind) = def {
1016991
def_kind == kind
@@ -1086,19 +1061,10 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
10861061
let def = Def::Macro(def_id, MacroKind::Bang);
10871062
self.all_macros.insert(ident.name, def);
10881063
if attr::contains_name(&item.attrs, "macro_export") {
1089-
if self.use_extern_macros {
1090-
let module = self.graph_root;
1091-
let vis = ty::Visibility::Public;
1092-
self.define(module, ident, MacroNS,
1093-
(def, vis, item.span, expansion, IsMacroExport));
1094-
} else {
1095-
self.macro_exports.push(Export {
1096-
ident: ident.modern(),
1097-
def: def,
1098-
vis: ty::Visibility::Public,
1099-
span: item.span,
1100-
});
1101-
}
1064+
let module = self.graph_root;
1065+
let vis = ty::Visibility::Public;
1066+
self.define(module, ident, MacroNS,
1067+
(def, vis, item.span, expansion, IsMacroExport));
11021068
} else {
11031069
self.unused_macros.insert(def_id);
11041070
}

src/librustc_resolve/resolve_imports.rs

+1-29
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc::lint::builtin::{DUPLICATE_MACRO_EXPORTS, PUB_USE_OF_PRIVATE_EXTERN_CR
2424
use rustc::hir::def_id::{CRATE_DEF_INDEX, DefId};
2525
use rustc::hir::def::*;
2626
use rustc::session::DiagnosticMessageId;
27-
use rustc::util::nodemap::{FxHashMap, FxHashSet};
27+
use rustc::util::nodemap::FxHashSet;
2828

2929
use syntax::ast::{Ident, Name, NodeId, CRATE_NODE_ID};
3030
use syntax::ext::base::Determinacy::{self, Determined, Undetermined};
@@ -1142,24 +1142,6 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
11421142
*module.globs.borrow_mut() = Vec::new();
11431143

11441144
let mut reexports = Vec::new();
1145-
let mut exported_macro_names = FxHashMap();
1146-
if ptr::eq(module, self.graph_root) {
1147-
let macro_exports = mem::replace(&mut self.macro_exports, Vec::new());
1148-
for export in macro_exports.into_iter().rev() {
1149-
if let Some(later_span) = exported_macro_names.insert(export.ident.modern(),
1150-
export.span) {
1151-
self.session.buffer_lint_with_diagnostic(
1152-
DUPLICATE_MACRO_EXPORTS,
1153-
CRATE_NODE_ID,
1154-
later_span,
1155-
&format!("a macro named `{}` has already been exported", export.ident),
1156-
BuiltinLintDiagnostics::DuplicatedMacroExports(
1157-
export.ident, export.span, later_span));
1158-
} else {
1159-
reexports.push(export);
1160-
}
1161-
}
1162-
}
11631145

11641146
for (&(ident, ns), resolution) in module.resolutions.borrow().iter() {
11651147
let resolution = &mut *resolution.borrow_mut();
@@ -1174,16 +1156,6 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
11741156
if !def.def_id().is_local() {
11751157
self.cstore.export_macros_untracked(def.def_id().krate);
11761158
}
1177-
if let Def::Macro(..) = def {
1178-
if let Some(&span) = exported_macro_names.get(&ident.modern()) {
1179-
let msg =
1180-
format!("a macro named `{}` has already been exported", ident);
1181-
self.session.struct_span_err(span, &msg)
1182-
.span_label(span, format!("`{}` already exported", ident))
1183-
.span_note(binding.span, "previous macro export here")
1184-
.emit();
1185-
}
1186-
}
11871159
reexports.push(Export {
11881160
ident: ident.modern(),
11891161
def: def,

src/libstd/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
#![feature(unboxed_closures)]
303303
#![feature(untagged_unions)]
304304
#![feature(unwind_attributes)]
305-
#![feature(use_extern_macros)]
305+
#![cfg_attr(stage0, feature(use_extern_macros))]
306306
#![feature(doc_cfg)]
307307
#![feature(doc_masked)]
308308
#![feature(doc_spotlight)]

src/libsyntax/ext/expand.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -1124,9 +1124,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
11241124
return attrs;
11251125
}
11261126

1127-
if self.cx.ecfg.use_extern_macros_enabled() {
1128-
attr = find_attr_invoc(&mut attrs);
1129-
}
1127+
attr = find_attr_invoc(&mut attrs);
11301128
traits = collect_derives(&mut self.cx, &mut attrs);
11311129
attrs
11321130
});
@@ -1147,9 +1145,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
11471145
return attrs;
11481146
}
11491147

1150-
if self.cx.ecfg.use_extern_macros_enabled() {
1151-
attr = find_attr_invoc(&mut attrs);
1152-
}
1148+
attr = find_attr_invoc(&mut attrs);
11531149
attrs
11541150
});
11551151

@@ -1667,10 +1663,6 @@ impl<'feat> ExpansionConfig<'feat> {
16671663
fn proc_macro_expr = proc_macro_expr,
16681664
fn proc_macro_non_items = proc_macro_non_items,
16691665
}
1670-
1671-
pub fn use_extern_macros_enabled(&self) -> bool {
1672-
self.features.map_or(false, |features| features.use_extern_macros())
1673-
}
16741666
}
16751667

16761668
// A Marker adds the given mark to the syntax context.

0 commit comments

Comments
 (0)