rustc_typeck: Use Deref for FnCtxt, Inherited and InferCtxt fields and methods.

This commit is contained in:
Eduard Burtescu 2016-03-24 18:49:04 +02:00
parent 76affa5d6f
commit 0053b442f8
17 changed files with 804 additions and 855 deletions

View file

@ -58,7 +58,7 @@ fn bad_struct_kind_err(sess: &Session, pat: &hir::Pat, path: &hir::Path, lint: b
impl<'a, 'tcx> PatCtxt<'a, 'tcx, 'tcx> {
pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
let tcx = self.tcx();
let tcx = self.tcx;
debug!("check_pat(pat={:?},expected={:?})", pat, expected);
@ -126,15 +126,15 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
span_err!(tcx.sess, span, E0029,
"only char and numeric types are allowed in range patterns\n \
start type: {}\n end type: {}",
self.infcx().ty_to_string(lhs_ty),
self.infcx().ty_to_string(rhs_ty)
self.ty_to_string(lhs_ty),
self.ty_to_string(rhs_ty)
);
return;
}
// Check that the types of the end-points can be unified.
let types_unify = require_same_types(
self.ccx, Some(self.infcx()), pat.span, rhs_ty, lhs_ty,
self.ccx, Some(self), pat.span, rhs_ty, lhs_ty,
"mismatched types in range",
);
@ -145,7 +145,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
// Now that we know the types can be unified we find the unified type and use
// it to type the entire expression.
let common_type = self.infcx().resolve_type_vars_if_possible(&lhs_ty);
let common_type = self.resolve_type_vars_if_possible(&lhs_ty);
self.write_ty(pat.id, common_type);
@ -181,7 +181,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
// ref x | ref const x | ref mut x
// then `x` is assigned a value of type `&M T` where M is the mutability
// and T is the expected type.
let region_var = self.infcx().next_region_var(infer::PatternRegion(pat.span));
let region_var = self.next_region_var(infer::PatternRegion(pat.span));
let mt = ty::TypeAndMut { ty: expected, mutbl: mutbl };
let region_ty = tcx.mk_ref(tcx.mk_region(region_var), mt);
@ -227,14 +227,14 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
let self_ty = self.to_ty(&qself.ty);
let path_res = if let Some(&d) = tcx.def_map.borrow().get(&pat.id) {
if d.base_def == Def::Err {
self.infcx().set_tainted_by_errors();
self.set_tainted_by_errors();
self.write_error(pat.id);
return;
}
d
} else if qself.position == 0 {
// This is just a sentinel for finish_resolving_def_to_ty.
let sentinel = self.tcx().map.local_def_id(ast::CRATE_NODE_ID);
let sentinel = self.tcx.map.local_def_id(ast::CRATE_NODE_ID);
def::PathResolution {
base_def: Def::Mod(sentinel),
depth: path.segments.len()
@ -264,8 +264,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
}
PatKind::Tup(ref elements) => {
let element_tys: Vec<_> =
(0..elements.len()).map(|_| self.infcx().next_ty_var())
.collect();
(0..elements.len()).map(|_| self.next_ty_var()).collect();
let pat_ty = tcx.mk_tup(element_tys.clone());
self.write_ty(pat.id, pat_ty);
self.demand_eqtype(pat.span, expected, pat_ty);
@ -274,7 +273,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
}
}
PatKind::Box(ref inner) => {
let inner_ty = self.infcx().next_ty_var();
let inner_ty = self.next_ty_var();
let uniq_ty = tcx.mk_box(inner_ty);
if self.check_dereferencable(pat.span, expected, &inner) {
@ -290,7 +289,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
}
}
PatKind::Ref(ref inner, mutbl) => {
let expected = self.infcx().shallow_resolve(expected);
let expected = self.shallow_resolve(expected);
if self.check_dereferencable(pat.span, expected, &inner) {
// `demand::subtype` would be good enough, but using
// `eqtype` turns out to be equally general. See (*)
@ -305,9 +304,9 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
(expected, mt.ty)
}
_ => {
let inner_ty = self.infcx().next_ty_var();
let inner_ty = self.next_ty_var();
let mt = ty::TypeAndMut { ty: inner_ty, mutbl: mutbl };
let region = self.infcx().next_region_var(infer::PatternRegion(pat.span));
let region = self.next_region_var(infer::PatternRegion(pat.span));
let rptr_ty = tcx.mk_ref(tcx.mk_region(region), mt);
self.demand_eqtype(pat.span, expected, rptr_ty);
(rptr_ty, inner_ty)
@ -323,7 +322,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
}
PatKind::Vec(ref before, ref slice, ref after) => {
let expected_ty = self.structurally_resolved_type(pat.span, expected);
let inner_ty = self.infcx().next_ty_var();
let inner_ty = self.next_ty_var();
let pat_ty = match expected_ty.sty {
ty::TyArray(_, size) => tcx.mk_array(inner_ty, {
let min_len = before.len() + after.len();
@ -333,7 +332,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
}
}),
_ => {
let region = self.infcx().next_region_var(infer::PatternRegion(pat.span));
let region = self.next_region_var(infer::PatternRegion(pat.span));
tcx.mk_ref(tcx.mk_region(region), ty::TypeAndMut {
ty: tcx.mk_slice(inner_ty),
mutbl: expected_ty.builtin_deref(true, ty::NoPreference).map(|mt| mt.mutbl)
@ -353,7 +352,7 @@ pub fn check_pat(&self, pat: &'tcx hir::Pat, expected: Ty<'tcx>) {
self.check_pat(&elt, inner_ty);
}
if let Some(ref slice) = *slice {
let region = self.infcx().next_region_var(infer::PatternRegion(pat.span));
let region = self.next_region_var(infer::PatternRegion(pat.span));
let mutbl = expected_ty.builtin_deref(true, ty::NoPreference)
.map_or(hir::MutImmutable, |mt| mt.mutbl);
@ -425,7 +424,7 @@ fn check_assoc_item_is_const(&self, def: Def, span: Span) -> bool {
match def {
Def::AssociatedConst(..) => true,
Def::Method(..) => {
span_err!(self.tcx().sess, span, E0327,
span_err!(self.tcx.sess, span, E0327,
"associated items in match patterns must be constants");
false
}
@ -436,16 +435,16 @@ fn check_assoc_item_is_const(&self, def: Def, span: Span) -> bool {
}
pub fn check_dereferencable(&self, span: Span, expected: Ty<'tcx>, inner: &hir::Pat) -> bool {
let tcx = self.tcx();
let tcx = self.tcx;
if pat_is_binding(&tcx.def_map.borrow(), inner) {
let expected = self.infcx().shallow_resolve(expected);
let expected = self.shallow_resolve(expected);
expected.builtin_deref(true, ty::NoPreference).map_or(true, |mt| match mt.ty.sty {
ty::TyTrait(_) => {
// This is "x = SomeTrait" being reduced from
// "let &x = &SomeTrait" or "let box x = Box<SomeTrait>", an error.
span_err!(tcx.sess, span, E0033,
"type `{}` cannot be dereferenced",
self.infcx().ty_to_string(expected));
self.ty_to_string(expected));
false
}
_ => true
@ -463,7 +462,7 @@ pub fn check_match(&self,
arms: &'tcx [hir::Arm],
expected: Expectation<'tcx>,
match_src: hir::MatchSource) {
let tcx = self.tcx();
let tcx = self.tcx;
// Not entirely obvious: if matches may create ref bindings, we
// want to use the *precise* type of the discriminant, *not* some
@ -482,7 +481,7 @@ pub fn check_match(&self,
// ...but otherwise we want to use any supertype of the
// discriminant. This is sort of a workaround, see note (*) in
// `check_pat` for some details.
discrim_ty = self.infcx().next_ty_var();
discrim_ty = self.next_ty_var();
self.check_expr_has_type(discrim, discrim_ty);
};
@ -508,14 +507,14 @@ pub fn check_match(&self,
// of execution reach it, we will panic, so bottom is an appropriate
// type in that case)
let expected = expected.adjust_for_branches(self);
let mut result_ty = self.infcx().next_diverging_ty_var();
let mut result_ty = self.next_diverging_ty_var();
let coerce_first = match expected {
// We don't coerce to `()` so that if the match expression is a
// statement it's branches can have any consistent type. That allows
// us to give better error messages (pointing to a usually better
// arm for inconsistent arms or to the whole match when a `()` type
// is required).
Expectation::ExpectHasType(ety) if ety != self.tcx().mk_nil() => {
Expectation::ExpectHasType(ety) if ety != self.tcx.mk_nil() => {
ety
}
_ => result_ty
@ -547,7 +546,7 @@ pub fn check_match(&self,
};
let result = if is_if_let_fallback {
self.infcx().eq_types(true, origin, arm_ty, result_ty)
self.eq_types(true, origin, arm_ty, result_ty)
.map(|InferOk { obligations, .. }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
@ -569,8 +568,8 @@ pub fn check_match(&self,
} else {
(result_ty, arm_ty)
};
self.infcx().report_mismatched_types(origin, expected, found, e);
self.tcx().types.err
self.report_mismatched_types(origin, expected, found, e);
self.tcx.types.err
}
};
}
@ -583,7 +582,7 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx, 'tcx> {
pub fn check_pat_struct(&self, pat: &'tcx hir::Pat,
path: &hir::Path, fields: &'tcx [Spanned<hir::FieldPat>],
etc: bool, expected: Ty<'tcx>) {
let tcx = self.tcx();
let tcx = self.tcx;
let def = tcx.def_map.borrow().get(&pat.id).unwrap().full_def();
let variant = match self.def_struct_variant(def, path.span) {
@ -621,12 +620,12 @@ fn check_pat_enum(&self,
is_tuple_struct_pat: bool)
{
// Typecheck the path.
let tcx = self.tcx();
let tcx = self.tcx;
let path_res = match tcx.def_map.borrow().get(&pat.id) {
Some(&path_res) if path_res.base_def != Def::Err => path_res,
_ => {
self.infcx().set_tainted_by_errors();
self.set_tainted_by_errors();
self.write_error(pat.id);
if let Some(subpats) = subpats {
@ -767,7 +766,7 @@ pub fn check_struct_pat_fields(&self,
variant: ty::VariantDef<'tcx>,
substs: &Substs<'tcx>,
etc: bool) {
let tcx = self.tcx();
let tcx = self.tcx;
// Index the struct fields' types.
let field_map = variant.fields

View file

@ -128,13 +128,13 @@ fn try_overloaded_call_step(&self,
// Check whether this is a call to a closure where we
// haven't yet decided on whether the closure is fn vs
// fnmut vs fnonce. If so, we have to defer further processing.
if self.infcx().closure_kind(def_id).is_none() {
if self.closure_kind(def_id).is_none() {
let closure_ty =
self.infcx().closure_type(def_id, substs);
self.closure_type(def_id, substs);
let fn_sig =
self.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
infer::FnCall,
&closure_ty.sig).0;
self.replace_late_bound_regions_with_fresh_var(call_expr.span,
infer::FnCall,
&closure_ty.sig).0;
self.record_deferred_call_resolution(def_id, Box::new(CallResolution {
call_expr: call_expr,
callee_expr: callee_expr,
@ -175,9 +175,9 @@ fn try_overloaded_call_traits(&self,
{
// Try the options that are least restrictive on the caller first.
for &(opt_trait_def_id, method_name) in &[
(self.tcx().lang_items.fn_trait(), token::intern("call")),
(self.tcx().lang_items.fn_mut_trait(), token::intern("call_mut")),
(self.tcx().lang_items.fn_once_trait(), token::intern("call_once")),
(self.tcx.lang_items.fn_trait(), token::intern("call")),
(self.tcx.lang_items.fn_mut_trait(), token::intern("call_mut")),
(self.tcx.lang_items.fn_once_trait(), token::intern("call_once")),
] {
let trait_def_id = match opt_trait_def_id {
Some(def_id) => def_id,
@ -221,7 +221,7 @@ fn confirm_builtin_call(&self,
}, callee_ty, None);
if let hir::ExprCall(ref expr, _) = call_expr.node {
let tcx = self.tcx();
let tcx = self.tcx;
if let Some(pr) = tcx.def_map.borrow().get(&expr.id) {
if pr.depth == 0 && pr.base_def != Def::Err {
if let Some(span) = tcx.map.span_if_local(pr.def_id()) {
@ -238,7 +238,7 @@ fn confirm_builtin_call(&self,
// set up all the node type bindings.
error_fn_sig = ty::Binder(ty::FnSig {
inputs: self.err_args(arg_exprs.len()),
output: ty::FnConverging(self.tcx().types.err),
output: ty::FnConverging(self.tcx.types.err),
variadic: false
});
@ -252,9 +252,9 @@ fn confirm_builtin_call(&self,
// previously appeared within a `Binder<>` and hence would not
// have been normalized before.
let fn_sig =
self.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
infer::FnCall,
fn_sig).0;
self.replace_late_bound_regions_with_fresh_var(call_expr.span,
infer::FnCall,
fn_sig).0;
let fn_sig =
self.normalize_associated_types_in(call_expr.span, &fn_sig);
@ -323,7 +323,7 @@ fn write_overloaded_call_method_map(&self,
call_expr: &hir::Expr,
method_callee: ty::MethodCallee<'tcx>) {
let method_call = ty::MethodCall::expr(call_expr.id);
self.inh.tables.borrow_mut().method_map.insert(method_call, method_callee);
self.tables.borrow_mut().method_map.insert(method_call, method_callee);
}
}
@ -344,7 +344,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
// we should not be invoked until the closure kind has been
// determined by upvar inference
assert!(fcx.infcx().closure_kind(self.closure_def_id).is_some());
assert!(fcx.closure_kind(self.closure_def_id).is_some());
// We may now know enough to figure out fn vs fnmut etc.
match fcx.try_overloaded_call_traits(self.call_expr, self.callee_expr,
@ -358,8 +358,8 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
// can't because of the annoying need for a TypeTrace.
// (This always bites me, should find a way to
// refactor it.)
let method_sig = fcx.tcx().no_late_bound_regions(method_callee.ty.fn_sig())
.unwrap();
let method_sig = fcx.tcx.no_late_bound_regions(method_callee.ty.fn_sig())
.unwrap();
debug!("attempt_resolution: method_callee={:?}",
method_callee);
@ -370,7 +370,7 @@ impl<'tcx> DeferredCallResolution<'tcx> for CallResolution<'tcx> {
fcx.demand_eqtype(self.call_expr.span, self_arg_ty, method_arg_ty);
}
let nilty = fcx.tcx().mk_nil();
let nilty = fcx.tcx.mk_nil();
fcx.demand_eqtype(self.call_expr.span,
method_sig.output.unwrap_or(nilty),
self.fn_sig.output.unwrap_or(nilty));

View file

@ -83,7 +83,7 @@ fn unsize_kind(&self, t: Ty<'tcx>) -> Option<UnsizeKind<'tcx>> {
// FIXME(arielb1): do some kind of normalization
match def.struct_variant().fields.last() {
None => None,
Some(f) => self.unsize_kind(f.ty(self.tcx(), substs))
Some(f) => self.unsize_kind(f.ty(self.tcx, substs))
}
}
// We should really try to normalize here.
@ -148,7 +148,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
fcx.type_error_struct(self.span, |actual| {
format!("casting `{}` as `{}` is invalid",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
fcx.ty_to_string(self.cast_ty))
}, self.expr_ty, None)
.help(&format!("cast through {} first", match e {
CastError::NeedViaPtr => "a raw pointer",
@ -160,7 +160,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
.emit();
}
CastError::CastToBool => {
struct_span_err!(fcx.tcx().sess, self.span, E0054, "cannot cast as `bool`")
struct_span_err!(fcx.tcx.sess, self.span, E0054, "cannot cast as `bool`")
.help("compare with zero instead")
.emit();
}
@ -173,28 +173,28 @@ impl<'a, 'tcx> CastCheck<'tcx> {
fcx.type_error_message(self.span, |actual| {
format!("non-scalar cast: `{}` as `{}`",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
fcx.ty_to_string(self.cast_ty))
}, self.expr_ty, None);
}
CastError::IllegalCast => {
fcx.type_error_message(self.span, |actual| {
format!("casting `{}` as `{}` is invalid",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
fcx.ty_to_string(self.cast_ty))
}, self.expr_ty, None);
}
CastError::SizedUnsizedCast => {
fcx.type_error_message(self.span, |actual| {
format!("cannot cast thin pointer `{}` to fat pointer `{}`",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
fcx.ty_to_string(self.cast_ty))
}, self.expr_ty, None)
}
CastError::DifferingKinds => {
fcx.type_error_struct(self.span, |actual| {
format!("casting `{}` as `{}` is invalid",
actual,
fcx.infcx().ty_to_string(self.cast_ty))
fcx.ty_to_string(self.cast_ty))
}, self.expr_ty, None)
.note("vtable kinds may not match")
.emit();
@ -210,7 +210,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
return;
}
let tstr = fcx.infcx().ty_to_string(self.cast_ty);
let tstr = fcx.ty_to_string(self.cast_ty);
let mut err = fcx.type_error_struct(self.span, |actual| {
format!("cast to unsized type: `{}` as `{}`", actual, tstr)
}, self.expr_ty, None);
@ -221,7 +221,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
hir::MutImmutable => ""
};
if self.cast_ty.is_trait() {
match fcx.tcx().sess.codemap().span_to_snippet(self.cast_span) {
match fcx.tcx.sess.codemap().span_to_snippet(self.cast_span) {
Ok(s) => {
err.span_suggestion(self.cast_span,
"try casting to a reference instead:",
@ -238,7 +238,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
}
}
ty::TyBox(..) => {
match fcx.tcx().sess.codemap().span_to_snippet(self.cast_span) {
match fcx.tcx.sess.codemap().span_to_snippet(self.cast_span) {
Ok(s) => {
err.span_suggestion(self.cast_span,
"try casting to a `Box` instead:",
@ -260,23 +260,23 @@ impl<'a, 'tcx> CastCheck<'tcx> {
let t_cast = self.cast_ty;
let t_expr = self.expr_ty;
if t_cast.is_numeric() && t_expr.is_numeric() {
fcx.tcx().sess.add_lint(lint::builtin::TRIVIAL_NUMERIC_CASTS,
self.expr.id,
self.span,
format!("trivial numeric cast: `{}` as `{}`. Cast can be \
replaced by coercion, this might require type \
ascription or a temporary variable",
fcx.infcx().ty_to_string(t_expr),
fcx.infcx().ty_to_string(t_cast)));
fcx.tcx.sess.add_lint(lint::builtin::TRIVIAL_NUMERIC_CASTS,
self.expr.id,
self.span,
format!("trivial numeric cast: `{}` as `{}`. Cast can be \
replaced by coercion, this might require type \
ascription or a temporary variable",
fcx.ty_to_string(t_expr),
fcx.ty_to_string(t_cast)));
} else {
fcx.tcx().sess.add_lint(lint::builtin::TRIVIAL_CASTS,
self.expr.id,
self.span,
format!("trivial cast: `{}` as `{}`. Cast can be \
replaced by coercion, this might require type \
ascription or a temporary variable",
fcx.infcx().ty_to_string(t_expr),
fcx.infcx().ty_to_string(t_cast)));
fcx.tcx.sess.add_lint(lint::builtin::TRIVIAL_CASTS,
self.expr.id,
self.span,
format!("trivial cast: `{}` as `{}`. Cast can be \
replaced by coercion, this might require type \
ascription or a temporary variable",
fcx.ty_to_string(t_expr),
fcx.ty_to_string(t_cast)));
}
}
@ -295,12 +295,12 @@ impl<'a, 'tcx> CastCheck<'tcx> {
} else if self.try_coercion_cast(fcx) {
self.trivial_cast_lint(fcx);
debug!(" -> CoercionCast");
fcx.tcx().cast_kinds.borrow_mut().insert(self.expr.id,
CastKind::CoercionCast);
fcx.tcx.cast_kinds.borrow_mut().insert(self.expr.id,
CastKind::CoercionCast);
} else { match self.do_check(fcx) {
Ok(k) => {
debug!(" -> {:?}", k);
fcx.tcx().cast_kinds.borrow_mut().insert(self.expr.id, k);
fcx.tcx.cast_kinds.borrow_mut().insert(self.expr.id, k);
}
Err(e) => self.report_cast_error(fcx, e)
};}
@ -321,7 +321,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
if let ty::TyFnDef(_, _, f) = self.expr_ty.sty {
// Attempt a coercion to a fn pointer type.
let res = fcx.try_coerce(self.expr,
fcx.tcx().mk_ty(ty::TyFnPtr(f)));
fcx.tcx.mk_ty(ty::TyFnPtr(f)));
if !res.is_ok() {
return Err(CastError::NonScalar);
}
@ -482,10 +482,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx, 'tcx> {
span: Span)
-> bool
{
traits::type_known_to_meet_builtin_bound(self.infcx(),
ty,
ty::BoundSized,
span)
traits::type_known_to_meet_builtin_bound(self, ty, ty::BoundSized, span)
}
}

View file

@ -46,7 +46,7 @@ fn check_closure(&self,
decl: &'tcx hir::FnDecl,
body: &'tcx hir::Block,
expected_sig: Option<ty::FnSig<'tcx>>) {
let expr_def_id = self.tcx().map.local_def_id(expr.id);
let expr_def_id = self.tcx.map.local_def_id(expr.id);
debug!("check_closure opt_kind={:?} expected_sig={:?}",
opt_kind,
@ -61,20 +61,20 @@ fn check_closure(&self,
// Create type variables (for now) to represent the transformed
// types of upvars. These will be unified during the upvar
// inference phase (`upvar.rs`).
let num_upvars = self.tcx().with_freevars(expr.id, |fv| fv.len());
let upvar_tys = self.infcx().next_ty_vars(num_upvars);
let num_upvars = self.tcx.with_freevars(expr.id, |fv| fv.len());
let upvar_tys = self.next_ty_vars(num_upvars);
debug!("check_closure: expr.id={:?} upvar_tys={:?}",
expr.id, upvar_tys);
let closure_type = self.tcx().mk_closure(expr_def_id,
self.tcx().mk_substs(self.inh.infcx.parameter_environment.free_substs.clone()),
let closure_type = self.tcx.mk_closure(expr_def_id,
self.tcx.mk_substs(self.parameter_environment.free_substs.clone()),
upvar_tys);
self.write_ty(expr.id, closure_type);
let fn_sig = self.tcx().liberate_late_bound_regions(
self.tcx().region_maps.call_site_extent(expr.id, body.id), &fn_ty.sig);
let fn_sig = self.tcx.liberate_late_bound_regions(
self.tcx.region_maps.call_site_extent(expr.id, body.id), &fn_ty.sig);
check_fn(self.ccx,
hir::Unsafety::Normal,
@ -83,20 +83,20 @@ fn check_closure(&self,
decl,
expr.id,
&body,
self.inh);
self);
// Tuple up the arguments and insert the resulting function type into
// the `closures` table.
fn_ty.sig.0.inputs = vec![self.tcx().mk_tup(fn_ty.sig.0.inputs)];
fn_ty.sig.0.inputs = vec![self.tcx.mk_tup(fn_ty.sig.0.inputs)];
debug!("closure for {:?} --> sig={:?} opt_kind={:?}",
expr_def_id,
fn_ty.sig,
opt_kind);
self.inh.tables.borrow_mut().closure_tys.insert(expr_def_id, fn_ty);
self.tables.borrow_mut().closure_tys.insert(expr_def_id, fn_ty);
match opt_kind {
Some(kind) => { self.inh.tables.borrow_mut().closure_kinds.insert(expr_def_id, kind); }
Some(kind) => { self.tables.borrow_mut().closure_kinds.insert(expr_def_id, kind); }
None => { }
}
}
@ -109,12 +109,12 @@ fn deduce_expectations_from_expected_type(&self, expected_ty: Ty<'tcx>)
match expected_ty.sty {
ty::TyTrait(ref object_type) => {
let proj_bounds = object_type.projection_bounds_with_self_ty(self.tcx(),
self.tcx().types.err);
let proj_bounds = object_type.projection_bounds_with_self_ty(self.tcx,
self.tcx.types.err);
let sig = proj_bounds.iter()
.filter_map(|pb| self.deduce_sig_from_projection(pb))
.next();
let kind = self.tcx().lang_items.fn_trait_kind(object_type.principal_def_id());
let kind = self.tcx.lang_items.fn_trait_kind(object_type.principal_def_id());
(sig, kind)
}
ty::TyInfer(ty::TyVar(vid)) => {
@ -129,7 +129,7 @@ fn deduce_expectations_from_expected_type(&self, expected_ty: Ty<'tcx>)
fn deduce_expectations_from_obligations(&self, expected_vid: ty::TyVid)
-> (Option<ty::FnSig<'tcx>>, Option<ty::ClosureKind>)
{
let fulfillment_cx = self.inh.fulfillment_cx.borrow();
let fulfillment_cx = self.fulfillment_cx.borrow();
// Here `expected_ty` is known to be a type inference variable.
let expected_sig =
@ -188,7 +188,7 @@ fn deduce_expectations_from_obligations(&self, expected_vid: ty::TyVid)
};
opt_trait_ref
.and_then(|trait_ref| self.self_type_matches_expected_vid(trait_ref, expected_vid))
.and_then(|trait_ref| self.tcx().lang_items.fn_trait_kind(trait_ref.def_id()))
.and_then(|trait_ref| self.tcx.lang_items.fn_trait_kind(trait_ref.def_id()))
})
.fold(None, |best, cur| Some(best.map_or(cur, |best| cmp::min(best, cur))));
@ -201,7 +201,7 @@ fn deduce_sig_from_projection(&self,
projection: &ty::PolyProjectionPredicate<'tcx>)
-> Option<ty::FnSig<'tcx>>
{
let tcx = self.tcx();
let tcx = self.tcx;
debug!("deduce_sig_from_projection({:?})",
projection);
@ -213,7 +213,7 @@ fn deduce_sig_from_projection(&self,
}
let arg_param_ty = *trait_ref.substs().types.get(subst::TypeSpace, 0);
let arg_param_ty = self.infcx().resolve_type_vars_if_possible(&arg_param_ty);
let arg_param_ty = self.resolve_type_vars_if_possible(&arg_param_ty);
debug!("deduce_sig_from_projection: arg_param_ty {:?}", arg_param_ty);
let input_tys = match arg_param_ty.sty {
@ -223,7 +223,7 @@ fn deduce_sig_from_projection(&self,
debug!("deduce_sig_from_projection: input_tys {:?}", input_tys);
let ret_param_ty = projection.0.ty;
let ret_param_ty = self.infcx().resolve_type_vars_if_possible(&ret_param_ty);
let ret_param_ty = self.resolve_type_vars_if_possible(&ret_param_ty);
debug!("deduce_sig_from_projection: ret_param_ty {:?}", ret_param_ty);
let fn_sig = ty::FnSig {
@ -241,7 +241,7 @@ fn self_type_matches_expected_vid(&self,
expected_vid: ty::TyVid)
-> Option<ty::PolyTraitRef<'tcx>>
{
let self_ty = self.infcx().shallow_resolve(trait_ref.self_ty());
let self_ty = self.shallow_resolve(trait_ref.self_ty());
debug!("self_type_matches_expected_vid(trait_ref={:?}, self_ty={:?})",
trait_ref,
self_ty);

View file

@ -62,12 +62,13 @@
use check::{FnCtxt, UnresolvedTypeAction};
use rustc::hir;
use rustc::infer::{Coercion, InferOk, TypeOrigin, TypeTrace};
use rustc::traits::{self, ObligationCause};
use rustc::ty::adjustment::{AutoAdjustment, AutoDerefRef, AdjustDerefRef};
use rustc::ty::adjustment::{AutoPtr, AutoUnsafe, AdjustReifyFnPointer};
use rustc::ty::adjustment::{AdjustUnsafeFnPointer, AdjustMutToConstPointer};
use rustc::ty::{self, LvaluePreference, TypeAndMut, Ty, TyCtxt};
use rustc::ty::{self, LvaluePreference, TypeAndMut, Ty};
use rustc::ty::fold::TypeFoldable;
use rustc::ty::error::TypeError;
use rustc::ty::relate::RelateResult;
@ -75,7 +76,7 @@ use util::common::indent;
use std::cell::RefCell;
use std::collections::VecDeque;
use rustc::hir;
use std::ops::Deref;
struct Coerce<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
@ -84,6 +85,13 @@ struct Coerce<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
unsizing_obligations: RefCell<Vec<traits::PredicateObligation<'tcx>>>,
}
impl<'a, 'gcx, 'tcx> Deref for Coerce<'a, 'gcx, 'tcx> {
type Target = FnCtxt<'a, 'gcx, 'tcx>;
fn deref(&self) -> &Self::Target {
&self.fcx
}
}
type CoerceResult<'tcx> = RelateResult<'tcx, (Ty<'tcx>, AutoAdjustment<'tcx>)>;
fn coerce_mutbls<'tcx>(from_mutbl: hir::Mutability,
@ -107,23 +115,18 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
}
}
fn tcx(&self) -> TyCtxt<'f, 'tcx, 'tcx> {
self.fcx.tcx()
}
fn unify(&self, a: Ty<'tcx>, b: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
let infcx = self.fcx.infcx();
infcx.commit_if_ok(|_| {
self.commit_if_ok(|_| {
let trace = TypeTrace::types(self.origin, false, a, b);
if self.use_lub {
infcx.lub(false, trace, &a, &b)
self.lub(false, trace, &a, &b)
.map(|InferOk { value, obligations }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
value
})
} else {
infcx.sub(false, trace, &a, &b)
self.sub(false, trace, &a, &b)
.map(|InferOk { value, obligations }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
@ -156,7 +159,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
where E: Fn() -> I,
I: IntoIterator<Item=&'a hir::Expr> {
let a = self.fcx.infcx().shallow_resolve(a);
let a = self.shallow_resolve(a);
debug!("Coerce.tys({:?} => {:?})", a, b);
// Just ignore error types.
@ -240,10 +243,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
let lvalue_pref = LvaluePreference::from_mutbl(mt_b.mutbl);
let mut first_error = None;
let mut r_borrow_var = None;
let (_, autoderefs, success) = self.fcx.autoderef(span, a, exprs,
UnresolvedTypeAction::Ignore,
lvalue_pref,
|referent_ty, autoderef|
let (_, autoderefs, success) = self.autoderef(span, a, exprs,
UnresolvedTypeAction::Ignore,
lvalue_pref,
|referent_ty, autoderef|
{
if autoderef == 0 {
// Don't let this pass, otherwise it would cause
@ -328,12 +331,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
} else {
if r_borrow_var.is_none() { // create var lazilly, at most once
let coercion = Coercion(span);
let r = self.fcx.infcx().next_region_var(coercion);
r_borrow_var = Some(self.tcx().mk_region(r)); // [4] above
let r = self.next_region_var(coercion);
r_borrow_var = Some(self.tcx.mk_region(r)); // [4] above
}
r_borrow_var.unwrap()
};
let derefd_ty_a = self.tcx().mk_ref(r, TypeAndMut {
let derefd_ty_a = self.tcx.mk_ref(r, TypeAndMut {
ty: referent_ty,
mutbl: mt_b.mutbl // [1] above
});
@ -405,8 +408,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
source,
target);
let traits = (self.tcx().lang_items.unsize_trait(),
self.tcx().lang_items.coerce_unsized_trait());
let traits = (self.tcx.lang_items.unsize_trait(),
self.tcx.lang_items.coerce_unsized_trait());
let (unsize_did, coerce_unsized_did) = if let (Some(u), Some(cu)) = traits {
(u, cu)
} else {
@ -425,8 +428,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
coerce_mutbls(mt_a.mutbl, mt_b.mutbl)?;
let coercion = Coercion(self.origin.span());
let r_borrow = self.fcx.infcx().next_region_var(coercion);
let region = self.tcx().mk_region(r_borrow);
let r_borrow = self.next_region_var(coercion);
let region = self.tcx.mk_region(r_borrow);
(mt_a.ty, Some(AutoPtr(region, mt_b.mutbl)))
}
(&ty::TyRef(_, mt_a), &ty::TyRawPtr(mt_b)) => {
@ -435,21 +438,21 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
}
_ => (source, None)
};
let source = source.adjust_for_autoref(self.tcx(), reborrow);
let source = source.adjust_for_autoref(self.tcx, reborrow);
let mut selcx = traits::SelectionContext::new(self.fcx.infcx());
let mut selcx = traits::SelectionContext::new(self);
// Use a FIFO queue for this custom fulfillment procedure.
let mut queue = VecDeque::new();
let mut leftover_predicates = vec![];
// Create an obligation for `Source: CoerceUnsized<Target>`.
let cause = ObligationCause::misc(self.origin.span(), self.fcx.body_id);
queue.push_back(self.tcx().predicate_for_trait_def(cause,
coerce_unsized_did,
0,
source,
vec![target]));
let cause = ObligationCause::misc(self.origin.span(), self.body_id);
queue.push_back(self.tcx.predicate_for_trait_def(cause,
coerce_unsized_did,
0,
source,
vec![target]));
// Keep resolving `CoerceUnsized` and `Unsize` predicates to avoid
// emitting a coercion in cases like `Foo<$1>` -> `Foo<$2>`, where
@ -475,7 +478,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
// Object safety violations or miscellaneous.
Err(err) => {
self.fcx.infcx().report_selection_error(&obligation, &err, None);
self.report_selection_error(&obligation, &err, None);
// Treat this like an obligation and follow through
// with the unsizing - the lack of a coercion should
// be silent, as it causes a type mismatch later.
@ -511,13 +514,13 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
* into a closure or a `proc`.
*/
let b = self.fcx.infcx().shallow_resolve(b);
let b = self.shallow_resolve(b);
debug!("coerce_from_fn_pointer(a={:?}, b={:?})", a, b);
if let ty::TyFnPtr(fn_ty_b) = b.sty {
match (fn_ty_a.unsafety, fn_ty_b.unsafety) {
(hir::Unsafety::Normal, hir::Unsafety::Unsafe) => {
let unsafe_a = self.tcx().safe_to_unsafe_fn_ty(fn_ty_a);
let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a);
return self.unify_and_identity(unsafe_a, b).map(|(ty, _)| {
(ty, AdjustUnsafeFnPointer)
});
@ -538,12 +541,12 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
* into a closure or a `proc`.
*/
let b = self.fcx.infcx().shallow_resolve(b);
let b = self.shallow_resolve(b);
debug!("coerce_from_fn_item(a={:?}, b={:?})", a, b);
match b.sty {
ty::TyFnPtr(_) => {
let a_fn_pointer = self.tcx().mk_ty(ty::TyFnPtr(fn_ty_a));
let a_fn_pointer = self.tcx.mk_ty(ty::TyFnPtr(fn_ty_a));
self.unify_and_identity(a_fn_pointer, b).map(|(ty, _)| {
(ty, AdjustReifyFnPointer)
})
@ -570,7 +573,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx, 'tcx> {
};
// Check that the types which they point at are compatible.
let a_unsafe = self.tcx().mk_ptr(ty::TypeAndMut{ mutbl: mutbl_b, ty: mt_a.ty });
let a_unsafe = self.tcx.mk_ptr(ty::TypeAndMut{ mutbl: mutbl_b, ty: mt_a.ty });
let (ty, noop) = self.unify_and_identity(a_unsafe, b)?;
coerce_mutbls(mt_a.mutbl, mutbl_b)?;
@ -623,16 +626,16 @@ pub fn try_coerce(&self,
expr: &hir::Expr,
target: Ty<'tcx>)
-> RelateResult<'tcx, Ty<'tcx>> {
let source = self.resolve_type_vars_if_possible(self.expr_ty(expr));
let source = self.resolve_type_vars_with_obligations(self.expr_ty(expr));
debug!("coercion::try({:?}: {:?} -> {:?})", expr, source, target);
let mut coerce = Coerce::new(self, TypeOrigin::ExprAssignable(expr.span));
self.infcx().commit_if_ok(|_| {
self.commit_if_ok(|_| {
let (ty, adjustment) =
apply(&mut coerce, &|| Some(expr), source, target)?;
if !adjustment.is_identity() {
debug!("Success, coerced with {:?}", adjustment);
assert!(!self.inh.tables.borrow().adjustments.contains_key(&expr.id));
assert!(!self.tables.borrow().adjustments.contains_key(&expr.id));
self.write_adjustment(expr.id, adjustment);
}
Ok(ty)
@ -652,8 +655,8 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
where E: Fn() -> I,
I: IntoIterator<Item=&'b hir::Expr> {
let prev_ty = self.resolve_type_vars_if_possible(prev_ty);
let new_ty = self.resolve_type_vars_if_possible(self.expr_ty(new));
let prev_ty = self.resolve_type_vars_with_obligations(prev_ty);
let new_ty = self.resolve_type_vars_with_obligations(self.expr_ty(new));
debug!("coercion::try_find_lub({:?}, {:?})", prev_ty, new_ty);
let trace = TypeTrace::types(origin, true, prev_ty, new_ty);
@ -664,7 +667,7 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
(&ty::TyFnDef(a_def_id, a_substs, a_fty),
&ty::TyFnDef(b_def_id, b_substs, b_fty)) => {
// The signature must always match.
let fty = self.infcx().lub(true, trace.clone(), a_fty, b_fty)
let fty = self.lub(true, trace.clone(), a_fty, b_fty)
.map(|InferOk { value, obligations }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
@ -673,28 +676,28 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
if a_def_id == b_def_id {
// Same function, maybe the parameters match.
let substs = self.infcx().commit_if_ok(|_| {
self.infcx().lub(true, trace.clone(), a_substs, b_substs)
let substs = self.commit_if_ok(|_| {
self.lub(true, trace.clone(), a_substs, b_substs)
.map(|InferOk { value, obligations }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
value
})
}).map(|s| self.tcx().mk_substs(s));
}).map(|s| self.tcx.mk_substs(s));
if let Ok(substs) = substs {
// We have a LUB of prev_ty and new_ty, just return it.
return Ok(self.tcx().mk_fn_def(a_def_id, substs, fty));
return Ok(self.tcx.mk_fn_def(a_def_id, substs, fty));
}
}
// Reify both sides and return the reified fn pointer type.
for expr in exprs().into_iter().chain(Some(new)) {
// No adjustments can produce a fn item, so this should never trip.
assert!(!self.inh.tables.borrow().adjustments.contains_key(&expr.id));
assert!(!self.tables.borrow().adjustments.contains_key(&expr.id));
self.write_adjustment(expr.id, AdjustReifyFnPointer);
}
return Ok(self.tcx().mk_fn_ptr(fty));
return Ok(self.tcx.mk_fn_ptr(fty));
}
_ => {}
}
@ -705,8 +708,8 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
// First try to coerce the new expression to the type of the previous ones,
// but only if the new expression has no coercion already applied to it.
let mut first_error = None;
if !self.inh.tables.borrow().adjustments.contains_key(&new.id) {
let result = self.infcx().commit_if_ok(|_| {
if !self.tables.borrow().adjustments.contains_key(&new.id) {
let result = self.commit_if_ok(|_| {
apply(&mut coerce, &|| Some(new), new_ty, prev_ty)
});
match result {
@ -724,7 +727,7 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
// This requires ensuring there are no coercions applied to *any* of the
// previous expressions, other than noop reborrows (ignoring lifetimes).
for expr in exprs() {
let noop = match self.inh.tables.borrow().adjustments.get(&expr.id) {
let noop = match self.tables.borrow().adjustments.get(&expr.id) {
Some(&AdjustDerefRef(AutoDerefRef {
autoderefs: 1,
autoref: Some(AutoPtr(_, mutbl_adj)),
@ -741,8 +744,8 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
};
if !noop {
return self.infcx().commit_if_ok(|_| {
self.infcx().lub(true, trace.clone(), &prev_ty, &new_ty)
return self.commit_if_ok(|_| {
self.lub(true, trace.clone(), &prev_ty, &new_ty)
.map(|InferOk { value, obligations }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
@ -752,14 +755,14 @@ pub fn try_find_coercion_lub<'b, E, I>(&self,
}
}
match self.infcx().commit_if_ok(|_| apply(&mut coerce, &exprs, prev_ty, new_ty)) {
match self.commit_if_ok(|_| apply(&mut coerce, &exprs, prev_ty, new_ty)) {
Err(_) => {
// Avoid giving strange errors on failed attempts.
if let Some(e) = first_error {
Err(e)
} else {
self.infcx().commit_if_ok(|_| {
self.infcx().lub(true, trace, &prev_ty, &new_ty)
self.commit_if_ok(|_| {
self.lub(true, trace, &prev_ty, &new_ty)
.map(|InferOk { value, obligations }| {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());

View file

@ -21,37 +21,37 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx, 'tcx> {
// they don't.
pub fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
let origin = TypeOrigin::Misc(sp);
match self.infcx().sub_types(false, origin, actual, expected) {
match self.sub_types(false, origin, actual, expected) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
},
Err(e) => {
self.infcx().report_mismatched_types(origin, expected, actual, e);
self.report_mismatched_types(origin, expected, actual, e);
}
}
}
pub fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>) {
let origin = TypeOrigin::Misc(sp);
match self.infcx().eq_types(false, origin, actual, expected) {
match self.eq_types(false, origin, actual, expected) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
},
Err(e) => {
self.infcx().report_mismatched_types(origin, expected, actual, e);
self.report_mismatched_types(origin, expected, actual, e);
}
}
}
// Checks that the type of `expr` can be coerced to `expected`.
pub fn demand_coerce(&self, expr: &hir::Expr, expected: Ty<'tcx>) {
let expected = self.resolve_type_vars_if_possible(expected);
let expected = self.resolve_type_vars_with_obligations(expected);
if let Err(e) = self.try_coerce(expr, expected) {
let origin = TypeOrigin::Misc(expr.span);
let expr_ty = self.resolve_type_vars_if_possible(self.expr_ty(expr));
self.infcx().report_mismatched_types(origin, expected, expr_ty, e);
let expr_ty = self.resolve_type_vars_with_obligations(self.expr_ty(expr));
self.report_mismatched_types(origin, expected, expr_ty, e);
}
}
}

View file

@ -281,7 +281,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'tcx>(rcx: &mut RegionCtxt<'a
debug!("check_safety_of_destructor_if_necessary typ: {:?} scope: {:?}",
typ, scope);
let parent_scope = rcx.tcx().region_maps.opt_encl_scope(scope).unwrap_or_else(|| {
let parent_scope = rcx.tcx.region_maps.opt_encl_scope(scope).unwrap_or_else(|| {
span_bug!(span, "no enclosing scope found for scope: {:?}", scope)
});
@ -298,7 +298,7 @@ pub fn check_safety_of_destructor_if_necessary<'a, 'tcx>(rcx: &mut RegionCtxt<'a
match result {
Ok(()) => {}
Err(Error::Overflow(ref ctxt, ref detected_on_typ)) => {
let tcx = rcx.tcx();
let tcx = rcx.tcx;
let mut err = struct_span_err!(tcx.sess, span, E0320,
"overflow while adding drop-check rules for {}", typ);
match *ctxt {
@ -360,7 +360,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>(
ty: Ty<'tcx>,
depth: usize) -> Result<(), Error<'tcx>>
{
let tcx = cx.rcx.tcx();
let tcx = cx.rcx.tcx;
// Issue #22443: Watch out for overflow. While we are careful to
// handle regular types properly, non-regular ones cause problems.
let recursion_limit = tcx.sess.recursion_limit.get();
@ -373,7 +373,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>(
// canoncialize the regions in `ty` before inserting - infinitely many
// region variables can refer to the same region.
let ty = cx.rcx.infcx().resolve_type_and_region_vars_if_possible(&ty);
let ty = cx.rcx.resolve_type_and_region_vars_if_possible(&ty);
if !cx.breadcrumbs.insert(ty) {
debug!("iterate_over_potentially_unsafe_regions_in_type \
@ -453,7 +453,7 @@ fn iterate_over_potentially_unsafe_regions_in_type<'a, 'b, 'tcx>(
for variant in &def.variants {
for field in variant.fields.iter() {
let fty = field.ty(tcx, substs);
let fty = cx.rcx.fcx.resolve_type_vars_if_possible(
let fty = cx.rcx.fcx.resolve_type_vars_with_obligations(
cx.rcx.fcx.normalize_associated_types_in(cx.span, &fty));
iterate_over_potentially_unsafe_regions_in_type(
cx,
@ -504,7 +504,7 @@ fn has_dtor_of_interest<'a, 'b, 'tcx>(cx: &DropckContext<'a, 'b, 'tcx, 'tcx>,
ty: ty::Ty<'tcx>) -> bool {
match ty.sty {
ty::TyEnum(def, _) | ty::TyStruct(def, _) => {
def.is_dtorck(cx.rcx.tcx())
def.is_dtorck(cx.rcx.tcx)
}
ty::TyTrait(..) | ty::TyProjection(..) => {
debug!("ty: {:?} isn't known, and therefore is a dropck type", ty);

View file

@ -15,14 +15,15 @@ use check::UnresolvedTypeAction;
use hir::def_id::DefId;
use rustc::ty::subst::{self};
use rustc::traits;
use rustc::ty::{self, NoPreference, PreferMutLvalue, Ty, TyCtxt};
use rustc::ty::{self, NoPreference, PreferMutLvalue, Ty};
use rustc::ty::adjustment::{AdjustDerefRef, AutoDerefRef, AutoPtr};
use rustc::ty::fold::TypeFoldable;
use rustc::infer;
use rustc::infer::{InferCtxt, InferOk, TypeOrigin};
use rustc::infer::{self, InferOk, TypeOrigin};
use syntax::codemap::Span;
use rustc::hir;
use std::ops::Deref;
struct ConfirmContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a>{
fcx: &'a FnCtxt<'a, 'gcx, 'tcx>,
span: Span,
@ -30,6 +31,13 @@ struct ConfirmContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a>{
call_expr: &'gcx hir::Expr,
}
impl<'a, 'gcx, 'tcx> Deref for ConfirmContext<'a, 'gcx, 'tcx> {
type Target = FnCtxt<'a, 'gcx, 'tcx>;
fn deref(&self) -> &Self::Target {
&self.fcx
}
}
struct InstantiatedMethodSig<'tcx> {
/// Function signature of the method being invoked. The 0th
/// argument is the receiver.
@ -100,7 +108,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
let InstantiatedMethodSig {
method_sig, all_substs, method_predicates
} = self.instantiate_method_sig(&pick, all_substs);
let all_substs = self.tcx().mk_substs(all_substs);
let all_substs = self.tcx.mk_substs(all_substs);
let method_self_ty = method_sig.inputs[0];
// Unify the (adjusted) self type with what the method expects.
@ -109,7 +117,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// Create the method type
let def_id = pick.item.def_id();
let method_ty = pick.item.as_opt_method().unwrap();
let fty = self.tcx().mk_fn_def(def_id, all_substs, ty::BareFnTy {
let fty = self.tcx.mk_fn_def(def_id, all_substs, ty::BareFnTy {
sig: ty::Binder(method_sig),
unsafety: method_ty.fty.unsafety,
abi: method_ty.fty.abi.clone(),
@ -141,10 +149,10 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
-> Ty<'tcx>
{
let (autoref, unsize) = if let Some(mutbl) = pick.autoref {
let region = self.infcx().next_region_var(infer::Autoref(self.span));
let autoref = AutoPtr(self.tcx().mk_region(region), mutbl);
let region = self.next_region_var(infer::Autoref(self.span));
let autoref = AutoPtr(self.tcx.mk_region(region), mutbl);
(Some(autoref), pick.unsize.map(|target| {
target.adjust_for_autoref(self.tcx(), Some(autoref))
target.adjust_for_autoref(self.tcx, Some(autoref))
}))
} else {
// No unsizing should be performed without autoref (at
@ -157,12 +165,12 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// Commit the autoderefs by calling `autoderef again, but this
// time writing the results into the various tables.
let (autoderefd_ty, n, result) = self.fcx.autoderef(self.span,
unadjusted_self_ty,
|| Some(self.self_expr),
UnresolvedTypeAction::Error,
NoPreference,
|_, n| {
let (autoderefd_ty, n, result) = self.autoderef(self.span,
unadjusted_self_ty,
|| Some(self.self_expr),
UnresolvedTypeAction::Error,
NoPreference,
|_, n| {
if n == pick.autoderefs {
Some(())
} else {
@ -173,8 +181,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
assert_eq!(result, Some(()));
// Write out the final adjustment.
self.fcx.write_adjustment(self.self_expr.id,
AdjustDerefRef(AutoDerefRef {
self.write_adjustment(self.self_expr.id, AdjustDerefRef(AutoDerefRef {
autoderefs: pick.autoderefs,
autoref: autoref,
unsize: unsize
@ -183,7 +190,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
if let Some(target) = unsize {
target
} else {
autoderefd_ty.adjust_for_autoref(self.tcx(), autoref)
autoderefd_ty.adjust_for_autoref(self.tcx, autoref)
}
}
@ -204,9 +211,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
match pick.kind {
probe::InherentImplPick => {
let impl_def_id = pick.item.container().id();
assert!(self.tcx().impl_trait_ref(impl_def_id).is_none(),
assert!(self.tcx.impl_trait_ref(impl_def_id).is_none(),
"impl {:?} is not an inherent impl", impl_def_id);
self.fcx.impl_self_ty(self.span, impl_def_id).substs
self.impl_self_ty(self.span, impl_def_id).substs
}
probe::ObjectPick => {
@ -223,7 +230,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// been ruled out when we deemed the trait to be
// "object safe".
let original_poly_trait_ref =
data.principal_trait_ref_with_self_ty(this.tcx(), object_ty);
data.principal_trait_ref_with_self_ty(this.tcx, object_ty);
let upcast_poly_trait_ref =
this.upcast(original_poly_trait_ref.clone(), trait_def_id);
let upcast_trait_ref =
@ -246,27 +253,27 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// respectively, then we want to return the type
// parameters from the trait ([$A,$B]), not those from
// the impl ([$A,$B,$C]) not the receiver type ([$C]).
let impl_polytype = self.fcx.impl_self_ty(self.span, impl_def_id);
let impl_polytype = self.impl_self_ty(self.span, impl_def_id);
let impl_trait_ref =
self.fcx.instantiate_type_scheme(
self.instantiate_type_scheme(
self.span,
&impl_polytype.substs,
&self.tcx().impl_trait_ref(impl_def_id).unwrap());
&self.tcx.impl_trait_ref(impl_def_id).unwrap());
impl_trait_ref.substs.clone()
}
probe::TraitPick => {
let trait_def_id = pick.item.container().id();
let trait_def = self.tcx().lookup_trait_def(trait_def_id);
let trait_def = self.tcx.lookup_trait_def(trait_def_id);
// Make a trait reference `$0 : Trait<$1...$n>`
// consisting entirely of type variables. Later on in
// the process we will unify the transformed-self-type
// of the method with the actual type in order to
// unify some of these variables.
self.infcx().fresh_substs_for_trait(self.span,
&trait_def.generics,
self.infcx().next_ty_var())
self.fresh_substs_for_trait(self.span,
&trait_def.generics,
self.next_ty_var())
}
probe::WhereClausePick(ref poly_trait_ref) => {
@ -328,7 +335,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
//
// FIXME -- permit users to manually specify lifetimes
let method_regions =
self.fcx.infcx().region_vars_for_defs(
self.region_vars_for_defs(
self.span,
pick.item.as_opt_method().unwrap()
.generics.regions.get_slice(subst::FnSpace));
@ -338,26 +345,26 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
let mut final_substs = subst::Substs { types: types, regions: regions };
if num_supplied_types == 0 {
self.fcx.infcx().type_vars_for_defs(
self.type_vars_for_defs(
self.span,
subst::FnSpace,
&mut final_substs,
method_types);
} else if num_method_types == 0 {
span_err!(self.tcx().sess, self.span, E0035,
span_err!(self.tcx.sess, self.span, E0035,
"does not take type parameters");
self.fcx.infcx().type_vars_for_defs(
self.type_vars_for_defs(
self.span,
subst::FnSpace,
&mut final_substs,
method_types);
} else if num_supplied_types != num_method_types {
span_err!(self.tcx().sess, self.span, E0036,
span_err!(self.tcx.sess, self.span, E0036,
"incorrect number of type parameters given for this method: expected {}, found {}",
num_method_types, num_supplied_types);
final_substs.types.replace(
subst::FnSpace,
vec![self.tcx().types.err; num_method_types]);
vec![self.tcx.types.err; num_method_types]);
} else {
final_substs.types.replace(subst::FnSpace, supplied_method_types);
}
@ -369,8 +376,8 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
self_ty: Ty<'tcx>,
method_self_ty: Ty<'tcx>)
{
match self.fcx.infcx().sub_types(false, TypeOrigin::Misc(self.span),
self_ty, method_self_ty) {
match self.sub_types(false, TypeOrigin::Misc(self.span),
self_ty, method_self_ty) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());
@ -400,9 +407,9 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// type/early-bound-regions substitutions performed. There can
// be no late-bound regions appearing here.
let method_predicates = pick.item.as_opt_method().unwrap()
.predicates.instantiate(self.tcx(), &all_substs);
let method_predicates = self.fcx.normalize_associated_types_in(self.span,
&method_predicates);
.predicates.instantiate(self.tcx, &all_substs);
let method_predicates = self.normalize_associated_types_in(self.span,
&method_predicates);
debug!("method_predicates after subst = {:?}",
method_predicates);
@ -418,7 +425,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
debug!("late-bound lifetimes from method instantiated, method_sig={:?}",
method_sig);
let method_sig = self.fcx.instantiate_type_scheme(self.span, &all_substs, &method_sig);
let method_sig = self.instantiate_type_scheme(self.span, &all_substs, &method_sig);
debug!("type scheme substituted, method_sig={:?}",
method_sig);
@ -438,20 +445,18 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
all_substs,
method_predicates);
self.fcx.add_obligations_for_parameters(
traits::ObligationCause::misc(self.span, self.fcx.body_id),
self.add_obligations_for_parameters(
traits::ObligationCause::misc(self.span, self.body_id),
method_predicates);
// this is a projection from a trait reference, so we have to
// make sure that the trait reference inputs are well-formed.
self.fcx.add_wf_bounds(
all_substs,
self.call_expr);
self.add_wf_bounds(all_substs, self.call_expr);
// the function type must also be well-formed (this is not
// implied by the substs being well-formed because of inherent
// impls and late-bound regions - see issue #28609).
self.fcx.register_wf_obligation(fty, self.span, traits::MiscObligation);
self.register_wf_obligation(fty, self.span, traits::MiscObligation);
}
///////////////////////////////////////////////////////////////////////////
@ -495,9 +500,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// Fix up autoderefs and derefs.
for (i, &expr) in exprs.iter().rev().enumerate() {
// Count autoderefs.
let autoderef_count = match self.fcx
.inh
.tables
let autoderef_count = match self.tables
.borrow()
.adjustments
.get(&expr.id) {
@ -510,12 +513,12 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
i, expr, autoderef_count);
if autoderef_count > 0 {
self.fcx.autoderef(expr.span,
self.fcx.expr_ty(expr),
|| Some(expr),
UnresolvedTypeAction::Error,
PreferMutLvalue,
|_, autoderefs| {
self.autoderef(expr.span,
self.expr_ty(expr),
|| Some(expr),
UnresolvedTypeAction::Error,
PreferMutLvalue,
|_, autoderefs| {
if autoderefs == autoderef_count + 1 {
Some(())
} else {
@ -538,8 +541,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
// expects. This is annoying and horrible. We
// ought to recode this routine so it doesn't
// (ab)use the normal type checking paths.
let adj = self.fcx.inh.tables.borrow().adjustments.get(&base_expr.id)
.cloned();
let adj = self.tables.borrow().adjustments.get(&base_expr.id).cloned();
let (autoderefs, unsize) = match adj {
Some(AdjustDerefRef(adr)) => match adr.autoref {
None => {
@ -570,16 +572,16 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
let (adjusted_base_ty, unsize) = if let Some(target) = unsize {
(target, true)
} else {
(self.fcx.adjust_expr_ty(base_expr,
(self.adjust_expr_ty(base_expr,
Some(&AdjustDerefRef(AutoDerefRef {
autoderefs: autoderefs,
autoref: None,
unsize: None
}))), false)
};
let index_expr_ty = self.fcx.expr_ty(&index_expr);
let index_expr_ty = self.expr_ty(&index_expr);
let result = self.fcx.try_index_step(
let result = self.try_index_step(
ty::MethodCall::expr(expr.id),
expr,
&base_expr,
@ -590,23 +592,23 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
index_expr_ty);
if let Some((input_ty, return_ty)) = result {
self.fcx.demand_suptype(index_expr.span, input_ty, index_expr_ty);
self.demand_suptype(index_expr.span, input_ty, index_expr_ty);
let expr_ty = self.fcx.expr_ty(&expr);
self.fcx.demand_suptype(expr.span, expr_ty, return_ty);
let expr_ty = self.expr_ty(&expr);
self.demand_suptype(expr.span, expr_ty, return_ty);
}
}
hir::ExprUnary(hir::UnDeref, ref base_expr) => {
// if this is an overloaded deref, then re-evaluate with
// a preference for mut
let method_call = ty::MethodCall::expr(expr.id);
if self.fcx.inh.tables.borrow().method_map.contains_key(&method_call) {
let method = self.fcx.try_overloaded_deref(expr.span,
if self.tables.borrow().method_map.contains_key(&method_call) {
let method = self.try_overloaded_deref(expr.span,
Some(&base_expr),
self.fcx.expr_ty(&base_expr),
self.expr_ty(&base_expr),
PreferMutLvalue);
let method = method.expect("re-trying deref failed");
self.fcx.inh.tables.borrow_mut().method_map.insert(method_call, method);
self.tables.borrow_mut().method_map.insert(method_call, method);
}
}
_ => {}
@ -617,19 +619,11 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
///////////////////////////////////////////////////////////////////////////
// MISCELLANY
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.fcx.tcx()
}
fn infcx(&self) -> &'a InferCtxt<'a, 'tcx, 'tcx> {
self.fcx.infcx()
}
fn enforce_illegal_method_limitations(&self, pick: &probe::Pick) {
// Disallow calls to the method `drop` defined in the `Drop` trait.
match pick.item.container() {
ty::TraitContainer(trait_def_id) => {
callee::check_legal_trait_for_method_call(self.fcx.ccx, self.span, trait_def_id)
callee::check_legal_trait_for_method_call(self.ccx, self.span, trait_def_id)
}
ty::ImplContainer(..) => {}
}
@ -640,8 +634,8 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
target_trait_def_id: DefId)
-> ty::PolyTraitRef<'tcx>
{
let upcast_trait_refs = self.tcx().upcast_choices(source_trait_ref.clone(),
target_trait_def_id);
let upcast_trait_refs = self.tcx.upcast_choices(source_trait_ref.clone(),
target_trait_def_id);
// must be exactly one trait ref or we'd get an ambig error etc
if upcast_trait_refs.len() != 1 {
@ -659,7 +653,7 @@ impl<'a,'tcx> ConfirmContext<'a,'tcx, 'tcx> {
fn replace_late_bound_regions_with_fresh_var<T>(&self, value: &ty::Binder<T>) -> T
where T : TypeFoldable<'tcx>
{
self.infcx().replace_late_bound_regions_with_fresh_var(
self.fcx.replace_late_bound_regions_with_fresh_var(
self.span, infer::FnCall, value).0
}
}

View file

@ -127,11 +127,11 @@ pub fn lookup_method(&self,
self_expr);
let mode = probe::Mode::MethodCall;
let self_ty = self.infcx().resolve_type_vars_if_possible(&self_ty);
let self_ty = self.resolve_type_vars_if_possible(&self_ty);
let pick = self.probe_method(span, mode, method_name, self_ty, call_expr.id)?;
if let Some(import_id) = pick.import_id {
self.tcx().used_trait_imports.borrow_mut().insert(import_id);
self.tcx.used_trait_imports.borrow_mut().insert(import_id);
}
Ok(self.confirm_method(span, self_expr, call_expr, self_ty, pick, supplied_method_types))
@ -176,7 +176,7 @@ pub fn lookup_method_in_trait_adjusted(&self,
m_name,
trait_def_id);
let trait_def = self.tcx().lookup_trait_def(trait_def_id);
let trait_def = self.tcx.lookup_trait_def(trait_def_id);
let type_parameter_defs = trait_def.generics.types.get_slice(subst::TypeSpace);
let expected_number_of_input_types = type_parameter_defs.len();
@ -194,7 +194,7 @@ pub fn lookup_method_in_trait_adjusted(&self,
}
None => {
self.inh.infcx.type_vars_for_defs(
self.type_vars_for_defs(
span,
subst::ParamSpace::TypeSpace,
&mut substs,
@ -202,7 +202,7 @@ pub fn lookup_method_in_trait_adjusted(&self,
}
}
let trait_ref = ty::TraitRef::new(trait_def_id, self.tcx().mk_substs(substs));
let trait_ref = ty::TraitRef::new(trait_def_id, self.tcx.mk_substs(substs));
// Construct an obligation
let poly_trait_ref = trait_ref.to_poly_trait_ref();
@ -211,7 +211,7 @@ pub fn lookup_method_in_trait_adjusted(&self,
poly_trait_ref.to_predicate());
// Now we want to know if this can be matched
let mut selcx = traits::SelectionContext::new(self.infcx());
let mut selcx = traits::SelectionContext::new(self);
if !selcx.evaluate_obligation(&obligation) {
debug!("--> Cannot match obligation");
return None; // Cannot be matched, no such method resolution is possible.
@ -219,7 +219,7 @@ pub fn lookup_method_in_trait_adjusted(&self,
// Trait must have a method named `m_name` and it should not have
// type parameters or early-bound regions.
let tcx = self.tcx();
let tcx = self.tcx;
let method_item = self.trait_item(trait_def_id, m_name).unwrap();
let method_ty = method_item.as_opt_method().unwrap();
assert_eq!(method_ty.generics.types.len(subst::FnSpace), 0);
@ -234,9 +234,9 @@ pub fn lookup_method_in_trait_adjusted(&self,
// NB: Instantiate late-bound regions first so that
// `instantiate_type_scheme` can normalize associated types that
// may reference those regions.
let fn_sig = self.infcx().replace_late_bound_regions_with_fresh_var(span,
infer::FnCall,
&method_ty.fty.sig).0;
let fn_sig = self.replace_late_bound_regions_with_fresh_var(span,
infer::FnCall,
&method_ty.fty.sig).0;
let fn_sig = self.instantiate_type_scheme(span, trait_ref.substs, &fn_sig);
let transformed_self_ty = fn_sig.inputs[0];
let def_id = method_item.def_id();
@ -347,14 +347,14 @@ pub fn resolve_ufcs(&self,
let pick = self.probe_method(span, mode, method_name, self_ty, expr_id)?;
if let Some(import_id) = pick.import_id {
self.tcx().used_trait_imports.borrow_mut().insert(import_id);
self.tcx.used_trait_imports.borrow_mut().insert(import_id);
}
let def = pick.item.def();
if let probe::InherentImplPick = pick.kind {
if !pick.item.vis().is_accessible_from(self.body_id, &self.tcx().map) {
if !pick.item.vis().is_accessible_from(self.body_id, &self.tcx.map) {
let msg = format!("{} `{}` is private", def.kind_name(), &method_name.as_str());
self.tcx().sess.span_err(span, &msg);
self.tcx.sess.span_err(span, &msg);
}
}
Ok(def)
@ -367,7 +367,7 @@ pub fn trait_item(&self,
item_name: ast::Name)
-> Option<ty::ImplOrTraitItem<'tcx>>
{
let trait_items = self.tcx().trait_items(trait_def_id);
let trait_items = self.tcx.trait_items(trait_def_id);
trait_items.iter()
.find(|item| item.name() == item_name)
.cloned()
@ -378,11 +378,11 @@ pub fn impl_item(&self,
item_name: ast::Name)
-> Option<ty::ImplOrTraitItem<'tcx>>
{
let impl_items = self.tcx().impl_items.borrow();
let impl_items = self.tcx.impl_items.borrow();
let impl_items = impl_items.get(&impl_def_id).unwrap();
impl_items
.iter()
.map(|&did| self.tcx().impl_or_trait_item(did.def_id()))
.map(|&did| self.tcx.impl_or_trait_item(did.def_id()))
.find(|m| m.name() == item_name)
}
}

View file

@ -19,13 +19,14 @@ use hir::def::Def;
use rustc::ty::subst;
use rustc::ty::subst::Subst;
use rustc::traits;
use rustc::ty::{self, NoPreference, Ty, TyCtxt, ToPolyTraitRef, TraitRef, TypeFoldable};
use rustc::infer::{self, InferCtxt, InferOk, TypeOrigin};
use rustc::ty::{self, NoPreference, Ty, ToPolyTraitRef, TraitRef, TypeFoldable};
use rustc::infer::{InferOk, TypeOrigin};
use syntax::ast;
use syntax::codemap::{Span, DUMMY_SP};
use rustc::hir;
use std::collections::HashSet;
use std::mem;
use std::ops::Deref;
use std::rc::Rc;
use self::CandidateKind::*;
@ -55,6 +56,13 @@ struct ProbeContext<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
unsatisfied_predicates: Vec<TraitRef<'tcx>>
}
impl<'a, 'gcx, 'tcx> Deref for ProbeContext<'a, 'gcx, 'tcx> {
type Target = FnCtxt<'a, 'gcx, 'tcx>;
fn deref(&self) -> &Self::Target {
&self.fcx
}
}
#[derive(Debug)]
struct CandidateStep<'tcx> {
self_ty: Ty<'tcx>,
@ -148,7 +156,7 @@ pub fn probe_method(&self,
// side-effects. This is a bit of a pain to refactor. So just let
// it ride, although it's really not great, and in fact could I
// think cause spurious errors. Really though this part should
// take place in the `self.infcx().probe` below.
// take place in the `self.probe` below.
let steps = if mode == Mode::MethodCall {
match self.create_steps(span, self_ty) {
Some(steps) => steps,
@ -166,7 +174,7 @@ pub fn probe_method(&self,
// Create a list of simplified self types, if we can.
let mut simplified_steps = Vec::new();
for step in &steps {
match ty::fast_reject::simplify_type(self.tcx(), step.self_ty, true) {
match ty::fast_reject::simplify_type(self.tcx, step.self_ty, true) {
None => { break; }
Some(simplified_type) => { simplified_steps.push(simplified_type); }
}
@ -184,7 +192,7 @@ pub fn probe_method(&self,
// this creates one big transaction so that all type variables etc
// that we create during the probe process are removed later
self.infcx().probe(|_| {
self.probe(|_| {
let mut probe_cx = ProbeContext::new(self,
span,
mode,
@ -220,7 +228,7 @@ fn create_steps(&self,
match final_ty.sty {
ty::TyArray(elem_ty, _) => {
steps.push(CandidateStep {
self_ty: self.tcx().mk_slice(elem_ty),
self_ty: self.tcx.mk_slice(elem_ty),
autoderefs: dereferences,
unsize: true
});
@ -267,14 +275,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
self.private_candidate = None;
}
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.fcx.tcx()
}
fn infcx(&self) -> &'a InferCtxt<'a, 'tcx, 'tcx> {
self.fcx.infcx()
}
///////////////////////////////////////////////////////////////////////////
// CANDIDATE ASSEMBLY
@ -299,7 +299,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
self.assemble_inherent_impl_candidates_for_type(def.did);
}
ty::TyBox(_) => {
if let Some(box_did) = self.tcx().lang_items.owned_box() {
if let Some(box_did) = self.tcx.lang_items.owned_box() {
self.assemble_inherent_impl_candidates_for_type(box_did);
}
}
@ -307,71 +307,71 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
self.assemble_inherent_candidates_from_param(self_ty, p);
}
ty::TyChar => {
let lang_def_id = self.tcx().lang_items.char_impl();
let lang_def_id = self.tcx.lang_items.char_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyStr => {
let lang_def_id = self.tcx().lang_items.str_impl();
let lang_def_id = self.tcx.lang_items.str_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TySlice(_) => {
let lang_def_id = self.tcx().lang_items.slice_impl();
let lang_def_id = self.tcx.lang_items.slice_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutImmutable }) => {
let lang_def_id = self.tcx().lang_items.const_ptr_impl();
let lang_def_id = self.tcx.lang_items.const_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyRawPtr(ty::TypeAndMut { ty: _, mutbl: hir::MutMutable }) => {
let lang_def_id = self.tcx().lang_items.mut_ptr_impl();
let lang_def_id = self.tcx.lang_items.mut_ptr_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyInt(ast::IntTy::I8) => {
let lang_def_id = self.tcx().lang_items.i8_impl();
let lang_def_id = self.tcx.lang_items.i8_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyInt(ast::IntTy::I16) => {
let lang_def_id = self.tcx().lang_items.i16_impl();
let lang_def_id = self.tcx.lang_items.i16_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyInt(ast::IntTy::I32) => {
let lang_def_id = self.tcx().lang_items.i32_impl();
let lang_def_id = self.tcx.lang_items.i32_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyInt(ast::IntTy::I64) => {
let lang_def_id = self.tcx().lang_items.i64_impl();
let lang_def_id = self.tcx.lang_items.i64_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyInt(ast::IntTy::Is) => {
let lang_def_id = self.tcx().lang_items.isize_impl();
let lang_def_id = self.tcx.lang_items.isize_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyUint(ast::UintTy::U8) => {
let lang_def_id = self.tcx().lang_items.u8_impl();
let lang_def_id = self.tcx.lang_items.u8_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyUint(ast::UintTy::U16) => {
let lang_def_id = self.tcx().lang_items.u16_impl();
let lang_def_id = self.tcx.lang_items.u16_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyUint(ast::UintTy::U32) => {
let lang_def_id = self.tcx().lang_items.u32_impl();
let lang_def_id = self.tcx.lang_items.u32_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyUint(ast::UintTy::U64) => {
let lang_def_id = self.tcx().lang_items.u64_impl();
let lang_def_id = self.tcx.lang_items.u64_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyUint(ast::UintTy::Us) => {
let lang_def_id = self.tcx().lang_items.usize_impl();
let lang_def_id = self.tcx.lang_items.usize_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyFloat(ast::FloatTy::F32) => {
let lang_def_id = self.tcx().lang_items.f32_impl();
let lang_def_id = self.tcx.lang_items.f32_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
ty::TyFloat(ast::FloatTy::F64) => {
let lang_def_id = self.tcx().lang_items.f64_impl();
let lang_def_id = self.tcx.lang_items.f64_impl();
self.assemble_inherent_impl_for_primitive(lang_def_id);
}
_ => {
@ -381,7 +381,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
fn assemble_inherent_impl_for_primitive(&mut self, lang_def_id: Option<DefId>) {
if let Some(impl_def_id) = lang_def_id {
self.tcx().populate_implementations_for_primitive_if_necessary(impl_def_id);
self.tcx.populate_implementations_for_primitive_if_necessary(impl_def_id);
self.assemble_inherent_impl_probe(impl_def_id);
}
@ -390,9 +390,9 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId) {
// Read the inherent implementation candidates for this type from the
// metadata if necessary.
self.tcx().populate_inherent_implementations_for_type_if_necessary(def_id);
self.tcx.populate_inherent_implementations_for_type_if_necessary(def_id);
if let Some(impl_infos) = self.tcx().inherent_impls.borrow().get(&def_id) {
if let Some(impl_infos) = self.tcx.inherent_impls.borrow().get(&def_id) {
for &impl_def_id in impl_infos.iter() {
self.assemble_inherent_impl_probe(impl_def_id);
}
@ -416,21 +416,21 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
return self.record_static_candidate(ImplSource(impl_def_id));
}
if !item.vis().is_accessible_from(self.fcx.body_id, &self.tcx().map) {
if !item.vis().is_accessible_from(self.body_id, &self.tcx.map) {
self.private_candidate = Some(item.def());
return
}
let (impl_ty, impl_substs) = self.impl_ty_and_substs(impl_def_id);
let impl_ty = impl_ty.subst(self.tcx(), &impl_substs);
let impl_ty = impl_ty.subst(self.tcx, &impl_substs);
// Determine the receiver type that the method itself expects.
let xform_self_ty = self.xform_self_ty(&item, impl_ty, &impl_substs);
// We can't use normalize_associated_types_in as it will pollute the
// fcx's fulfillment context after this probe is over.
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx());
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let mut selcx = &mut traits::SelectionContext::new(self.fcx);
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, cause, &xform_self_ty);
debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
@ -457,7 +457,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
// a substitution that replaces `Self` with the object type
// itself. Hence, a `&self` method will wind up with an
// argument type like `&Trait`.
let trait_ref = data.principal_trait_ref_with_self_ty(self.tcx(), self_ty);
let trait_ref = data.principal_trait_ref_with_self_ty(self.tcx, self_ty);
self.elaborate_bounds(&[trait_ref], |this, new_trait_ref, item| {
let new_trait_ref = this.erase_late_bound_regions(&new_trait_ref);
@ -480,7 +480,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
// FIXME -- Do we want to commit to this behavior for param bounds?
let bounds: Vec<_> =
self.fcx.inh.infcx.parameter_environment.caller_bounds
self.parameter_environment.caller_bounds
.iter()
.filter_map(|predicate| {
match *predicate {
@ -561,7 +561,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
{
debug!("elaborate_bounds(bounds={:?})", bounds);
let tcx = self.tcx();
let tcx = self.tcx;
for bound_trait_ref in traits::transitive_bounds(tcx, bounds) {
let item = match self.trait_item(bound_trait_ref.def_id()) {
Some(v) => v,
@ -581,7 +581,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
-> Result<(), MethodError<'tcx>>
{
let mut duplicates = HashSet::new();
let opt_applicable_traits = self.fcx.ccx.trait_map.get(&expr_id);
let opt_applicable_traits = self.ccx.trait_map.get(&expr_id);
if let Some(applicable_traits) = opt_applicable_traits {
for trait_candidate in applicable_traits {
let trait_did = trait_candidate.def_id;
@ -598,7 +598,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
fn assemble_extension_candidates_for_all_traits(&mut self) -> Result<(), MethodError<'tcx>> {
let mut duplicates = HashSet::new();
for trait_info in suggest::all_traits(self.fcx.ccx) {
for trait_info in suggest::all_traits(self.ccx) {
if duplicates.insert(trait_info.def_id) {
self.assemble_extension_candidates_for_trait(trait_info.def_id)?;
}
@ -615,7 +615,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
// Check whether `trait_def_id` defines a method with suitable name:
let trait_items =
self.tcx().trait_items(trait_def_id);
self.tcx.trait_items(trait_def_id);
let maybe_item =
trait_items.iter()
.find(|item| item.name() == self.item_name);
@ -646,10 +646,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
trait_def_id: DefId,
item: ty::ImplOrTraitItem<'tcx>)
{
let trait_def = self.tcx().lookup_trait_def(trait_def_id);
let trait_def = self.tcx.lookup_trait_def(trait_def_id);
// FIXME(arielb1): can we use for_each_relevant_impl here?
trait_def.for_each_impl(self.tcx(), |impl_def_id| {
trait_def.for_each_impl(self.tcx, |impl_def_id| {
debug!("assemble_extension_candidates_for_trait_impl: trait_def_id={:?} \
impl_def_id={:?}",
trait_def_id,
@ -664,9 +664,9 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
debug!("impl_substs={:?}", impl_substs);
let impl_trait_ref =
self.tcx().impl_trait_ref(impl_def_id)
self.tcx.impl_trait_ref(impl_def_id)
.unwrap() // we know this is a trait impl
.subst(self.tcx(), &impl_substs);
.subst(self.tcx, &impl_substs);
debug!("impl_trait_ref={:?}", impl_trait_ref);
@ -679,8 +679,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
// Normalize the receiver. We can't use normalize_associated_types_in
// as it will pollute the fcx's fulfillment context after this probe
// is over.
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx());
let cause = traits::ObligationCause::misc(self.span, self.body_id);
let mut selcx = &mut traits::SelectionContext::new(self.fcx);
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, cause, &xform_self_ty);
@ -701,9 +701,9 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
None => { return true; }
};
let impl_type = self.tcx().lookup_item_type(impl_def_id);
let impl_type = self.tcx.lookup_item_type(impl_def_id);
let impl_simplified_type =
match ty::fast_reject::simplify_type(self.tcx(), impl_type.ty, false) {
match ty::fast_reject::simplify_type(self.tcx, impl_type.ty, false) {
Some(simplified_type) => simplified_type,
None => { return true; }
};
@ -717,7 +717,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
-> Result<(), MethodError<'tcx>>
{
// Check if this is one of the Fn,FnMut,FnOnce traits.
let tcx = self.tcx();
let tcx = self.tcx;
let kind = if Some(trait_def_id) == tcx.lang_items.fn_trait() {
ty::ClosureKind::Fn
} else if Some(trait_def_id) == tcx.lang_items.fn_mut_trait() {
@ -737,7 +737,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
_ => continue,
};
let closure_kinds = &self.fcx.inh.tables.borrow().closure_kinds;
let closure_kinds = &self.tables.borrow().closure_kinds;
let closure_kind = match closure_kinds.get(&closure_def_id) {
Some(&k) => k,
None => {
@ -754,10 +754,10 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
// for the purposes of our method lookup, we only take
// receiver type into account, so we can just substitute
// fresh types here to use during substitution and subtyping.
let trait_def = self.tcx().lookup_trait_def(trait_def_id);
let substs = self.infcx().fresh_substs_for_trait(self.span,
&trait_def.generics,
step.self_ty);
let trait_def = self.tcx.lookup_trait_def(trait_def_id);
let substs = self.fresh_substs_for_trait(self.span,
&trait_def.generics,
step.self_ty);
let xform_self_ty = self.xform_self_ty(&item,
step.self_ty,
@ -795,13 +795,13 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
debug!("assemble_projection_candidates: projection_trait_ref={:?}",
projection_trait_ref);
let trait_predicates = self.tcx().lookup_predicates(projection_trait_ref.def_id);
let bounds = trait_predicates.instantiate(self.tcx(), projection_trait_ref.substs);
let trait_predicates = self.tcx.lookup_predicates(projection_trait_ref.def_id);
let bounds = trait_predicates.instantiate(self.tcx, projection_trait_ref.substs);
let predicates = bounds.predicates.into_vec();
debug!("assemble_projection_candidates: predicates={:?}",
predicates);
for poly_bound in
traits::elaborate_predicates(self.tcx(), predicates)
traits::elaborate_predicates(self.tcx, predicates)
.filter_map(|p| p.to_opt_poly_trait_ref())
.filter(|b| b.def_id() == trait_def_id)
{
@ -811,7 +811,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
projection_trait_ref,
bound);
if self.infcx().can_equate(&step.self_ty, &bound.self_ty()).is_ok() {
if self.can_equate(&step.self_ty, &bound.self_ty()).is_ok() {
let xform_self_ty = self.xform_self_ty(&item,
bound.self_ty(),
bound.substs);
@ -838,8 +838,8 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
debug!("assemble_where_clause_candidates(trait_def_id={:?})",
trait_def_id);
let caller_predicates = self.fcx.inh.infcx.parameter_environment.caller_bounds.clone();
for poly_bound in traits::elaborate_predicates(self.tcx(), caller_predicates)
let caller_predicates = self.parameter_environment.caller_bounds.clone();
for poly_bound in traits::elaborate_predicates(self.tcx, caller_predicates)
.filter_map(|p| p.to_opt_poly_trait_ref())
.filter(|b| b.def_id() == trait_def_id)
{
@ -878,7 +878,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
self.reset();
let span = self.span;
let tcx = self.tcx();
let tcx = self.tcx;
self.assemble_extension_candidates_for_all_traits()?;
@ -973,7 +973,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
step: &CandidateStep<'tcx>)
-> Option<PickResult<'tcx>>
{
let tcx = self.tcx();
let tcx = self.tcx;
// In general, during probing we erase regions. See
// `impl_self_ty()` for an explanation.
@ -999,7 +999,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
}
fn pick_method(&mut self, self_ty: Ty<'tcx>) -> Option<PickResult<'tcx>> {
debug!("pick_method(self_ty={})", self.infcx().ty_to_string(self_ty));
debug!("pick_method(self_ty={})", self.ty_to_string(self_ty));
let mut possibly_unsatisfied_predicates = Vec::new();
@ -1057,10 +1057,14 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
self_ty,
probe);
self.infcx().probe(|_| {
self.probe(|_| {
// First check that the self type can be related.
match self.make_sub_ty(self_ty, probe.xform_self_ty) {
Ok(()) => { }
match self.sub_types(false, TypeOrigin::Misc(DUMMY_SP),
self_ty, probe.xform_self_ty) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty())
}
Err(_) => {
debug!("--> cannot relate self-types");
return false;
@ -1088,12 +1092,12 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
}
};
let selcx = &mut traits::SelectionContext::new(self.infcx());
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
let selcx = &mut traits::SelectionContext::new(self);
let cause = traits::ObligationCause::misc(self.span, self.body_id);
// Check whether the impl imposes obligations we have to worry about.
let impl_bounds = self.tcx().lookup_predicates(impl_def_id);
let impl_bounds = impl_bounds.instantiate(self.tcx(), substs);
let impl_bounds = self.tcx.lookup_predicates(impl_def_id);
let impl_bounds = impl_bounds.instantiate(self.tcx, substs);
let traits::Normalized { value: impl_bounds,
obligations: norm_obligations } =
traits::normalize(selcx, cause.clone(), &impl_bounds);
@ -1163,13 +1167,6 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
///////////////////////////////////////////////////////////////////////////
// MISCELLANY
fn make_sub_ty(&self, sub: Ty<'tcx>, sup: Ty<'tcx>) -> infer::UnitResult<'tcx> {
self.infcx().sub_types(false, TypeOrigin::Misc(DUMMY_SP), sub, sup)
// FIXME(#32730) propagate obligations
.map(|InferOk { obligations, .. }| assert!(obligations.is_empty()))
}
fn has_applicable_self(&self, item: &ty::ImplOrTraitItem) -> bool {
// "fast track" -- check for usage of sugar
match *item {
@ -1249,7 +1246,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
placeholder = (*substs).clone().with_method(Vec::new(), method_regions);
self.infcx().type_vars_for_defs(
self.type_vars_for_defs(
self.span,
subst::FnSpace,
&mut placeholder,
@ -1262,7 +1259,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
// in the values from the substitution.
let xform_self_ty = method.fty.sig.input(0);
let xform_self_ty = self.erase_late_bound_regions(&xform_self_ty);
let xform_self_ty = xform_self_ty.subst(self.tcx(), substs);
let xform_self_ty = xform_self_ty.subst(self.tcx, substs);
xform_self_ty
}
@ -1272,11 +1269,11 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
impl_def_id: DefId)
-> (Ty<'tcx>, subst::Substs<'tcx>)
{
let impl_pty = self.tcx().lookup_item_type(impl_def_id);
let impl_pty = self.tcx.lookup_item_type(impl_def_id);
let type_vars =
impl_pty.generics.types.map(
|_| self.infcx().next_ty_var());
|_| self.next_ty_var());
let region_placeholders =
impl_pty.generics.regions.map(
@ -1307,7 +1304,7 @@ impl<'a,'tcx> ProbeContext<'a,'tcx, 'tcx> {
fn erase_late_bound_regions<T>(&self, value: &ty::Binder<T>) -> T
where T : TypeFoldable<'tcx>
{
self.tcx().erase_late_bound_regions(value)
self.tcx.erase_late_bound_regions(value)
}
fn impl_item(&self, impl_def_id: DefId)

View file

@ -41,7 +41,7 @@ use super::probe::Mode;
impl<'a, 'tcx> FnCtxt<'a, 'tcx, 'tcx> {
fn is_fn_ty(&self, ty: &Ty<'tcx>, span: Span) -> bool {
let tcx = self.tcx();
let tcx = self.tcx;
match ty.sty {
// Not all of these (e.g. unsafe fns) implement FnOnce
// so we look for these beforehand
@ -50,16 +50,15 @@ fn is_fn_ty(&self, ty: &Ty<'tcx>, span: Span) -> bool {
_ => {
if let Ok(fn_once_trait_did) =
tcx.lang_items.require(FnOnceTraitLangItem) {
let infcx = self.infcx();
let (_, _, opt_is_fn) = self.autoderef(span,
ty,
|| None,
UnresolvedTypeAction::Ignore,
LvaluePreference::NoPreference,
|ty, _| {
infcx.probe(|_| {
self.probe(|_| {
let fn_once_substs =
Substs::new_trait(vec![infcx.next_ty_var()], vec![], ty);
Substs::new_trait(vec![self.next_ty_var()], vec![], ty);
let trait_ref =
ty::TraitRef::new(fn_once_trait_did,
tcx.mk_substs(fn_once_substs));
@ -68,7 +67,7 @@ fn is_fn_ty(&self, ty: &Ty<'tcx>, span: Span) -> bool {
self.body_id,
poly_trait_ref
.to_predicate());
let mut selcx = SelectionContext::new(infcx);
let mut selcx = SelectionContext::new(self);
if selcx.evaluate_obligation(&obligation) {
Some(())
@ -111,22 +110,22 @@ pub fn report_method_error(&self,
let item = self.impl_item(impl_did, item_name)
.or_else(|| {
self.trait_item(
self.tcx().impl_trait_ref(impl_did).unwrap().def_id,
self.tcx.impl_trait_ref(impl_did).unwrap().def_id,
item_name
)
}).unwrap();
let note_span = self.tcx().map.span_if_local(item.def_id()).or_else(|| {
self.tcx().map.span_if_local(impl_did)
let note_span = self.tcx.map.span_if_local(item.def_id()).or_else(|| {
self.tcx.map.span_if_local(impl_did)
});
let impl_ty = self.impl_self_ty(span, impl_did).ty;
let insertion = match self.tcx().impl_trait_ref(impl_did) {
let insertion = match self.tcx.impl_trait_ref(impl_did) {
None => format!(""),
Some(trait_ref) => {
format!(" of the trait `{}`",
self.tcx().item_path_str(trait_ref.def_id))
self.tcx.item_path_str(trait_ref.def_id))
}
};
@ -144,11 +143,11 @@ pub fn report_method_error(&self,
}
CandidateSource::TraitSource(trait_did) => {
let item = self.trait_item(trait_did, item_name).unwrap();
let item_span = self.tcx().map.def_id_span(item.def_id(), span);
let item_span = self.tcx.map.def_id_span(item.def_id(), span);
span_note!(err, item_span,
"candidate #{} is defined in the trait `{}`",
idx + 1,
self.tcx().item_path_str(trait_did));
self.tcx.item_path_str(trait_did));
}
}
}
@ -159,7 +158,7 @@ pub fn report_method_error(&self,
unsatisfied_predicates,
out_of_scope_traits,
mode, .. }) => {
let tcx = self.tcx();
let tcx = self.tcx;
let mut err = self.type_error_struct(
span,
@ -258,7 +257,7 @@ pub fn report_method_error(&self,
invoked on this closure as we have not yet inferred what \
kind of closure it is",
item_name,
self.tcx().item_path_str(trait_def_id));
self.tcx.item_path_str(trait_def_id));
let msg = if let Some(callee) = rcvr_expr {
format!("{}; use overloaded call notation instead (e.g., `{}()`)",
msg, pprust::expr_to_string(callee))
@ -270,7 +269,7 @@ pub fn report_method_error(&self,
MethodError::PrivateMatch(def) => {
let msg = format!("{} `{}` is private", def.kind_name(), item_name);
self.tcx().sess.span_err(span, &msg);
self.tcx.sess.span_err(span, &msg);
}
}
}
@ -299,7 +298,7 @@ fn suggest_traits_to_import(&self,
for (i, trait_did) in candidates.iter().enumerate() {
err.help(&format!("candidate #{}: `use {}`",
i + 1,
self.tcx().item_path_str(*trait_did)));
self.tcx.item_path_str(*trait_did)));
}
return
}
@ -343,7 +342,7 @@ fn suggest_traits_to_import(&self,
for (i, trait_info) in candidates.iter().enumerate() {
err.help(&format!("candidate #{}: `{}`",
i + 1,
self.tcx().item_path_str(trait_info.def_id)));
self.tcx.item_path_str(trait_info.def_id)));
}
}
}
@ -373,7 +372,7 @@ fn type_derefs_to_local(&self,
// This occurs for UFCS desugaring of `T::method`, where there is no
// receiver expression for the method call, and thus no autoderef.
if rcvr_expr.is_none() {
return is_local(self.resolve_type_vars_if_possible(rcvr_ty));
return is_local(self.resolve_type_vars_with_obligations(rcvr_ty));
}
self.autoderef(span, rcvr_ty, || None,

File diff suppressed because it is too large Load diff

View file

@ -27,10 +27,10 @@ pub fn check_binop_assign(&self,
{
self.check_expr_with_lvalue_pref(lhs_expr, PreferMutLvalue);
let lhs_ty = self.resolve_type_vars_if_possible(self.expr_ty(lhs_expr));
let lhs_ty = self.resolve_type_vars_with_obligations(self.expr_ty(lhs_expr));
let (rhs_ty, return_ty) =
self.check_overloaded_binop(expr, lhs_expr, lhs_ty, rhs_expr, op, IsAssign::Yes);
let rhs_ty = self.resolve_type_vars_if_possible(rhs_ty);
let rhs_ty = self.resolve_type_vars_with_obligations(rhs_ty);
if !lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() && is_builtin_binop(lhs_ty, rhs_ty, op) {
self.enforce_builtin_binop_types(lhs_expr, lhs_ty, rhs_expr, rhs_ty, op);
@ -39,7 +39,7 @@ pub fn check_binop_assign(&self,
self.write_ty(expr.id, return_ty);
}
let tcx = self.tcx();
let tcx = self.tcx;
if !tcx.expr_is_lval(lhs_expr) {
span_err!(tcx.sess, lhs_expr.span, E0067, "invalid left-hand side expression");
}
@ -52,7 +52,7 @@ pub fn check_binop(&self,
lhs_expr: &'tcx hir::Expr,
rhs_expr: &'tcx hir::Expr)
{
let tcx = self.tcx();
let tcx = self.tcx;
debug!("check_binop(expr.id={}, expr={:?}, op={:?}, lhs_expr={:?}, rhs_expr={:?})",
expr.id,
@ -62,7 +62,7 @@ pub fn check_binop(&self,
rhs_expr);
self.check_expr(lhs_expr);
let lhs_ty = self.resolve_type_vars_if_possible(self.expr_ty(lhs_expr));
let lhs_ty = self.resolve_type_vars_with_obligations(self.expr_ty(lhs_expr));
match BinOpCategory::from(op) {
BinOpCategory::Shortcircuit => {
@ -90,7 +90,7 @@ pub fn check_binop(&self,
// deduce that the result type should be `u32`, even
// though we don't know yet what type 2 has and hence
// can't pin this down to a specific impl.
let rhs_ty = self.resolve_type_vars_if_possible(rhs_ty);
let rhs_ty = self.resolve_type_vars_with_obligations(rhs_ty);
if
!lhs_ty.is_ty_var() && !rhs_ty.is_ty_var() &&
is_builtin_binop(lhs_ty, rhs_ty, op)
@ -115,7 +115,7 @@ fn enforce_builtin_binop_types(&self,
{
debug_assert!(is_builtin_binop(lhs_ty, rhs_ty, op));
let tcx = self.tcx();
let tcx = self.tcx;
match BinOpCategory::from(op) {
BinOpCategory::Shortcircuit => {
self.demand_suptype(lhs_expr.span, tcx.mk_bool(), lhs_ty);
@ -165,7 +165,7 @@ fn check_overloaded_binop(&self,
// using this variable as the expected type, which sometimes lets
// us do better coercions than we would be able to do otherwise,
// particularly for things like `String + &String`.
let rhs_ty_var = self.infcx().next_ty_var();
let rhs_ty_var = self.next_ty_var();
let return_ty = match self.lookup_op_method(expr, lhs_ty, vec![rhs_ty_var],
token::intern(name), trait_def_id,
@ -175,12 +175,12 @@ fn check_overloaded_binop(&self,
// error types are considered "builtin"
if !lhs_ty.references_error() {
if let IsAssign::Yes = is_assign {
span_err!(self.tcx().sess, lhs_expr.span, E0368,
span_err!(self.tcx.sess, lhs_expr.span, E0368,
"binary assignment operation `{}=` cannot be applied to type `{}`",
op.node.as_str(),
lhs_ty);
} else {
let mut err = struct_span_err!(self.tcx().sess, lhs_expr.span, E0369,
let mut err = struct_span_err!(self.tcx.sess, lhs_expr.span, E0369,
"binary operation `{}` cannot be applied to type `{}`",
op.node.as_str(),
lhs_ty);
@ -208,7 +208,7 @@ fn check_overloaded_binop(&self,
err.emit();
}
}
self.tcx().types.err
self.tcx.types.err
}
};
@ -238,7 +238,7 @@ pub fn check_user_unop(&self,
format!("cannot apply unary operator `{}` to type `{}`",
op_str, actual)
}, operand_ty, None);
self.tcx().types.err
self.tcx.types.err
}
}
}
@ -247,7 +247,7 @@ fn name_and_trait_def_id(&self,
op: hir::BinOp,
is_assign: IsAssign)
-> (&'static str, Option<DefId>) {
let lang = &self.tcx().lang_items;
let lang = &self.tcx.lang_items;
if let IsAssign::Yes = is_assign {
match op.node {
@ -329,12 +329,12 @@ fn lookup_op_method(&self,
// HACK(eddyb) Fully qualified path to work around a resolve bug.
let method_call = ::rustc::ty::MethodCall::expr(expr.id);
self.inh.tables.borrow_mut().method_map.insert(method_call, method);
self.tables.borrow_mut().method_map.insert(method_call, method);
// extract return type for method; all late bound regions
// should have been instantiated by now
let ret_ty = method_ty.fn_ret();
Ok(self.tcx().no_late_bound_regions(&ret_ty).unwrap().unwrap())
Ok(self.tcx.no_late_bound_regions(&ret_ty).unwrap().unwrap())
}
None => {
Err(())

View file

@ -90,13 +90,14 @@ use middle::mem_categorization::Categorization;
use middle::region::{self, CodeExtent};
use rustc::ty::subst::Substs;
use rustc::traits;
use rustc::ty::{self, Ty, TyCtxt, MethodCall, TypeFoldable};
use rustc::infer::{self, GenericKind, InferCtxt, InferOk, SubregionOrigin, TypeOrigin, VerifyBound};
use rustc::ty::{self, Ty, MethodCall, TypeFoldable};
use rustc::infer::{self, GenericKind, InferOk, SubregionOrigin, TypeOrigin, VerifyBound};
use hir::pat_util;
use rustc::ty::adjustment;
use rustc::ty::wf::ImpliedBound;
use std::mem;
use std::ops::Deref;
use syntax::ast;
use syntax::codemap::Span;
use rustc::hir::intravisit::{self, Visitor};
@ -132,7 +133,7 @@ pub fn regionck_item(&self,
debug!("regionck_item(item.id={:?}, wf_tys={:?}", item_id, wf_tys);
let mut rcx = RegionCtxt::new(self, RepeatingScope(item_id), item_id, Subject(item_id));
rcx.free_region_map.relate_free_regions_from_predicates(
&self.infcx().parameter_environment.caller_bounds);
&self.parameter_environment.caller_bounds);
rcx.relate_free_regions(wf_tys, item_id, span);
rcx.visit_region_obligations(item_id);
rcx.resolve_regions_and_report_errors();
@ -152,14 +153,14 @@ pub fn regionck_fn(&self,
}
rcx.free_region_map.relate_free_regions_from_predicates(
&self.infcx().parameter_environment.caller_bounds);
&self.parameter_environment.caller_bounds);
rcx.resolve_regions_and_report_errors();
// For the top-level fn, store the free-region-map. We don't store
// any map for closures; they just share the same map as the
// function that created them.
self.tcx().store_free_region_map(fn_id, rcx.free_region_map);
self.tcx.store_free_region_map(fn_id, rcx.free_region_map);
}
}
@ -187,6 +188,13 @@ pub struct RegionCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
}
impl<'a, 'gcx, 'tcx> Deref for RegionCtxt<'a, 'gcx, 'tcx> {
type Target = FnCtxt<'a, 'gcx, 'tcx>;
fn deref(&self) -> &Self::Target {
&self.fcx
}
}
pub struct RepeatingScope(ast::NodeId);
pub enum SubjectNode { Subject(ast::NodeId), None }
@ -207,14 +215,6 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
}
}
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.fcx.tcx()
}
pub fn infcx(&self) -> &InferCtxt<'a,'tcx, 'tcx> {
self.fcx.infcx()
}
fn set_call_site_scope(&mut self, call_site_scope: Option<CodeExtent>) -> Option<CodeExtent> {
mem::replace(&mut self.call_site_scope, call_site_scope)
}
@ -251,17 +251,17 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
/// of b will be `&<R0>.i32` and then `*b` will require that `<R0>` be bigger than the let and
/// the `*b` expression, so we will effectively resolve `<R0>` to be the block B.
pub fn resolve_type(&self, unresolved_ty: Ty<'tcx>) -> Ty<'tcx> {
self.fcx.infcx().resolve_type_vars_if_possible(&unresolved_ty)
self.resolve_type_vars_if_possible(&unresolved_ty)
}
/// Try to resolve the type for the given node.
fn resolve_node_type(&self, id: ast::NodeId) -> Ty<'tcx> {
let t = self.fcx.node_ty(id);
let t = self.node_ty(id);
self.resolve_type(t)
}
fn resolve_method_type(&self, method_call: MethodCall) -> Option<Ty<'tcx>> {
let method_ty = self.fcx.inh.tables.borrow().method_map
let method_ty = self.tables.borrow().method_map
.get(&method_call).map(|method| method.ty);
method_ty.map(|method_ty| self.resolve_type(method_ty))
}
@ -273,8 +273,8 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
ty_unadjusted
} else {
ty_unadjusted.adjust(
self.fcx.tcx(), expr.span, expr.id,
self.fcx.inh.tables.borrow().adjustments.get(&expr.id),
self.tcx, expr.span, expr.id,
self.tables.borrow().adjustments.get(&expr.id),
|method_call| self.resolve_method_type(method_call))
}
}
@ -288,12 +288,12 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
// When we enter a function, we can derive
debug!("visit_fn_body(id={})", id);
let call_site = self.fcx.tcx().region_maps.lookup_code_extent(
let call_site = self.tcx.region_maps.lookup_code_extent(
region::CodeExtentData::CallSiteScope { fn_id: id, body_id: body.id });
let old_call_site_scope = self.set_call_site_scope(Some(call_site));
let fn_sig = {
let fn_sig_map = &self.infcx().tables.borrow().liberated_fn_sigs;
let fn_sig_map = &self.tables.borrow().liberated_fn_sigs;
match fn_sig_map.get(&id) {
Some(f) => f.clone(),
None => {
@ -312,12 +312,12 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
let fn_sig_tys: Vec<_> =
fn_sig.inputs.iter()
.cloned()
.chain(Some(fn_sig.output.unwrap_or(self.tcx().types.bool)))
.chain(Some(fn_sig.output.unwrap_or(self.tcx.types.bool)))
.collect();
let old_body_id = self.set_body_id(body.id);
self.relate_free_regions(&fn_sig_tys[..], body.id, span);
self.link_fn_args(self.tcx().region_maps.node_extent(body.id),
self.link_fn_args(self.tcx.region_maps.node_extent(body.id),
&fn_decl.inputs[..]);
self.visit_block(body);
self.visit_region_obligations(body.id);
@ -342,14 +342,12 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
// region checking can introduce new pending obligations
// which, when processed, might generate new region
// obligations. So make sure we process those.
self.fcx.select_all_obligations_or_error();
self.select_all_obligations_or_error();
// Make a copy of the region obligations vec because we'll need
// to be able to borrow the fulfillment-cx below when projecting.
let region_obligations =
self.fcx
.inh
.fulfillment_cx
self.fulfillment_cx
.borrow()
.region_obligations(node_id)
.to_vec();
@ -364,7 +362,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
// Processing the region obligations should not cause the list to grow further:
assert_eq!(region_obligations.len(),
self.fcx.inh.fulfillment_cx.borrow().region_obligations(node_id).len());
self.fulfillment_cx.borrow().region_obligations(node_id).len());
}
fn code_to_origin(&self,
@ -399,7 +397,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
for &ty in fn_sig_tys {
let ty = self.resolve_type(ty);
debug!("relate_free_regions(t={:?})", ty);
let implied_bounds = ty::wf::implied_bounds(self.fcx.infcx(), body_id, ty, span);
let implied_bounds = ty::wf::implied_bounds(self, body_id, ty, span);
// Record any relations between free regions that we observe into the free-region-map.
self.free_region_map.relate_free_regions_from_implied_bounds(&implied_bounds);
@ -412,7 +410,7 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
match implication {
ImpliedBound::RegionSubRegion(ty::ReFree(free_a),
ty::ReVar(vid_b)) => {
self.fcx.inh.infcx.add_given(free_a, vid_b);
self.add_given(free_a, vid_b);
}
ImpliedBound::RegionSubParam(r_a, param_b) => {
self.region_bound_pairs.push((r_a, GenericKind::Param(param_b)));
@ -447,12 +445,12 @@ impl<'a, 'tcx> RegionCtxt<'a, 'tcx, 'tcx> {
}
};
self.fcx.infcx().resolve_regions_and_report_errors(&self.free_region_map,
subject_node_id);
self.fcx.resolve_regions_and_report_errors(&self.free_region_map,
subject_node_id);
}
fn constrain_bindings_in_pat(&mut self, pat: &hir::Pat) {
let tcx = self.fcx.tcx();
let tcx = self.tcx;
debug!("regionck::visit_pat(pat={:?})", pat);
pat_util::pat_bindings(&tcx.def_map, pat, |_, id, span, _| {
// If we have a variable that contains region'd data, that
@ -528,12 +526,12 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
// scope of that expression. This also guarantees basic WF.
let expr_ty = self.resolve_node_type(expr.id);
// the region corresponding to this expression
let expr_region = ty::ReScope(self.tcx().region_maps.node_extent(expr.id));
let expr_region = ty::ReScope(self.tcx.region_maps.node_extent(expr.id));
self.type_must_outlive(infer::ExprTypeIsNotInScope(expr_ty, expr.span),
expr_ty, expr_region);
let method_call = MethodCall::expr(expr.id);
let opt_method_callee = self.fcx.inh.tables.borrow().method_map.get(&method_call).cloned();
let opt_method_callee = self.tables.borrow().method_map.get(&method_call).cloned();
let has_method_map = opt_method_callee.is_some();
// If we are calling a method (either explicitly or via an
@ -556,7 +554,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
}
// Check any autoderefs or autorefs that appear.
let adjustment = self.fcx.inh.tables.borrow().adjustments.get(&expr.id).map(|a| a.clone());
let adjustment = self.tables.borrow().adjustments.get(&expr.id).map(|a| a.clone());
if let Some(adjustment) = adjustment {
debug!("adjustment={:?}", adjustment);
match adjustment {
@ -592,7 +590,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
// If necessary, constrain destructors in the unadjusted form of this
// expression.
let cmt_result = {
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
mc.cat_expr_unadjusted(expr)
};
match cmt_result {
@ -601,8 +599,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
expr.span);
}
Err(..) => {
let tcx = self.fcx.tcx();
tcx.sess.delay_span_bug(expr.span, "cat_expr_unadjusted Errd");
self.tcx.sess.delay_span_bug(expr.span, "cat_expr_unadjusted Errd");
}
}
}
@ -610,7 +607,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
// If necessary, constrain destructors in this expression. This will be
// the adjusted form if there is an adjustment.
let cmt_result = {
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
mc.cat_expr(expr)
};
match cmt_result {
@ -618,8 +615,7 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
self.check_safety_of_rvalue_destructor_if_necessary(head_cmt, expr.span);
}
Err(..) => {
let tcx = self.fcx.tcx();
tcx.sess.delay_span_bug(expr.span, "cat_expr Errd");
self.tcx.sess.delay_span_bug(expr.span, "cat_expr Errd");
}
}
@ -707,12 +703,12 @@ fn visit_expr(&mut self, expr: &hir::Expr) {
hir::ExprUnary(hir::UnDeref, ref base) => {
// For *a, the lifetime of a must enclose the deref
let method_call = MethodCall::expr(expr.id);
let base_ty = match self.fcx.inh.tables.borrow().method_map.get(&method_call) {
let base_ty = match self.tables.borrow().method_map.get(&method_call) {
Some(method) => {
self.constrain_call(expr, Some(&base),
None::<hir::Expr>.iter(), true);
let fn_ret = // late-bound regions in overloaded method calls are instantiated
self.tcx().no_late_bound_regions(&method.ty.fn_ret()).unwrap();
self.tcx.no_late_bound_regions(&method.ty.fn_ret()).unwrap();
fn_ret.unwrap()
}
None => self.resolve_node_type(base.id)
@ -824,7 +820,7 @@ fn constrain_cast(&mut self,
/*From:*/ (&ty::TyRef(from_r, ref from_mt),
/*To: */ &ty::TyRef(to_r, ref to_mt)) => {
// Target cannot outlive source, naturally.
self.fcx.infcx().sub_regions(infer::Reborrow(cast_expr.span), *to_r, *from_r);
self.sub_regions(infer::Reborrow(cast_expr.span), *to_r, *from_r);
self.walk_cast(cast_expr, from_mt.ty, to_mt.ty);
}
@ -893,7 +889,7 @@ fn constrain_call<'b, I: Iterator<Item=&'b hir::Expr>>(&mut self,
// call occurs.
//
// FIXME(#6268) to support nested method calls, should be callee_id
let callee_scope = self.tcx().region_maps.node_extent(call_expr.id);
let callee_scope = self.tcx.region_maps.node_extent(call_expr.id);
let callee_region = ty::ReScope(callee_scope);
debug!("callee_region={:?}", callee_region);
@ -938,13 +934,13 @@ fn constrain_autoderefs(&mut self,
derefs,
derefd_ty);
let s_deref_expr = self.tcx().region_maps.node_extent(deref_expr.id);
let s_deref_expr = self.tcx.region_maps.node_extent(deref_expr.id);
let r_deref_expr = ty::ReScope(s_deref_expr);
for i in 0..derefs {
let method_call = MethodCall::autoderef(deref_expr.id, i as u32);
debug!("constrain_autoderefs: method_call={:?} (of {:?} total)", method_call, derefs);
let method = self.fcx.inh.tables.borrow().method_map.get(&method_call).map(|m| m.clone());
let method = self.tables.borrow().method_map.get(&method_call).map(|m| m.clone());
derefd_ty = match method {
Some(method) => {
@ -958,7 +954,7 @@ fn constrain_autoderefs(&mut self,
// was applied on the base type, as that is always the case.
let fn_sig = method.ty.fn_sig();
let fn_sig = // late-bound regions should have been instantiated
self.tcx().no_late_bound_regions(fn_sig).unwrap();
self.tcx.no_late_bound_regions(fn_sig).unwrap();
let self_ty = fn_sig.inputs[0];
let (m, r) = match self_ty.sty {
ty::TyRef(r, ref m) => (m.mutbl, r),
@ -974,7 +970,7 @@ fn constrain_autoderefs(&mut self,
r, m);
{
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
debug!("constrain_autoderefs: self_cmt={:?}",
self_cmt);
@ -1015,8 +1011,8 @@ pub fn mk_subregion_due_to_dereference(&mut self,
deref_span: Span,
minimum_lifetime: ty::Region,
maximum_lifetime: ty::Region) {
self.fcx.infcx().sub_regions(infer::DerefPointer(deref_span),
minimum_lifetime, maximum_lifetime)
self.sub_regions(infer::DerefPointer(deref_span),
minimum_lifetime, maximum_lifetime)
}
fn check_safety_of_rvalue_destructor_if_necessary(&mut self,
@ -1052,14 +1048,14 @@ fn constrain_index(&mut self,
indexed_ty: Ty<'tcx>)
{
debug!("constrain_index(index_expr=?, indexed_ty={}",
self.fcx.infcx().ty_to_string(indexed_ty));
self.ty_to_string(indexed_ty));
let r_index_expr = ty::ReScope(self.tcx().region_maps.node_extent(index_expr.id));
let r_index_expr = ty::ReScope(self.tcx.region_maps.node_extent(index_expr.id));
if let ty::TyRef(r_ptr, mt) = indexed_ty.sty {
match mt.ty.sty {
ty::TySlice(_) | ty::TyStr => {
self.fcx.infcx().sub_regions(infer::IndexSlice(index_expr.span),
r_index_expr, *r_ptr);
self.sub_regions(infer::IndexSlice(index_expr.span),
r_index_expr, *r_ptr);
}
_ => {}
}
@ -1073,14 +1069,14 @@ fn type_of_node_must_outlive(&mut self,
id: ast::NodeId,
minimum_lifetime: ty::Region)
{
let tcx = self.fcx.tcx();
let tcx = self.tcx;
// Try to resolve the type. If we encounter an error, then typeck
// is going to fail anyway, so just stop here and let typeck
// report errors later on in the writeback phase.
let ty0 = self.resolve_node_type(id);
let ty = ty0.adjust(tcx, origin.span(), id,
self.fcx.inh.tables.borrow().adjustments.get(&id),
self.tables.borrow().adjustments.get(&id),
|method_call| self.resolve_method_type(method_call));
debug!("constrain_regions_in_type_of_node(\
ty={}, ty0={}, id={}, minimum_lifetime={:?})",
@ -1096,7 +1092,7 @@ fn link_addr_of(&mut self, expr: &hir::Expr,
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
let cmt = {
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
ignore_err!(mc.cat_expr(base))
};
@ -1114,7 +1110,7 @@ fn link_local(&self, local: &hir::Local) {
None => { return; }
Some(ref expr) => &**expr,
};
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
self.link_pattern(mc, discr_cmt, &local.pat);
}
@ -1124,7 +1120,7 @@ fn link_local(&self, local: &hir::Local) {
/// linked to the lifetime of its guarantor (if any).
fn link_match(&self, discr: &hir::Expr, arms: &[hir::Arm]) {
debug!("regionck::for_match()");
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
let discr_cmt = ignore_err!(mc.cat_expr(discr));
debug!("discr_cmt={:?}", discr_cmt);
for arm in arms {
@ -1139,9 +1135,9 @@ fn link_match(&self, discr: &hir::Expr, arms: &[hir::Arm]) {
/// linked to the lifetime of its guarantor (if any).
fn link_fn_args(&self, body_scope: CodeExtent, args: &[hir::Arg]) {
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
for arg in args {
let arg_ty = self.fcx.node_ty(arg.id);
let arg_ty = self.node_ty(arg.id);
let re_scope = ty::ReScope(body_scope);
let arg_cmt = mc.cat_rvalue(arg.id, arg.ty.span, re_scope, arg_ty);
debug!("arg_ty={:?} arg_cmt={:?} arg={:?}",
@ -1193,7 +1189,7 @@ fn link_autoref(&self,
autoref: &adjustment::AutoRef)
{
debug!("link_autoref(autoref={:?})", autoref);
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
debug!("expr_cmt={:?}", expr_cmt);
@ -1204,7 +1200,7 @@ fn link_autoref(&self,
}
adjustment::AutoUnsafe(m) => {
let r = ty::ReScope(self.tcx().region_maps.node_extent(expr.id));
let r = ty::ReScope(self.tcx.region_maps.node_extent(expr.id));
self.link_region(expr.span, &r, ty::BorrowKind::from_mutbl(m), expr_cmt);
}
}
@ -1217,7 +1213,7 @@ fn link_by_ref(&self,
callee_scope: CodeExtent) {
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
expr, callee_scope);
let mc = mc::MemCategorizationContext::new(self.fcx.infcx());
let mc = mc::MemCategorizationContext::new(self);
let expr_cmt = ignore_err!(mc.cat_expr(expr));
let borrow_region = ty::ReScope(callee_scope);
self.link_region(expr.span, &borrow_region, ty::ImmBorrow, expr_cmt);
@ -1357,7 +1353,7 @@ fn link_reborrowed_region(&self,
// Detect by-ref upvar `x`:
let cause = match note {
mc::NoteUpvarRef(ref upvar_id) => {
let upvar_capture_map = &self.fcx.inh.tables.borrow_mut().upvar_capture_map;
let upvar_capture_map = &self.tables.borrow_mut().upvar_capture_map;
match upvar_capture_map.get(upvar_id) {
Some(&ty::UpvarCapture::ByRef(ref upvar_borrow)) => {
// The mutability of the upvar may have been modified
@ -1385,7 +1381,7 @@ fn link_reborrowed_region(&self,
debug!("link_reborrowed_region: {:?} <= {:?}",
borrow_region,
ref_region);
self.fcx.infcx().sub_regions(cause, *borrow_region, ref_region);
self.sub_regions(cause, *borrow_region, ref_region);
// If we end up needing to recurse and establish a region link
// with `ref_cmt`, calculate what borrow kind we will end up
@ -1467,7 +1463,7 @@ fn substs_wf_in_scope(&mut self,
let origin = infer::ParameterInScope(origin, expr_span);
for &region in &substs.regions {
self.fcx.infcx().sub_regions(origin.clone(), expr_region, region);
self.sub_regions(origin.clone(), expr_region, region);
}
for &ty in &substs.types {
@ -1493,7 +1489,7 @@ pub fn type_must_outlive(&self,
assert!(!ty.has_escaping_regions());
let components = self.infcx().outlives_components(ty);
let components = self.outlives_components(ty);
self.components_must_outlive(origin, components, region);
}
@ -1506,7 +1502,7 @@ fn components_must_outlive(&self,
let origin = origin.clone();
match component {
ty::outlives::Component::Region(region1) => {
self.fcx.infcx().sub_regions(origin, region, region1);
self.sub_regions(origin, region, region1);
}
ty::outlives::Component::Param(param_ty) => {
self.param_ty_must_outlive(origin, region, param_ty);
@ -1521,7 +1517,7 @@ fn components_must_outlive(&self,
// ignore this, we presume it will yield an error
// later, since if a type variable is not resolved by
// this point it never will be
self.tcx().sess.delay_span_bug(
self.tcx.sess.delay_span_bug(
origin.span(),
&format!("unresolved inference variable in outlives: {:?}", v));
}
@ -1538,7 +1534,7 @@ fn param_ty_must_outlive(&self,
let verify_bound = self.param_bound(param_ty);
let generic = GenericKind::Param(param_ty);
self.fcx.infcx().verify_generic_bound(origin, generic, region, verify_bound);
self.verify_generic_bound(origin, generic, region, verify_bound);
}
fn projection_must_outlive(&self,
@ -1604,7 +1600,7 @@ fn projection_must_outlive(&self,
}
for &r in &projection_ty.trait_ref.substs.regions {
self.fcx.infcx().sub_regions(origin.clone(), region, r);
self.sub_regions(origin.clone(), region, r);
}
return;
@ -1625,7 +1621,7 @@ fn projection_must_outlive(&self,
.any(|r| env_bounds.contains(r))
{
debug!("projection_must_outlive: unique declared bound appears in trait ref");
self.fcx.infcx().sub_regions(origin.clone(), region, unique_bound);
self.sub_regions(origin.clone(), region, unique_bound);
return;
}
}
@ -1637,7 +1633,7 @@ fn projection_must_outlive(&self,
// even though a satisfactory solution exists.
let verify_bound = self.projection_bound(origin.span(), env_bounds, projection_ty);
let generic = GenericKind::Projection(projection_ty);
self.fcx.infcx().verify_generic_bound(origin, generic.clone(), region, verify_bound);
self.verify_generic_bound(origin, generic.clone(), region, verify_bound);
}
fn type_bound(&self, span: Span, ty: Ty<'tcx>) -> VerifyBound {
@ -1656,7 +1652,7 @@ fn type_bound(&self, span: Span, ty: Ty<'tcx>) -> VerifyBound {
}
fn param_bound(&self, param_ty: ty::ParamTy) -> VerifyBound {
let param_env = &self.infcx().parameter_environment;
let param_env = &self.parameter_environment;
debug!("param_bound(param_ty={:?})",
param_ty);
@ -1696,7 +1692,7 @@ fn projection_bound(&self,
// see the extensive comment in projection_must_outlive
let ty = self.tcx().mk_projection(projection_ty.trait_ref, projection_ty.item_name);
let ty = self.tcx.mk_projection(projection_ty.trait_ref, projection_ty.item_name);
let recursive_bound = self.recursive_type_bound(span, ty);
VerifyBound::AnyRegion(declared_bounds).or(recursive_bound)
@ -1726,11 +1722,11 @@ fn recursive_type_bound(&self, span: Span, ty: Ty<'tcx>) -> VerifyBound {
fn declared_generic_bounds_from_env(&self, generic: GenericKind<'tcx>)
-> Vec<ty::Region>
{
let param_env = &self.infcx().parameter_environment;
let param_env = &self.parameter_environment;
// To start, collect bounds from user:
let mut param_bounds = self.tcx().required_region_bounds(generic.to_ty(self.tcx()),
param_env.caller_bounds.clone());
let mut param_bounds = self.tcx.required_region_bounds(generic.to_ty(self.tcx),
param_env.caller_bounds.clone());
// Next, collect regions we scraped from the well-formedness
// constraints in the fn signature. To do that, we walk the list
@ -1760,14 +1756,11 @@ fn declared_projection_bounds_from_trait(&self,
projection_ty: ty::ProjectionTy<'tcx>)
-> Vec<ty::Region>
{
let fcx = self.fcx;
let tcx = fcx.tcx();
let infcx = fcx.infcx();
debug!("projection_bounds(projection_ty={:?})",
projection_ty);
let ty = tcx.mk_projection(projection_ty.trait_ref.clone(), projection_ty.item_name);
let ty = self.tcx.mk_projection(projection_ty.trait_ref.clone(),
projection_ty.item_name);
// Say we have a projection `<T as SomeTrait<'a>>::SomeType`. We are interested
// in looking for a trait definition like:
@ -1779,9 +1772,9 @@ fn declared_projection_bounds_from_trait(&self,
// ```
//
// we can thus deduce that `<T as SomeTrait<'a>>::SomeType : 'a`.
let trait_predicates = tcx.lookup_predicates(projection_ty.trait_ref.def_id);
let trait_predicates = self.tcx.lookup_predicates(projection_ty.trait_ref.def_id);
let predicates = trait_predicates.predicates.as_slice().to_vec();
traits::elaborate_predicates(tcx, predicates)
traits::elaborate_predicates(self.tcx, predicates)
.filter_map(|predicate| {
// we're only interesting in `T : 'a` style predicates:
let outlives = match predicate {
@ -1793,16 +1786,16 @@ fn declared_projection_bounds_from_trait(&self,
outlives);
// apply the substitutions (and normalize any projected types)
let outlives = fcx.instantiate_type_scheme(span,
projection_ty.trait_ref.substs,
&outlives);
let outlives = self.instantiate_type_scheme(span,
projection_ty.trait_ref.substs,
&outlives);
debug!("projection_bounds: outlives={:?} (2)",
outlives);
let region_result = infcx.commit_if_ok(|_| {
let region_result = self.commit_if_ok(|_| {
let (outlives, _) =
infcx.replace_late_bound_regions_with_fresh_var(
self.replace_late_bound_regions_with_fresh_var(
span,
infer::AssocTypeProjection(projection_ty.item_name),
&outlives);
@ -1811,7 +1804,7 @@ fn declared_projection_bounds_from_trait(&self,
outlives);
// check whether this predicate applies to our current projection
match infcx.eq_types(false, TypeOrigin::Misc(span), ty, outlives.0) {
match self.eq_types(false, TypeOrigin::Misc(span), ty, outlives.0) {
Ok(InferOk { obligations, .. }) => {
// FIXME(#32730) propagate obligations
assert!(obligations.is_empty());

View file

@ -45,8 +45,8 @@ use super::FnCtxt;
use middle::expr_use_visitor as euv;
use middle::mem_categorization as mc;
use middle::mem_categorization::Categorization;
use rustc::ty::{self, Ty, TyCtxt};
use rustc::infer::{InferCtxt, UpvarRegion};
use rustc::ty::{self, Ty};
use rustc::infer::UpvarRegion;
use std::collections::HashSet;
use syntax::ast;
use syntax::codemap::Span;
@ -66,7 +66,7 @@ pub fn closure_analyze_fn(&self, body: &hir::Block) {
adjust.visit_block(body);
// it's our job to process these.
assert!(self.inh.deferred_call_resolutions.borrow().is_empty());
assert!(self.deferred_call_resolutions.borrow().is_empty());
}
pub fn closure_analyze_const(&self, body: &hir::Expr) {
@ -78,7 +78,7 @@ pub fn closure_analyze_const(&self, body: &hir::Expr) {
adjust.visit_expr(body);
// it's our job to process these.
assert!(self.inh.deferred_call_resolutions.borrow().is_empty());
assert!(self.deferred_call_resolutions.borrow().is_empty());
}
}
@ -109,29 +109,21 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx, 'tcx> {
SeedBorrowKind { fcx: fcx, closures_with_inferred_kinds: HashSet::new() }
}
fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.fcx.tcx()
}
fn infcx(&self) -> &'a InferCtxt<'a,'tcx, 'tcx> {
self.fcx.infcx()
}
fn check_closure(&mut self,
expr: &hir::Expr,
capture_clause: hir::CaptureClause,
_body: &hir::Block)
{
let closure_def_id = self.tcx().map.local_def_id(expr.id);
if !self.fcx.inh.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
let closure_def_id = self.fcx.tcx.map.local_def_id(expr.id);
if !self.fcx.tables.borrow().closure_kinds.contains_key(&closure_def_id) {
self.closures_with_inferred_kinds.insert(expr.id);
self.fcx.inh.tables.borrow_mut().closure_kinds
.insert(closure_def_id, ty::ClosureKind::Fn);
self.fcx.tables.borrow_mut().closure_kinds
.insert(closure_def_id, ty::ClosureKind::Fn);
debug!("check_closure: adding closure_id={:?} to closures_with_inferred_kinds",
closure_def_id);
}
self.tcx().with_freevars(expr.id, |freevars| {
self.fcx.tcx.with_freevars(expr.id, |freevars| {
for freevar in freevars {
let var_node_id = freevar.def.var_id();
let upvar_id = ty::UpvarId { var_id: var_node_id,
@ -144,14 +136,14 @@ impl<'a,'tcx> SeedBorrowKind<'a,'tcx, 'tcx> {
}
hir::CaptureByRef => {
let origin = UpvarRegion(upvar_id, expr.span);
let freevar_region = self.infcx().next_region_var(origin);
let freevar_region = self.fcx.next_region_var(origin);
let upvar_borrow = ty::UpvarBorrow { kind: ty::ImmBorrow,
region: freevar_region };
ty::UpvarCapture::ByRef(upvar_borrow)
}
};
self.fcx.inh.tables.borrow_mut().upvar_capture_map.insert(upvar_id, capture_kind);
self.fcx.tables.borrow_mut().upvar_capture_map.insert(upvar_id, capture_kind);
}
});
}
@ -184,7 +176,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
debug!("analyze_closure(id={:?}, body.id={:?})", id, body.id);
{
let mut euv = euv::ExprUseVisitor::new(self, self.fcx.infcx());
let mut euv = euv::ExprUseVisitor::new(self, self.fcx);
euv.walk_fn(decl, body);
}
@ -221,7 +213,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
// Now we must process and remove any deferred resolutions,
// since we have a concrete closure kind.
let closure_def_id = self.fcx.tcx().map.local_def_id(id);
let closure_def_id = self.fcx.tcx.map.local_def_id(id);
if self.closures_with_inferred_kinds.contains(&id) {
let mut deferred_call_resolutions =
self.fcx.remove_deferred_call_resolutions(closure_def_id);
@ -238,7 +230,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
// local crate or were inlined into it along with some function.
// This may change if abstract return types of some sort are
// implemented.
let tcx = self.fcx.tcx();
let tcx = self.fcx.tcx;
tcx.with_freevars(closure_id, |freevars| {
freevars.iter()
.map(|freevar| {
@ -248,7 +240,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
var_id: freevar_node_id,
closure_expr_id: closure_id
};
let capture = self.fcx.infcx().upvar_capture(upvar_id).unwrap();
let capture = self.fcx.upvar_capture(upvar_id).unwrap();
debug!("freevar_node_id={:?} freevar_ty={:?} capture={:?}",
freevar_node_id, freevar_ty, capture);
@ -299,7 +291,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
self.adjust_closure_kind(upvar_id.closure_expr_id, ty::ClosureKind::FnOnce);
let upvar_capture_map =
&mut self.fcx.inh.tables.borrow_mut().upvar_capture_map;
&mut self.fcx.tables.borrow_mut().upvar_capture_map;
upvar_capture_map.insert(upvar_id, ty::UpvarCapture::ByValue);
}
mc::NoteClosureEnv(upvar_id) => {
@ -407,7 +399,7 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
// borrow_kind of the upvar to make sure it
// is inferred to mutable if necessary
{
let upvar_capture_map = &mut self.fcx.inh.tables.borrow_mut().upvar_capture_map;
let upvar_capture_map = &mut self.fcx.tables.borrow_mut().upvar_capture_map;
let ub = upvar_capture_map.get_mut(&upvar_id).unwrap();
self.adjust_upvar_borrow_kind(upvar_id, ub, borrow_kind);
}
@ -475,8 +467,8 @@ impl<'a,'tcx> AdjustBorrowKind<'a,'tcx, 'tcx> {
return;
}
let closure_def_id = self.fcx.tcx().map.local_def_id(closure_id);
let closure_kinds = &mut self.fcx.inh.tables.borrow_mut().closure_kinds;
let closure_def_id = self.fcx.tcx.map.local_def_id(closure_id);
let closure_kinds = &mut self.fcx.tables.borrow_mut().closure_kinds;
let existing_kind = *closure_kinds.get(&closure_def_id).unwrap();
debug!("adjust_closure_kind: closure_id={}, existing_kind={:?}, new_kind={:?}",

View file

@ -130,15 +130,15 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
fn check_trait_or_impl_item(&mut self, item_id: ast::NodeId, span: Span) {
let code = self.code.clone();
self.with_fcx(item_id, span, |fcx, this| {
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let free_id_outlive = fcx.inh.infcx.parameter_environment.free_id_outlive;
let free_substs = &fcx.parameter_environment.free_substs;
let free_id_outlive = fcx.parameter_environment.free_id_outlive;
let item = fcx.tcx().impl_or_trait_item(fcx.tcx().map.local_def_id(item_id));
let item = fcx.tcx.impl_or_trait_item(fcx.tcx.map.local_def_id(item_id));
let (mut implied_bounds, self_ty) = match item.container() {
ty::TraitContainer(_) => (vec![], fcx.tcx().mk_self_type()),
ty::TraitContainer(_) => (vec![], fcx.tcx.mk_self_type()),
ty::ImplContainer(def_id) => (fcx.impl_implied_bounds(def_id, span),
fcx.tcx().lookup_item_type(def_id).ty)
fcx.tcx.lookup_item_type(def_id).ty)
};
match item {
@ -147,7 +147,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
fcx.register_wf_obligation(ty, span, code.clone());
}
ty::MethodTraitItem(method) => {
reject_shadowing_type_parameters(fcx.tcx(), span, &method.generics);
reject_shadowing_type_parameters(fcx.tcx, span, &method.generics);
let method_ty = fcx.instantiate_type_scheme(span, free_substs, &method.fty);
let predicates = fcx.instantiate_bounds(span, free_substs, &method.predicates);
this.check_fn_or_method(fcx, span, &method_ty, &predicates,
@ -181,8 +181,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
let ccx = self.ccx;
let param_env = ty::ParameterEnvironment::for_item(ccx.tcx, id);
let tables = RefCell::new(ty::Tables::empty());
let inh = Inherited::new(ccx.tcx, &tables, param_env);
let fcx = FnCtxt::new(ccx, &inh, ty::FnDiverging, id);
let inh = Inherited::new(ccx, &tables, param_env);
let fcx = FnCtxt::new(&inh, ty::FnDiverging, id);
let wf_tys = f(&fcx, self);
fcx.select_all_obligations_or_error();
fcx.regionck_item(id, span, &wf_tys);
@ -214,8 +214,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
}
}
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let predicates = fcx.tcx().lookup_predicates(fcx.tcx().map.local_def_id(item.id));
let free_substs = &fcx.parameter_environment.free_substs;
let predicates = fcx.tcx.lookup_predicates(fcx.tcx.map.local_def_id(item.id));
let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
this.check_where_clauses(fcx, item.span, &predicates);
@ -236,8 +236,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
}
self.with_item_fcx(item, |fcx, this| {
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let predicates = fcx.tcx().lookup_predicates(trait_def_id);
let free_substs = &fcx.parameter_environment.free_substs;
let predicates = fcx.tcx.lookup_predicates(trait_def_id);
let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
this.check_where_clauses(fcx, item.span, &predicates);
vec![]
@ -249,8 +249,8 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
body: &hir::Block)
{
self.with_item_fcx(item, |fcx, this| {
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id));
let free_substs = &fcx.parameter_environment.free_substs;
let type_scheme = fcx.tcx.lookup_item_type(fcx.tcx.map.local_def_id(item.id));
let item_ty = fcx.instantiate_type_scheme(item.span, free_substs, &type_scheme.ty);
let bare_fn_ty = match item_ty.sty {
ty::TyFnDef(_, _, ref bare_fn_ty) => bare_fn_ty,
@ -259,11 +259,11 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
}
};
let predicates = fcx.tcx().lookup_predicates(fcx.tcx().map.local_def_id(item.id));
let predicates = fcx.tcx.lookup_predicates(fcx.tcx.map.local_def_id(item.id));
let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
let mut implied_bounds = vec![];
let free_id_outlive = fcx.tcx().region_maps.call_site_extent(item.id, body.id);
let free_id_outlive = fcx.tcx.region_maps.call_site_extent(item.id, body.id);
this.check_fn_or_method(fcx, item.span, bare_fn_ty, &predicates,
free_id_outlive, &mut implied_bounds);
implied_bounds
@ -276,11 +276,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
debug!("check_item_type: {:?}", item);
self.with_item_fcx(item, |fcx, this| {
let type_scheme = fcx.tcx().lookup_item_type(fcx.tcx().map.local_def_id(item.id));
let type_scheme = fcx.tcx.lookup_item_type(fcx.tcx.map.local_def_id(item.id));
let item_ty = fcx.instantiate_type_scheme(item.span,
&fcx.inh
.infcx
.parameter_environment
&fcx.parameter_environment
.free_substs,
&type_scheme.ty);
@ -298,17 +296,17 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
debug!("check_impl: {:?}", item);
self.with_item_fcx(item, |fcx, this| {
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let item_def_id = fcx.tcx().map.local_def_id(item.id);
let free_substs = &fcx.parameter_environment.free_substs;
let item_def_id = fcx.tcx.map.local_def_id(item.id);
match *ast_trait_ref {
Some(ref ast_trait_ref) => {
let trait_ref = fcx.tcx().impl_trait_ref(item_def_id).unwrap();
let trait_ref = fcx.tcx.impl_trait_ref(item_def_id).unwrap();
let trait_ref =
fcx.instantiate_type_scheme(
ast_trait_ref.path.span, free_substs, &trait_ref);
let obligations =
ty::wf::trait_obligations(fcx.infcx(),
ty::wf::trait_obligations(fcx,
fcx.body_id,
&trait_ref,
ast_trait_ref.path.span);
@ -317,17 +315,17 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
}
}
None => {
let self_ty = fcx.tcx().node_id_to_type(item.id);
let self_ty = fcx.tcx.node_id_to_type(item.id);
let self_ty = fcx.instantiate_type_scheme(item.span, free_substs, &self_ty);
fcx.register_wf_obligation(self_ty, ast_self_ty.span, this.code.clone());
}
}
let predicates = fcx.tcx().lookup_predicates(item_def_id);
let predicates = fcx.tcx.lookup_predicates(item_def_id);
let predicates = fcx.instantiate_bounds(item.span, free_substs, &predicates);
this.check_where_clauses(fcx, item.span, &predicates);
fcx.impl_implied_bounds(fcx.tcx().map.local_def_id(item.id), item.span)
fcx.impl_implied_bounds(fcx.tcx.map.local_def_id(item.id), item.span)
});
}
@ -339,7 +337,7 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
let obligations =
predicates.predicates
.iter()
.flat_map(|p| ty::wf::predicate_obligations(fcx.infcx(),
.flat_map(|p| ty::wf::predicate_obligations(fcx,
fcx.body_id,
p,
span));
@ -357,9 +355,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
free_id_outlive: CodeExtent,
implied_bounds: &mut Vec<Ty<'tcx>>)
{
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let free_substs = &fcx.parameter_environment.free_substs;
let fty = fcx.instantiate_type_scheme(span, free_substs, fty);
let sig = fcx.tcx().liberate_late_bound_regions(free_id_outlive, &fty.sig);
let sig = fcx.tcx.liberate_late_bound_regions(free_id_outlive, &fty.sig);
for &input_ty in &sig.inputs {
fcx.register_wf_obligation(input_ty, span, self.code.clone());
@ -389,9 +387,9 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
// check that the type of the method's receiver matches the
// method's first parameter.
let free_substs = &fcx.inh.infcx.parameter_environment.free_substs;
let free_substs = &fcx.parameter_environment.free_substs;
let fty = fcx.instantiate_type_scheme(span, free_substs, &method.fty);
let sig = fcx.tcx().liberate_late_bound_regions(free_id_outlive, &fty.sig);
let sig = fcx.tcx.liberate_late_bound_regions(free_id_outlive, &fty.sig);
debug!("check_method_receiver({:?},cat={:?},self_ty={:?},sig={:?})",
method.name, method.explicit_self, self_ty, sig);
@ -400,21 +398,21 @@ impl<'ccx, 'tcx> CheckTypeWellFormedVisitor<'ccx, 'tcx> {
ty::ExplicitSelfCategory::Static => return,
ty::ExplicitSelfCategory::ByValue => self_ty,
ty::ExplicitSelfCategory::ByReference(region, mutability) => {
fcx.tcx().mk_ref(fcx.tcx().mk_region(region), ty::TypeAndMut {
fcx.tcx.mk_ref(fcx.tcx.mk_region(region), ty::TypeAndMut {
ty: self_ty,
mutbl: mutability
})
}
ty::ExplicitSelfCategory::ByBox => fcx.tcx().mk_box(self_ty)
ty::ExplicitSelfCategory::ByBox => fcx.tcx.mk_box(self_ty)
};
let rcvr_ty = fcx.instantiate_type_scheme(span, free_substs, &rcvr_ty);
let rcvr_ty = fcx.tcx().liberate_late_bound_regions(free_id_outlive,
&ty::Binder(rcvr_ty));
let rcvr_ty = fcx.tcx.liberate_late_bound_regions(free_id_outlive,
&ty::Binder(rcvr_ty));
debug!("check_method_receiver: receiver ty = {:?}", rcvr_ty);
let _ = ::require_same_types(
fcx.ccx, Some(fcx.infcx()), span,
fcx.ccx, Some(fcx), span,
sig.inputs[0], rcvr_ty,
"mismatched method receiver");
}
@ -559,10 +557,9 @@ fn struct_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
let fields =
struct_def.fields().iter()
.map(|field| {
let field_ty = self.tcx().node_id_to_type(field.id);
let field_ty = self.tcx.node_id_to_type(field.id);
let field_ty = self.instantiate_type_scheme(field.span,
&self.infcx()
.parameter_environment
&self.parameter_environment
.free_substs,
&field_ty);
AdtField { ty: field_ty, span: field.span }
@ -578,8 +575,8 @@ fn enum_variants(&self, enum_def: &hir::EnumDef) -> Vec<AdtVariant<'tcx>> {
}
fn impl_implied_bounds(&self, impl_def_id: DefId, span: Span) -> Vec<Ty<'tcx>> {
let free_substs = &self.inh.infcx.parameter_environment.free_substs;
match self.tcx().impl_trait_ref(impl_def_id) {
let free_substs = &self.parameter_environment.free_substs;
match self.tcx.impl_trait_ref(impl_def_id) {
Some(ref trait_ref) => {
// Trait impl: take implied bounds from all types that
// appear in the trait reference.
@ -589,7 +586,7 @@ fn impl_implied_bounds(&self, impl_def_id: DefId, span: Span) -> Vec<Ty<'tcx>> {
None => {
// Inherent impl: take implied bounds from the self type.
let self_ty = self.tcx().lookup_item_type(impl_def_id).ty;
let self_ty = self.tcx.lookup_item_type(impl_def_id).ty;
let self_ty = self.instantiate_type_scheme(span, free_substs, &self_ty);
vec![self_ty]
}

View file

@ -54,7 +54,7 @@ pub fn resolve_type_vars_in_fn(&self, decl: &hir::FnDecl, blk: &hir::Block) {
wbcx.visit_pat(&arg.pat);
// Privacy needs the type for the whole pattern, not just each binding
if !pat_util::pat_is_binding(&self.tcx().def_map.borrow(), &arg.pat) {
if !pat_util::pat_is_binding(&self.tcx.def_map.borrow(), &arg.pat) {
wbcx.visit_node_id(ResolvingPattern(arg.pat.span),
arg.pat.id);
}
@ -84,7 +84,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
}
fn tcx(&self) -> TyCtxt<'cx, 'tcx, 'tcx> {
self.fcx.tcx()
self.fcx.tcx
}
// Hacky hack: During type-checking, we treat *all* operators
@ -96,13 +96,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
hir::ExprBinary(ref op, ref lhs, ref rhs) |
hir::ExprAssignOp(ref op, ref lhs, ref rhs) => {
let lhs_ty = self.fcx.node_ty(lhs.id);
let lhs_ty = self.fcx.infcx().resolve_type_vars_if_possible(&lhs_ty);
let lhs_ty = self.fcx.resolve_type_vars_if_possible(&lhs_ty);
let rhs_ty = self.fcx.node_ty(rhs.id);
let rhs_ty = self.fcx.infcx().resolve_type_vars_if_possible(&rhs_ty);
let rhs_ty = self.fcx.resolve_type_vars_if_possible(&rhs_ty);
if lhs_ty.is_scalar() && rhs_ty.is_scalar() {
self.fcx.inh.tables.borrow_mut().method_map.remove(&MethodCall::expr(e.id));
self.fcx.tables.borrow_mut().method_map.remove(&MethodCall::expr(e.id));
// weird but true: the by-ref binops put an
// adjustment on the lhs but not the rhs; the
@ -111,11 +111,11 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
match e.node {
hir::ExprBinary(..) => {
if !op.node.is_by_value() {
self.fcx.inh.tables.borrow_mut().adjustments.remove(&lhs.id);
self.fcx.tables.borrow_mut().adjustments.remove(&lhs.id);
}
},
hir::ExprAssignOp(..) => {
self.fcx.inh.tables.borrow_mut().adjustments.remove(&lhs.id);
self.fcx.tables.borrow_mut().adjustments.remove(&lhs.id);
},
_ => {},
}
@ -220,7 +220,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
return;
}
for (upvar_id, upvar_capture) in self.fcx.inh.tables.borrow().upvar_capture_map.iter() {
for (upvar_id, upvar_capture) in self.fcx.tables.borrow().upvar_capture_map.iter() {
let new_upvar_capture = match *upvar_capture {
ty::UpvarCapture::ByValue => ty::UpvarCapture::ByValue,
ty::UpvarCapture::ByRef(ref upvar_borrow) => {
@ -233,11 +233,11 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
debug!("Upvar capture for {:?} resolved to {:?}",
upvar_id,
new_upvar_capture);
self.fcx.tcx()
.tables
.borrow_mut()
.upvar_capture_map
.insert(*upvar_id, new_upvar_capture);
self.tcx()
.tables
.borrow_mut()
.upvar_capture_map
.insert(*upvar_id, new_upvar_capture);
}
}
@ -246,13 +246,13 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
return
}
for (def_id, closure_ty) in self.fcx.inh.tables.borrow().closure_tys.iter() {
for (def_id, closure_ty) in self.fcx.tables.borrow().closure_tys.iter() {
let closure_ty = self.resolve(closure_ty, ResolvingClosure(*def_id));
self.fcx.tcx().tables.borrow_mut().closure_tys.insert(*def_id, closure_ty);
self.tcx().tables.borrow_mut().closure_tys.insert(*def_id, closure_ty);
}
for (def_id, &closure_kind) in self.fcx.inh.tables.borrow().closure_kinds.iter() {
self.fcx.tcx().tables.borrow_mut().closure_kinds.insert(*def_id, closure_kind);
for (def_id, &closure_kind) in self.fcx.tables.borrow().closure_kinds.iter() {
self.tcx().tables.borrow_mut().closure_kinds.insert(*def_id, closure_kind);
}
}
@ -274,7 +274,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
}
fn visit_adjustments(&self, reason: ResolveReason, id: ast::NodeId) {
let adjustments = self.fcx.inh.tables.borrow_mut().adjustments.remove(&id);
let adjustments = self.fcx.tables.borrow_mut().adjustments.remove(&id);
match adjustments {
None => {
debug!("No adjustments for node {}", id);
@ -318,7 +318,7 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
reason: ResolveReason,
method_call: MethodCall) {
// Resolve any method map entry
let new_method = match self.fcx.inh.tables.borrow_mut().method_map.remove(&method_call) {
let new_method = match self.fcx.tables.borrow_mut().method_map.remove(&method_call) {
Some(method) => {
debug!("writeback::resolve_method_map_entry(call={:?}, entry={:?})",
method_call,
@ -346,14 +346,14 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx, 'tcx> {
}
fn visit_liberated_fn_sigs(&self) {
for (&node_id, fn_sig) in self.fcx.inh.tables.borrow().liberated_fn_sigs.iter() {
for (&node_id, fn_sig) in self.fcx.tables.borrow().liberated_fn_sigs.iter() {
let fn_sig = self.resolve(fn_sig, ResolvingFnSig(node_id));
self.tcx().tables.borrow_mut().liberated_fn_sigs.insert(node_id, fn_sig.clone());
}
}
fn visit_fru_field_types(&self) {
for (&node_id, ftys) in self.fcx.inh.tables.borrow().fru_field_types.iter() {
for (&node_id, ftys) in self.fcx.tables.borrow().fru_field_types.iter() {
let ftys = self.resolve(ftys, ResolvingFieldTypes(node_id));
self.tcx().tables.borrow_mut().fru_field_types.insert(node_id, ftys);
}
@ -420,7 +420,7 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx, 'tcx> {
reason: ResolveReason)
-> Resolver<'cx, 'tcx, 'tcx>
{
Resolver::from_infcx(fcx.infcx(), &fcx.writeback_errors, reason)
Resolver::from_infcx(fcx, &fcx.writeback_errors, reason)
}
fn from_infcx(infcx: &'cx InferCtxt<'cx, 'tcx, 'tcx>,