-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
10 changed files
with
180 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 () {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |