Skip to content

Commit

Permalink
Always check type_dependent_defs
Browse files Browse the repository at this point in the history
  • Loading branch information
varkor committed Jun 28, 2018
1 parent 4fe88c0 commit 4071adf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -96,7 +96,11 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn lookup_and_handle_method(&mut self, id: hir::HirId) {
self.check_def_id(self.tables.type_dependent_defs()[id].def_id());
if let Some(def) = self.tables.type_dependent_defs().get(id) {
self.check_def_id(def.def_id());
} else {
bug!("no type-dependent def for method");
}
}

fn handle_field_access(&mut self, lhs: &hir::Expr, node_id: ast::NodeId) {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Expand Up @@ -120,7 +120,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
Some(self.tables.qpath_def(qpath, expr.hir_id))
}
hir::ExprMethodCall(..) => {
Some(self.tables.type_dependent_defs()[expr.hir_id])
self.tables.type_dependent_defs().get(expr.hir_id).cloned()
}
_ => None
};
Expand Down
13 changes: 9 additions & 4 deletions src/librustc_lint/builtin.rs
Expand Up @@ -1007,10 +1007,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnconditionalRecursion {
// Check for method calls and overloaded operators.
if cx.tables.is_method_call(expr) {
let hir_id = cx.tcx.hir.definitions().node_to_hir_id(id);
let def_id = cx.tables.type_dependent_defs()[hir_id].def_id();
let substs = cx.tables.node_substs(hir_id);
if method_call_refers_to_method(cx, method, def_id, substs, id) {
return true;
if let Some(def) = cx.tables.type_dependent_defs().get(hir_id) {
let def_id = def.def_id();
let substs = cx.tables.node_substs(hir_id);
if method_call_refers_to_method(cx, method, def_id, substs, id) {
return true;
}
} else {
cx.tcx.sess.delay_span_bug(expr.span,
"no type-dependent def for method call");
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/librustc_mir/hair/cx/expr.rs
Expand Up @@ -692,8 +692,11 @@ fn method_callee<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>,
-> Expr<'tcx> {
let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id);
let (def_id, substs) = custom_callee.unwrap_or_else(|| {
(cx.tables().type_dependent_defs()[expr.hir_id].def_id(),
cx.tables().node_substs(expr.hir_id))
if let Some(def) = cx.tables().type_dependent_defs().get(expr.hir_id) {
(def.def_id(), cx.tables().node_substs(expr.hir_id))
} else {
span_bug!(expr.span, "no type-dependent def for method callee")
}
});
let ty = cx.tcx().mk_fn_def(def_id, substs);
Expr {
Expand Down
11 changes: 8 additions & 3 deletions src/librustc_privacy/lib.rs
Expand Up @@ -795,10 +795,15 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
}
hir::ExprMethodCall(_, span, _) => {
// Method calls have to be checked specially.
let def_id = self.tables.type_dependent_defs()[expr.hir_id].def_id();
self.span = span;
if self.tcx.type_of(def_id).visit_with(self) {
return;
if let Some(def) = self.tables.type_dependent_defs().get(expr.hir_id) {
let def_id = def.def_id();
if self.tcx.type_of(def_id).visit_with(self) {
return;
}
} else {
self.tcx.sess.delay_span_bug(expr.span,
"no type-dependent def for method call");
}
}
_ => {}
Expand Down

0 comments on commit 4071adf

Please sign in to comment.