Reuse existing HirId → DefId table

This commit is contained in:
Esteban Küber 2019-12-11 15:33:45 -08:00
parent 94ab9ec36b
commit 45550ef2ff
3 changed files with 4 additions and 44 deletions

View File

@ -1,4 +1,4 @@
use crate::hir::def::Namespace;
use crate::hir::def::{DefKind, Namespace};
use crate::hir::{self, Body, FunctionRetTy, Expr, ExprKind, HirId, Local, Pat};
use crate::hir::intravisit::{self, Visitor, NestedVisitorMap};
use crate::infer::InferCtxt;
@ -447,9 +447,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&segment.args,
) {
let borrow = tables.borrow();
let method_defs = borrow.node_method_def_id();
if let Some(did) = method_defs.get(e.hir_id) {
let generics = self.tcx.generics_of(*did);
if let Some((DefKind::Method, did)) = borrow.type_dependent_def(e.hir_id) {
let generics = self.tcx.generics_of(did);
if !generics.params.is_empty() {
err.span_suggestion(
segment.ident.span,
@ -468,7 +467,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
Applicability::HasPlaceholders,
);
} else {
let sig = self.tcx.fn_sig(*did);
let sig = self.tcx.fn_sig(did);
err.span_label(e.span, &format!(
"this method call resolves to `{:?}`",
sig.output().skip_binder(),

View File

@ -338,8 +338,6 @@ pub struct TypeckTables<'tcx> {
/// typeck::check::fn_ctxt for details.
node_types: ItemLocalMap<Ty<'tcx>>,
node_method_def_id: ItemLocalMap<DefId>,
/// Stores the type parameters which were substituted to obtain the type
/// of this node. This only applies to nodes that refer to entities
/// parameterized by type parameters, such as generic fns, types, or
@ -444,7 +442,6 @@ impl<'tcx> TypeckTables<'tcx> {
user_provided_types: Default::default(),
user_provided_sigs: Default::default(),
node_types: Default::default(),
node_method_def_id: Default::default(),
node_substs: Default::default(),
adjustments: Default::default(),
pat_binding_modes: Default::default(),
@ -545,20 +542,6 @@ impl<'tcx> TypeckTables<'tcx> {
}
}
pub fn node_method_def_id(&self) -> LocalTableInContext<'_, DefId> {
LocalTableInContext {
local_id_root: self.local_id_root,
data: &self.node_method_def_id
}
}
pub fn node_method_def_id_mut(&mut self) -> LocalTableInContextMut<'_, DefId> {
LocalTableInContextMut {
local_id_root: self.local_id_root,
data: &mut self.node_method_def_id
}
}
pub fn node_type(&self, id: hir::HirId) -> Ty<'tcx> {
self.node_type_opt(id).unwrap_or_else(||
bug!("node_type: no type for node `{}`",
@ -765,7 +748,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
ref user_provided_types,
ref user_provided_sigs,
ref node_types,
ref node_method_def_id,
ref node_substs,
ref adjustments,
ref pat_binding_modes,
@ -792,7 +774,6 @@ impl<'a, 'tcx> HashStable<StableHashingContext<'a>> for TypeckTables<'tcx> {
user_provided_types.hash_stable(hcx, hasher);
user_provided_sigs.hash_stable(hcx, hasher);
node_types.hash_stable(hcx, hasher);
node_method_def_id.hash_stable(hcx, hasher);
node_substs.hash_stable(hcx, hasher);
adjustments.hash_stable(hcx, hasher);
pat_binding_modes.hash_stable(hcx, hasher);

View File

@ -874,26 +874,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// We could add a "consider `foo::<params>`" suggestion here, but I wasn't able to
// trigger this codepath causing `structuraly_resolved_type` to emit an error.
// We could do this only when type params are present in the method to reducte
// memory usage, but doing it unconditionally lets us also point at the method
// expression and state the resolved return value:
// ```
// error[E0282]: type annotations needed
// --> $DIR/issue-65611.rs:59:20
// |
// LL | let x = buffer.last().unwrap().0.clone();
// | -------^^^^--
// | | |
// | | cannot infer type for `T`
// | this method call resolves to `std::option::Option<&T>`
// |
// = note: type must be known at this point
// ```
self.tables.borrow_mut().node_method_def_id_mut().insert(
expr.hir_id,
method.def_id,
);
self.write_method_call(expr.hir_id, method);
Ok(method)
}