auto merge of #5966 : alexcrichton/rust/issue-3083, r=graydon

Closes #3083.

This takes a similar approach to #5797 where a set is present on the `tcx` of used mutable definitions. Everything is by default warned about, and analyses must explicitly add mutable definitions to this set so they're not warned about.

Most of this was pretty straightforward, although there was one caveat that I ran into when implementing it. Apparently when the old modes are used (or maybe `legacy_modes`, I'm not sure) some different code paths are taken to cause spurious warnings to be issued which shouldn't be issued. I'm not really sure how modes even worked, so I was having a lot of trouble tracking this down. I figured that because they're a legacy thing that I'd just de-mode the compiler so that the warnings wouldn't be a problem anymore (or at least for the compiler).

Other than that, the entire compiler compiles without warnings of unused mutable variables. To prevent bad warnings, #5965 should be landed (which in turn is waiting on #5963) before landing this. I figured I'd stick it out for review anyway though.
This commit is contained in:
bors
2013-04-22 15:36:51 -07:00
52 changed files with 265 additions and 120 deletions
+14 -14
View File
@@ -810,7 +810,7 @@ fn is_named_argument(&self) -> bool {
// This version of parse arg doesn't necessarily require
// identifier names.
fn parse_arg_general(&self, require_name: bool) -> arg {
let mut m;
let m;
let mut is_mutbl = false;
let pat = if require_name || self.is_named_argument() {
m = self.parse_arg_mode();
@@ -1154,7 +1154,7 @@ fn parse_bottom_expr(&self) -> @expr {
let lo = self.span.lo;
let mut hi = self.span.hi;
let mut ex: expr_;
let ex: expr_;
if *self.token == token::LPAREN {
self.bump();
@@ -1629,9 +1629,9 @@ fn parse_matcher(&self, name_idx: @mut uint) -> matcher {
// parse a prefix-operator expr
fn parse_prefix_expr(&self) -> @expr {
let lo = self.span.lo;
let mut hi;
let hi;
let mut ex;
let ex;
match *self.token {
token::NOT => {
self.bump();
@@ -1781,7 +1781,7 @@ fn parse_assign_expr(&self) -> @expr {
token::BINOPEQ(op) => {
self.bump();
let rhs = self.parse_expr();
let mut aop;
let aop;
match op {
token::PLUS => aop = add,
token::MINUS => aop = subtract,
@@ -1956,7 +1956,7 @@ fn parse_while_expr(&self) -> @expr {
let lo = self.last_span.lo;
let cond = self.parse_expr();
let body = self.parse_block_no_value();
let mut hi = body.span.hi;
let hi = body.span.hi;
return self.mk_expr(lo, hi, expr_while(cond, body));
}
@@ -1984,7 +1984,7 @@ fn parse_loop_expr(&self) -> @expr {
let lo = self.last_span.lo;
let body = self.parse_block_no_value();
let mut hi = body.span.hi;
let hi = body.span.hi;
return self.mk_expr(lo, hi, expr_loop(body, opt_ident));
} else {
// This is a 'continue' expression
@@ -2043,7 +2043,7 @@ fn parse_match_expr(&self) -> @expr {
arms.push(ast::arm { pats: pats, guard: guard, body: blk });
}
let mut hi = self.span.hi;
let hi = self.span.hi;
self.bump();
return self.mk_expr(lo, hi, expr_match(discriminant, arms));
}
@@ -2162,7 +2162,7 @@ fn parse_pat_fields(&self, refutable: bool) -> (~[ast::field_pat], bool) {
let hi1 = self.last_span.lo;
let fieldpath = ast_util::ident_to_path(mk_sp(lo1, hi1),
fieldname);
let mut subpat;
let subpat;
if *self.token == token::COLON {
self.bump();
subpat = self.parse_pat(refutable);
@@ -2183,7 +2183,7 @@ fn parse_pat(&self, refutable: bool) -> @pat {
let lo = self.span.lo;
let mut hi = self.span.hi;
let mut pat;
let pat;
match *self.token {
token::UNDERSCORE => { self.bump(); pat = pat_wild; }
token::AT => {
@@ -2534,7 +2534,7 @@ fn check_expected_item(p: &Parser, current_attrs: &[attribute]) {
match self.parse_item_or_view_item(/*bad*/ copy item_attrs,
true, false, false) {
iovi_item(i) => {
let mut hi = i.span.hi;
let hi = i.span.hi;
let decl = @spanned(lo, hi, decl_item(i));
return @spanned(lo, hi, stmt_decl(decl, self.get_id()));
}
@@ -2704,7 +2704,7 @@ fn parse_block_tail_(&self, lo: BytePos, s: blk_check_mode,
}
}
}
let mut hi = self.span.hi;
let hi = self.span.hi;
self.bump();
let bloc = ast::blk_ {
view_items: view_items,
@@ -3590,7 +3590,7 @@ fn parse_item_foreign_fn(&self, attrs: ~[attribute]) -> @foreign_item {
let purity = self.parse_fn_purity();
let (ident, generics) = self.parse_fn_header();
let decl = self.parse_fn_decl(|p| p.parse_arg());
let mut hi = self.span.hi;
let hi = self.span.hi;
self.expect(&token::SEMI);
@ast::foreign_item { ident: ident,
attrs: attrs,
@@ -3798,7 +3798,7 @@ fn parse_struct_def(&self) -> @struct_def {
}
}
self.bump();
let mut actual_dtor = do the_dtor.map |dtor| {
let actual_dtor = do the_dtor.map |dtor| {
let (d_body, d_attrs, d_s) = copy *dtor;
codemap::spanned { node: ast::struct_dtor_ { id: self.get_id(),
attrs: d_attrs,