summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/trait-upcasting
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/traits/trait-upcasting')
-rw-r--r--tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs33
-rw-r--r--tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr14
-rw-r--r--tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr9
3 files changed, 49 insertions, 7 deletions
diff --git a/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs
new file mode 100644
index 000000000..4a5e445d1
--- /dev/null
+++ b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.rs
@@ -0,0 +1,33 @@
+#![feature(trait_upcasting)]
+#![feature(trait_alias)]
+
+// Although we *elaborate* `T: Alias` to `i32: B`, we should
+// not consider `B` to be a supertrait of the type.
+trait Alias = A where i32: B;
+
+trait A {}
+
+trait B {
+ fn test(&self);
+}
+
+trait C: Alias {}
+
+impl A for () {}
+
+impl C for () {}
+
+impl B for i32 {
+ fn test(&self) {
+ println!("hi {self}");
+ }
+}
+
+fn test(x: &dyn C) -> &dyn B {
+ x
+ //~^ ERROR mismatched types
+}
+
+fn main() {
+ let x: &dyn C = &();
+}
diff --git a/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr
new file mode 100644
index 000000000..5574a0320
--- /dev/null
+++ b/tests/ui/traits/trait-upcasting/alias-where-clause-isnt-supertrait.stderr
@@ -0,0 +1,14 @@
+error[E0308]: mismatched types
+ --> $DIR/alias-where-clause-isnt-supertrait.rs:27:5
+ |
+LL | fn test(x: &dyn C) -> &dyn B {
+ | ------ expected `&dyn B` because of return type
+LL | x
+ | ^ expected trait `B`, found trait `C`
+ |
+ = note: expected reference `&dyn B`
+ found reference `&dyn C`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr
index 15faab16a..ca98e1831 100644
--- a/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr
+++ b/tests/ui/traits/trait-upcasting/cyclic-trait-resolution.stderr
@@ -1,15 +1,10 @@
error[E0391]: cycle detected when computing the super predicates of `A`
- --> $DIR/cyclic-trait-resolution.rs:1:1
- |
-LL | trait A: B + A {}
- | ^^^^^^^^^^^^^^
- |
-note: ...which requires computing the super traits of `A`...
--> $DIR/cyclic-trait-resolution.rs:1:14
|
LL | trait A: B + A {}
| ^
- = note: ...which again requires computing the super predicates of `A`, completing the cycle
+ |
+ = note: ...which immediately requires computing the super predicates of `A` again
note: cycle used when collecting item types in top-level module
--> $DIR/cyclic-trait-resolution.rs:1:1
|