about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/associated-types/dont-suggest-cyclic-constraint.rs11
-rw-r--r--tests/ui/associated-types/dont-suggest-cyclic-constraint.stderr12
-rw-r--r--tests/ui/inference/deref-suggestion.stderr13
-rw-r--r--tests/ui/issues/issue-100605.stderr15
-rw-r--r--tests/ui/let-else/let-else-ref-bindings.stderr18
-rw-r--r--tests/ui/suggestions/as-ref.rs2
-rw-r--r--tests/ui/suggestions/as-ref.stderr32
-rw-r--r--tests/ui/suggestions/dont-suggest-try_into-in-macros.stderr12
-rw-r--r--tests/ui/switched-expectations.stderr4
-rw-r--r--tests/ui/typeck/issue-89856.stderr2
10 files changed, 92 insertions, 29 deletions
diff --git a/tests/ui/associated-types/dont-suggest-cyclic-constraint.rs b/tests/ui/associated-types/dont-suggest-cyclic-constraint.rs
new file mode 100644
index 00000000000..6894f6b6cc4
--- /dev/null
+++ b/tests/ui/associated-types/dont-suggest-cyclic-constraint.rs
@@ -0,0 +1,11 @@
+use std::fmt::Debug;
+
+fn foo<I: Iterator>(mut iter: I, value: &I::Item)
+where
+    I::Item: Eq + Debug,
+{
+    debug_assert_eq!(iter.next(), Some(value));
+    //~^ ERROR mismatched types
+}
+
+fn main() {}
diff --git a/tests/ui/associated-types/dont-suggest-cyclic-constraint.stderr b/tests/ui/associated-types/dont-suggest-cyclic-constraint.stderr
new file mode 100644
index 00000000000..3ecac9c83e5
--- /dev/null
+++ b/tests/ui/associated-types/dont-suggest-cyclic-constraint.stderr
@@ -0,0 +1,12 @@
+error[E0308]: mismatched types
+  --> $DIR/dont-suggest-cyclic-constraint.rs:7:35
+   |
+LL |     debug_assert_eq!(iter.next(), Some(value));
+   |                                   ^^^^^^^^^^^ expected `Option<<I as Iterator>::Item>`, found `Option<&<I as Iterator>::Item>`
+   |
+   = note: expected enum `Option<<I as Iterator>::Item>`
+              found enum `Option<&<I as Iterator>::Item>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/inference/deref-suggestion.stderr b/tests/ui/inference/deref-suggestion.stderr
index c58aab42269..096989db0b4 100644
--- a/tests/ui/inference/deref-suggestion.stderr
+++ b/tests/ui/inference/deref-suggestion.stderr
@@ -84,15 +84,16 @@ LL | fn foo3(_: u32) {}
    |    ^^^^ ------
 
 error[E0308]: mismatched types
-  --> $DIR/deref-suggestion.rs:37:5
+  --> $DIR/deref-suggestion.rs:37:22
    |
 LL |     assert_eq!(3i32, &3i32);
-   |     ^^^^^^^^^^^^^^^^^^^^^^^
-   |     |
-   |     expected `i32`, found `&i32`
-   |     expected because this is `i32`
+   |                      ^^^^^ expected `i32`, found `&i32`
+   |
+help: consider removing the borrow
+   |
+LL -     assert_eq!(3i32, &3i32);
+LL +     assert_eq!(3i32, 3i32);
    |
-   = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
 
 error[E0308]: mismatched types
   --> $DIR/deref-suggestion.rs:40:17
diff --git a/tests/ui/issues/issue-100605.stderr b/tests/ui/issues/issue-100605.stderr
index be30eef2af4..6f11f44755a 100644
--- a/tests/ui/issues/issue-100605.stderr
+++ b/tests/ui/issues/issue-100605.stderr
@@ -13,10 +13,6 @@ note: function defined here
    |
 LL | fn takes_option(_arg: Option<&String>) {}
    |    ^^^^^^^^^^^^ ---------------------
-help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`
-   |
-LL |     takes_option(None.as_ref());
-   |                  ~~~~~~~~~~~~~
 help: consider removing the borrow
    |
 LL -     takes_option(&None);
@@ -27,10 +23,8 @@ error[E0308]: mismatched types
   --> $DIR/issue-100605.rs:8:18
    |
 LL |     takes_option(&res);
