about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.rs24
-rw-r--r--src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr9
-rw-r--r--src/test/ui/methods/field-method-suggestion-using-return-ty.rs18
-rw-r--r--src/test/ui/methods/field-method-suggestion-using-return-ty.stderr27
-rw-r--r--src/test/ui/privacy/private-field-ty-err.stderr5
-rw-r--r--src/test/ui/suggestions/method-access-to-range-literal-typo.fixed34
-rw-r--r--src/test/ui/suggestions/method-access-to-range-literal-typo.rs14
-rw-r--r--src/test/ui/suggestions/method-access-to-range-literal-typo.stderr24
8 files changed, 133 insertions, 22 deletions
diff --git a/src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.rs b/src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.rs
new file mode 100644
index 00000000000..f2f87a90817
--- /dev/null
+++ b/src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.rs
@@ -0,0 +1,24 @@
+// edition:2021
+
+// Test that we do not suggest `.await` when it doesn't make sense.
+
+struct A;
+
+impl A {
+    fn test(&self) -> i32 {
+        1
+    }
+}
+
+async fn foo() -> A {
+    A
+}
+
+async fn async_main() {
+    let x: u32 = foo().test();
+    //~^ ERROR no method named `test` found for opaque type `impl Future<Output = A>` in the current scope
+}
+
+fn main() {
+    let _ = async_main();
+}
diff --git a/src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr b/src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr
new file mode 100644
index 00000000000..e65d9d0e5d3
--- /dev/null
+++ b/src/test/ui/async-await/dont-suggest-await-on-method-return-mismatch.stderr
@@ -0,0 +1,9 @@
+error[E0599]: no method named `test` found for opaque type `impl Future<Output = A>` in the current scope
+  --> $DIR/dont-suggest-await-on-method-return-mismatch.rs:18:24
+   |
+LL |     let x: u32 = foo().test();
+   |                        ^^^^ method not found in `impl Future<Output = A>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/methods/field-method-suggestion-using-return-ty.rs b/src/test/ui/methods/field-method-suggestion-using-return-ty.rs
new file mode 100644
index 00000000000..07b975c44c9
--- /dev/null
+++ b/src/test/ui/methods/field-method-suggestion-using-return-ty.rs
@@ -0,0 +1,18 @@
+struct Wrapper<T>(T);
+
+impl Wrapper<Option<i32>> {
+    fn inner_mut(&self) -> Option<&mut i32> {
+        self.as_mut()
+        //~^ ERROR no method named `as_mut` found for reference `&Wrapper<Option<i32>>` in the current scope
+        //~| HELP one of the expressions' fields has a method of the same name
+        //~| HELP items from traits can only be used if
+    }
+
+    fn inner_mut_bad(&self) -> Option<&mut u32> {
+        self.as_mut()
+        //~^ ERROR no method named `as_mut` found for reference `&Wrapper<Option<i32>>` in the current scope
+        //~| HELP items from traits can only be used if
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/methods/field-method-suggestion-using-return-ty.stderr b/src/test/ui/methods/field-method-suggestion-using-return-ty.stderr
new file mode 100644
index 00000000000..51c52a07e10
--- /dev/null
+++ b/src/test/ui/methods/field-method-suggestion-using-return-ty.stderr
@@ -0,0 +1,27 @@
+error[E0599]: no method named `as_mut` found for reference `&Wrapper<Option<i32>>` in the current scope
+  --> $DIR/field-method-suggestion-using-return-ty.rs:5:14
+   |
+LL |         self.as_mut()
+   |              ^^^^^^ method not found in `&Wrapper<Option<i32>>`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+   = note: the following trait defines an item `as_mut`, perhaps you need to implement it:
+           candidate #1: `AsMut`
+help: one of the expressions' fields has a method of the same name
+   |
+LL |         self.0.as_mut()
+   |              ++
+
+error[E0599]: no method named `as_mut` found for reference `&Wrapper<Option<i32>>` in the current scope
+  --> $DIR/field-method-suggestion-using-return-ty.rs:12:14
+   |
+LL |         self.as_mut()
+   |              ^^^^^^ method not found in `&Wrapper<Option<i32>>`
+   |
+   = help: items from traits can only be used if the trait is implemented and in scope
+   = note: the following trait defines an item `as_mut`, perhaps you need to implement it:
+           candidate #1: `AsMut`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/privacy/private-field-ty-err.stderr b/src/test/ui/privacy/private-field-ty-err.stderr
index e583a25fd8f..98ba7856e57 100644
--- a/src/test/ui/privacy/private-field-ty-err.stderr
+++ b/src/test/ui/privacy/private-field-ty-err.stderr
@@ -3,11 +3,6 @@ error[E0616]: field `len` of struct `Foo` is private
    |
 LL |     if x.len {
    |          ^^^ private field
-   |
-help: a method `len` also exists, call it with parentheses
-   |
-LL |     if x.len() {
-   |             ++
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/suggestions/method-access-to-range-literal-typo.fixed b/src/test/ui/suggestions/method-access-to-range-literal-typo.fixed
new file mode 100644
index 00000000000..13601eef6c2
--- /dev/null
+++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.fixed
@@ -0,0 +1,34 @@
+// run-rustfix
+
+#![allow(unused)]
+
+fn as_ref() -> Option<Vec<u8>> {
+    None
+}
+struct Type {
+    option: Option<Vec<u8>>
+}
+trait Trait {
+    fn foo(&self) -> &Vec<u8>;
+}
+impl Trait for Option<Vec<u8>> {
+    fn foo(&self) -> &Vec<u8> {
+        self.as_ref().unwrap()
+    }
+}
+
+impl Type {
+    fn method(&self) -> Option<&Vec<u8>> {
+        self.option.as_ref().map(|x| x)
+        //~^ ERROR E0308
+    }
+    fn method2(&self) -> Option<&u8> {
+        self.option.foo().get(0)
+        //~^ ERROR E0425
+        //~| ERROR E0308
+    }
+}
+
+fn main() {
+    let _ = Type { option: None }.method();
+}
diff --git a/src/test/ui/suggestions/method-access-to-range-literal-typo.rs b/src/test/ui/suggestions/method-access-to-range-literal-typo.rs
index ac662edafe6..fdcd6425d32 100644
--- a/src/test/ui/suggestions/method-access-to-range-literal-typo.rs
+++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.rs
@@ -1,3 +1,7 @@
+// run-rustfix
+
+#![allow(unused)]
+
 fn as_ref() -> Option<Vec<u8>> {
     None
 }
@@ -5,20 +9,20 @@ struct Type {
     option: Option<Vec<u8>>
 }
 trait Trait {
-    fn foo(&self) -> Vec<u8>;
+    fn foo(&self) -> &Vec<u8>;
 }
 impl Trait for Option<Vec<u8>> {
-    fn foo(&self) -> Vec<u8> {
-        vec![1, 2, 3]
+    fn foo(&self) -> &Vec<u8> {
+        self.as_ref().unwrap()
     }
 }
 
 impl Type {
-    fn method(&self) -> Option<Vec<u8>> {
+    fn method(&self) -> Option<&Vec<u8>> {
         self.option..as_ref().map(|x| x)
         //~^ ERROR E0308
     }
-    fn method2(&self) -> &u8 {
+    fn method2(&self) -> Option<&u8> {
         self.option..foo().get(0)
         //~^ ERROR E0425
         //~| ERROR E0308
diff --git a/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr b/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr
index c84f9467891..f421408944b 100644
--- a/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr
+++ b/src/test/ui/suggestions/method-access-to-range-literal-typo.stderr
@@ -1,5 +1,5 @@
 error[E0425]: cannot find function `foo` in this scope
-  --> $DIR/method-access-to-range-literal-typo.rs:22:22
+  --> $DIR/method-access-to-range-literal-typo.rs:26:22
    |
 LL |         self.option..foo().get(0)
    |                      ^^^ not found in this scope
@@ -11,15 +11,15 @@ LL +         self.option.foo().get(0)
    |
 
 error[E0308]: mismatched types
-  --> $DIR/method-access-to-range-literal-typo.rs:18:9
+  --> $DIR/method-access-to-range-literal-typo.rs:22:9
    |
-LL |     fn method(&self) -> Option<Vec<u8>> {
-   |                         --------------- expected `Option<Vec<u8>>` because of return type
+LL |     fn method(&self) -> Option<&Vec<u8>> {
+   |                         ---------------- expected `Option<&Vec<u8>>` because of return type
 LL |         self.option..as_ref().map(|x| x)
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found struct `Range`
    |
-   = note: expected enum `Option<_>`
-            found struct `std::ops::Range<Option<_>>`
+   = note: expected enum `Option<&Vec<u8>>`
+            found struct `std::ops::Range<Option<Vec<u8>>>`
 help: you likely meant to write a method call instead of a range
    |
 LL -         self.option..as_ref().map(|x| x)
@@ -27,15 +27,15 @@ LL +         self.option.as_ref().map(|x| x)
    |
 
 error[E0308]: mismatched types
-  --> $DIR/method-access-to-range-literal-typo.rs:22:9
+  --> $DIR/method-access-to-range-literal-typo.rs:26:9
    |
-LL |     fn method2(&self) -> &u8 {
-   |                          --- expected `&u8` because of return type
+LL |     fn method2(&self) -> Option<&u8> {
+   |                          ----------- expected `Option<&u8>` because of return type
 LL |         self.option..foo().get(0)
-   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&u8`, found struct `Range`
+   |         ^^^^^^^^^^^^^^^^^^^^^^^^^ expected enum `Option`, found struct `Range`
    |
-   = note: expected reference `&u8`
-                 found struct `std::ops::Range<Option<Vec<u8>>>`
+   = note: expected enum `Option<&u8>`
+            found struct `std::ops::Range<Option<Vec<u8>>>`
 help: you likely meant to write a method call instead of a range
    |
 LL -         self.option..foo().get(0)