mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
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).
This commit is contained in:
parent
a331278451
commit
d792183fde
@ -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())
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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(..) |
|
||||
|
@ -2002,7 +2002,6 @@ impl<'tcx> ctxt<'tcx> {
|
||||
hir::ExprCall(..) |
|
||||
hir::ExprMethodCall(..) |
|
||||
hir::ExprStruct(..) |
|
||||
hir::ExprRange(..) |
|
||||
hir::ExprTup(..) |
|
||||
hir::ExprIf(..) |
|
||||
hir::ExprMatch(..) |
|
||||
|
@ -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())),
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
|
@ -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))
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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(..) |
|
||||
|
@ -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 {
|
||||
|
@ -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(..) |
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user