Skip to content

Commit ab5a2bc

Browse files
committedNov 1, 2022
Auto merge of #103841 - Dylan-DPC:rollup-rff2x1l, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #84022 (Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error) - #103760 (resolve: Turn the binding from `#[macro_export]` into a proper `Import`) - #103813 (rustdoc: remove unnecessary CSS `.search-results { clear: both }`) - #103817 (rustdoc: rename syntax highlighting CSS class `attribute` to `attr`) - #103833 (:arrow_up: rust-analyzer) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 4c736a2 + 2b10891 commit ab5a2bc

Some content is hidden

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

61 files changed

+1126
-824
lines changed
 

‎compiler/rustc_lint_defs/src/builtin.rs

-68
Original file line numberDiff line numberDiff line change
@@ -1982,73 +1982,6 @@ declare_lint! {
19821982
};
19831983
}
19841984

1985-
declare_lint! {
1986-
/// The `proc_macro_derive_resolution_fallback` lint detects proc macro
1987-
/// derives using inaccessible names from parent modules.
1988-
///
1989-
/// ### Example
1990-
///
1991-
/// ```rust,ignore (proc-macro)
1992-
/// // foo.rs
1993-
/// #![crate_type = "proc-macro"]
1994-
///
1995-
/// extern crate proc_macro;
1996-
///
1997-
/// use proc_macro::*;
1998-
///
1999-
/// #[proc_macro_derive(Foo)]
2000-
/// pub fn foo1(a: TokenStream) -> TokenStream {
2001-
/// drop(a);
2002-
/// "mod __bar { static mut BAR: Option<Something> = None; }".parse().unwrap()
2003-
/// }
2004-
/// ```
2005-
///
2006-
/// ```rust,ignore (needs-dependency)
2007-
/// // bar.rs
2008-
/// #[macro_use]
2009-
/// extern crate foo;
2010-
///
2011-
/// struct Something;
2012-
///
2013-
/// #[derive(Foo)]
2014-
/// struct Another;
2015-
///
2016-
/// fn main() {}
2017-
/// ```
2018-
///
2019-
/// This will produce:
2020-
///
2021-
/// ```text
2022-
/// warning: cannot find type `Something` in this scope
2023-
/// --> src/main.rs:8:10
2024-
/// |
2025-
/// 8 | #[derive(Foo)]
2026-
/// | ^^^ names from parent modules are not accessible without an explicit import
2027-
/// |
2028-
/// = note: `#[warn(proc_macro_derive_resolution_fallback)]` on by default
2029-
/// = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
2030-
/// = note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
2031-
/// ```
2032-
///
2033-
/// ### Explanation
2034-
///
2035-
/// If a proc-macro generates a module, the compiler unintentionally
2036-
/// allowed items in that module to refer to items in the crate root
2037-
/// without importing them. This is a [future-incompatible] lint to
2038-
/// transition this to a hard error in the future. See [issue #50504] for
2039-
/// more details.
2040-
///
2041-
/// [issue #50504]: https://github.com/rust-lang/rust/issues/50504
2042-
/// [future-incompatible]: ../index.md#future-incompatible-lints
2043-
pub PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
2044-
Deny,
2045-
"detects proc macro derives using inaccessible names from parent modules",
2046-
@future_incompatible = FutureIncompatibleInfo {
2047-
reference: "issue #83583 <https://github.com/rust-lang/rust/issues/83583>",
2048-
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,
2049-
};
2050-
}
2051-
20521985
declare_lint! {
20531986
/// The `macro_use_extern_crate` lint detects the use of the
20541987
/// [`macro_use` attribute].
@@ -3287,7 +3220,6 @@ declare_lint_pass! {
32873220
UNSTABLE_NAME_COLLISIONS,
32883221
IRREFUTABLE_LET_PATTERNS,
32893222
WHERE_CLAUSES_OBJECT_SAFETY,
3290-
PROC_MACRO_DERIVE_RESOLUTION_FALLBACK,
32913223
MACRO_USE_EXTERN_CRATE,
32923224
MACRO_EXPANDED_MACRO_EXPORTS_ACCESSED_BY_ABSOLUTE_PATHS,
32933225
ILL_FORMED_ATTRIBUTE_INPUT,

‎compiler/rustc_resolve/src/build_reduced_graph.rs

+22-33
Original file line numberDiff line numberDiff line change
@@ -56,21 +56,7 @@ impl<'a, Id: Into<DefId>> ToNameBinding<'a>
5656
impl<'a, Id: Into<DefId>> ToNameBinding<'a> for (Res, ty::Visibility<Id>, Span, LocalExpnId) {
5757
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
5858
arenas.alloc_name_binding(NameBinding {
59-
kind: NameBindingKind::Res(self.0, false),
60-
ambiguity: None,
61-
vis: self.1.to_def_id(),
62-
span: self.2,
63-
expansion: self.3,
64-
})
65-
}
66-
}
67-
68-
struct IsMacroExport;
69-
70-
impl<'a> ToNameBinding<'a> for (Res, ty::Visibility, Span, LocalExpnId, IsMacroExport) {
71-
fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> {
72-
arenas.alloc_name_binding(NameBinding {
73-
kind: NameBindingKind::Res(self.0, true),
59+
kind: NameBindingKind::Res(self.0),
7460
ambiguity: None,
7561
vis: self.1.to_def_id(),
7662
span: self.2,
@@ -364,7 +350,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
364350
module_path: Vec<Segment>,
365351
kind: ImportKind<'a>,
366352
span: Span,
367-
id: NodeId,
368353
item: &ast::Item,
369354
root_span: Span,
370355
root_id: NodeId,
@@ -377,7 +362,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
377362
module_path,
378363
imported_module: Cell::new(None),
379364
span,
380-
id,
381365
use_span: item.span,
382366
use_span_with_attributes: item.span_with_attributes(),
383367
has_attributes: !item.attrs.is_empty(),
@@ -574,27 +558,20 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
574558
},
575559
type_ns_only,
576560
nested,
561+
id,
577562
additional_ids: (id1, id2),
578563
};
579564

580-
self.add_import(
581-
module_path,
582-
kind,
583-
use_tree.span,
584-
id,
585-
item,
586-
root_span,
587-
item.id,
588-
vis,
589-
);
565+
self.add_import(module_path, kind, use_tree.span, item, root_span, item.id, vis);
590566
}
591567
ast::UseTreeKind::Glob => {
592568
let kind = ImportKind::Glob {
593569
is_prelude: self.r.session.contains_name(&item.attrs, sym::prelude_import),
594570
max_vis: Cell::new(None),
571+
id,
595572
};
596573
self.r.visibilities.insert(self.r.local_def_id(id), vis);
597-
self.add_import(prefix, kind, use_tree.span, id, item, root_span, item.id, vis);
574+
self.add_import(prefix, kind, use_tree.span, item, root_span, item.id, vis);
598575
}
599576
ast::UseTreeKind::Nested(ref items) => {
600577
// Ensure there is at most one `self` in the list
@@ -881,9 +858,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
881858
})
882859
.unwrap_or((true, None, self.r.dummy_binding));
883860
let import = self.r.arenas.alloc_import(Import {
884-
kind: ImportKind::ExternCrate { source: orig_name, target: ident },
861+
kind: ImportKind::ExternCrate { source: orig_name, target: ident, id: item.id },
885862
root_id: item.id,
886-
id: item.id,
887863
parent_scope: self.parent_scope,
888864
imported_module: Cell::new(module),
889865
has_attributes: !item.attrs.is_empty(),
@@ -1118,7 +1094,6 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
11181094
this.r.arenas.alloc_import(Import {
11191095
kind: ImportKind::MacroUse,
11201096
root_id: item.id,
1121-
id: item.id,
11221097
parent_scope: this.parent_scope,
11231098
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
11241099
use_span_with_attributes: item.span_with_attributes(),
@@ -1278,8 +1253,22 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
12781253
let binding = (res, vis, span, expansion).to_name_binding(self.r.arenas);
12791254
self.r.set_binding_parent_module(binding, parent_scope.module);
12801255
if is_macro_export {
1281-
let module = self.r.graph_root;
1282-
self.r.define(module, ident, MacroNS, (res, vis, span, expansion, IsMacroExport));
1256+
let import = self.r.arenas.alloc_import(Import {
1257+
kind: ImportKind::MacroExport,
1258+
root_id: item.id,
1259+
parent_scope: self.parent_scope,
1260+
imported_module: Cell::new(None),
1261+
has_attributes: false,
1262+
use_span_with_attributes: span,
1263+
use_span: span,
1264+
root_span: span,
1265+
span: span,
1266+
module_path: Vec::new(),
1267+
vis: Cell::new(Some(vis)),
1268+
used: Cell::new(true),
1269+
});
1270+
let import_binding = self.r.import(binding, import);
1271+
self.r.define(self.r.graph_root, ident, MacroNS, import_binding);
12831272
} else {
12841273
self.r.check_reserved_macro_name(ident, res);
12851274
self.insert_unused_macro(ident, def_id, item.id, &rule_spans);

0 commit comments

Comments
 (0)
Please sign in to comment.