-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #37863 - mikhail-m1:mut_error, r=nikomatsakis
add hint to fix error for immutable ref in arg fix #36412 part of #35233 r? @jonathandturner
- Loading branch information
Showing
15 changed files
with
342 additions
and
46 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
File renamed without changes.
86 changes: 86 additions & 0 deletions
86
src/test/ui/span/borrowck-borrow-overloaded-auto-deref-mut.stderr
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,86 @@ | ||
error: cannot borrow immutable argument `x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:63:24 | ||
| | ||
62 | fn deref_mut_field1(x: Own<Point>) { | ||
| - use `mut x` here to make mutable | ||
63 | let __isize = &mut x.y; //~ ERROR cannot borrow | ||
| ^ cannot borrow mutably | ||
|
||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:75:10 | ||
| | ||
74 | fn deref_extend_mut_field1(x: &Own<Point>) -> &mut isize { | ||
| ----------- use `&mut Own<Point>` here to make mutable | ||
75 | &mut x.y //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error[E0499]: cannot borrow `*x` as mutable more than once at a time | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:88:19 | ||
| | ||
87 | let _x = &mut x.x; | ||
| - first mutable borrow occurs here | ||
88 | let _y = &mut x.y; //~ ERROR cannot borrow | ||
| ^ second mutable borrow occurs here | ||
89 | } | ||
| - first borrow ends here | ||
|
||
error: cannot borrow immutable argument `x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:98:5 | ||
| | ||
97 | fn assign_field1<'a>(x: Own<Point>) { | ||
| - use `mut x` here to make mutable | ||
98 | x.y = 3; //~ ERROR cannot borrow | ||
| ^ cannot borrow mutably | ||
|
||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:102:5 | ||
| | ||
101 | fn assign_field2<'a>(x: &'a Own<Point>) { | ||
| -------------- use `&'a mut Own<Point>` here to make mutable | ||
102 | x.y = 3; //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error[E0499]: cannot borrow `*x` as mutable more than once at a time | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:111:5 | ||
| | ||
110 | let _p: &mut Point = &mut **x; | ||
| -- first mutable borrow occurs here | ||
111 | x.y = 3; //~ ERROR cannot borrow | ||
| ^ second mutable borrow occurs here | ||
112 | } | ||
| - first borrow ends here | ||
|
||
error: cannot borrow immutable argument `x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:119:5 | ||
| | ||
118 | fn deref_mut_method1(x: Own<Point>) { | ||
| - use `mut x` here to make mutable | ||
119 | x.set(0, 0); //~ ERROR cannot borrow | ||
| ^ cannot borrow mutably | ||
|
||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:131:5 | ||
| | ||
130 | fn deref_extend_mut_method1(x: &Own<Point>) -> &mut isize { | ||
| ----------- use `&mut Own<Point>` here to make mutable | ||
131 | x.y_mut() //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error: cannot borrow immutable argument `x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:139:6 | ||
| | ||
138 | fn assign_method1<'a>(x: Own<Point>) { | ||
| - use `mut x` here to make mutable | ||
139 | *x.y_mut() = 3; //~ ERROR cannot borrow | ||
| ^ cannot borrow mutably | ||
|
||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-auto-deref-mut.rs:143:6 | ||
| | ||
142 | fn assign_method2<'a>(x: &'a Own<Point>) { | ||
| -------------- use `&'a mut Own<Point>` here to make mutable | ||
143 | *x.y_mut() = 3; //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error: aborting due to 10 previous errors | ||
|
File renamed without changes.
34 changes: 34 additions & 0 deletions
34
src/test/ui/span/borrowck-borrow-overloaded-deref-mut.stderr
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,34 @@ | ||
error: cannot borrow immutable argument `x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:39:25 | ||
| | ||
38 | fn deref_mut1(x: Own<isize>) { | ||
| - use `mut x` here to make mutable | ||
39 | let __isize = &mut *x; //~ ERROR cannot borrow | ||
| ^ cannot borrow mutably | ||
|
||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:51:11 | ||
| | ||
50 | fn deref_extend_mut1<'a>(x: &'a Own<isize>) -> &'a mut isize { | ||
| -------------- use `&'a mut Own<isize>` here to make mutable | ||
51 | &mut **x //~ ERROR cannot borrow | ||
| ^^ | ||
|
||
error: cannot borrow immutable argument `x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:59:6 | ||
| | ||
58 | fn assign1<'a>(x: Own<isize>) { | ||
| - use `mut x` here to make mutable | ||
59 | *x = 3; //~ ERROR cannot borrow | ||
| ^ cannot borrow mutably | ||
|
||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-borrow-overloaded-deref-mut.rs:63:6 | ||
| | ||
62 | fn assign2<'a>(x: &'a Own<isize>) { | ||
| -------------- use `&'a mut Own<isize>` here to make mutable | ||
63 | **x = 3; //~ ERROR cannot borrow | ||
| ^^ | ||
|
||
error: aborting due to 4 previous errors | ||
|
File renamed without changes.
43 changes: 43 additions & 0 deletions
43
src/test/ui/span/borrowck-call-is-borrow-issue-12224.stderr
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,43 @@ | ||
error[E0499]: cannot borrow `f` as mutable more than once at a time | ||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:23:16 | ||
| | ||
23 | f(Box::new(|| { | ||
| - ^^ second mutable borrow occurs here | ||
| | | ||
| first mutable borrow occurs here | ||
24 | //~^ ERROR: cannot borrow `f` as mutable more than once | ||
25 | f((Box::new(|| {}))) | ||
| - borrow occurs due to use of `f` in closure | ||
26 | })); | ||
| - first borrow ends here | ||
|
||
error: cannot borrow immutable borrowed content `*f` as mutable | ||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:36:5 | ||
| | ||
35 | fn test2<F>(f: &F) where F: FnMut() { | ||
| -- use `&mut F` here to make mutable | ||
36 | (*f)(); //~ ERROR: cannot borrow immutable borrowed content `*f` as mutable | ||
| ^^^^ | ||
|
||
error: cannot borrow immutable `Box` content `*f.f` as mutable | ||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:44:5 | ||
| | ||
44 | f.f.call_mut(()) //~ ERROR: cannot borrow immutable `Box` content `*f.f` as mutable | ||
| ^^^ | ||
|
||
error[E0504]: cannot move `f` into closure because it is borrowed | ||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:63:13 | ||
| | ||
62 | f(Box::new(|a| { | ||
| - borrow of `f` occurs here | ||
63 | foo(f); | ||
| ^ move into closure occurs here | ||
|
||
error[E0507]: cannot move out of captured outer variable in an `FnMut` closure | ||
--> $DIR/borrowck-call-is-borrow-issue-12224.rs:63:13 | ||
| | ||
63 | foo(f); | ||
| ^ cannot move out of captured outer variable in an `FnMut` closure | ||
|
||
error: aborting due to 5 previous errors | ||
|
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
src/test/ui/span/borrowck-call-method-from-mut-aliasable.stderr
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,11 @@ | ||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-call-method-from-mut-aliasable.rs:27:5 | ||
| | ||
25 | fn b(x: &Foo) { | ||
| ---- use `&mut Foo` here to make mutable | ||
26 | x.f(); | ||
27 | x.h(); //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
File renamed without changes.
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,10 @@ | ||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-fn-in-const-b.rs:17:9 | ||
| | ||
16 | fn broken(x: &Vec<String>) { | ||
| ------------ use `&mut Vec<String>` here to make mutable | ||
17 | x.push(format!("this is broken")); | ||
| ^ | ||
|
||
error: aborting due to previous error | ||
|
File renamed without changes.
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,17 @@ | ||
error: cannot borrow immutable borrowed content `*x` as mutable | ||
--> $DIR/borrowck-object-mutability.rs:19:5 | ||
| | ||
17 | fn borrowed_receiver(x: &Foo) { | ||
| ---- use `&mut Foo` here to make mutable | ||
18 | x.borrowed(); | ||
19 | x.borrowed_mut(); //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error: cannot borrow immutable `Box` content `*x` as mutable | ||
--> $DIR/borrowck-object-mutability.rs:29:5 | ||
| | ||
29 | x.borrowed_mut(); //~ ERROR cannot borrow | ||
| ^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
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,32 @@ | ||
// Copyright 2015 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. | ||
|
||
trait B { | ||
fn foo(mut a: &String) { | ||
a.push_str("bar"); | ||
} | ||
} | ||
|
||
pub fn foo<'a>(mut a: &'a String) { | ||
a.push_str("foo"); | ||
} | ||
|
||
struct A {} | ||
|
||
impl A { | ||
pub fn foo(mut a: &String) { | ||
a.push_str("foo"); | ||
} | ||
} | ||
|
||
fn main() { | ||
foo(&"a".to_string()); | ||
A::foo(&"a".to_string()); | ||
} |
Oops, something went wrong.