Skip to content

Always check type_dependent_defs #51882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured this wouldn't really be a problem, because if it ever does occur, the stack trace should narrow it down precisely. I'm also hoping that if this case is ever hit, the error message won't be hit anyway, because a proper UI error should have occurred.

}
}
_ => {}
Expand Down