//! There are a number of troublesome scenarios in the tests
//! `region-dependent-*.rs`, but here is one example:
//!
-//! struct Foo { i: int }
+//! struct Foo { i: i32 }
//! struct Bar { foo: Foo }
-//! fn get_i(x: &'a Bar) -> &'a int {
+//! fn get_i(x: &'a Bar) -> &'a i32 {
//! let foo = &x.foo; // Lifetime L1
//! &foo.i // Lifetime L2
//! }
use middle::subst::Substs;
use middle::traits;
use middle::ty::{self, RegionEscape, ReScope, Ty, MethodCall, HasTypeFlags};
-use middle::infer::{self, GenericKind, InferCtxt, SubregionOrigin, VerifyBound};
+use middle::infer::{self, GenericKind, InferCtxt, SubregionOrigin, TypeOrigin, VerifyBound};
use middle::pat_util;
use middle::ty::adjustment;
use middle::ty::wf::ImpliedBound;
use std::rc::Rc;
use syntax::ast;
use syntax::codemap::Span;
-use rustc_front::visit;
-use rustc_front::visit::Visitor;
+use rustc_front::intravisit::{self, Visitor};
use rustc_front::hir;
use rustc_front::util as hir_util;
/// Consider this silly example:
///
/// ```
- /// fn borrow(x: &int) -> &int {x}
- /// fn foo(x: @int) -> int { // block: B
+ /// fn borrow(x: &i32) -> &i32 {x}
+ /// fn foo(x: @i32) -> i32 { // block: B
/// let b = borrow(x); // region: <R0>
/// *b
/// }
/// Here, the region of `b` will be `<R0>`. `<R0>` is constrained to be some subregion of the
/// block B and some superregion of the call. If we forced it now, we'd choose the smaller
/// region (the call). But that would make the *b illegal. Since we don't resolve, the type
- /// of b will be `&<R0>.int` and then `*b` will require that `<R0>` be bigger than the let and
+ /// 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)
// hierarchy, and in particular the relationships between free
// regions, until regionck, as described in #3238.
- fn visit_fn(&mut self, _fk: visit::FnKind<'v>, fd: &'v hir::FnDecl,
+ fn visit_fn(&mut self, _fk: intravisit::FnKind<'v>, fd: &'v hir::FnDecl,
b: &'v hir::Block, span: Span, id: ast::NodeId) {
self.visit_fn_body(id, fd, b, span)
}
- fn visit_item(&mut self, i: &hir::Item) { visit_item(self, i); }
-
fn visit_expr(&mut self, ex: &hir::Expr) { visit_expr(self, ex); }
//visit_pat: visit_pat, // (..) see above
fn visit_block(&mut self, b: &hir::Block) { visit_block(self, b); }
}
-fn visit_item(_rcx: &mut Rcx, _item: &hir::Item) {
- // Ignore items
-}
-
fn visit_block(rcx: &mut Rcx, b: &hir::Block) {
- visit::walk_block(rcx, b);
+ intravisit::walk_block(rcx, b);
}
fn visit_arm(rcx: &mut Rcx, arm: &hir::Arm) {
constrain_bindings_in_pat(&**p, rcx);
}
- visit::walk_arm(rcx, arm);
+ intravisit::walk_arm(rcx, arm);
}
fn visit_local(rcx: &mut Rcx, l: &hir::Local) {
// see above
constrain_bindings_in_pat(&*l.pat, rcx);
link_local(rcx, l);
- visit::walk_local(rcx, l);
+ intravisit::walk_local(rcx, l);
}
fn constrain_bindings_in_pat(pat: &hir::Pat, rcx: &mut Rcx) {
args.iter().map(|e| &**e), false);
}
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprMethodCall(_, _, ref args) => {
constrain_call(rcx, expr, Some(&*args[0]),
args[1..].iter().map(|e| &**e), false);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprAssignOp(_, ref lhs, ref rhs) => {
Some(&**rhs).into_iter(), false);
}
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprIndex(ref lhs, ref rhs) if has_method_map => {
constrain_call(rcx, expr, Some(&**lhs),
Some(&**rhs).into_iter(), true);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
},
hir::ExprBinary(op, ref lhs, ref rhs) if has_method_map => {
constrain_call(rcx, expr, Some(&**lhs),
Some(&**rhs).into_iter(), implicitly_ref_args);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprBinary(_, ref lhs, ref rhs) => {
ty,
expr_region);
}
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprUnary(op, ref lhs) if has_method_map => {
constrain_call(rcx, expr, Some(&**lhs),
None::<hir::Expr>.iter(), implicitly_ref_args);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprUnary(hir::UnDeref, ref base) => {
rcx, expr.span, expr_region, *r_ptr);
}
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprIndex(ref vec_expr, _) => {
let vec_type = rcx.resolve_expr_type_adjusted(&**vec_expr);
constrain_index(rcx, expr, vec_type);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprCast(ref source, _) => {
// instance. If so, we have to be sure that the type of
// the source obeys the trait's region bound.
constrain_cast(rcx, expr, &**source);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprAddrOf(m, ref base) => {
// FIXME(#6268) nested method calls requires that this rule change
let ty0 = rcx.resolve_node_type(expr.id);
type_must_outlive(rcx, infer::AddrOf(expr.span), ty0, expr_region);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprMatch(ref discr, ref arms, _) => {
link_match(rcx, &**discr, &arms[..]);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
hir::ExprClosure(_, _, ref body) => {
hir::ExprLoop(ref body, _) => {
let repeating_scope = rcx.set_repeating_scope(body.id);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
rcx.set_repeating_scope(repeating_scope);
}
}
_ => {
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
}
}
}
expr: &hir::Expr,
body: &hir::Block) {
let repeating_scope = rcx.set_repeating_scope(body.id);
- visit::walk_expr(rcx, expr);
+ intravisit::walk_expr(rcx, expr);
rcx.set_repeating_scope(repeating_scope);
}
let mut declared_bounds =
declared_generic_bounds_from_env(rcx, GenericKind::Projection(projection_ty));
- declared_bounds.push_all(
+ declared_bounds.extend_from_slice(
&declared_projection_bounds_from_trait(rcx, span, projection_ty));
declared_bounds
outlives);
// check whether this predicate applies to our current projection
- match infer::mk_eqty(infcx, false, infer::Misc(span), ty, outlives.0) {
+ match infer::mk_eqty(infcx, false, TypeOrigin::Misc(span), ty, outlives.0) {
Ok(()) => { Ok(outlives.1) }
Err(_) => { Err(()) }
}