Improve implicit self mutability suggestions.
This commit adds an `ImplicitSelfKind` to the HIR and the MIR that keeps track of whether a implicit self argument is immutable by-value, mutable by-value, immutable reference or mutable reference so that the addition of the `mut` keyword can be suggested for the immutable by-value case.
This commit is contained in:
parent
f55129d003
commit
43b5d725d0
10 changed files with 180 additions and 26 deletions
|
|
@ -270,7 +270,7 @@ trait TraitChangeModeSelfOwnToMut: Sized {
|
|||
#[rustc_clean(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
trait TraitChangeModeSelfOwnToMut: Sized {
|
||||
#[rustc_clean(label="Hir", cfg="cfail2")]
|
||||
#[rustc_dirty(label="Hir", cfg="cfail2")]
|
||||
#[rustc_clean(label="Hir", cfg="cfail3")]
|
||||
#[rustc_dirty(label="HirBody", cfg="cfail2")]
|
||||
#[rustc_clean(label="HirBody", cfg="cfail3")]
|
||||
|
|
|
|||
37
src/test/ui/nll/issue-51191.rs
Normal file
37
src/test/ui/nll/issue-51191.rs
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
struct Struct;
|
||||
|
||||
impl Struct {
|
||||
fn bar(self: &mut Self) {
|
||||
(&mut self).bar(); //~ ERROR cannot borrow
|
||||
}
|
||||
|
||||
fn imm(self) {
|
||||
(&mut self).bar(); //~ ERROR cannot borrow
|
||||
}
|
||||
|
||||
fn mtbl(mut self) {
|
||||
(&mut self).bar();
|
||||
}
|
||||
|
||||
fn immref(&self) {
|
||||
(&mut self).bar(); //~ ERROR cannot borrow
|
||||
}
|
||||
|
||||
fn mtblref(&mut self) {
|
||||
(&mut self).bar();
|
||||
}
|
||||
}
|
||||
|
||||
fn main () {}
|
||||
37
src/test/ui/nll/issue-51191.stderr
Normal file
37
src/test/ui/nll/issue-51191.stderr
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||
--> $DIR/issue-51191.rs:17:9
|
||||
|
|
||||
LL | fn bar(self: &mut Self) {
|
||||
| ---- help: consider changing this to be mutable: `mut self`
|
||||
LL | (&mut self).bar(); //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||
--> $DIR/issue-51191.rs:21:9
|
||||
|
|
||||
LL | fn imm(self) {
|
||||
| ---- help: consider changing this to be mutable: `mut self`
|
||||
LL | (&mut self).bar(); //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||
--> $DIR/issue-51191.rs:29:9
|
||||
|
|
||||
LL | (&mut self).bar(); //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
||||
error[E0596]: cannot borrow data in a `&` reference as mutable
|
||||
--> $DIR/issue-51191.rs:29:9
|
||||
|
|
||||
LL | (&mut self).bar(); //~ ERROR cannot borrow
|
||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
||||
error[E0596]: cannot borrow `self` as mutable, as it is not declared as mutable
|
||||
--> $DIR/issue-51191.rs:33:9
|
||||
|
|
||||
LL | (&mut self).bar();
|
||||
| ^^^^^^^^^^^ cannot borrow as mutable
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0596`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue