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/impl-inherent-non-conflict.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/test/ui/impl-inherent-non-conflict.rs (limited to 'src/test/ui/impl-inherent-non-conflict.rs') diff --git a/src/test/ui/impl-inherent-non-conflict.rs b/src/test/ui/impl-inherent-non-conflict.rs new file mode 100644 index 000000000..be524f87c --- /dev/null +++ b/src/test/ui/impl-inherent-non-conflict.rs @@ -0,0 +1,23 @@ +// run-pass +// Ensure that a user-defined type admits multiple inherent methods +// with the same name, which can be called on values that have a +// precise enough type to allow distinguishing between the methods. + + +struct Foo(T); + +impl Foo { + fn bar(&self) -> i32 { self.0 as i32 } +} + +impl Foo { + fn bar(&self) -> i32 { -(self.0 as i32) } +} + +fn main() { + let foo_u = Foo::(5); + assert_eq!(foo_u.bar(), 5); + + let foo_i = Foo::(3); + assert_eq!(foo_i.bar(), -3); +} -- cgit v1.2.3