mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-06 08:36:52 -04:00
Remove most uses of def_id_to_node_id
Especially those happening during normal resolving, where we are actually looking at current parent scopes
This commit is contained in:
@@ -5,7 +5,8 @@ use std::ops::ControlFlow;
|
||||
use itertools::Itertools as _;
|
||||
use rustc_ast::visit::{self, Visitor};
|
||||
use rustc_ast::{
|
||||
self as ast, CRATE_NODE_ID, Crate, ItemKind, ModKind, NodeId, Path, join_path_idents,
|
||||
self as ast, CRATE_NODE_ID, Crate, DUMMY_NODE_ID, ItemKind, ModKind, NodeId, Path,
|
||||
join_path_idents,
|
||||
};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
@@ -192,11 +193,11 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
}
|
||||
|
||||
fn report_with_use_injections(&mut self, krate: &Crate) {
|
||||
for UseError { mut err, candidates, def_id, instead, suggestion, path, is_call } in
|
||||
for UseError { mut err, candidates, node_id, instead, suggestion, path, is_call } in
|
||||
mem::take(&mut self.use_injections)
|
||||
{
|
||||
let (span, found_use) = if let Some(def_id) = def_id.as_local() {
|
||||
UsePlacementFinder::check(krate, self.def_id_to_node_id(def_id))
|
||||
let (span, found_use) = if node_id != DUMMY_NODE_ID {
|
||||
UsePlacementFinder::check(krate, node_id)
|
||||
} else {
|
||||
(None, FoundUse::No)
|
||||
};
|
||||
@@ -1705,9 +1706,9 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
|
||||
|
||||
let import_suggestions =
|
||||
self.lookup_import_candidates(ident, Namespace::MacroNS, parent_scope, is_expected);
|
||||
let (span, found_use) = match parent_scope.module.nearest_parent_mod().as_local() {
|
||||
Some(def_id) => UsePlacementFinder::check(krate, self.def_id_to_node_id(def_id)),
|
||||
None => (None, FoundUse::No),
|
||||
let (span, found_use) = match parent_scope.module.nearest_parent_mod_node_id() {
|
||||
DUMMY_NODE_ID => (None, FoundUse::No),
|
||||
node_id => UsePlacementFinder::check(krate, node_id),
|
||||
};
|
||||
show_candidates(
|
||||
self.tcx,
|
||||
|
||||
@@ -4515,7 +4515,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
parent_qself,
|
||||
);
|
||||
|
||||
let def_id = this.parent_scope.module.nearest_parent_mod();
|
||||
let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
|
||||
let instead = res.is_some();
|
||||
let (suggestion, const_err) = if let Some((start, end)) =
|
||||
this.diag_metadata.in_range
|
||||
@@ -4557,7 +4557,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
let ue = UseError {
|
||||
err,
|
||||
candidates,
|
||||
def_id,
|
||||
node_id,
|
||||
instead,
|
||||
suggestion,
|
||||
path: path.into(),
|
||||
@@ -4646,7 +4646,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
|
||||
parent_err.cancel();
|
||||
|
||||
let def_id = this.parent_scope.module.nearest_parent_mod();
|
||||
let node_id = this.parent_scope.module.nearest_parent_mod_node_id();
|
||||
|
||||
if this.should_report_errs() {
|
||||
if candidates.is_empty() {
|
||||
@@ -4671,7 +4671,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
|
||||
this.r.use_injections.push(UseError {
|
||||
err,
|
||||
candidates,
|
||||
def_id,
|
||||
node_id,
|
||||
instead: false,
|
||||
suggestion: None,
|
||||
path: prefix_path.into(),
|
||||
|
||||
@@ -1001,8 +1001,8 @@ struct UseError<'a> {
|
||||
err: Diag<'a>,
|
||||
/// Candidates which user could `use` to access the missing type.
|
||||
candidates: Vec<ImportSuggestion>,
|
||||
/// The `DefId` of the module to place the use-statements in.
|
||||
def_id: DefId,
|
||||
/// The `NodeId` of the module to place the use-statements in.
|
||||
node_id: NodeId,
|
||||
/// Whether the diagnostic should say "instead" (as in `consider importing ... instead`).
|
||||
instead: bool,
|
||||
/// Extra free-form suggestion.
|
||||
|
||||
Reference in New Issue
Block a user