| 
10 | 10 | 
 
  | 
11 | 11 | use syntax_pos::Span;  | 
12 | 12 | use rustc::middle::region::ScopeTree;  | 
13 |  | -use rustc::mir::{BorrowKind, Field, Local, Location, Operand};  | 
 | 13 | +use rustc::mir::{BorrowKind, Field, Local, LocalKind, Location, Operand};  | 
14 | 14 | use rustc::mir::{Place, ProjectionElem, Rvalue, Statement, StatementKind};  | 
15 | 15 | use rustc::ty::{self, RegionKind};  | 
16 | 16 | use rustc_data_structures::indexed_vec::Idx;  | 
@@ -568,19 +568,39 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {  | 
568 | 568 |         (place, span): (&Place<'tcx>, Span),  | 
569 | 569 |         assigned_span: Span,  | 
570 | 570 |     ) {  | 
 | 571 | +        let is_arg = if let Place::Local(local) = place {  | 
 | 572 | +            if let LocalKind::Arg = self.mir.local_kind(*local) {  | 
 | 573 | +                true  | 
 | 574 | +            } else {  | 
 | 575 | +                false  | 
 | 576 | +            }  | 
 | 577 | +        } else {  | 
 | 578 | +            false  | 
 | 579 | +        };  | 
 | 580 | + | 
571 | 581 |         let mut err = self.tcx.cannot_reassign_immutable(  | 
572 | 582 |             span,  | 
573 | 583 |             &self.describe_place(place).unwrap_or("_".to_owned()),  | 
 | 584 | +            is_arg,  | 
574 | 585 |             Origin::Mir,  | 
575 | 586 |         );  | 
576 |  | -        err.span_label(span, "cannot assign twice to immutable variable");  | 
 | 587 | +        let msg = if is_arg {  | 
 | 588 | +            "cannot assign to immutable argument"  | 
 | 589 | +        } else {  | 
 | 590 | +            "cannot assign twice to immutable variable"  | 
 | 591 | +        };  | 
577 | 592 |         if span != assigned_span {  | 
578 |  | -            let value_msg = match self.describe_place(place) {  | 
579 |  | -                Some(name) => format!("`{}`", name),  | 
580 |  | -                None => "value".to_owned(),  | 
581 |  | -            };  | 
582 |  | -            err.span_label(assigned_span, format!("first assignment to {}", value_msg));  | 
 | 593 | +            if is_arg {  | 
 | 594 | +                err.span_label(assigned_span, "argument not declared as `mut`");  | 
 | 595 | +            } else {  | 
 | 596 | +                let value_msg = match self.describe_place(place) {  | 
 | 597 | +                    Some(name) => format!("`{}`", name),  | 
 | 598 | +                    None => "value".to_owned(),  | 
 | 599 | +                };  | 
 | 600 | +                err.span_label(assigned_span, format!("first assignment to {}", value_msg));  | 
 | 601 | +            }  | 
583 | 602 |         }  | 
 | 603 | +        err.span_label(span, msg);  | 
584 | 604 |         err.emit();  | 
585 | 605 |     }  | 
586 | 606 | }  | 
 | 
0 commit comments