parent
2f45294a50
commit
a18d9842ed
7 changed files with 23 additions and 23 deletions
|
@ -2655,8 +2655,8 @@ macro_rules! step_impl_signed {
|
||||||
#[allow(trivial_numeric_casts)]
|
#[allow(trivial_numeric_casts)]
|
||||||
fn steps_between(start: &$t, end: &$t, by: &$t) -> Option<usize> {
|
fn steps_between(start: &$t, end: &$t, by: &$t) -> Option<usize> {
|
||||||
if *by == 0 { return None; }
|
if *by == 0 { return None; }
|
||||||
let mut diff: usize;
|
let diff: usize;
|
||||||
let mut by_u: usize;
|
let by_u: usize;
|
||||||
if *by > 0 {
|
if *by > 0 {
|
||||||
if *start >= *end {
|
if *start >= *end {
|
||||||
return Some(0);
|
return Some(0);
|
||||||
|
|
|
@ -399,7 +399,7 @@ impl<'a> Parser<'a> {
|
||||||
}
|
}
|
||||||
Some(..) | None => { return &self.input[..0]; }
|
Some(..) | None => { return &self.input[..0]; }
|
||||||
};
|
};
|
||||||
let mut end;
|
let end;
|
||||||
loop {
|
loop {
|
||||||
match self.cur.clone().next() {
|
match self.cur.clone().next() {
|
||||||
Some((_, c)) if c.is_xid_continue() => {
|
Some((_, c)) if c.is_xid_continue() => {
|
||||||
|
|
|
@ -1854,7 +1854,7 @@ impl LifeGiver {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn give_lifetime(&self) -> ast::Lifetime {
|
fn give_lifetime(&self) -> ast::Lifetime {
|
||||||
let mut lifetime;
|
let lifetime;
|
||||||
loop {
|
loop {
|
||||||
let mut s = String::from("'");
|
let mut s = String::from("'");
|
||||||
s.push_str(&num_to_string(self.counter.get()));
|
s.push_str(&num_to_string(self.counter.get()));
|
||||||
|
|
|
@ -182,7 +182,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> {
|
||||||
None => { }
|
None => { }
|
||||||
}
|
}
|
||||||
|
|
||||||
self.check_assignment(assignment_id, assignment_span, assignee_cmt, mode);
|
self.check_assignment(assignment_id, assignment_span, assignee_cmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { }
|
fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { }
|
||||||
|
@ -782,16 +782,9 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
|
||||||
fn check_assignment(&self,
|
fn check_assignment(&self,
|
||||||
assignment_id: ast::NodeId,
|
assignment_id: ast::NodeId,
|
||||||
assignment_span: Span,
|
assignment_span: Span,
|
||||||
assignee_cmt: mc::cmt<'tcx>,
|
assignee_cmt: mc::cmt<'tcx>) {
|
||||||
mode: euv::MutateMode) {
|
|
||||||
debug!("check_assignment(assignee_cmt={:?})", assignee_cmt);
|
debug!("check_assignment(assignee_cmt={:?})", assignee_cmt);
|
||||||
|
|
||||||
// Initializations never cause borrow errors as they only
|
|
||||||
// affect a fresh local.
|
|
||||||
if mode == euv::Init {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that we don't invalidate any outstanding loans
|
// Check that we don't invalidate any outstanding loans
|
||||||
if let Some(loan_path) = opt_loan_path(&assignee_cmt) {
|
if let Some(loan_path) = opt_loan_path(&assignee_cmt) {
|
||||||
let scope = region::CodeExtent::from_node_id(assignment_id);
|
let scope = region::CodeExtent::from_node_id(assignment_id);
|
||||||
|
@ -801,17 +794,15 @@ impl<'a, 'tcx> CheckLoanCtxt<'a, 'tcx> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local variables can always be assigned to, expect for reassignments
|
// Check for reassignments to (immutable) local variables. This
|
||||||
// of immutable variables (or assignments that invalidate loans,
|
// needs to be done here instead of in check_loans because we
|
||||||
// of course).
|
// depend on move data.
|
||||||
if let mc::cat_local(local_id) = assignee_cmt.cat {
|
if let mc::cat_local(local_id) = assignee_cmt.cat {
|
||||||
if assignee_cmt.mutbl.is_mutable() {
|
|
||||||
self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
let lp = opt_loan_path(&assignee_cmt).unwrap();
|
let lp = opt_loan_path(&assignee_cmt).unwrap();
|
||||||
self.move_data.each_assignment_of(assignment_id, &lp, |assign| {
|
self.move_data.each_assignment_of(assignment_id, &lp, |assign| {
|
||||||
if !assignee_cmt.mutbl.is_mutable() {
|
if assignee_cmt.mutbl.is_mutable() {
|
||||||
|
self.tcx().used_mut_nodes.borrow_mut().insert(local_id);
|
||||||
|
} else {
|
||||||
self.bccx.report_reassigned_immutable_variable(
|
self.bccx.report_reassigned_immutable_variable(
|
||||||
assignment_span,
|
assignment_span,
|
||||||
&*lp,
|
&*lp,
|
||||||
|
|
|
@ -308,7 +308,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
|
||||||
|
|
||||||
debug!("process_method: {}:{}", id, token::get_name(name));
|
debug!("process_method: {}:{}", id, token::get_name(name));
|
||||||
|
|
||||||
let mut scope_id;
|
let scope_id;
|
||||||
// The qualname for a method is the trait name or name of the struct in an impl in
|
// The qualname for a method is the trait name or name of the struct in an impl in
|
||||||
// which the method is declared in, followed by the method's name.
|
// which the method is declared in, followed by the method's name.
|
||||||
let qualname = match self.tcx.impl_of_method(ast_util::local_def(id)) {
|
let qualname = match self.tcx.impl_of_method(ast_util::local_def(id)) {
|
||||||
|
|
|
@ -598,7 +598,7 @@ impl<'a> StringReader<'a> {
|
||||||
|
|
||||||
/// Lex a LIT_INTEGER or a LIT_FLOAT
|
/// Lex a LIT_INTEGER or a LIT_FLOAT
|
||||||
fn scan_number(&mut self, c: char) -> token::Lit {
|
fn scan_number(&mut self, c: char) -> token::Lit {
|
||||||
let mut num_digits;
|
let num_digits;
|
||||||
let mut base = 10;
|
let mut base = 10;
|
||||||
let start_bpos = self.last_pos;
|
let start_bpos = self.last_pos;
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,15 @@ fn main() {
|
||||||
let mut b = 3; //~ ERROR: variable does not need to be mutable
|
let mut b = 3; //~ ERROR: variable does not need to be mutable
|
||||||
let mut a = vec!(3); //~ ERROR: variable does not need to be mutable
|
let mut a = vec!(3); //~ ERROR: variable does not need to be mutable
|
||||||
let (mut a, b) = (1, 2); //~ ERROR: variable does not need to be mutable
|
let (mut a, b) = (1, 2); //~ ERROR: variable does not need to be mutable
|
||||||
|
let mut a; //~ ERROR: variable does not need to be mutable
|
||||||
|
a = 3;
|
||||||
|
|
||||||
|
let mut b; //~ ERROR: variable does not need to be mutable
|
||||||
|
if true {
|
||||||
|
b = 3;
|
||||||
|
} else {
|
||||||
|
b = 4;
|
||||||
|
}
|
||||||
|
|
||||||
match 30 {
|
match 30 {
|
||||||
mut x => {} //~ ERROR: variable does not need to be mutable
|
mut x => {} //~ ERROR: variable does not need to be mutable
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue