From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../traits/trait-upcasting/type-checking-test-1.rs | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/ui/traits/trait-upcasting/type-checking-test-1.rs (limited to 'tests/ui/traits/trait-upcasting/type-checking-test-1.rs') diff --git a/tests/ui/traits/trait-upcasting/type-checking-test-1.rs b/tests/ui/traits/trait-upcasting/type-checking-test-1.rs new file mode 100644 index 000000000..6bc9f4a75 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/type-checking-test-1.rs @@ -0,0 +1,26 @@ +#![feature(trait_upcasting)] + +trait Foo: Bar + Bar {} +trait Bar { + fn bar(&self) -> Option { + None + } +} + +fn test_specific(x: &dyn Foo) { + let _ = x as &dyn Bar; // OK + let _ = x as &dyn Bar; // OK +} + +fn test_unknown_version(x: &dyn Foo) { + let _ = x as &dyn Bar<_>; // Ambiguous + //~^ ERROR non-primitive cast + //~^^ ERROR the trait bound `&dyn Foo: Bar<_>` is not satisfied +} + +fn test_infer_version(x: &dyn Foo) { + let a = x as &dyn Bar<_>; // OK + let _: Option = a.bar(); +} + +fn main() {} -- cgit v1.2.3