Skip to content

Commit a772542

Browse files
nrcnikomatsakis
authored andcommitted
Remove old slicing hacks and make new slicing work
1 parent 38cf43f commit a772542

File tree

9 files changed

+136
-402
lines changed

9 files changed

+136
-402
lines changed

src/librustc/middle/expr_use_visitor.rs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -441,28 +441,12 @@ impl<'d,'t,'tcx,TYPER:mc::Typer<'tcx>> ExprUseVisitor<'d,'t,'tcx,TYPER> {
441441
}
442442

443443
ast::ExprIndex(ref lhs, ref rhs) => { // lhs[rhs]
444-
match rhs.node {
445-
ast::ExprRange(ref start, ref end) => {
446-
// Hacked slicing syntax (KILLME).
447-
let args = match (start, end) {
448-
(&Some(ref e1), &Some(ref e2)) => vec![&**e1, &**e2],
449-
(&Some(ref e), &None) => vec![&**e],
450-
(&None, &Some(ref e)) => vec![&**e],
451-
(&None, &None) => Vec::new()
452-
};
453-
let overloaded =
454-
self.walk_overloaded_operator(expr, &**lhs, args, PassArgs::ByRef);
455-
assert!(overloaded);
456-
}
457-
_ => {
458-
if !self.walk_overloaded_operator(expr,
459-
&**lhs,
460-
vec![&**rhs],
461-
PassArgs::ByRef) {
462-
self.select_from_expr(&**lhs);
463-
self.consume_expr(&**rhs);
464-
}
465-
}
444+
if !self.walk_overloaded_operator(expr,
445+
&**lhs,
446+
vec![&**rhs],
447+
PassArgs::ByRef) {
448+
self.select_from_expr(&**lhs);
449+
self.consume_expr(&**rhs);
466450
}
467451
}
468452

src/librustc/middle/lang_items.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,6 @@ lets_do_this! {
266266
ShrTraitLangItem, "shr", shr_trait;
267267
IndexTraitLangItem, "index", index_trait;
268268
IndexMutTraitLangItem, "index_mut", index_mut_trait;
269-
SliceTraitLangItem, "slice", slice_trait;
270-
SliceMutTraitLangItem, "slice_mut", slice_mut_trait;
271269
RangeStructLangItem, "range", range_struct;
272270
RangeFromStructLangItem, "range_from", range_from_struct;
273271
RangeToStructLangItem, "range_to", range_to_struct;

src/librustc/middle/mem_categorization.rs

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -490,28 +490,20 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
490490
Ok(self.cat_tup_field(expr, base_cmt, idx.node, expr_ty))
491491
}
492492

493-
ast::ExprIndex(ref base, ref idx) => {
494-
match idx.node {
495-
ast::ExprRange(..) => {
496-
// Slicing syntax special case (KILLME).
497-
Ok(self.cat_rvalue_node(expr.id(), expr.span(), expr_ty))
493+
ast::ExprIndex(ref base, _) => {
494+
let method_call = ty::MethodCall::expr(expr.id());
495+
match self.typer.node_method_ty(method_call) {
496+
Some(method_ty) => {
497+
// If this is an index implemented by a method call, then it will
498+
// include an implicit deref of the result.
499+
let ret_ty = ty::ty_fn_ret(method_ty).unwrap();
500+
self.cat_deref(expr,
501+
self.cat_rvalue_node(expr.id(),
502+
expr.span(),
503+
ret_ty), 1, true)
498504
}
499-
_ => {
500-
let method_call = ty::MethodCall::expr(expr.id());
501-
match self.typer.node_method_ty(method_call) {
502-
Some(method_ty) => {
503-
// If this is an index implemented by a method call, then it will
504-
// include an implicit deref of the result.
505-
let ret_ty = ty::ty_fn_ret(method_ty).unwrap();
506-
self.cat_deref(expr,
507-
self.cat_rvalue_node(expr.id(),
508-
expr.span(),
509-
ret_ty), 1, true)
510-
}
511-
None => {
512-
self.cat_index(expr, try!(self.cat_expr(&**base)))
513-
}
514-
}
505+
None => {
506+
self.cat_index(expr, self.cat_expr(&**base))
515507
}
516508
}
517509
}

src/librustc/middle/ty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,7 @@ pub struct ClosureTy<'tcx> {
10481048
pub abi: abi::Abi,
10491049
}
10501050

1051-
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
1051+
#[derive(Clone, Copy, PartialEq, Eq, Hash, Show)]
10521052
pub enum FnOutput<'tcx> {
10531053
FnConverging(Ty<'tcx>),
10541054
FnDiverging
@@ -1701,8 +1701,7 @@ impl fmt::Show for RegionVid {
17011701

17021702
impl<'tcx> fmt::Show for FnSig<'tcx> {
17031703
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1704-
// grr, without tcx not much we can do.
1705-
write!(f, "(...)")
1704+
write!(f, "({}; variadic: {})->{}", self.inputs, self.variadic, self.output)
17061705
}
17071706
}
17081707

src/librustc_trans/trans/cleanup.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ use trans::common;
2424
use trans::common::{Block, FunctionContext, ExprId, NodeInfo};
2525
use trans::debuginfo;
2626
use trans::glue;
27-
// Temporary due to slicing syntax hacks (KILLME)
28-
//use middle::region;
27+
use middle::region;
2928
use trans::type_::Type;
3029
use middle::ty::{self, Ty};
3130
use std::fmt;
@@ -129,16 +128,15 @@ impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
129128
// excluding id's that correspond to closure bodies only). For
130129
// now we just say that if there is already an AST scope on the stack,
131130
// this new AST scope had better be its immediate child.
132-
// Temporarily removed due to slicing syntax hacks (KILLME).
133-
/*let top_scope = self.top_ast_scope();
131+
let top_scope = self.top_ast_scope();
134132
if top_scope.is_some() {
135133
assert_eq!(self.ccx
136134
.tcx()
137135
.region_maps
138136
.opt_encl_scope(region::CodeExtent::from_node_id(debug_loc.id))
139137
.map(|s|s.node_id()),
140138
top_scope);
141-
}*/
139+
}
142140

143141
self.push_scope(CleanupScope::new(AstScopeKind(debug_loc.id),
144142
Some(debug_loc)));

src/librustc_trans/trans/expr.rs

Lines changed: 1 addition & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -592,40 +592,7 @@ fn trans_datum_unadjusted<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
592592
trans_rec_tup_field(bcx, &**base, idx.node)
593593
}
594594
ast::ExprIndex(ref base, ref idx) => {
595-
match idx.node {
596-
ast::ExprRange(ref start, ref end) => {
597-
// Special case for slicing syntax (KILLME).
598-
let _icx = push_ctxt("trans_slice");
599-
let ccx = bcx.ccx();
600-
601-
let method_call = MethodCall::expr(expr.id);
602-
let method_ty = ccx.tcx()
603-
.method_map
604-
.borrow()
605-
.get(&method_call)
606-
.map(|method| method.ty);
607-
let base_datum = unpack_datum!(bcx, trans(bcx, &**base));
608-
609-
let mut args = vec![];
610-
start.as_ref().map(|e| args.push((unpack_datum!(bcx, trans(bcx, &**e)), e.id)));
611-
end.as_ref().map(|e| args.push((unpack_datum!(bcx, trans(bcx, &**e)), e.id)));
612-
613-
let result_ty = ty::ty_fn_ret(monomorphize_type(bcx,
614-
method_ty.unwrap())).unwrap();
615-
let scratch = rvalue_scratch_datum(bcx, result_ty, "trans_slice");
616-
617-
unpack_result!(bcx,
618-
trans_overloaded_op(bcx,
619-
expr,
620-
method_call,
621-
base_datum,
622-
args,
623-
Some(SaveIn(scratch.val)),
624-
true));
625-
DatumBlock::new(bcx, scratch.to_expr_datum())
626-
}
627-
_ => trans_index(bcx, expr, &**base, &**idx, MethodCall::expr(expr.id))
628-
}
595+
trans_index(bcx, expr, &**base, &**idx, MethodCall::expr(expr.id))
629596
}
630597
ast::ExprBox(_, ref contents) => {
631598
// Special case for `Box<T>`

0 commit comments

Comments
 (0)