Skip to content

Commit 45550ef

Browse files
committed
Reuse existing HirId → DefId table
1 parent 94ab9ec commit 45550ef

File tree

3 files changed

+4
-44
lines changed

3 files changed

+4
-44
lines changed

src/librustc/infer/error_reporting/need_type_info.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::hir::def::Namespace;
1+
use crate::hir::def::{DefKind, Namespace};
22
use crate::hir::{self, Body, FunctionRetTy, Expr, ExprKind, HirId, Local, Pat};
33
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
44
use crate::infer::InferCtxt;
@@ -447,9 +447,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
447447
&segment.args,
448448
) {
449449
let borrow = tables.borrow();
450-
let method_defs = borrow.node_method_def_id();
451-
if let Some(did) = method_defs.get(e.hir_id) {
452-
let generics = self.tcx.generics_of(*did);
450+
if let Some((DefKind::Method, did)) = borrow.type_dependent_def(e.hir_id) {
451+
let generics = self.tcx.generics_of(did);
453452
if !generics.params.is_empty() {
454453
err.span_suggestion(
455454
segment.ident.span,
@@ -468,7 +467,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
468467
Applicability::HasPlaceholders,
469468
);
470469
} else {
471-
let sig = self.tcx.fn_sig(*did);
470+
let sig = self.tcx.fn_sig(did);
472471
err.span_label(e.span, &format!(
473472
"this method call resolves to `{:?}`",
474473
sig.output().skip_binder(),

src/librustc/ty/context.rs

-19
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,6 @@ pub struct TypeckTables<'tcx> {
338338
/// typeck::check::fn_ctxt for details.
339339
node_types: ItemLocalMap<Ty<'tcx>>,
340340

341-
node_method_def_id: ItemLocalMap<DefId>,
342-
343341
/// Stores the type parameters which were substituted to obtain the type
344342
/// of this node. This only applies to nodes that refer to entities
345343
/// parameterized by type parameters, such as generic fns, types, or
@@ -444,7 +442,6 @@ impl<'tcx> TypeckTables<'tcx> {
444442
user_provided_types: Default::default(),
445443
user_provided_sigs: Default::default(),
446444
node_types: Default::default(),
447-
node_method_def_id: Default::default(),
448445
node_substs: Default::default(),
449446
adjustments: Default::default(),
450447
pat_binding_modes: Default::default(),
@@ -545,20 +542,6 @@ impl<'tcx> TypeckTables<'tcx> {
545542
}
546543
}
547544

548-
pub fn node_method_def_id(&self) -> LocalTableInContext<'_, DefId> {
549-
LocalTableInContext {
550-
local_id_root: self.local_id_root,
551-
data: &self.node_method_def_id
552-
}
553-
}
554-
555-
pub fn node_method_def_id_mut(&mut self) -> LocalTableInContextMut<'_, DefId> {
556-
LocalTableInContextMut {
557-
local_id_root: self.local_id_root,
558-
data: &mut self.node_method_def_id
559-
}
560-
}
561-
562545
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
563546
self.node_type_opt(id).unwrap_or_else(||
564547
bug!("node_type: no type for node `{}`",
@@ -765,7 +748,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
765748
ref user_provided_types,
766749
ref user_provided_sigs,
767750
ref node_types,
768-
ref node_method_def_id,
769751
ref node_substs,
770752
ref adjustments,
771753
ref pat_binding_modes,
@@ -792,7 +774,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
792774
user_provided_types.hash_stable(hcx, hasher);
793775
user_provided_sigs.hash_stable(hcx, hasher);
794776
node_types.hash_stable(hcx, hasher);
795-
node_method_def_id.hash_stable(hcx, hasher);
796777
node_substs.hash_stable(hcx, hasher);
797778
adjustments.hash_stable(hcx, hasher);
798779
pat_binding_modes.hash_stable(hcx, hasher);

src/librustc_typeck/check/expr.rs

-20
Original file line numberDiff line numberDiff line change
@@ -874,26 +874,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
874874
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
875875
// trigger this codepath causing `structuraly_resolved_type` to emit an error.
876876

877-
// We could do this only when type params are present in the method to reducte
878-
// memory usage, but doing it unconditionally lets us also point at the method
879-
// expression and state the resolved return value:
880-
// ```
881-
// error[E0282]: type annotations needed
882-
// --> $DIR/issue-65611.rs:59:20
883-
// |
884-
// LL | let x = buffer.last().unwrap().0.clone();
885-
// | -------^^^^--
886-
// | | |
887-
// | | cannot infer type for `T`
888-
// | this method call resolves to `std::option::Option<&T>`
889-
// |
890-
// = note: type must be known at this point
891-
// ```
892-
self.tables.borrow_mut().node_method_def_id_mut().insert(
893-
expr.hir_id,
894-
method.def_id,
895-
);
896-
897877
self.write_method_call(expr.hir_id, method);
898878
Ok(method)
899879
}

0 commit comments

Comments
 (0)