about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-01-25 20:11:05 +0100
committerNilstrieb <48135649+Nilstrieb@users.noreply.github.com>2023-01-25 21:25:42 +0100
commit943000fdcf9eac6c77b44923f551409aa06a46b5 (patch)
treeba91fa9df8a942a3f8ad8dfcc671e2df4a4aab43 /tests
parentb222f2e2660f8d81dc30061c918d774147fcf1a6 (diff)
downloadrust-943000fdcf9eac6c77b44923f551409aa06a46b5.tar.gz
rust-943000fdcf9eac6c77b44923f551409aa06a46b5.zip
Use `can_eq` to compare types for default assoc type error
This works correctly with inference variables.
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/associated-types/defaults-in-other-trait-items.rs14
-rw-r--r--tests/ui/associated-types/defaults-in-other-trait-items.stderr17
-rw-r--r--tests/ui/associated-types/issue-26681.stderr4
3 files changed, 32 insertions, 3 deletions
diff --git a/tests/ui/associated-types/defaults-in-other-trait-items.rs b/tests/ui/associated-types/defaults-in-other-trait-items.rs
index 505751969b6..f263809552f 100644
--- a/tests/ui/associated-types/defaults-in-other-trait-items.rs
+++ b/tests/ui/associated-types/defaults-in-other-trait-items.rs
@@ -44,4 +44,18 @@ impl AssocConst for () {
     const C: Self::Ty = 0u8;
 }
 
+pub trait Trait {
+    type Res = isize; //~ NOTE associated type defaults can't be assumed inside the trait defining them
+
+    fn infer_me_correctly() -> Self::Res {
+        //~^ NOTE expected `<Self as Trait>::Res` because of return type
+
+        // {integer} == isize
+        2
+        //~^ ERROR mismatched types
+        //~| NOTE expected associated type, found integer
+        //~| NOTE expected associated type `<Self as Trait>::Res`
+    }
+}
+
 fn main() {}
diff --git a/tests/ui/associated-types/defaults-in-other-trait-items.stderr b/tests/ui/associated-types/defaults-in-other-trait-items.stderr
index 71d421926e7..bdcfadd3955 100644
--- a/tests/ui/associated-types/defaults-in-other-trait-items.stderr
+++ b/tests/ui/associated-types/defaults-in-other-trait-items.stderr
@@ -24,6 +24,21 @@ LL |     const C: Self::Ty = 0u8;
    = note: expected associated type `<Self as AssocConst>::Ty`
                          found type `u8`
 
-error: aborting due to 2 previous errors
+error[E0308]: mismatched types
+  --> $DIR/defaults-in-other-trait-items.rs:54:9
+   |
+LL |     type Res = isize;
+   |     ----------------- associated type defaults can't be assumed inside the trait defining them
+LL |
+LL |     fn infer_me_correctly() -> Self::Res {
+   |                                --------- expected `<Self as Trait>::Res` because of return type
+...
+LL |         2
+   |         ^ expected associated type, found integer
+   |
+   = note: expected associated type `<Self as Trait>::Res`
+                         found type `{integer}`
+
+error: aborting due to 3 previous errors
 
 For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/associated-types/issue-26681.stderr b/tests/ui/associated-types/issue-26681.stderr
index 74411008c9d..977620d9052 100644
--- a/tests/ui/associated-types/issue-26681.stderr
+++ b/tests/ui/associated-types/issue-26681.stderr
@@ -1,13 +1,13 @@
 error[E0308]: mismatched types
   --> $DIR/issue-26681.rs:17:39
    |
+LL |     type Fv: Foo = u8;
+   |     ------------------ associated type defaults can't be assumed inside the trait defining them
 LL |     const C: <Self::Fv as Foo>::Bar = 6665;
    |                                       ^^^^ expected associated type, found integer
    |
    = note: expected associated type `<<Self as Baz>::Fv as Foo>::Bar`
                          found type `{integer}`
-   = help: consider constraining the associated type `<<Self as Baz>::Fv as Foo>::Bar` to `{integer}`
-   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
 
 error: aborting due to previous error