Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syntax: remove obsolete mutability from ExprVec and ExprRepeat. #13308

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 7 additions & 11 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,17 @@ fn is_test_crate(krate: &ast::Crate) -> bool {
}

fn mk_test_descs(cx: &TestCtxt) -> @ast::Expr {
let mut descs = Vec::new();
debug!("building test vector from {} tests", cx.testfns.borrow().len());
for test in cx.testfns.borrow().iter() {
descs.push(mk_test_desc_and_fn_rec(cx, test));
}

let inner_expr = @ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprVec(descs, ast::MutImmutable),
span: DUMMY_SP,
};

@ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprVstore(inner_expr, ast::ExprVstoreSlice),
node: ast::ExprVstore(@ast::Expr {
id: ast::DUMMY_NODE_ID,
node: ast::ExprVec(cx.testfns.borrow().iter().map(|test| {
mk_test_desc_and_fn_rec(cx, test)
}).collect()),
span: DUMMY_SP,
}, ast::ExprVstoreSlice),
span: DUMMY_SP,
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'a> CFGBuilder<'a> {
self.add_node(expr.id, [])
}

ast::ExprVec(ref elems, _) => {
ast::ExprVec(ref elems) => {
self.straightline(expr, pred, elems.as_slice())
}

Expand Down Expand Up @@ -379,7 +379,7 @@ impl<'a> CFGBuilder<'a> {
self.straightline(expr, base_exit, field_exprs.as_slice())
}

ast::ExprRepeat(elem, count, _) => {
ast::ExprRepeat(elem, count) => {
self.straightline(expr, pred, [elem, count])
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ fn check_expr(v: &mut CheckCrateVisitor, e: &Expr, is_const: bool) {
}
ExprVstore(_, ExprVstoreMutSlice) |
ExprVstore(_, ExprVstoreSlice) |
ExprVec(_, MutImmutable) |
ExprVec(_) |
ExprAddrOf(MutImmutable, _) |
ExprParen(..) |
ExprField(..) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ impl<'a> ConstEvalVisitor<'a> {
join(self.classify(a), self.classify(b)),

ast::ExprTup(ref es) |
ast::ExprVec(ref es, ast::MutImmutable) =>
ast::ExprVec(ref es) =>
join_all(es.iter().map(|e| self.classify(*e))),

ast::ExprVstore(e, vstore) => {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,11 +538,11 @@ impl<'a, 'b, O:DataFlowOperator> PropagationContext<'a, 'b, O> {
self.walk_expr(l, in_out, loop_scopes);
}

ast::ExprVec(ref exprs, _) => {
ast::ExprVec(ref exprs) => {
self.walk_exprs(exprs.as_slice(), in_out, loop_scopes)
}

ast::ExprRepeat(l, r, _) => {
ast::ExprRepeat(l, r) => {
self.walk_expr(l, in_out, loop_scopes);
self.walk_expr(r, in_out, loop_scopes);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub fn check_expr(cx: &mut Context, e: &Expr) {
let target_ty = ty::expr_ty(cx.tcx, e);
check_trait_cast(cx, source_ty, target_ty, source.span);
}
ExprRepeat(element, count_expr, _) => {
ExprRepeat(element, count_expr) => {
let count = ty::eval_repeat_count(cx.tcx, count_expr);
if count > 1 {
let element_ty = ty::expr_ty(cx.tcx, element);
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1109,11 +1109,11 @@ impl<'a> Liveness<'a> {
self.propagate_through_expr(expr, succ)
}

ExprVec(ref exprs, _) => {
ExprVec(ref exprs) => {
self.propagate_through_exprs(exprs.as_slice(), succ)
}

ExprRepeat(element, count, _) => {
ExprRepeat(element, count) => {
let succ = self.propagate_through_expr(count, succ);
self.propagate_through_expr(element, succ)
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/moves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ impl<'a> VisitContext<'a> {
self.use_expr(base, expr_mode);
}

ExprVec(ref exprs, _) => {
ExprVec(ref exprs) => {
self.consume_exprs(exprs.as_slice());
}

Expand Down Expand Up @@ -539,7 +539,7 @@ impl<'a> VisitContext<'a> {
// }
}

ExprRepeat(base, count, _) => {
ExprRepeat(base, count) => {
self.consume_expr(base);
self.consume_expr(count);
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ fn resolve_local(visitor: &mut RegionResolutionVisitor,
visitor.region_maps.record_rvalue_scope(subexpr.id, blk_id);
record_rvalue_scope_if_borrow_expr(visitor, subexpr, blk_id);
}
ast::ExprVec(ref subexprs, _) |
ast::ExprVec(ref subexprs) |
ast::ExprTup(ref subexprs) => {
for &subexpr in subexprs.iter() {
record_rvalue_scope_if_borrow_expr(
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
inlineable.iter().fold(true, |a, &b| a && b))
})
}
ast::ExprVec(ref es, ast::MutImmutable) => {
ast::ExprVec(ref es) => {
let (v, _, inlineable) = const_vec(cx,
e,
es.as_slice(),
Expand All @@ -573,7 +573,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
_ => { cx.sess().span_bug(e.span, "bad const-slice lit") }
}
}
ast::ExprVec(ref es, ast::MutImmutable) => {
ast::ExprVec(ref es) => {
let (cv, llunitty, _) = const_vec(cx,
e,
es.as_slice(),
Expand All @@ -592,7 +592,7 @@ fn const_expr_unadjusted(cx: &CrateContext, e: &ast::Expr,
_ => cx.sess().span_bug(e.span, "bad const-slice expr")
}
}
ast::ExprRepeat(elem, count, _) => {
ast::ExprRepeat(elem, count) => {
let vec_ty = ty::expr_ty(cx.tcx(), e);
let unit_ty = ty::sequence_element_type(cx.tcx(), vec_ty);
let llunitty = type_of::type_of(cx, unit_ty);
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2619,15 +2619,15 @@ fn populate_scope_map(cx: &CrateContext,
walk_expr(cx, rhs, scope_stack, scope_map);
}

ast::ExprVec(ref init_expressions, _) |
ast::ExprTup(ref init_expressions) => {
ast::ExprVec(ref init_expressions) |
ast::ExprTup(ref init_expressions) => {
for ie in init_expressions.iter() {
walk_expr(cx, *ie, scope_stack, scope_map);
}
}

ast::ExprAssign(sub_exp1, sub_exp2) |
ast::ExprRepeat(sub_exp1, sub_exp2, _) => {
ast::ExprAssign(sub_exp1, sub_exp2) |
ast::ExprRepeat(sub_exp1, sub_exp2) => {
walk_expr(cx, sub_exp1, scope_stack, scope_map);
walk_expr(cx, sub_exp2, scope_stack, scope_map);
}
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/trans/tvec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ pub fn write_content<'a>(
}
}
}
ast::ExprVec(ref elements, _) => {
ast::ExprVec(ref elements) => {
match dest {
Ignore => {
for element in elements.iter() {
Expand All @@ -418,7 +418,7 @@ pub fn write_content<'a>(
}
return bcx;
}
ast::ExprRepeat(element, count_expr, _) => {
ast::ExprRepeat(element, count_expr) => {
match dest {
Ignore => {
return expr::trans_into(bcx, element, Ignore);
Expand Down Expand Up @@ -486,8 +486,8 @@ pub fn elements_required(bcx: &Block, content_expr: &ast::Expr) -> uint {
}
}
},
ast::ExprVec(ref es, _) => es.len(),
ast::ExprRepeat(_, count_expr, _) => {
ast::ExprVec(ref es) => es.len(),
ast::ExprRepeat(_, count_expr) => {
ty::eval_repeat_count(bcx.tcx(), count_expr)
}
_ => bcx.tcx().sess.span_bug(content_expr.span,
Expand Down
18 changes: 9 additions & 9 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2482,13 +2482,13 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
ty::mk_str(tcx, tt)
}
ast::ExprVec(ref args, mutbl) => {
ast::ExprVec(ref args) => {
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
let mut any_error = false;
let mut any_bot = false;
let mutability = match vst {
ast::ExprVstoreMutSlice => ast::MutMutable,
_ => mutbl,
_ => ast::MutImmutable,
};
let t: ty::t = fcx.infcx().next_ty_var();
for e in args.iter() {
Expand All @@ -2509,13 +2509,13 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
ty::mk_vec(tcx, ty::mt {ty: t, mutbl: mutability}, tt)
}
}
ast::ExprRepeat(element, count_expr, mutbl) => {
ast::ExprRepeat(element, count_expr) => {
check_expr_with_hint(fcx, count_expr, ty::mk_uint());
let _ = ty::eval_repeat_count(fcx, count_expr);
let tt = ast_expr_vstore_to_vstore(fcx, ev, vst);
let mutability = match vst {
ast::ExprVstoreMutSlice => ast::MutMutable,
_ => mutbl,
_ => ast::MutImmutable,
};
let t: ty::t = fcx.infcx().next_ty_var();
check_expr_has_type(fcx, element, t);
Expand Down Expand Up @@ -3017,16 +3017,16 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
fcx.write_ty(id, t_1);
}
}
ast::ExprVec(ref args, mutbl) => {
ast::ExprVec(ref args) => {
let t: ty::t = fcx.infcx().next_ty_var();
for e in args.iter() {
check_expr_has_type(fcx, *e, t);
}
let typ = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: mutbl},
let typ = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: ast::MutImmutable},
ty::vstore_fixed(args.len()));
fcx.write_ty(id, typ);
}
ast::ExprRepeat(element, count_expr, mutbl) => {
ast::ExprRepeat(element, count_expr) => {
check_expr_with_hint(fcx, count_expr, ty::mk_uint());
let count = ty::eval_repeat_count(fcx, count_expr);
let t: ty::t = fcx.infcx().next_ty_var();
Expand All @@ -3039,7 +3039,7 @@ fn check_expr_with_unifier(fcx: &FnCtxt,
fcx.write_bot(id);
}
else {
let t = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: mutbl},
let t = ty::mk_vec(tcx, ty::mt {ty: t, mutbl: ast::MutImmutable},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a mt now, or can it do with just a t?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been wanting to do this for a while, actually.
Mutability of vstore_slice and RegionTraitStore should be stored in the variants themselves, not in ty_vec or ty_trait.

ty::vstore_fixed(count));
fcx.write_ty(id, t);
}
Expand Down Expand Up @@ -3864,7 +3864,7 @@ pub fn ast_expr_vstore_to_vstore(fcx: &FnCtxt,
// string literals and *empty slices* live in static memory
ty::vstore_slice(ty::ReStatic)
}
ast::ExprVec(ref elements, _) if elements.len() == 0 => {
ast::ExprVec(ref elements) if elements.len() == 0 => {
// string literals and *empty slices* live in static memory
ty::vstore_slice(ty::ReStatic)
}
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ pub enum Expr_ {
ExprVstore(@Expr, ExprVstore),
// First expr is the place; second expr is the value.
ExprBox(@Expr, @Expr),
ExprVec(Vec<@Expr>, Mutability),
ExprVec(Vec<@Expr>),
ExprCall(@Expr, Vec<@Expr>),
ExprMethodCall(Ident, Vec<P<Ty>>, Vec<@Expr>),
ExprTup(Vec<@Expr>),
Expand Down Expand Up @@ -536,7 +536,7 @@ pub enum Expr_ {
ExprStruct(Path, Vec<Field> , Option<@Expr> /* base */),

// A vector literal constructed from one repeated element.
ExprRepeat(@Expr /* element */, @Expr /* count */, Mutability),
ExprRepeat(@Expr /* element */, @Expr /* count */),

// No-op: used solely so we can pretty-print faithfully
ExprParen(@Expr)
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
self.expr(sp, ast::ExprVstore(expr, vst))
}
fn expr_vec(&self, sp: Span, exprs: Vec<@ast::Expr> ) -> @ast::Expr {
self.expr(sp, ast::ExprVec(exprs, ast::MutImmutable))
self.expr(sp, ast::ExprVec(exprs))
}
fn expr_vec_ng(&self, sp: Span) -> @ast::Expr {
self.expr_call_global(sp,
Expand Down
8 changes: 4 additions & 4 deletions src/libsyntax/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,11 +740,11 @@ pub fn noop_fold_expr<T: Folder>(e: @Expr, folder: &mut T) -> @Expr {
ExprBox(p, e) => {
ExprBox(folder.fold_expr(p), folder.fold_expr(e))
}
ExprVec(ref exprs, mutt) => {
ExprVec(exprs.iter().map(|&x| folder.fold_expr(x)).collect(), mutt)
ExprVec(ref exprs) => {
ExprVec(exprs.iter().map(|&x| folder.fold_expr(x)).collect())
}
ExprRepeat(expr, count, mutt) => {
ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count), mutt)
ExprRepeat(expr, count) => {
ExprRepeat(folder.fold_expr(expr), folder.fold_expr(count))
}
ExprTup(ref elts) => ExprTup(elts.iter().map(|x| folder.fold_expr(*x)).collect()),
ExprCall(f, ref args) => {
Expand Down
9 changes: 4 additions & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1819,12 +1819,11 @@ impl<'a> Parser<'a> {
return self.parse_block_expr(lo, UnsafeBlock(ast::UserProvided));
} else if self.token == token::LBRACKET {
self.bump();
let mutbl = MutImmutable;

if self.token == token::RBRACKET {
// Empty vector.
self.bump();
ex = ExprVec(Vec::new(), mutbl);
ex = ExprVec(Vec::new());
} else {
// Nonempty vector.
let first_expr = self.parse_expr();
Expand All @@ -1835,7 +1834,7 @@ impl<'a> Parser<'a> {
self.bump();
let count = self.parse_expr();
self.expect(&token::RBRACKET);
ex = ExprRepeat(first_expr, count, mutbl);
ex = ExprRepeat(first_expr, count);
} else if self.token == token::COMMA {
// Vector with two or more elements.
self.bump();
Expand All @@ -1846,11 +1845,11 @@ impl<'a> Parser<'a> {
);
let mut exprs = vec!(first_expr);
exprs.push_all_move(remaining_exprs);
ex = ExprVec(exprs, mutbl);
ex = ExprVec(exprs);
} else {
// Vector with one element.
self.expect(&token::RBRACKET);
ex = ExprVec(vec!(first_expr), mutbl);
ex = ExprVec(vec!(first_expr));
}
}
hi = self.last_span.hi;
Expand Down
12 changes: 2 additions & 10 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1110,25 +1110,17 @@ impl<'a> State<'a> {
try!(self.word_space(")"));
try!(self.print_expr(e));
}
ast::ExprVec(ref exprs, mutbl) => {
ast::ExprVec(ref exprs) => {
try!(self.ibox(indent_unit));
try!(word(&mut self.s, "["));
if mutbl == ast::MutMutable {
try!(word(&mut self.s, "mut"));
if exprs.len() > 0u { try!(self.nbsp()); }
}
try!(self.commasep_exprs(Inconsistent, exprs.as_slice()));
try!(word(&mut self.s, "]"));
try!(self.end());
}

ast::ExprRepeat(element, count, mutbl) => {
ast::ExprRepeat(element, count) => {
try!(self.ibox(indent_unit));
try!(word(&mut self.s, "["));
if mutbl == ast::MutMutable {
try!(word(&mut self.s, "mut"));
try!(self.nbsp());
}
try!(self.print_expr(element));
try!(word(&mut self.s, ","));
try!(word(&mut self.s, ".."));
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,10 +635,10 @@ pub fn walk_expr<E: Clone, V: Visitor<E>>(visitor: &mut V, expression: &Expr, en
visitor.visit_expr(place, env.clone());
visitor.visit_expr(subexpression, env.clone())
}
ExprVec(ref subexpressions, _) => {
ExprVec(ref subexpressions) => {
walk_exprs(visitor, subexpressions.as_slice(), env.clone())
}
ExprRepeat(element, count, _) => {
ExprRepeat(element, count) => {
visitor.visit_expr(element, env.clone());
visitor.visit_expr(count, env.clone())
}
Expand Down