From 45550ef2ff47020ab8af5feb08669c8c4ab879e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Wed, 11 Dec 2019 15:33:45 -0800 Subject: [PATCH] =?UTF-8?q?Reuse=20existing=20HirId=20=E2=86=92=20DefId=20?= =?UTF-8?q?table?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infer/error_reporting/need_type_info.rs | 9 ++++----- src/librustc/ty/context.rs | 19 ------------------ src/librustc_typeck/check/expr.rs | 20 ------------------- 3 files changed, 4 insertions(+), 44 deletions(-) diff --git a/src/librustc/infer/error_reporting/need_type_info.rs b/src/librustc/infer/error_reporting/need_type_info.rs index 487736dee30d..4baab0492a5a 100644 --- a/src/librustc/infer/error_reporting/need_type_info.rs +++ b/src/librustc/infer/error_reporting/need_type_info.rs @@ -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(), diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index fa4ad021072d..f7e422b0403d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -338,8 +338,6 @@ pub struct TypeckTables<'tcx> { /// typeck::check::fn_ctxt for details. node_types: ItemLocalMap>, - node_method_def_id: ItemLocalMap, - /// 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> 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> 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); diff --git a/src/librustc_typeck/check/expr.rs b/src/librustc_typeck/check/expr.rs index 999038e7ea79..fc7d19766373 100644 --- a/src/librustc_typeck/check/expr.rs +++ b/src/librustc_typeck/check/expr.rs @@ -874,26 +874,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // We could add a "consider `foo::`" 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) }