diff options
| author | Alex Burka <aburka@seas.upenn.edu> | 2016-01-13 01:26:36 -0500 |
|---|---|---|
| committer | Alex Burka <aburka@seas.upenn.edu> | 2016-02-27 02:01:41 -0500 |
| commit | d792183fdeea5623c7ec909d5aa2eccf9171582c (patch) | |
| tree | 70b283460135593c3a479fcee34376d74d85dee5 | |
| parent | a3312784518b9fa95e43f9a2d773acb0c083147a (diff) | |
| download | rust-d792183fdeea5623c7ec909d5aa2eccf9171582c.tar.gz rust-d792183fdeea5623c7ec909d5aa2eccf9171582c.zip | |
fallout from removing hir::ExprRange
A whole bunch of stuff gets folded into struct handling! Plus, removes an ugly hack from trans and accidentally fixes a bug with constructing ranges from references (see later commits with tests).
| -rw-r--r-- | src/librustc/middle/cfg/construct.rs | 6 | ||||
| -rw-r--r-- | src/librustc/middle/expr_use_visitor.rs | 5 | ||||
| -rw-r--r-- | src/librustc/middle/liveness.rs | 9 | ||||
| -rw-r--r-- | src/librustc/middle/mem_categorization.rs | 2 | ||||
| -rw-r--r-- | src/librustc/middle/ty/mod.rs | 1 | ||||
| -rw-r--r-- | src/librustc_back/svh.rs | 2 | ||||
| -rw-r--r-- | src/librustc_front/fold.rs | 4 | ||||
| -rw-r--r-- | src/librustc_front/intravisit.rs | 4 | ||||
| -rw-r--r-- | src/librustc_front/print/pprust.rs | 9 | ||||
| -rw-r--r-- | src/librustc_mir/hair/cx/expr.rs | 33 | ||||
| -rw-r--r-- | src/librustc_passes/consts.rs | 3 | ||||
| -rw-r--r-- | src/librustc_trans/trans/debuginfo/create_scope_map.rs | 5 | ||||
| -rw-r--r-- | src/librustc_trans/trans/expr.rs | 56 | ||||
| -rw-r--r-- | src/librustc_typeck/check/mod.rs | 81 |
14 files changed, 3 insertions, 217 deletions
diff --git a/src/librustc/middle/cfg/construct.rs b/src/librustc/middle/cfg/construct.rs index 701a4596908..4d955173e80 100644 --- a/src/librustc/middle/cfg/construct.rs +++ b/src/librustc/middle/cfg/construct.rs @@ -317,12 +317,6 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { self.call(expr, pred, &l, Some(&**r).into_iter()) } - hir::ExprRange(ref start, ref end) => { - let fields = start.as_ref().map(|e| &**e).into_iter() - .chain(end.as_ref().map(|e| &**e)); - self.straightline(expr, pred, fields) - } - hir::ExprUnary(_, ref e) if self.tcx.is_method_call(expr.id) => { self.call(expr, pred, &e, None::<hir::Expr>.iter()) } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 93cc158cd12..48e9d73c9db 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -399,11 +399,6 @@ impl<'d,'t,'a,'tcx> ExprUseVisitor<'d,'t,'a,'tcx> { } } - hir::ExprRange(ref start, ref end) => { - start.as_ref().map(|e| self.consume_expr(&e)); - end.as_ref().map(|e| self.consume_expr(&e)); - } - hir::ExprCall(ref callee, ref args) => { // callee(args) self.walk_callee(expr, &callee); self.consume_exprs(args); diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index a487ddbc2b1..8d7f49fdb9c 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -498,7 +498,7 @@ fn visit_expr(ir: &mut IrMaps, expr: &Expr) { hir::ExprBlock(..) | hir::ExprAssign(..) | hir::ExprAssignOp(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) | hir::ExprInlineAsm(..) | hir::ExprBox(..) | - hir::ExprRange(..) | hir::ExprType(..) => { + hir::ExprType(..) => { intravisit::walk_expr(ir, expr); } } @@ -1154,11 +1154,6 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { self.propagate_through_expr(&l, r_succ) } - hir::ExprRange(ref e1, ref e2) => { - let succ = e2.as_ref().map_or(succ, |e| self.propagate_through_expr(&e, succ)); - e1.as_ref().map_or(succ, |e| self.propagate_through_expr(&e, succ)) - } - hir::ExprBox(ref e) | hir::ExprAddrOf(_, ref e) | hir::ExprCast(ref e, _) | @@ -1446,7 +1441,7 @@ fn check_expr(this: &mut Liveness, expr: &Expr) { hir::ExprBlock(..) | hir::ExprAddrOf(..) | hir::ExprStruct(..) | hir::ExprRepeat(..) | hir::ExprClosure(..) | hir::ExprPath(..) | hir::ExprBox(..) | - hir::ExprRange(..) | hir::ExprType(..) => { + hir::ExprType(..) => { intravisit::walk_expr(this, expr); } } diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index fef35764e1c..c79c6d91e7f 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -526,7 +526,7 @@ impl<'t, 'a,'tcx> MemCategorizationContext<'t, 'a, 'tcx> { hir::ExprAddrOf(..) | hir::ExprCall(..) | hir::ExprAssign(..) | hir::ExprAssignOp(..) | hir::ExprClosure(..) | hir::ExprRet(..) | - hir::ExprUnary(..) | hir::ExprRange(..) | + hir::ExprUnary(..) | hir::ExprMethodCall(..) | hir::ExprCast(..) | hir::ExprVec(..) | hir::ExprTup(..) | hir::ExprIf(..) | hir::ExprBinary(..) | hir::ExprWhile(..) | diff --git a/src/librustc/middle/ty/mod.rs b/src/librustc/middle/ty/mod.rs index 00a011c6b5d..84b57585c6f 100644 --- a/src/librustc/middle/ty/mod.rs +++ b/src/librustc/middle/ty/mod.rs @@ -2002,7 +2002,6 @@ impl<'tcx> ctxt<'tcx> { hir::ExprCall(..) | hir::ExprMethodCall(..) | hir::ExprStruct(..) | - hir::ExprRange(..) | hir::ExprTup(..) | hir::ExprIf(..) | hir::ExprMatch(..) | diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index b2911630991..b01b80b8133 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -243,7 +243,6 @@ mod svh_visitor { SawExprAssign, SawExprAssignOp(hir::BinOp_), SawExprIndex, - SawExprRange, SawExprPath(Option<usize>), SawExprAddrOf(hir::Mutability), SawExprRet, @@ -275,7 +274,6 @@ mod svh_visitor { ExprField(_, name) => SawExprField(name.node.as_str()), ExprTupField(_, id) => SawExprTupField(id.node), ExprIndex(..) => SawExprIndex, - ExprRange(..) => SawExprRange, ExprPath(ref qself, _) => SawExprPath(qself.as_ref().map(|q| q.position)), ExprAddrOf(m, _) => SawExprAddrOf(m), ExprBreak(id) => SawExprBreak(id.map(|id| id.node.name.as_str())), diff --git a/src/librustc_front/fold.rs b/src/librustc_front/fold.rs index b5e56edb6e4..84d291e5375 100644 --- a/src/librustc_front/fold.rs +++ b/src/librustc_front/fold.rs @@ -1092,10 +1092,6 @@ pub fn noop_fold_expr<T: Folder>(Expr { id, node, span, attrs }: Expr, folder: & ExprIndex(el, er) => { ExprIndex(folder.fold_expr(el), folder.fold_expr(er)) } - ExprRange(e1, e2) => { - ExprRange(e1.map(|x| folder.fold_expr(x)), - e2.map(|x| folder.fold_expr(x))) - } ExprPath(qself, path) => { let qself = qself.map(|QSelf { ty, position }| { QSelf { diff --git a/src/librustc_front/intravisit.rs b/src/librustc_front/intravisit.rs index c1bcaab9d68..a4423c3a991 100644 --- a/src/librustc_front/intravisit.rs +++ b/src/librustc_front/intravisit.rs @@ -784,10 +784,6 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { visitor.visit_expr(main_expression); visitor.visit_expr(index_expression) } - ExprRange(ref start, ref end) => { - walk_list!(visitor, visit_expr, start); - walk_list!(visitor, visit_expr, end); - } ExprPath(ref maybe_qself, ref path) => { if let Some(ref qself) = *maybe_qself { visitor.visit_ty(&qself.ty); diff --git a/src/librustc_front/print/pprust.rs b/src/librustc_front/print/pprust.rs index d837ab0f8f6..d5931dcd14d 100644 --- a/src/librustc_front/print/pprust.rs +++ b/src/librustc_front/print/pprust.rs @@ -1459,15 +1459,6 @@ impl<'a> State<'a> { try!(self.print_expr(&index)); try!(word(&mut self.s, "]")); } - hir::ExprRange(ref start, ref end) => { - if let &Some(ref e) = start { - try!(self.print_expr(&e)); - } - try!(word(&mut self.s, "..")); - if let &Some(ref e) = end { - try!(self.print_expr(&e)); - } - } hir::ExprPath(None, ref path) => { try!(self.print_path(path, true, 0)) } diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index ac1cff527fe..cb54cadfcd1 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -22,7 +22,6 @@ use rustc::middle::ty::{self, VariantDef, Ty}; 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 { @@ -324,38 +323,6 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { } } - 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) } diff --git a/src/librustc_passes/consts.rs b/src/librustc_passes/consts.rs index b0d459063ef..f6e4f3191ef 100644 --- a/src/librustc_passes/consts.rs +++ b/src/librustc_passes/consts.rs @@ -747,9 +747,6 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, hir::ExprAgain(_) | hir::ExprRet(_) | - // Miscellaneous expressions that could be implemented. - hir::ExprRange(..) | - // Expressions with side-effects. hir::ExprAssign(..) | hir::ExprAssignOp(..) | diff --git a/src/librustc_trans/trans/debuginfo/create_scope_map.rs b/src/librustc_trans/trans/debuginfo/create_scope_map.rs index 73fdbd54b29..4ba103c0c0d 100644 --- a/src/librustc_trans/trans/debuginfo/create_scope_map.rs +++ b/src/librustc_trans/trans/debuginfo/create_scope_map.rs @@ -346,11 +346,6 @@ fn walk_expr(cx: &CrateContext, walk_expr(cx, &rhs, scope_stack, scope_map); } - hir::ExprRange(ref start, ref end) => { - start.as_ref().map(|e| walk_expr(cx, &e, scope_stack, scope_map)); - end.as_ref().map(|e| walk_expr(cx, &e, scope_stack, scope_map)); - } - hir::ExprVec(ref init_expressions) | hir::ExprTup(ref init_expressions) => { for ie in init_expressions { diff --git a/src/librustc_trans/trans/expr.rs b/src/librustc_trans/trans/expr.rs index 782e38d3af2..ec6c2cdde59 100644 --- a/src/librustc_trans/trans/expr.rs +++ b/src/librustc_trans/trans/expr.rs @@ -86,7 +86,6 @@ use rustc_front::hir; use syntax::{ast, codemap}; use syntax::parse::token::InternedString; use syntax::ptr::P; -use syntax::parse::token; use std::mem; // Destinations @@ -1059,7 +1058,6 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, -> Block<'blk, 'tcx> { let _icx = push_ctxt("trans_rvalue_dps_unadjusted"); let mut bcx = bcx; - let tcx = bcx.tcx(); debuginfo::set_source_location(bcx.fcx, expr.id, expr.span); @@ -1088,59 +1086,6 @@ fn trans_rvalue_dps_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, node_id_type(bcx, expr.id), dest) } - hir::ExprRange(ref start, ref end) => { - // FIXME it is just not right that we are synthesising ast nodes in - // trans. Shudder. - fn make_field(field_name: &str, expr: P<hir::Expr>) -> hir::Field { - hir::Field { - name: codemap::dummy_spanned(token::intern(field_name)), - expr: expr, - span: codemap::DUMMY_SP, - } - } - - // A range just desugars into a struct. - // Note that the type of the start and end may not be the same, but - // they should only differ in their lifetime, which should not matter - // in trans. - let (did, fields, ty_params) = match (start, end) { - (&Some(ref start), &Some(ref end)) => { - // Desugar to Range - let fields = vec![make_field("start", start.clone()), - make_field("end", end.clone())]; - (tcx.lang_items.range_struct(), fields, vec![node_id_type(bcx, start.id)]) - } - (&Some(ref start), &None) => { - // Desugar to RangeFrom - let fields = vec![make_field("start", start.clone())]; - (tcx.lang_items.range_from_struct(), fields, vec![node_id_type(bcx, start.id)]) - } - (&None, &Some(ref end)) => { - // Desugar to RangeTo - let fields = vec![make_field("end", end.clone())]; - (tcx.lang_items.range_to_struct(), fields, vec![node_id_type(bcx, end.id)]) - } - _ => { - // Desugar to RangeFull - (tcx.lang_items.range_full_struct(), vec![], vec![]) - } - }; - - if let Some(did) = did { - let substs = Substs::new_type(ty_params, vec![]); - trans_struct(bcx, - &fields, - None, - expr.span, - expr.id, - tcx.mk_struct(tcx.lookup_adt_def(did), - tcx.mk_substs(substs)), - dest) - } else { - tcx.sess.span_bug(expr.span, - "No lang item for ranges (how did we get this far?)") - } - } hir::ExprTup(ref args) => { let numbered_fields: Vec<(usize, &hir::Expr)> = args.iter().enumerate().map(|(i, arg)| (i, &**arg)).collect(); @@ -2625,7 +2570,6 @@ fn expr_kind(tcx: &ty::ctxt, expr: &hir::Expr) -> ExprKind { hir::ExprCall(..) | hir::ExprMethodCall(..) | hir::ExprStruct(..) | - hir::ExprRange(..) | hir::ExprTup(..) | hir::ExprIf(..) | hir::ExprMatch(..) | diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 7ab4975c8b8..0eb1d2ee2fd 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3677,87 +3677,6 @@ fn check_expr_with_unifier<'a, 'tcx, F>(fcx: &FnCtxt<'a, 'tcx>, } } } - hir::ExprRange(ref start, ref end) => { - let t_start = start.as_ref().map(|e| { - check_expr(fcx, &e); - fcx.expr_ty(&e) - }); - let t_end = end.as_ref().map(|e| { - check_expr(fcx, &e); - fcx.expr_ty(&e) - }); - - let idx_type = match (t_start, t_end) { - (Some(ty), None) | (None, Some(ty)) => { - Some(ty) - } - (Some(t_start), Some(t_end)) if (t_start.references_error() || - t_end.references_error()) => { - Some(fcx.tcx().types.err) - } - (Some(t_start), Some(t_end)) => { - Some(infer::common_supertype(fcx.infcx(), - TypeOrigin::RangeExpression(expr.span), - true, - t_start, - t_end)) - } - _ => None - }; - - // Note that we don't check the type of start/end satisfy any - // bounds because right now the range structs do not have any. If we add - // some bounds, then we'll need to check `t_start` against them here. - - let range_type = match idx_type { - Some(idx_type) if idx_type.references_error() => { - fcx.tcx().types.err - } - Some(idx_type) => { - // Find the did from the appropriate lang item. - let did = match (start, end) { - (&Some(_), &Some(_)) => tcx.lang_items.range_struct(), - (&Some(_), &None) => tcx.lang_items.range_from_struct(), - (&None, &Some(_)) => tcx.lang_items.range_to_struct(), - (&None, &None) => { - tcx.sess.span_bug(expr.span, "full range should be dealt with above") - } - }; - - if let Some(did) = did { - let def = tcx.lookup_adt_def(did); - let predicates = tcx.lookup_predicates(did); - let substs = Substs::new_type(vec![idx_type], vec![]); - let bounds = fcx.instantiate_bounds(expr.span, &substs, &predicates); - fcx.add_obligations_for_parameters( - traits::ObligationCause::new(expr.span, - fcx.body_id, - traits::ItemObligation(did)), - &bounds); - - tcx.mk_struct(def, tcx.mk_substs(substs)) - } else { - span_err!(tcx.sess, expr.span, E0236, "no lang item for range syntax"); - fcx.tcx().types.err - } - } - None => { - // Neither start nor end => RangeFull - if let Some(did) = tcx.lang_items.range_full_struct() { - tcx.mk_struct( - tcx.lookup_adt_def(did), - tcx.mk_substs(Substs::empty()) - ) - } else { - span_err!(tcx.sess, expr.span, E0237, "no lang item for range syntax"); - fcx.tcx().types.err - } - } - }; - - fcx.write_ty(id, range_type); - } - } debug!("type of expr({}) {} is...", expr.id, |
