From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- src/test/ui/traits/inheritance/subst2.rs | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/test/ui/traits/inheritance/subst2.rs (limited to 'src/test/ui/traits/inheritance/subst2.rs') diff --git a/src/test/ui/traits/inheritance/subst2.rs b/src/test/ui/traits/inheritance/subst2.rs new file mode 100644 index 000000000..ccc9628c7 --- /dev/null +++ b/src/test/ui/traits/inheritance/subst2.rs @@ -0,0 +1,37 @@ +// run-pass + +trait Panda { + fn chomp(&self, bamboo: &T) -> T; +} + +trait Add: Panda { + fn add(&self, rhs: &RHS) -> Result; +} + +trait MyNum : Sized + Add { } + +struct MyInt { val: isize } + +impl Panda for MyInt { + fn chomp(&self, bamboo: &MyInt) -> MyInt { + mi(self.val + bamboo.val) + } +} + +impl Add for MyInt { + fn add(&self, other: &MyInt) -> MyInt { self.chomp(other) } +} + +impl MyNum for MyInt {} + +fn f(x: T, y: T) -> T { + return x.add(&y).chomp(&y); +} + +fn mi(v: isize) -> MyInt { MyInt { val: v } } + +pub fn main() { + let (x, y) = (mi(3), mi(5)); + let z = f(x, y); + assert_eq!(z.val, 13); +} -- cgit v1.2.3