Skip to content

Commit a082567

Browse files
committed
Follow-up cleanups reusing the now-available LocalDefIds
1 parent 400240a commit a082567

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
@@ -356,13 +356,16 @@ struct UnresolvedImportError {
356356

357357
// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
358358
// are permitted for backward-compatibility under a deprecation lint.
359-
fn pub_use_of_private_extern_crate_hack(import: ImportSummary, decl: Decl<'_>) -> Option<NodeId> {
359+
fn pub_use_of_private_extern_crate_hack(
360+
import: ImportSummary,
361+
decl: Decl<'_>,
362+
) -> Option<LocalDefId> {
360363
match (import.is_single, decl.kind) {
361364
(true, DeclKind::Import { import: decl_import, .. })
362-
if let ImportKind::ExternCrate { id, .. } = decl_import.kind
365+
if let ImportKind::ExternCrate { def_id, .. } = decl_import.kind
363366
&& import.vis.is_public() =>
364367
{
365-
Some(id)
368+
Some(def_id)
366369
}
367370
_ => None,
368371
}
@@ -1282,7 +1285,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
12821285

12831286
let (ident, target, bindings, import_id) = match import.kind {
12841287
ImportKind::Single { source, target, ref decls, id, .. } => (source, target, decls, id),
1285-
ImportKind::Glob { ref max_vis, id, def_id: _ } => {
1288+
ImportKind::Glob { ref max_vis, id, def_id } => {
12861289
if import.module_path.len() <= 1 {
12871290
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
12881291
// 2 segments, so the `resolve_path` above won't trigger it.
@@ -1309,7 +1312,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
13091312
if let Some(max_vis) = max_vis.get()
13101313
&& import.vis.greater_than(max_vis, self.tcx)
13111314
{
1312-
let def_id = self.local_def_id(id);
13131315
self.lint_buffer.buffer_lint(
13141316
UNUSED_IMPORTS,
13151317
id,
@@ -1629,7 +1631,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16291631
if let Some(extern_crate_id) = pub_use_of_private_extern_crate_hack(import.summary(), decl)
16301632
{
16311633
let ImportKind::Single { id, .. } = import.kind else { unreachable!() };
1632-
let sugg = self.tcx.source_span(self.local_def_id(extern_crate_id)).shrink_to_lo();
1634+
let sugg = self.tcx.source_span(extern_crate_id).shrink_to_lo();
16331635
let diagnostic = crate::errors::PrivateExternCrateReexport { ident, sugg };
16341636
return Some(BufferedEarlyLint {
16351637
lint_id: LintId::of(PUB_USE_OF_PRIVATE_EXTERN_CRATE),
@@ -1671,7 +1673,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16711673

16721674
pub(crate) fn check_for_redundant_imports(&mut self, import: Import<'ra>) -> bool {
16731675
// This function is only called for single imports.
1674-
let ImportKind::Single { source, target, ref decls, id, .. } = import.kind else {
1676+
let ImportKind::Single { source, target, ref decls, id, def_id, .. } = import.kind else {
16751677
unreachable!()
16761678
};
16771679

@@ -1690,7 +1692,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
16901692
// Skip if the import is public or was used through non scope-based resolution,
16911693
// e.g. through a module-relative path.
16921694
if self.import_use_map.get(&import) == Some(&Used::Other)
1693-
|| self.effective_visibilities.is_exported(self.local_def_id(id))
1695+
|| self.effective_visibilities.is_exported(def_id)
16941696
{
16951697
return false;
16961698
}

compiler/rustc_resolve/src/lib.rs

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

22922292
#[inline]
22932293
fn add_to_glob_map(&mut self, import: Import<'_>, name: Symbol) {
2294-
if let ImportKind::Glob { id, .. } = import.kind {
2295-
let def_id = self.local_def_id(id);
2294+
if let ImportKind::Glob { def_id, .. } = import.kind {
22962295
self.glob_map.entry(def_id).or_default().insert(name);
22972296
}
22982297
}

0 commit comments

Comments
 (0)