Skip to content

Commit ab5a2bc

Browse files
committed
Auto merge of rust-lang#103841 - Dylan-DPC:rollup-rff2x1l, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - rust-lang#84022 (Make PROC_MACRO_DERIVE_RESOLUTION_FALLBACK a hard error) - rust-lang#103760 (resolve: Turn the binding from `#[macro_export]` into a proper `Import`) - rust-lang#103813 (rustdoc: remove unnecessary CSS `.search-results { clear: both }`) - rust-lang#103817 (rustdoc: rename syntax highlighting CSS class `attribute` to `attr`) - rust-lang#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);

compiler/rustc_resolve/src/check_unused.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ impl Resolver<'_> {
234234
if !import.span.is_dummy() {
235235
self.lint_buffer.buffer_lint(
236236
MACRO_USE_EXTERN_CRATE,
237-
import.id,
237+
import.root_id,
238238
import.span,
239239
"deprecated `#[macro_use]` attribute used to \
240240
import macros should be replaced at use sites \
@@ -244,13 +244,13 @@ impl Resolver<'_> {
244244
}
245245
}
246246
}
247-
ImportKind::ExternCrate { .. } => {
248-
let def_id = self.local_def_id(import.id);
247+
ImportKind::ExternCrate { id, .. } => {
248+
let def_id = self.local_def_id(id);
249249
self.maybe_unused_extern_crates.push((def_id, import.span));
250250
}
251251
ImportKind::MacroUse => {
252252
let msg = "unused `#[macro_use]` import";
253-
self.lint_buffer.buffer_lint(UNUSED_IMPORTS, import.id, import.span, msg);
253+
self.lint_buffer.buffer_lint(UNUSED_IMPORTS, import.root_id, import.span, msg);
254254
}
255255
_ => {}
256256
}

compiler/rustc_resolve/src/diagnostics.rs

+22-16
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ impl<'a> Resolver<'a> {
190190
ModuleKind::Block => "block",
191191
};
192192

193-
let old_noun = match old_binding.is_import() {
193+
let old_noun = match old_binding.is_import_user_facing() {
194194
true => "import",
195195
false => "definition",
196196
};
197197

198-
let new_participle = match new_binding.is_import() {
198+
let new_participle = match new_binding.is_import_user_facing() {
199199
true => "imported",
200200
false => "defined",
201201
};
@@ -226,7 +226,7 @@ impl<'a> Resolver<'a> {
226226
true => struct_span_err!(self.session, span, E0254, "{}", msg),
227227
false => struct_span_err!(self.session, span, E0260, "{}", msg),
228228
},
229-
_ => match (old_binding.is_import(), new_binding.is_import()) {
229+
_ => match (old_binding.is_import_user_facing(), new_binding.is_import_user_facing()) {
230230
(false, false) => struct_span_err!(self.session, span, E0428, "{}", msg),
231231
(true, true) => struct_span_err!(self.session, span, E0252, "{}", msg),
232232
_ => struct_span_err!(self.session, span, E0255, "{}", msg),
@@ -248,14 +248,18 @@ impl<'a> Resolver<'a> {
248248

249249
// See https://github.com/rust-lang/rust/issues/32354
250250
use NameBindingKind::Import;
251+
let can_suggest = |binding: &NameBinding<'_>, import: &self::Import<'_>| {
252+
!binding.span.is_dummy()
253+
&& !matches!(import.kind, ImportKind::MacroUse | ImportKind::MacroExport)
254+
};
251255
let import = match (&new_binding.kind, &old_binding.kind) {
252256
// If there are two imports where one or both have attributes then prefer removing the
253257
// import without attributes.
254258
(Import { import: new, .. }, Import { import: old, .. })
255259
if {
256-
!new_binding.span.is_dummy()
257-
&& !old_binding.span.is_dummy()
258-
&& (new.has_attributes || old.has_attributes)
260+
(new.has_attributes || old.has_attributes)
261+
&& can_suggest(old_binding, old)
262+
&& can_suggest(new_binding, new)
259263
} =>
260264
{
261265
if old.has_attributes {
@@ -265,10 +269,10 @@ impl<'a> Resolver<'a> {
265269
}
266270
}
267271
// Otherwise prioritize the new binding.
268-
(Import { import, .. }, other) if !new_binding.span.is_dummy() => {
272+
(Import { import, .. }, other) if can_suggest(new_binding, import) => {
269273
Some((import, new_binding.span, other.is_import()))
270274
}
271-
(other, Import { import, .. }) if !old_binding.span.is_dummy() => {
275+
(other, Import { import, .. }) if can_suggest(old_binding, import) => {
272276
Some((import, old_binding.span, other.is_import()))
273277
}
274278
_ => None,
@@ -353,7 +357,7 @@ impl<'a> Resolver<'a> {
353357
}
354358
}
355359
}
356-
ImportKind::ExternCrate { source, target } => {
360+
ImportKind::ExternCrate { source, target, .. } => {
357361
suggestion = Some(format!(
358362
"extern crate {} as {};",
359363
source.unwrap_or(target.name),
@@ -1202,7 +1206,7 @@ impl<'a> Resolver<'a> {
12021206
let root_module = this.resolve_crate_root(root_ident);
12031207
this.add_module_candidates(root_module, &mut suggestions, filter_fn, None);
12041208
}
1205-
Scope::Module(module, _) => {
1209+
Scope::Module(module) => {
12061210
this.add_module_candidates(module, &mut suggestions, filter_fn, None);
12071211
}
12081212
Scope::MacroUsePrelude => {
@@ -1683,7 +1687,7 @@ impl<'a> Resolver<'a> {
16831687
let a = if built_in.is_empty() { res.article() } else { "a" };
16841688
format!("{a}{built_in} {thing}{from}", thing = res.descr())
16851689
} else {
1686-
let introduced = if b.is_import() { "imported" } else { "defined" };
1690+
let introduced = if b.is_import_user_facing() { "imported" } else { "defined" };
16871691
format!("the {thing} {introduced} here", thing = res.descr())
16881692
}
16891693
}
@@ -1742,10 +1746,10 @@ impl<'a> Resolver<'a> {
17421746
/// If the binding refers to a tuple struct constructor with fields,
17431747
/// returns the span of its fields.
17441748
fn ctor_fields_span(&self, binding: &NameBinding<'_>) -> Option<Span> {
1745-
if let NameBindingKind::Res(
1746-
Res::Def(DefKind::Ctor(CtorOf::Struct, CtorKind::Fn), ctor_def_id),
1747-
_,
1748-
) = binding.kind
1749+
if let NameBindingKind::Res(Res::Def(
1750+
DefKind::Ctor(CtorOf::Struct, CtorKind::Fn),
1751+
ctor_def_id,
1752+
)) = binding.kind
17491753
{
17501754
let def_id = self.parent(ctor_def_id);
17511755
let fields = self.field_names.get(&def_id)?;
@@ -1789,7 +1793,9 @@ impl<'a> Resolver<'a> {
17891793
next_ident = source;
17901794
Some(binding)
17911795
}
1792-
ImportKind::Glob { .. } | ImportKind::MacroUse => Some(binding),
1796+
ImportKind::Glob { .. } | ImportKind::MacroUse | ImportKind::MacroExport => {
1797+
Some(binding)
1798+
}
17931799
ImportKind::ExternCrate { .. } => None,
17941800
},
17951801
_ => None,

0 commit comments

Comments
 (0)