Refactor inlined items some more

They don't implement FnLikeNode anymore, instead are handled differently
further up in the call tree. Also, keep less information (just def ids
for the args).
This commit is contained in:
Florian Diebold 2016-11-24 18:25:59 +01:00 committed by Florian Diebold
parent dd1491cfbe
commit d0ae2c8142
6 changed files with 91 additions and 102 deletions

View file

@ -27,7 +27,7 @@
use rustc::dep_graph::DepNode;
use rustc::ty::cast::CastKind;
use rustc_const_eval::{ConstEvalErr, lookup_const_fn_by_id, compare_lit_exprs};
use rustc_const_eval::{eval_const_expr_partial, lookup_const_by_id};
use rustc_const_eval::{ConstFnNode, eval_const_expr_partial, lookup_const_by_id};
use rustc_const_eval::ErrKind::{IndexOpFeatureGated, UnimplementedConstVal, MiscCatchAll, Math};
use rustc_const_eval::ErrKind::{ErroneousReferencedConstant, MiscBinaryOp, NonConstPath};
use rustc_const_eval::ErrKind::UnresolvedPath;
@ -180,30 +180,39 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> {
/// Returns true if the call is to a const fn or method.
fn handle_const_fn_call(&mut self, _expr: &hir::Expr, def_id: DefId, ret_ty: Ty<'gcx>) -> bool {
if let Some(fn_like) = lookup_const_fn_by_id(self.tcx, def_id) {
let node_id = fn_like.body().node_id();
let qualif = match self.tcx.const_qualif_map.borrow_mut().entry(node_id) {
Entry::Occupied(entry) => Some(*entry.get()),
_ => None
};
match lookup_const_fn_by_id(self.tcx, def_id) {
Some(ConstFnNode::Local(fn_like)) => {
let qualif = self.fn_like(fn_like.kind(),
fn_like.decl(),
fn_like.body(),
fn_like.span(),
fn_like.id());
let qualif = qualif.unwrap_or_else(|| {
self.fn_like(fn_like.kind(),
fn_like.decl(),
fn_like.body(),
fn_like.span(),
fn_like.id())
});
self.add_qualif(qualif);
self.add_qualif(qualif);
if ret_ty.type_contents(self.tcx).interior_unsafe() {
self.add_qualif(ConstQualif::MUTABLE_MEM);
}
if ret_ty.type_contents(self.tcx).interior_unsafe() {
self.add_qualif(ConstQualif::MUTABLE_MEM);
}
true
},
Some(ConstFnNode::Inlined(ii)) => {
let node_id = ii.body.id;
true
} else {
false
let qualif = match self.tcx.const_qualif_map.borrow_mut().entry(node_id) {
Entry::Occupied(entry) => *entry.get(),
_ => bug!("const qualif entry missing for inlined item")
};
self.add_qualif(qualif);
if ret_ty.type_contents(self.tcx).interior_unsafe() {
self.add_qualif(ConstQualif::MUTABLE_MEM);
}
true
},
None => false
}
}