use rustc::mir::repr::*;
use rustc_front::hir;
use rustc_front::util as hir_util;
-use syntax::parse::token;
use syntax::ptr::P;
impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr {
debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span);
let expr_ty = cx.tcx.expr_ty(self); // note: no adjustments (yet)!
+ let temp_lifetime = cx.tcx.region_maps.temporary_scope(self.id);
+ let expr_extent = cx.tcx.region_maps.node_extent(self.id);
let kind = match self.node {
// Here comes the interesting stuff:
let method = method_callee(cx, self, ty::MethodCall::expr(self.id));
let sig = match method.ty.sty {
- ty::TyBareFn(_, fn_ty) => &fn_ty.sig,
+ ty::TyFnDef(_, fn_ty) => &fn_ty.sig,
_ => cx.tcx.sess.span_bug(self.span, "type of method is not an fn")
};
let tupled_args = Expr {
ty: sig.inputs[1],
- temp_lifetime: cx.tcx.region_maps.temporary_scope(self.id),
+ temp_lifetime: temp_lifetime,
span: self.span,
kind: ExprKind::Tuple {
fields: args.iter().map(ToRef::to_ref).collect()
}
hir::ExprAssignOp(op, ref lhs, ref rhs) => {
- let op = bin_op(op.node);
- ExprKind::AssignOp {
- op: op,
- lhs: lhs.to_ref(),
- rhs: rhs.to_ref(),
+ if cx.tcx.is_method_call(self.id) {
+ let pass_args = if hir_util::is_by_value_binop(op.node) {
+ PassArgs::ByValue
+ } else {
+ PassArgs::ByRef
+ };
+ overloaded_operator(cx, self, ty::MethodCall::expr(self.id),
+ pass_args, lhs.to_ref(), vec![rhs])
+ } else {
+ ExprKind::AssignOp {
+ op: bin_op(op.node),
+ lhs: lhs.to_ref(),
+ rhs: rhs.to_ref(),
+ }
}
}
}
}
- hir::ExprRange(ref start, ref end) => {
- let range_ty = cx.tcx.expr_ty(self);
- let (adt_def, substs) = match range_ty.sty {
- ty::TyStruct(adt_def, substs) => (adt_def, substs),
- _ => {
- cx.tcx.sess.span_bug(self.span, "unexpanded ast");
- }
- };
-
- let field_expr_ref = |s: &'tcx P<hir::Expr>, name: &str| {
- let name = token::intern(name);
- let index = adt_def.variants[0].index_of_field_named(name).unwrap();
- FieldExprRef { name: Field::new(index), expr: s.to_ref() }
- };
-
- let start_field = start.as_ref()
- .into_iter()
- .map(|s| field_expr_ref(s, "start"));
-
- let end_field = end.as_ref()
- .into_iter()
- .map(|e| field_expr_ref(e, "end"));
-
- ExprKind::Adt {
- adt_def: adt_def,
- variant_index: 0,
- substs: substs,
- fields: start_field.chain(end_field).collect(),
- base: None,
- }
- }
-
hir::ExprPath(..) => {
convert_path_expr(cx, self)
}
ExprKind::Tuple { fields: fields.to_ref() },
};
- let temp_lifetime = cx.tcx.region_maps.temporary_scope(self.id);
- let expr_extent = cx.tcx.region_maps.node_extent(self.id);
-
let mut expr = Expr {
temp_lifetime: temp_lifetime,
ty: expr_ty,
Def::Struct(def_id) => match cx.tcx.node_id_to_type(expr.id).sty {
// A tuple-struct constructor. Should only be reached if not called in the same
// expression.
- ty::TyBareFn(..) => (def_id, ItemKind::Function),
+ ty::TyFnDef(..) => (def_id, ItemKind::Function),
// A unit struct which is used as a value. We return a completely different ExprKind
// here to account for this special case.
ty::TyStruct(adt_def, substs) => return ExprKind::Adt {
Def::Variant(enum_id, variant_id) => match cx.tcx.node_id_to_type(expr.id).sty {
// A variant constructor. Should only be reached if not called in the same
// expression.
- ty::TyBareFn(..) => (variant_id, ItemKind::Function),
+ ty::TyFnDef(..) => (variant_id, ItemKind::Function),
// A unit variant, similar special case to the struct case above.
ty::TyEnum(adt_def, substs) => {
debug_assert!(adt_def.did == enum_id);
let region = cx.tcx.mk_region(region);
let self_expr = match cx.tcx.closure_kind(cx.tcx.map.local_def_id(closure_expr_id)) {
- ty::ClosureKind::FnClosureKind => {
+ ty::ClosureKind::Fn => {
let ref_closure_ty =
cx.tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
}
}
}
- ty::ClosureKind::FnMutClosureKind => {
+ ty::ClosureKind::FnMut => {
let ref_closure_ty =
cx.tcx.mk_ref(region,
ty::TypeAndMut { ty: closure_ty,
}
}
}
- ty::ClosureKind::FnOnceClosureKind => {
+ ty::ClosureKind::FnOnce => {
Expr {
ty: closure_ty,
temp_lifetime: temp_lifetime,