From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/traits/issue-18412.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tests/ui/traits/issue-18412.rs (limited to 'tests/ui/traits/issue-18412.rs') diff --git a/tests/ui/traits/issue-18412.rs b/tests/ui/traits/issue-18412.rs new file mode 100644 index 000000000..fe1cfb3df --- /dev/null +++ b/tests/ui/traits/issue-18412.rs @@ -0,0 +1,26 @@ +// run-pass +// Test that non-static methods can be assigned to local variables as +// function pointers. + + +trait Foo { + fn foo(&self) -> usize; +} + +struct A(usize); + +impl A { + fn bar(&self) -> usize { self.0 } +} + +impl Foo for A { + fn foo(&self) -> usize { self.bar() } +} + +fn main() { + let f = A::bar; + let g = Foo::foo; + let a = A(42); + + assert_eq!(f(&a), g(&a)); +} -- cgit v1.2.3