-   |     ------------ ^^^^
-   |     |            |
-   |     |            expected `Option<&String>`, found `&Option<String>`
-   |     |            help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`: `res.as_ref()`
+   |     ------------ ^^^^ expected `Option<&String>`, found `&Option<String>`
+   |     |
    |     arguments to this function are incorrect
    |
    = note:   expected enum `Option<&String>`
@@ -40,6 +34,11 @@ note: function defined here
    |
 LL | fn takes_option(_arg: Option<&String>) {}
    |    ^^^^^^^^^^^^ ---------------------
+help: try using `.as_ref()` to convert `&Option<String>` to `Option<&String>`
+   |
+LL -     takes_option(&res);
+LL +     takes_option(res.as_ref());
+   |
 
 error: aborting due to 2 previous errors
 
diff --git a/tests/ui/let-else/let-else-ref-bindings.stderr b/tests/ui/let-else/let-else-ref-bindings.stderr
index ada1805e725..0886d7f1770 100644
--- a/tests/ui/let-else/let-else-ref-bindings.stderr
+++ b/tests/ui/let-else/let-else-ref-bindings.stderr
@@ -6,6 +6,10 @@ LL |     let Some(ref a): Option<&[u8]> = some else { return };
    |
    = note: expected enum `Option<&[u8]>`
               found enum `Option<Vec<u8>>`
+help: try using `.as_deref()` to convert `Option<Vec<u8>>` to `Option<&[u8]>`
+   |
+LL |     let Some(ref a): Option<&[u8]> = some.as_deref() else { return };
+   |                                          +++++++++++
 
 error[E0308]: mismatched types
   --> $DIR/let-else-ref-bindings.rs:20:38
@@ -15,6 +19,11 @@ LL |     let Some(ref a): Option<&[u8]> = &some else { return };
    |
    = note:   expected enum `Option<&[u8]>`
            found reference `&Option<Vec<u8>>`
+help: try using `.as_deref()` to convert `&Option<Vec<u8>>` to `Option<&[u8]>`
+   |
+LL -     let Some(ref a): Option<&[u8]> = &some else { return };
+LL +     let Some(ref a): Option<&[u8]> = some.as_deref() else { return };
+   |
 
 error[E0308]: mismatched types
   --> $DIR/let-else-ref-bindings.rs:24:34
@@ -26,6 +35,10 @@ LL |     let Some(a): Option<&[u8]> = some else { return };
    |
    = note: expected enum `Option<&[u8]>`
               found enum `Option<Vec<u8>>`
+help: try using `.as_deref()` to convert `Option<Vec<u8>>` to `Option<&[u8]>`
+   |
+LL |     let Some(a): Option<&[u8]> = some.as_deref() else { return };
+   |                                      +++++++++++
 
 error[E0308]: mismatched types
   --> $DIR/let-else-ref-bindings.rs:27:34
@@ -37,6 +50,11 @@ LL |     let Some(a): Option<&[u8]> = &some else { return };
    |
    = note:   expected enum `Option<&[u8]>`
            found reference `&Option<Vec<u8>>`
+help: try using `.as_deref()` to convert `&Option<Vec<u8>>` to `Option<&[u8]>`
+   |
+LL -     let Some(a): Option<&[u8]> = &some else { return };
+LL +     let Some(a): Option<&[u8]> = some.as_deref() else { return };
+   |
 
 error[E0308]: mismatched types
   --> $DIR/let-else-ref-bindings.rs:44:46
diff --git a/tests/ui/suggestions/as-ref.rs b/tests/ui/suggestions/as-ref.rs
index a0535344185..0d9790ac229 100644
--- a/tests/ui/suggestions/as-ref.rs
+++ b/tests/ui/suggestions/as-ref.rs
@@ -24,4 +24,6 @@ fn main() {
     let multiple_ref_result = &&Ok(Foo);
     multiple_ref_result.map(|arg| takes_ref(arg)); //~ ERROR mismatched types [E0308]
     multiple_ref_result.and_then(|arg| Ok(takes_ref(arg))); //~ ERROR mismatched types [E0308]
+
+    let _: Result<&usize, _> = &Ok(42); //~ ERROR mismatched types [E0308]
 }
diff --git a/tests/ui/suggestions/as-ref.stderr b/tests/ui/suggestions/as-ref.stderr
index 2147d2d92e3..c5b2bb1260f 100644
--- a/tests/ui/suggestions/as-ref.stderr
+++ b/tests/ui/suggestions/as-ref.stderr
@@ -74,14 +74,16 @@ error[E0308]: mismatched types
   --> $DIR/as-ref.rs:13:29
    |
 LL |     let y: Option<&usize> = x;
-   |            --------------   ^
-   |            |                |
-   |            |                expected `Option<&usize>`, found `&Option<usize>`
-   |            |                help: you can convert from `&Option<T>` to `Option<&T>` using `.as_ref()`: `x.as_ref()`
+   |            --------------   ^ expected `Option<&usize>`, found `&Option<usize>`
+   |            |
    |            expected due to this
    |
    = note:   expected enum `Option<&usize>`
            found reference `&Option<usize>`
+help: try using `.as_ref()` to convert `&Option<usize>` to `Option<&usize>`
+   |
+LL |     let y: Option<&usize> = x.as_ref();
+   |                              +++++++++
 
 error[E0308]: mismatched types
   --> $DIR/as-ref.rs:15:37
@@ -93,10 +95,10 @@ LL |     let y: Result<&usize, &usize> = x;
    |
    = note:   expected enum `Result<&usize, &usize>`
            found reference `&Result<usize, usize>`
-help: you can convert from `&Result<T, E>` to `Result<&T, &E>` using `.as_ref()`
+help: try using `.as_ref()` to convert `&Result<usize, usize>` to `Result<&usize, &usize>`
    |
 LL |     let y: Result<&usize, &usize> = x.as_ref();
-   |                                     ~~~~~~~~~~
+   |                                      +++++++++
 
 error[E0308]: mismatched types
   --> $DIR/as-ref.rs:19:36
@@ -181,6 +183,22 @@ help: consider using `as_ref` instead
 LL |     multiple_ref_result.as_ref().and_then(|arg| Ok(takes_ref(arg)));
    |                         +++++++++
 
-error: aborting due to 11 previous errors
+error[E0308]: mismatched types
+  --> $DIR/as-ref.rs:28:32
+   |
+LL |     let _: Result<&usize, _> = &Ok(42);
+   |            -----------------   ^^^^^^^ expected `Result<&usize, _>`, found `&Result<{integer}, _>`
+   |            |
+   |            expected due to this
+   |
+   = note:   expected enum `Result<&usize, _>`
+           found reference `&Result<{integer}, _>`
+help: try using `.as_ref()` to convert `&Result<{integer}, _>` to `Result<&usize, _>`
+   |
+LL -     let _: Result<&usize, _> = &Ok(42);
+LL +     let _: Result<&usize, _> = Ok(42).as_ref();
+   |
+
+error: aborting due to 12 previous errors
 
 For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/suggestions/dont-suggest-try_into-in-macros.stderr b/tests/ui/suggestions/dont-suggest-try_into-in-macros.stderr
index bc6342004f4..319d866003b 100644
--- a/tests/ui/suggestions/dont-suggest-try_into-in-macros.stderr
+++ b/tests/ui/suggestions/dont-suggest-try_into-in-macros.stderr
@@ -1,13 +1,13 @@
 error[E0308]: mismatched types
-  --> $DIR/dont-suggest-try_into-in-macros.rs:2:5
+  --> $DIR/dont-suggest-try_into-in-macros.rs:2:23
    |
 LL |     assert_eq!(10u64, 10usize);
-   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |     |
-   |     expected `u64`, found `usize`
-   |     expected because this is `u64`
+   |                       ^^^^^^^ expected `u64`, found `usize`
    |
-   = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
+help: change the type of the numeric literal from `usize` to `u64`
+   |
+LL |     assert_eq!(10u64, 10u64);
+   |                         ~~~
 
 error: aborting due to previous error
 
diff --git a/tests/ui/switched-expectations.stderr b/tests/ui/switched-expectations.stderr
index 744d8483bd3..6e1bbf701d7 100644
--- a/tests/ui/switched-expectations.stderr
+++ b/tests/ui/switched-expectations.stderr
@@ -2,7 +2,9 @@ error[E0308]: mismatched types
   --> $DIR/switched-expectations.rs:3:30
    |
 LL |     let ref string: String = var;
-   |                              ^^^ expected `String`, found `i32`
+   |                              ^^^- help: try using a conversion method: `.to_string()`
+   |                              |
+   |                              expected `String`, found `i32`
 
 error: aborting due to previous error
 
diff --git a/tests/ui/typeck/issue-89856.stderr b/tests/ui/typeck/issue-89856.stderr
index bd76f172468..0db3e67ede0 100644
--- a/tests/ui/typeck/issue-89856.stderr
+++ b/tests/ui/typeck/issue-89856.stderr
@@ -13,7 +13,7 @@ note: function defined here
    |
 LL | fn take_str_maybe(_: Option<&str>) { }
    |    ^^^^^^^^^^^^^^ ---------------
-help: try converting the passed type into a `&str`
+help: try using `.as_deref()` to convert `Option<String>` to `Option<&str>`
    |
 LL |     take_str_maybe(option.as_deref());
    |                          +++++++++++