diff options
| author | bors <bors@rust-lang.org> | 2019-07-13 13:44:40 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-07-13 13:44:40 +0000 |
| commit | ec30876f30082a7b32876bd78a8da01f11dcde1e (patch) | |
| tree | 42882a1242f0a60f3666cce6057338841444d619 /src/test/ui | |
| parent | 6b468c6360cba002ba1e97b70cf51223a498442e (diff) | |
| parent | 38306adf16ea6eecb6ccfaf0f701b0a1117bb19d (diff) | |
Auto merge of #62468 - rust-lang:mutable-overloaded-operators, r=estebank
Improve diagnostics for invalid mutation through overloaded operators Closes #58864 Closes #52941 Closes #57839
Diffstat (limited to 'src/test/ui')
10 files changed, 97 insertions, 75 deletions
diff --git a/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.rs b/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.rs index 01dc0af8550..83eab7fdeab 100644 --- a/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.rs +++ b/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.rs @@ -2,18 +2,7 @@ // Deref and not DerefMut is implemented. use std::ops::Deref; - -struct Rc<T> { - value: *const T -} - -impl<T> Deref for Rc<T> { - type Target = T; - - fn deref(&self) -> &T { - unsafe { &*self.value } - } -} +use std::rc::Rc; struct Point { x: isize, diff --git a/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.stderr b/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.stderr index dc52685363e..d262c578843 100644 --- a/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.stderr +++ b/src/test/ui/borrowck/borrowck-borrow-overloaded-auto-deref.stderr @@ -1,86 +1,114 @@ -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:47:19 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:36:19 | LL | let __isize = &mut x.y; | ^^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:51:19 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:40:19 | LL | let __isize = &mut x.y; | ^^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:59:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:48:5 | LL | &mut x.y | ^^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:63:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:52:5 | LL | &mut x.y | ^^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0594]: cannot assign to data in a `&` reference - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:67:5 +error[E0594]: cannot assign to data in an `Rc` + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:56:5 | LL | x.y = 3; | ^^^^^^^ cannot assign + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0594]: cannot assign to data in a `&` reference - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:71:5 +error[E0594]: cannot assign to data in an `Rc` + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:60:5 | LL | x.y = 3; | ^^^^^^^ cannot assign + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0594]: cannot assign to data in a `&` reference - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:75:5 +error[E0594]: cannot assign to data in an `Rc` + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:64:5 | LL | x.y = 3; | ^^^^^^^ cannot assign + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:83:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:72:5 | LL | x.set(0, 0); | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:87:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:76:5 | LL | x.set(0, 0); | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:95:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:84:5 | LL | x.y_mut() | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:99:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:88:5 | LL | x.y_mut() | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:103:6 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:92:6 | LL | *x.y_mut() = 3; | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:107:6 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:96:6 | LL | *x.y_mut() = 3; | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:111:6 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-auto-deref.rs:100:6 | LL | *x.y_mut() = 3; | ^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<Point>` error: aborting due to 14 previous errors diff --git a/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.rs b/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.rs index 39fa70c4e59..2b98a7b9483 100644 --- a/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.rs +++ b/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.rs @@ -2,18 +2,7 @@ // Deref and not DerefMut is implemented. use std::ops::Deref; - -struct Rc<T> { - value: *const T -} - -impl<T> Deref for Rc<T> { - type Target = T; - - fn deref<'a>(&'a self) -> &'a T { - unsafe { &*self.value } - } -} +use std::rc::Rc; fn deref_imm(x: Rc<isize>) { let __isize = &*x; diff --git a/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.stderr b/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.stderr index 1755b22f59d..8cacc29414d 100644 --- a/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.stderr +++ b/src/test/ui/borrowck/borrowck-borrow-overloaded-deref.stderr @@ -1,44 +1,58 @@ -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-deref.rs:23:19 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-deref.rs:12:19 | LL | let __isize = &mut *x; | ^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-deref.rs:27:19 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-deref.rs:16:19 | LL | let __isize = &mut *x; | ^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-deref.rs:35:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-deref.rs:24:5 | LL | &mut **x | ^^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` -error[E0596]: cannot borrow data in a `&` reference as mutable - --> $DIR/borrowck-borrow-overloaded-deref.rs:39:5 +error[E0596]: cannot borrow data in an `Rc` as mutable + --> $DIR/borrowck-borrow-overloaded-deref.rs:28:5 | LL | &mut **x | ^^^^^^^^ cannot borrow as mutable + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` -error[E0594]: cannot assign to data in a `&` reference - --> $DIR/borrowck-borrow-overloaded-deref.rs:43:5 +error[E0594]: cannot assign to data in an `Rc` + --> $DIR/borrowck-borrow-overloaded-deref.rs:32:5 | LL | *x = 3; | ^^^^^^ cannot assign + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` -error[E0594]: cannot assign to data in a `&` reference - --> $DIR/borrowck-borrow-overloaded-deref.rs:47:5 +error[E0594]: cannot assign to data in an `Rc` + --> $DIR/borrowck-borrow-overloaded-deref.rs:36:5 | LL | **x = 3; | ^^^^^^^ cannot assign + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` -error[E0594]: cannot assign to data in a `&` reference - --> $DIR/borrowck-borrow-overloaded-deref.rs:51:5 +error[E0594]: cannot assign to data in an `Rc` + --> $DIR/borrowck-borrow-overloaded-deref.rs:40:5 | LL | **x = 3; | ^^^^^^^ cannot assign + | + = help: trait `DerefMut` is required to modify through a dereference, but it is not implemented for `std::rc::Rc<isize>` error: aborting due to 7 previous errors diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.rs b/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.rs index cb20873432b..8adafaa8e93 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.rs +++ b/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.rs @@ -54,6 +54,6 @@ fn main() { x: 1, }; s[2] = 20; - //~^ ERROR cannot assign to data in a `&` reference + //~^ ERROR cannot assign to data in an index of `Bar` drop(rs); } diff --git a/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.stderr b/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.stderr index fcbfe72a34b..84fe17d8544 100644 --- a/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.stderr +++ b/src/test/ui/borrowck/borrowck-overloaded-index-ref-index.stderr @@ -21,11 +21,13 @@ LL | f[&s] = 10; LL | drop(rs); | -- mutable borrow later used here -error[E0594]: cannot assign to data in a `&` reference +error[E0594]: cannot assign to data in an index of `Bar` --> $DIR/borrowck-overloaded-index-ref-index.rs:56:5 | LL | s[2] = 20; | ^^^^^^^^^ cannot assign + | + = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `Bar` error: aborting due to 3 previous errors diff --git a/src/test/ui/borrowck/index-mut-help-with-impl.stderr b/src/test/ui/borrowck/index-mut-help-with-impl.stderr index 4b29beb02b3..89391f4099a 100644 --- a/src/test/ui/borrowck/index-mut-help-with-impl.stderr +++ b/src/test/ui/borrowck/index-mut-help-with-impl.stderr @@ -3,8 +3,6 @@ error[E0596]: cannot borrow data in a `&` reference as mutable | LL | Index::index(&v, 1..2).make_ascii_uppercase(); | ^^^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable - | - = help: trait `IndexMut` is required to modify indexed content error: aborting due to previous error diff --git a/src/test/ui/borrowck/index-mut-help.stderr b/src/test/ui/borrowck/index-mut-help.stderr index fbc427a6e6d..47f2171f88c 100644 --- a/src/test/ui/borrowck/index-mut-help.stderr +++ b/src/test/ui/borrowck/index-mut-help.stderr @@ -1,4 +1,4 @@ -error[E0596]: cannot borrow data in a `&` reference as mutable +error[E0596]: cannot borrow data in an index of `std::collections::HashMap<&str, std::string::String>` as mutable --> $DIR/index-mut-help.rs:11:5 | LL | map["peter"].clear(); @@ -6,13 +6,15 @@ LL | map["peter"].clear(); | = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap<&str, std::string::String>` -error[E0594]: cannot assign to data in a `&` reference +error[E0594]: cannot assign to data in an index of `std::collections::HashMap<&str, std::string::String>` --> $DIR/index-mut-help.rs:12:5 | LL | map["peter"] = "0".to_string(); | ^^^^^^^^^^^^ cannot assign + | + = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `std::collections::HashMap<&str, std::string::String>` -error[E0596]: cannot borrow data in a `&` reference as mutable +error[E0596]: cannot borrow data in an index of `std::collections::HashMap<&str, std::string::String>` as mutable --> $DIR/index-mut-help.rs:13:13 | LL | let _ = &mut map["peter"]; diff --git a/src/test/ui/issues/issue-41726.rs b/src/test/ui/issues/issue-41726.rs index ed056293890..39631912c00 100644 --- a/src/test/ui/issues/issue-41726.rs +++ b/src/test/ui/issues/issue-41726.rs @@ -2,6 +2,6 @@ use std::collections::HashMap; fn main() { let things: HashMap<String, Vec<String>> = HashMap::new(); for src in things.keys() { - things[src.as_str()].sort(); //~ ERROR cannot borrow data in a `&` reference as mutable + things[src.as_str()].sort(); //~ ERROR cannot borrow data in an index of } } diff --git a/src/test/ui/issues/issue-41726.stderr b/src/test/ui/issues/issue-41726.stderr index c92753d6e3d..aa7f23511dd 100644 --- a/src/test/ui/issues/issue-41726.stderr +++ b/src/test/ui/issues/issue-41726.stderr @@ -1,4 +1,4 @@ -error[E0596]: cannot borrow data in a `&` reference as mutable +error[E0596]: cannot borrow data in an index of `std::collections::HashMap<std::string::String, std::vec::Vec<std::string::String>>` as mutable --> $DIR/issue-41726.rs:5:9 | LL | things[src.as_str()].sort(); |
