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 --- .../correct-supertrait-substitution.rs | 38 ++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 tests/ui/traits/trait-upcasting/correct-supertrait-substitution.rs (limited to 'tests/ui/traits/trait-upcasting/correct-supertrait-substitution.rs') diff --git a/tests/ui/traits/trait-upcasting/correct-supertrait-substitution.rs b/tests/ui/traits/trait-upcasting/correct-supertrait-substitution.rs new file mode 100644 index 000000000..eae5cf8d5 --- /dev/null +++ b/tests/ui/traits/trait-upcasting/correct-supertrait-substitution.rs @@ -0,0 +1,38 @@ +// run-pass +#![feature(trait_upcasting)] + +trait Foo: Bar + Bar {} +trait Bar { + fn bar(&self) -> String { + T::default().to_string() + } +} + +struct S1; + +impl Bar for S1 {} +impl Foo for S1 {} + +struct S2; +impl Bar for S2 {} +impl Bar for S2 {} +impl Foo for S2 {} + +fn test1(x: &dyn Foo) { + let s = x as &dyn Bar; + assert_eq!("0", &s.bar().to_string()); +} + +fn test2(x: &dyn Foo) { + let p = x as &dyn Bar; + assert_eq!("0", &p.bar().to_string()); + let q = x as &dyn Bar; + assert_eq!("false", &q.bar().to_string()); +} + +fn main() { + let s1 = S1; + test1(&s1); + let s2 = S2; + test2(&s2); +} -- cgit v1.2.3