Skip to content

Commit 0a151ca

Browse files
committed
Follow-up cleanups reusing the now-available LocalDefIds
1 parent c0fcaef commit 0a151ca

3 files changed

Lines changed: 12 additions & 12 deletions

File tree

compiler/rustc_resolve/src/check_unused.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,7 @@ impl Resolver<'_, '_> {
431431
}
432432
}
433433
}
434-
ImportKind::ExternCrate { id, .. } => {
435-
let def_id = self.local_def_id(id);
434+
ImportKind::ExternCrate { id, def_id, .. } => {
436435
if self.extern_crate_map.get(&def_id).is_none_or(|&cnum| {
437436
!tcx.is_compiler_builtins(cnum)
438437
&& !tcx.is_panic_runtime(cnum)

compiler/rustc_resolve/src/imports.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,16 @@ struct UnresolvedImportError {
346346

347347
// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
348348
// are permitted for backward-compatibility under a deprecation lint.
349-
fn pub_use_of_private_extern_crate_hack(import: ImportSummary, decl: Decl<'_>) -> Option<NodeId> {
349+
fn pub_use_of_private_extern_crate_hack(
350+
import: ImportSummary,
351+
decl: Decl<'_>,
352+
) -> Option<LocalDefId> {
350353
match (import.is_single, decl.kind) {
351354
(true, DeclKind::Import { import: decl_import, .. })
352-
if let ImportKind::ExternCrate { id, .. } = decl_import.kind
355+
if let ImportKind::ExternCrate { def_id, .. } = decl_import.kind
353356
&& import.vis.is_public() =>
354357
{
355-
Some(id)
358+
Some(def_id)
356359
}
357360
_ => None,
358361
}
@@ -1240,7 +1243,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12401243

12411244
let (ident, target, bindings, import_id) = match import.kind {
12421245
ImportKind::Single { source, target, ref decls, id, .. } => (source, target, decls, id),
1243-
ImportKind::Glob { ref max_vis, id, def_id: _ } => {
1246+
ImportKind::Glob { ref max_vis, id, def_id } => {
12441247
if import.module_path.len() <= 1 {
12451248
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
12461249
// 2 segments, so the `resolve_path` above won't trigger it.
@@ -1267,7 +1270,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12671270
if let Some(max_vis) = max_vis.get()
12681271
&& import.vis.greater_than(max_vis, self.tcx)
12691272
{
1270-
let def_id = self.local_def_id(id);
12711273
self.lint_buffer.buffer_lint(
12721274
UNUSED_IMPORTS,
12731275
id,
@@ -1549,7 +1551,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
15491551
if let Some(extern_crate_id) =
15501552
pub_use_of_private_extern_crate_hack(import.summary(), binding)
15511553
{
1552-
let extern_crate_sp = self.tcx.source_span(self.local_def_id(extern_crate_id));
1554+
let extern_crate_sp = self.tcx.source_span(extern_crate_id);
15531555
self.lint_buffer.buffer_lint(
15541556
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
15551557
import_id,
@@ -1625,7 +1627,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16251627

16261628
pub(crate) fn check_for_redundant_imports(&mut self, import: Import<'ra>) -> bool {
16271629
// This function is only called for single imports.
1628-
let ImportKind::Single { source, target, ref decls, id, .. } = import.kind else {
1630+
let ImportKind::Single { source, target, ref decls, id, def_id, .. } = import.kind else {
16291631
unreachable!()
16301632
};
16311633

@@ -1644,7 +1646,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16441646
// Skip if the import is public or was used through non scope-based resolution,
16451647
// e.g. through a module-relative path.
16461648
if self.import_use_map.get(&import) == Some(&Used::Other)
1647-
|| self.effective_visibilities.is_exported(self.local_def_id(id))
1649+
|| self.effective_visibilities.is_exported(def_id)
16481650
{
16491651
return false;
16501652
}

compiler/rustc_resolve/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,8 +2282,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
22822282

22832283
#[inline]
22842284
fn add_to_glob_map(&mut self, import: Import<'_>, name: Symbol) {
2285-
if let ImportKind::Glob { id, .. } = import.kind {
2286-
let def_id = self.local_def_id(id);
2285+
if let ImportKind::Glob { def_id, .. } = import.kind {
22872286
self.glob_map.entry(def_id).or_default().insert(name);
22882287
}
22892288
}

0 commit comments

Comments
 (0)