about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2019-05-23 10:32:01 -0700
committerEsteban Küber <esteban@kuber.com.ar>2019-05-23 10:32:01 -0700
commit7fbbcfaafd08023cc2296481425e16a02ccd3f1a (patch)
treeaf44bef5c0f28b45e5b6e1b8339f8f63bb153926
parent1e3302d85f6c9635c14535bb59d17964a9479c2d (diff)
downloadrust-7fbbcfaafd08023cc2296481425e16a02ccd3f1a.tar.gz
rust-7fbbcfaafd08023cc2296481425e16a02ccd3f1a.zip
Add regression test for negative case
-rw-r--r--src/test/ui/suggestions/mut-ref-reassignment.rs14
-rw-r--r--src/test/ui/suggestions/mut-ref-reassignment.stderr37
2 files changed, 47 insertions, 4 deletions
diff --git a/src/test/ui/suggestions/mut-ref-reassignment.rs b/src/test/ui/suggestions/mut-ref-reassignment.rs
index b9deaa96dbf..1428324934d 100644
--- a/src/test/ui/suggestions/mut-ref-reassignment.rs
+++ b/src/test/ui/suggestions/mut-ref-reassignment.rs
@@ -1,5 +1,17 @@
-fn change_opt(opt: &mut Option<String>){
+fn suggestion(opt: &mut Option<String>) {
+    opt = None; //~ ERROR mismatched types
+}
+
+fn no_suggestion(opt: &mut Result<String, ()>) {
     opt = None //~ ERROR mismatched types
 }
 
+fn suggestion2(opt: &mut Option<String>) {
+    opt = Some(String::new())//~ ERROR mismatched types
+}
+
+fn no_suggestion2(opt: &mut Option<String>) {
+    opt = Some(42)//~ ERROR mismatched types
+}
+
 fn main() {}
diff --git a/src/test/ui/suggestions/mut-ref-reassignment.stderr b/src/test/ui/suggestions/mut-ref-reassignment.stderr
index d90c13b3882..66b78a1b140 100644
--- a/src/test/ui/suggestions/mut-ref-reassignment.stderr
+++ b/src/test/ui/suggestions/mut-ref-reassignment.stderr
@@ -1,16 +1,47 @@
 error[E0308]: mismatched types
   --> $DIR/mut-ref-reassignment.rs:2:11
    |
-LL |     opt = None
+LL |     opt = None;
    |           ^^^^ expected mutable reference, found enum `std::option::Option`
    |
    = note: expected type `&mut std::option::Option<std::string::String>`
               found type `std::option::Option<_>`
 help: consider dereferencing here to assign to the mutable borrowed piece of memory
    |
-LL |     *opt = None
+LL |     *opt = None;
    |     ^^^^
 
-error: aborting due to previous error
+error[E0308]: mismatched types
+  --> $DIR/mut-ref-reassignment.rs:6:11
+   |
+LL |     opt = None
+   |           ^^^^ expected mutable reference, found enum `std::option::Option`
+   |
+   = note: expected type `&mut std::result::Result<std::string::String, ()>`
+              found type `std::option::Option<_>`
+
+error[E0308]: mismatched types
+  --> $DIR/mut-ref-reassignment.rs:10:11
+   |
+LL |     opt = Some(String::new())
+   |           ^^^^^^^^^^^^^^^^^^^ expected mutable reference, found enum `std::option::Option`
+   |
+   = note: expected type `&mut std::option::Option<std::string::String>`
+              found type `std::option::Option<std::string::String>`
+help: consider dereferencing here to assign to the mutable borrowed piece of memory
+   |
+LL |     *opt = Some(String::new())
+   |     ^^^^
+
+error[E0308]: mismatched types
+  --> $DIR/mut-ref-reassignment.rs:14:11
+   |
+LL |     opt = Some(42)
+   |           ^^^^^^^^ expected mutable reference, found enum `std::option::Option`
+   |
+   = note: expected type `&mut std::option::Option<std::string::String>`
+              found type `std::option::Option<{integer}>`
+
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0308`.