Skip to content

Commit fd701b7

Browse files
committed
Remove most uses of def_id_to_node_id
Especially those happening during normal resolving, where we are actually looking at current parent scopes
1 parent 71177d1 commit fd701b7

3 files changed

Lines changed: 14 additions & 13 deletions

File tree

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use std::ops::ControlFlow;
55
use itertools::Itertools as _;
66
use rustc_ast::visit::{self, Visitor};
77
use rustc_ast::{
8-
self as ast, CRATE_NODE_ID, Crate, ItemKind, ModKind, NodeId, Path, join_path_idents,
8+
self as ast, CRATE_NODE_ID, Crate, DUMMY_NODE_ID, ItemKind, ModKind, NodeId, Path,
9+
join_path_idents,
910
};
1011
use rustc_ast_pretty::pprust;
1112
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@@ -192,11 +193,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
192193
}
193194

194195
fn report_with_use_injections(&mut self, krate: &Crate) {
195-
for UseError { mut err, candidates, def_id, instead, suggestion, path, is_call } in
196+
for UseError { mut err, candidates, node_id, instead, suggestion, path, is_call } in
196197
mem::take(&mut self.use_injections)
197198
{
198-
let (span, found_use) = if let Some(def_id) = def_id.as_local() {
199-
UsePlacementFinder::check(krate, self.def_id_to_node_id(def_id))
199+
let (span, found_use) = if node_id != DUMMY_NODE_ID {
200+
UsePlacementFinder::check(krate, node_id)
200201
} else {
201202
(None, FoundUse::No)
202203
};
@@ -1705,9 +1706,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
17051706

17061707
let import_suggestions =
17071708
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
1708-
let (span, found_use) = match parent_scope.module.nearest_parent_mod().as_local() {
1709-
Some(def_id) => UsePlacementFinder::check(krate, self.def_id_to_node_id(def_id)),
1710-
None => (None, FoundUse::No),
1709+
let (span, found_use) = match parent_scope.module.nearest_parent_mod_node_id() {
1710+
DUMMY_NODE_ID => (None, FoundUse::No),
1711+
node_id => UsePlacementFinder::check(krate, node_id),
17111712
};
17121713
show_candidates(
17131714
self.tcx,

compiler/rustc_resolve/src/late.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4515,7 +4515,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45154515
parent_qself,
45164516
);
45174517

4518-
let def_id = this.parent_scope.module.nearest_parent_mod();
4518+
let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
45194519
let instead = res.is_some();
45204520
let (suggestion, const_err) = if let Some((start, end)) =
45214521
this.diag_metadata.in_range
@@ -4557,7 +4557,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
45574557
let ue = UseError {
45584558
err,
45594559
candidates,
4560-
def_id,
4560+
node_id,
45614561
instead,
45624562
suggestion,
45634563
path: path.into(),
@@ -4646,7 +4646,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46464646

46474647
parent_err.cancel();
46484648

4649-
let def_id = this.parent_scope.module.nearest_parent_mod();
4649+
let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
46504650

46514651
if this.should_report_errs() {
46524652
if candidates.is_empty() {
@@ -4671,7 +4671,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
46714671
this.r.use_injections.push(UseError {
46724672
err,
46734673
candidates,
4674-
def_id,
4674+
node_id,
46754675
instead: false,
46764676
suggestion: None,
46774677
path: prefix_path.into(),

compiler/rustc_resolve/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,8 +1001,8 @@ struct UseError<'a> {
10011001
err: Diag<'a>,
10021002
/// Candidates which user could `use` to access the missing type.
10031003
candidates: Vec<ImportSuggestion>,
1004-
/// The `DefId` of the module to place the use-statements in.
1005-
def_id: DefId,
1004+
/// The `NodeId` of the module to place the use-statements in.
1005+
node_id: NodeId,
10061006
/// Whether the diagnostic should say "instead" (as in `consider importing ... instead`).
10071007
instead: bool,
10081008
/// Extra free-form suggestion.

0 commit comments

Comments
 (0)