-> (Option<&'a ty::TypeckTables<'tcx>>,
Option<ty::TypeckTables<'tcx>>,
Option<ty::ParameterEnvironment<'tcx>>) {
- let item_id = tcx.hir.body_owner(self);
- (Some(tcx.typeck_tables_of(tcx.hir.local_def_id(item_id))),
+ let def_id = tcx.hir.body_owner_def_id(self);
+ (Some(tcx.typeck_tables_of(def_id)),
None,
- Some(ty::ParameterEnvironment::for_item(tcx, item_id)))
+ Some(tcx.parameter_environment(def_id)))
}
}
use self::VarKind::*;
use hir::def::*;
-use ty::{self, TyCtxt, ParameterEnvironment};
+use ty::{self, TyCtxt};
use traits::{self, Reveal};
use ty::subst::Subst;
use lint;
// check for various error conditions
lsets.visit_body(body);
- lsets.check_ret(id, sp, entry_ln, body);
+ lsets.check_ret(id, sp, entry_ln);
lsets.warn_about_unused_args(body, entry_ln);
}
fn check_ret(&self,
id: NodeId,
sp: Span,
- entry_ln: LiveNode,
- body: &hir::Body)
+ entry_ln: LiveNode)
{
- let fn_ty = self.ir.tcx.type_of(self.ir.tcx.hir.local_def_id(id));
+ let def_id = self.ir.tcx.hir.local_def_id(id);
+ let fn_ty = self.ir.tcx.type_of(def_id);
let fn_sig = match fn_ty.sty {
ty::TyClosure(closure_def_id, substs) => {
self.ir.tcx.closure_type(closure_def_id)
// and must outlive the *call-site* of the function.
let fn_ret =
self.ir.tcx.liberate_late_bound_regions(
- Some(self.ir.tcx.call_site_extent(id, body.value.id)),
+ Some(self.ir.tcx.call_site_extent(id)),
&fn_ret);
if !fn_ret.is_never() && self.live_on_entry(entry_ln, self.s.no_ret_var).is_some() {
- let param_env = ParameterEnvironment::for_item(self.ir.tcx, id);
+ let param_env = self.ir.tcx.parameter_environment(def_id);
let t_ret_subst = fn_ret.subst(self.ir.tcx, ¶m_env.free_substs);
let is_nil = self.ir.tcx.infer_ctxt(param_env, Reveal::All).enter(|infcx| {
let cause = traits::ObligationCause::dummy();
}
// create a parameter environment corresponding to a (skolemized) instantiation of impl1
- let penv = tcx.construct_parameter_environment(DUMMY_SP,
- impl1_def_id,
- None);
+ let penv = tcx.parameter_environment(impl1_def_id);
let impl1_trait_ref = tcx.impl_trait_ref(impl1_def_id)
.unwrap()
.subst(tcx, &penv.free_substs);
self.intern_code_extent(CodeExtentData::DestructionScope(n))
}
- pub fn call_site_extent(self, fn_id: ast::NodeId, body_id: ast::NodeId) -> CodeExtent<'gcx> {
- assert!(fn_id != body_id);
- self.intern_code_extent(CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body_id })
+ pub fn call_site_extent(self, fn_id: ast::NodeId) -> CodeExtent<'gcx> {
+ self.intern_code_extent(CodeExtentData::CallSiteScope {
+ fn_id,
+ body_id: self.hir.body_owned_by(fn_id).node_id
+ })
+ }
+
+ pub fn parameter_extent(self, fn_id: ast::NodeId) -> CodeExtent<'gcx> {
+ self.intern_code_extent(CodeExtentData::ParameterScope {
+ fn_id,
+ body_id: self.hir.body_owned_by(fn_id).node_id
+ })
}
pub fn intern_code_extent(self, data: CodeExtentData) -> CodeExtent<'gcx> {
let kind = if def.is_enum() || def.variants[0].fields.len() == 0{
StructKind::AlwaysSizedUnivariant
} else {
- let param_env = tcx.construct_parameter_environment(DUMMY_SP,
- def.did, None);
+ let param_env = tcx.parameter_environment(def.did);
let fields = &def.variants[0].fields;
let last_field = &fields[fields.len()-1];
let always_sized = last_field.ty(tcx, param_env.free_substs)
is_freeze_cache: RefCell::new(FxHashMap()),
}
}
-
- /// Construct a parameter environment given an item, impl item, or trait item
- pub fn for_item(tcx: TyCtxt<'a, 'tcx, 'tcx>, id: NodeId)
- -> ParameterEnvironment<'tcx> {
- match tcx.hir.find(id) {
- Some(hir_map::NodeImplItem(ref impl_item)) => {
- match impl_item.node {
- hir::ImplItemKind::Type(_) => {
- // associated types don't have their own entry (for some reason),
- // so for now just grab environment for the impl
- let impl_id = tcx.hir.get_parent(id);
- let impl_def_id = tcx.hir.local_def_id(impl_id);
- tcx.construct_parameter_environment(impl_item.span,
- impl_def_id,
- Some(tcx.item_extent(id)))
- }
- hir::ImplItemKind::Const(_, body) |
- hir::ImplItemKind::Method(_, body) => {
- tcx.construct_parameter_environment(
- impl_item.span,
- tcx.hir.local_def_id(id),
- Some(tcx.call_site_extent(id, body.node_id)))
- }
- }
- }
- Some(hir_map::NodeTraitItem(trait_item)) => {
- match trait_item.node {
- hir::TraitItemKind::Type(..) |
- hir::TraitItemKind::Const(_, None) |
- hir::TraitItemKind::Method(_, hir::TraitMethod::Required(_))=> {
- tcx.construct_parameter_environment(trait_item.span,
- tcx.hir.local_def_id(id),
- Some(tcx.item_extent(id)))
- }
- hir::TraitItemKind::Const(_, Some(body)) |
- hir::TraitItemKind::Method(_, hir::TraitMethod::Provided(body)) => {
- tcx.construct_parameter_environment(
- trait_item.span,
- tcx.hir.local_def_id(id),
- Some(tcx.call_site_extent(id, body.node_id)))
- }
- }
- }
- Some(hir_map::NodeItem(item)) => {
- match item.node {
- hir::ItemConst(_, body) |
- hir::ItemStatic(.., body) |
- hir::ItemFn(.., body) => {
- tcx.construct_parameter_environment(
- item.span,
- tcx.hir.local_def_id(id),
- Some(tcx.call_site_extent(id, body.node_id)))
- }
- hir::ItemEnum(..) |
- hir::ItemStruct(..) |
- hir::ItemUnion(..) |
- hir::ItemTy(..) |
- hir::ItemImpl(..) |
- hir::ItemTrait(..) => {
- let def_id = tcx.hir.local_def_id(id);
- tcx.construct_parameter_environment(item.span,
- def_id,
- Some(tcx.item_extent(id)))
- }
- _ => {
- span_bug!(item.span,
- "ParameterEnvironment::for_item():
- can't create a parameter \
- environment for this kind of item")
- }
- }
- }
- Some(hir_map::NodeExpr(expr)) => {
- // This is a convenience to allow closures to work.
- if let hir::ExprClosure(.., body, _) = expr.node {
- let def_id = tcx.hir.local_def_id(id);
- let base_def_id = tcx.closure_base_def_id(def_id);
- tcx.construct_parameter_environment(
- expr.span,
- base_def_id,
- Some(tcx.call_site_extent(id, body.node_id)))
- } else {
- tcx.empty_parameter_environment()
- }
- }
- Some(hir_map::NodeForeignItem(item)) => {
- let def_id = tcx.hir.local_def_id(id);
- tcx.construct_parameter_environment(item.span,
- def_id,
- None)
- }
- Some(hir_map::NodeStructCtor(..)) |
- Some(hir_map::NodeVariant(..)) => {
- let def_id = tcx.hir.local_def_id(id);
- tcx.construct_parameter_environment(tcx.hir.span(id),
- def_id,
- None)
- }
- it => {
- bug!("ParameterEnvironment::from_item(): \
- `{}` = {:?} is unsupported",
- tcx.hir.node_to_string(id), it)
- }
- }
- }
}
#[derive(Copy, Clone, Debug)]
self.global_tcx().mk_param_from_def(def)
});
- debug!("construct_parameter_environment: {:?}", substs);
+ debug!("parameter_environment: {:?}", substs);
substs
}
/// See `ParameterEnvironment` struct def'n for details.
- /// If you were using `free_id: NodeId`, you might try `self.region_maps().item_extent(free_id)`
- /// for the `free_id_outlive` parameter. (But note that this is not always quite right.)
- pub fn construct_parameter_environment(self,
- span: Span,
- def_id: DefId,
- free_id_outlive: Option<CodeExtent<'gcx>>)
- -> ParameterEnvironment<'gcx>
- {
+ pub fn parameter_environment(self, def_id: DefId) -> ParameterEnvironment<'gcx> {
//
// Construct the free substs.
//
+ let free_id_outlive = self.hir.as_local_node_id(def_id).map(|id| {
+ if self.hir.maybe_body_owned_by(id).is_some() {
+ self.call_site_extent(id)
+ } else {
+ self.item_extent(id)
+ }
+ });
let free_substs = self.construct_free_substs(def_id, free_id_outlive);
//
let body_id = free_id_outlive.map(|f| f.node_id())
.unwrap_or(DUMMY_NODE_ID);
- let cause = traits::ObligationCause::misc(span, body_id);
+ let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id);
traits::normalize_param_env_or_error(tcx, def_id, unnormalized_env, cause)
}
_ => return
}
let id = src.item_id();
- let param_env = ty::ParameterEnvironment::for_item(tcx, id);
+ let param_env = tcx.parameter_environment(tcx.hir.local_def_id(id));
let move_data = MoveData::gather_moves(mir, tcx, ¶m_env);
let elaborate_patch = {
let mir = &*mir;
// steals it, but it forces the `borrowck` query.
let mir = &tcx.mir_validated(def_id).borrow();
- let param_env = ty::ParameterEnvironment::for_item(tcx, id);
+ let param_env = tcx.parameter_environment(def_id);
let move_data = MoveData::gather_moves(mir, tcx, ¶m_env);
let mdpe = MoveDataParamEnv { move_data: move_data, param_env: param_env };
let dead_unwinds = IdxSetBuf::new_empty(mir.basic_blocks().len());
b: hir::BodyId, s: Span, id: ast::NodeId) {
intravisit::walk_fn(self, fk, fd, b, s, id);
- let region_context = self.tcx.hir.local_def_id(id);
- let region_maps = self.tcx.region_maps(region_context);
+ let def_id = self.tcx.hir.local_def_id(id);
MatchVisitor {
tcx: self.tcx,
tables: self.tcx.body_tables(b),
- region_maps: ®ion_maps,
- param_env: &ty::ParameterEnvironment::for_item(self.tcx, id)
+ region_maps: &self.tcx.region_maps(def_id),
+ param_env: &self.tcx.parameter_environment(def_id)
}.visit_body(self.tcx.hir.body(b));
}
}
traits::Obligation::new(traits::ObligationCause::misc(span, expr_id),
trait_ref.to_poly_trait_predicate());
- // unwrap() is ok here b/c `method` is the method
- // defined in this crate whose body we are
- // checking, so it's always local
- let node_id = tcx.hir.as_local_node_id(method.def_id).unwrap();
-
- let param_env = ty::ParameterEnvironment::for_item(tcx, node_id);
+ let param_env = tcx.parameter_environment(method.def_id);
tcx.infer_ctxt(param_env, Reveal::UserFacing).enter(|infcx| {
let mut selcx = traits::SelectionContext::new(&infcx);
match selcx.select(&obligation) {
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnionsWithDropFields {
fn check_item(&mut self, ctx: &LateContext, item: &hir::Item) {
if let hir::ItemUnion(ref vdata, _) = item.node {
- let param_env = &ty::ParameterEnvironment::for_item(ctx.tcx, item.id);
+ let param_env = &ctx.tcx.parameter_environment(ctx.tcx.hir.local_def_id(item.id));
for field in vdata.fields() {
let field_ty = ctx.tcx.type_of(ctx.tcx.hir.local_def_id(field.id));
if field_ty.needs_drop(ctx.tcx, param_env) {
use hair::Pattern;
use rustc::hir;
use rustc::hir::def_id::DefId;
-use rustc::middle::region::{CodeExtent, CodeExtentData};
+use rustc::middle::region::CodeExtent;
use rustc::mir::*;
use rustc::mir::transform::MirSource;
use rustc::mir::visit::MutVisitor;
{
let span = tcx.hir.span(ctor_id);
if let hir::VariantData::Tuple(ref fields, ctor_id) = *v {
- let pe = ty::ParameterEnvironment::for_item(tcx, ctor_id);
+ let pe = tcx.parameter_environment(tcx.hir.local_def_id(ctor_id));
tcx.infer_ctxt(pe, Reveal::UserFacing).enter(|infcx| {
let (mut mir, src) =
shim::build_adt_ctor(&infcx, ctor_id, fields, span);
let span = tcx.hir.span(fn_id);
let mut builder = Builder::new(hir.clone(), span, arguments.len(), return_ty);
- let call_site_extent =
- tcx.intern_code_extent(
- CodeExtentData::CallSiteScope { fn_id: fn_id, body_id: body.value.id });
- let arg_extent =
- tcx.intern_code_extent(
- CodeExtentData::ParameterScope { fn_id: fn_id, body_id: body.value.id });
+ let call_site_extent = tcx.call_site_extent(fn_id);
+ let arg_extent = tcx.parameter_extent(fn_id);
let mut block = START_BLOCK;
unpack!(block = builder.in_scope(call_site_extent, block, |builder| {
unpack!(block = builder.in_scope(arg_extent, block, |builder| {
{
debug!("make_shim({:?})", instance);
let did = instance.def_id();
- let span = tcx.def_span(did);
- let param_env = tcx.construct_parameter_environment(span, did, None);
+ let param_env = tcx.parameter_environment(did);
let mut result = match instance {
ty::InstanceDef::Item(..) =>
// FIXME: Give a bonus to functions with only a single caller
- let param_env = ty::ParameterEnvironment::for_item(tcx, self.source.item_id());
+ let def_id = tcx.hir.local_def_id(self.source.item_id());
+ let param_env = tcx.parameter_environment(def_id);
let mut first_block = true;
let mut cost = 0;
return Qualif::NOT_CONST.bits();
}
- let node_id = tcx.hir.as_local_node_id(def_id).unwrap();
- let param_env = ty::ParameterEnvironment::for_item(tcx, node_id);
+ let param_env = tcx.parameter_environment(def_id);
let mut qualifier = Qualifier::new(tcx, param_env, def_id, mir, Mode::Const);
qualifier.qualify_const().bits()
MirSource::Const(_) |
MirSource::Promoted(..) => return
};
- let param_env = ty::ParameterEnvironment::for_item(tcx, id);
+ let param_env = tcx.parameter_environment(def_id);
if mode == Mode::Fn || mode == Mode::ConstFn {
// This is ugly because Qualifier holds onto mir,
// broken MIR, so try not to report duplicate errors.
return;
}
- let param_env = ty::ParameterEnvironment::for_item(tcx, item_id);
+ let param_env = tcx.parameter_environment(def_id);
tcx.infer_ctxt(param_env, Reveal::UserFacing).enter(|infcx| {
let mut checker = TypeChecker::new(&infcx, item_id);
{
debug!("check_closure: expr.id={:?} closure_type={:?}", expr.id, closure_type);
- let extent = self.tcx.call_site_extent(expr.id, body.value.id);
+ let extent = self.tcx.call_site_extent(expr.id);
let fn_sig = self.tcx.liberate_late_bound_regions(Some(extent), &sig);
let fn_sig = self.inh.normalize_associated_types_in(body.value.span,
body.value.id, &fn_sig);
// Create a parameter environment that represents the implementation's
// method.
- let impl_param_env = ty::ParameterEnvironment::for_item(tcx, impl_m_node_id);
+ let impl_param_env = tcx.parameter_environment(impl_m.def_id);
// Create mapping from impl to skolemized.
let impl_to_skol_substs = &impl_param_env.free_substs;
// Create a parameter environment that represents the implementation's
// method.
let impl_c_node_id = tcx.hir.as_local_node_id(impl_c.def_id).unwrap();
- let impl_param_env = ty::ParameterEnvironment::for_item(tcx, impl_c_node_id);
+ let impl_param_env = tcx.parameter_environment(impl_c.def_id);
// Create mapping from impl to skolemized.
let impl_to_skol_substs = &impl_param_env.free_substs;
-> Result<(), ErrorReported>
{
let drop_impl_node_id = tcx.hir.as_local_node_id(drop_impl_did).unwrap();
- let self_type_node_id = tcx.hir.as_local_node_id(self_type_did).unwrap();
// check that the impl type can be made to match the trait type.
- let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id);
+ let impl_param_env = tcx.parameter_environment(self_type_did);
tcx.infer_ctxt(impl_param_env, Reveal::UserFacing).enter(|ref infcx| {
let tcx = infcx.tcx;
let mut fulfillment_cx = traits::FulfillmentContext::new();
fulfillment_cx.register_predicate_obligations(infcx, obligations);
}
Err(_) => {
- let item_span = tcx.hir.span(self_type_node_id);
+ let item_span = tcx.def_span(self_type_did);
struct_span_err!(tcx.sess, drop_impl_span, E0366,
"Implementations of Drop cannot be specialized")
.span_note(item_span,
use rustc::infer::type_variable::{TypeVariableOrigin};
use rustc::ty::subst::{Kind, Subst, Substs};
use rustc::traits::{self, FulfillmentContext, ObligationCause, ObligationCauseCode, Reveal};
-use rustc::ty::{ParamTy, ParameterEnvironment};
-use rustc::ty::{LvaluePreference, NoPreference, PreferMutLvalue};
+use rustc::ty::{ParamTy, LvaluePreference, NoPreference, PreferMutLvalue};
use rustc::ty::{self, Ty, TyCtxt, Visibility};
use rustc::ty::{MethodCall, MethodCallee};
use rustc::ty::adjustment::{Adjust, Adjustment, AutoBorrow};
}
impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
- pub fn build(tcx: TyCtxt<'a, 'gcx, 'gcx>, id: ast::NodeId)
+ pub fn build(tcx: TyCtxt<'a, 'gcx, 'gcx>, def_id: DefId)
-> InheritedBuilder<'a, 'gcx, 'tcx> {
let tables = ty::TypeckTables::empty();
- let param_env = ParameterEnvironment::for_item(tcx, id);
+ let param_env = tcx.parameter_environment(def_id);
InheritedBuilder {
infcx: tcx.infer_ctxt((tables, param_env), Reveal::UserFacing)
}
});
let body = tcx.hir.body(body_id);
- Inherited::build(tcx, id).enter(|inh| {
+ Inherited::build(tcx, def_id).enter(|inh| {
let fcx = if let Some(decl) = fn_decl {
let fn_sig = tcx.type_of(def_id).fn_sig();
check_abi(tcx, span, fn_sig.abi());
// Compute the fty from point of view of inside fn.
- let fn_scope = inh.tcx.call_site_extent(id, body_id.node_id);
+ let fn_scope = inh.tcx.call_site_extent(id);
let fn_sig =
fn_sig.subst(inh.tcx, &inh.parameter_environment.free_substs);
let fn_sig =
use middle::free_region::FreeRegionMap;
use middle::mem_categorization as mc;
use middle::mem_categorization::Categorization;
-use middle::region::{self, CodeExtent, RegionMaps};
+use middle::region::{CodeExtent, RegionMaps};
use rustc::hir::def_id::DefId;
use rustc::ty::subst::Substs;
use rustc::traits;
let body_id = body.id();
- let call_site = self.tcx.intern_code_extent(
- region::CodeExtentData::CallSiteScope { fn_id: id, body_id: body_id.node_id });
+ let call_site = self.tcx.call_site_extent(id);
let old_call_site_scope = self.set_call_site_scope(Some(call_site));
let fn_sig = {
error_192(tcx, item.span);
}
}
- hir::ItemFn(.., body_id) => {
- self.check_item_fn(item, body_id);
+ hir::ItemFn(..) => {
+ self.check_item_fn(item);
}
hir::ItemStatic(..) => {
self.check_item_type(item);
fn for_id<'tcx>(&self, id: ast::NodeId, span: Span)
-> CheckWfFcxBuilder<'a, 'gcx, 'tcx> {
CheckWfFcxBuilder {
- inherited: Inherited::build(self.tcx, id),
+ inherited: Inherited::build(self.tcx, self.tcx.hir.local_def_id(id)),
code: self.code.clone(),
id: id,
span: span
});
}
- fn check_item_fn(&mut self,
- item: &hir::Item,
- body_id: hir::BodyId)
- {
+ fn check_item_fn(&mut self, item: &hir::Item) {
self.for_item(item).with_fcx(|fcx, this| {
let free_substs = &fcx.parameter_environment.free_substs;
let def_id = fcx.tcx.hir.local_def_id(item.id);
let predicates = fcx.instantiate_bounds(item.span, def_id, free_substs);
let mut implied_bounds = vec![];
- let free_id_outlive = fcx.tcx.call_site_extent(item.id, body_id.node_id);
+ let free_id_outlive = fcx.tcx.call_site_extent(item.id);
this.check_fn_or_method(fcx, item.span, sig, &predicates,
Some(free_id_outlive), &mut implied_bounds);
implied_bounds
use rustc::traits::{self, ObligationCause, Reveal};
use rustc::ty::{self, Ty, TyCtxt};
-use rustc::ty::ParameterEnvironment;
use rustc::ty::TypeFoldable;
use rustc::ty::adjustment::CoerceUnsizedInfo;
use rustc::ty::subst::Subst;
self_type);
let span = tcx.hir.span(impl_node_id);
- let param_env = ParameterEnvironment::for_item(tcx, impl_node_id);
+ let param_env = tcx.parameter_environment(impl_did);
let self_type = self_type.subst(tcx, ¶m_env.free_substs);
assert!(!self_type.has_escaping_regions());
target);
let span = tcx.hir.span(impl_node_id);
- let param_env = ParameterEnvironment::for_item(tcx, impl_node_id);
+ let param_env = tcx.parameter_environment(impl_did);
let source = source.subst(tcx, ¶m_env.free_substs);
let target = target.subst(tcx, ¶m_env.free_substs);
assert!(!source.has_escaping_regions());