Skip to content
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

Type dependent defs wrappers #59216

Merged
merged 1 commit into from
Mar 29, 2019
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
4 changes: 2 additions & 2 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> {
}

fn lookup_and_handle_method(&mut self, id: hir::HirId) {
if let Some(def) = self.tables.type_dependent_defs().get(id) {
self.check_def_id(def.def_id());
if let Some(def_id) = self.tables.type_dependent_def_id(id) {
self.check_def_id(def_id);
} else {
bug!("no type-dependent def for method");
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/expr_use_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> {
}
ty::Error => { }
_ => {
if let Some(def) = self.mc.tables.type_dependent_defs().get(call.hir_id) {
let def_id = def.def_id();
if let Some(def_id) = self.mc.tables.type_dependent_def_id(call.hir_id) {
let call_scope = region::Scope {
id: call.hir_id.local_id,
data: region::ScopeData::Node
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 @@ -97,7 +97,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReachableContext<'a, 'tcx> {
Some(self.tables.qpath_def(qpath, expr.hir_id))
}
hir::ExprKind::MethodCall(..) => {
self.tables.type_dependent_defs().get(expr.hir_id).cloned()
self.tables.type_dependent_def(expr.hir_id)
}
_ => None
};
Expand Down
9 changes: 9 additions & 0 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,15 @@ impl<'tcx> TypeckTables<'tcx> {
}
}

pub fn type_dependent_def(&self, id: HirId) -> Option<Def> {
validate_hir_id_for_typeck_tables(self.local_id_root, id, false);
self.type_dependent_defs.get(&id.local_id).cloned()
}

pub fn type_dependent_def_id(&self, id: HirId) -> Option<DefId> {
self.type_dependent_def(id).map(|def| def.def_id())
}

pub fn type_dependent_defs_mut(&mut self) -> LocalTableInContextMut<'_, Def> {
LocalTableInContextMut {
local_id_root: self.local_id_root,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}
},
hir::ExprKind::MethodCall(..) => {
cx.tables.type_dependent_defs().get(expr.hir_id).cloned()
cx.tables.type_dependent_def(expr.hir_id)
},
_ => None
};
Expand Down
6 changes: 2 additions & 4 deletions src/librustc_mir/hair/cx/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,11 @@ fn method_callee<'a, 'gcx, 'tcx>(
let (def_id, substs, user_ty) = match overloaded_callee {
Some((def_id, substs)) => (def_id, substs, None),
None => {
let type_dependent_defs = cx.tables().type_dependent_defs();
let def = type_dependent_defs
.get(expr.hir_id)
let def = cx.tables().type_dependent_def(expr.hir_id)
.unwrap_or_else(|| {
span_bug!(expr.span, "no type-dependent def for method callee")
});
let user_ty = user_substs_applied_to_def(cx, expr.hir_id, def);
let user_ty = user_substs_applied_to_def(cx, expr.hir_id, &def);
debug!("method_callee: user_ty={:?}", user_ty);
(def.def_id(), cx.tables().node_substs(expr.hir_id), user_ty)
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc_passes/rvalue_promotion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,7 @@ fn check_expr_kind<'a, 'tcx>(
for index in hirvec.iter() {
method_call_result &= v.check_expr(index);
}
if let Some(def) = v.tables.type_dependent_defs().get(e.hir_id) {
let def_id = def.def_id();
if let Some(def_id) = v.tables.type_dependent_def_id(e.hir_id) {
match v.tcx.associated_item(def_id).container {
ty::ImplContainer(_) => method_call_result & v.handle_const_fn_call(def_id),
ty::TraitContainer(_) => NotPromotable,
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_privacy/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1041,8 +1041,8 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
hir::ExprKind::MethodCall(_, span, _) => {
// Method calls have to be checked specially.
self.span = span;
if let Some(def) = self.tables.type_dependent_defs().get(expr.hir_id) {
if self.visit(self.tcx.type_of(def.def_id())) {
if let Some(def_id) = self.tables.type_dependent_def_id(expr.hir_id) {
if self.visit(self.tcx.type_of(def_id)) {
return;
}
} else {
Expand Down Expand Up @@ -1071,7 +1071,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypePrivacyVisitor<'a, 'tcx> {
_ => None,
}
hir::QPath::TypeRelative(..) => {
self.tables.type_dependent_defs().get(id).cloned()
self.tables.type_dependent_def(id)
}
};
if let Some(def) = def {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,8 +565,8 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
}
ast::ExprKind::MethodCall(ref seg, ..) => {
let expr_hir_id = self.tcx.hir().definitions().node_to_hir_id(expr.id);
let method_id = match self.tables.type_dependent_defs().get(expr_hir_id) {
Some(id) => id.def_id(),
let method_id = match self.tables.type_dependent_def_id(expr_hir_id) {
Some(id) => id,
None => {
debug!("Could not resolve method id for {:?}", expr);
return None;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4757,10 +4757,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
(self.to_ty(qself), qself, segment)
}
};
if let Some(cached_def) = self.tables.borrow().type_dependent_defs().get(hir_id) {
if let Some(cached_def) = self.tables.borrow().type_dependent_def(hir_id) {
// Return directly on cache hit. This is useful to avoid doubly reporting
// errors with default match binding modes. See #44614.
return (*cached_def, Some(ty), slice::from_ref(&**item_segment))
return (cached_def, Some(ty), slice::from_ref(&**item_segment))
}
let item_name = item_segment.ident;
let def = match self.resolve_ufcs(span, item_name, ty, hir_id) {
Expand Down