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/confuse-field-and-method/issue-2392.rs | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/test/ui/confuse-field-and-method/issue-2392.rs (limited to 'src/test/ui/confuse-field-and-method/issue-2392.rs') diff --git a/src/test/ui/confuse-field-and-method/issue-2392.rs b/src/test/ui/confuse-field-and-method/issue-2392.rs new file mode 100644 index 000000000..8aef091fe --- /dev/null +++ b/src/test/ui/confuse-field-and-method/issue-2392.rs @@ -0,0 +1,69 @@ +struct FuncContainer { + f1: fn(data: u8), + f2: extern "C" fn(data: u8), + f3: unsafe fn(data: u8), +} + +struct FuncContainerOuter { + container: Box +} + +struct Obj where F: FnOnce() -> u32 { + closure: F, + not_closure: usize, +} + +struct BoxedObj { + boxed_closure: Box u32>, +} + +struct Wrapper where F: FnMut() -> u32 { + wrap: Obj, +} + +fn func() -> u32 { + 0 +} + +fn check_expression() -> Obj u32>> { + Obj { closure: Box::new(|| 42_u32) as Box u32>, not_closure: 42 } +} + +fn main() { + // test variations of function + + let o_closure = Obj { closure: || 42, not_closure: 42 }; + o_closure.closure(); //~ ERROR no method named `closure` found + + o_closure.not_closure(); + //~^ ERROR no method named `not_closure` found + + let o_func = Obj { closure: func, not_closure: 5 }; + o_func.closure(); //~ ERROR no method named `closure` found + + let boxed_fn = BoxedObj { boxed_closure: Box::new(func) }; + boxed_fn.boxed_closure();//~ ERROR no method named `boxed_closure` found + + let boxed_closure = BoxedObj { boxed_closure: Box::new(|| 42_u32) as Box u32> }; + boxed_closure.boxed_closure();//~ ERROR no method named `boxed_closure` found + + // test expression writing in the notes + + let w = Wrapper { wrap: o_func }; + w.wrap.closure();//~ ERROR no method named `closure` found + + w.wrap.not_closure(); + //~^ ERROR no method named `not_closure` found + + check_expression().closure();//~ ERROR no method named `closure` found +} + +impl FuncContainerOuter { + fn run(&self) { + unsafe { + (*self.container).f1(1); //~ ERROR no method named `f1` found + (*self.container).f2(1); //~ ERROR no method named `f2` found + (*self.container).f3(1); //~ ERROR no method named `f3` found + } + } +} -- cgit v1.2.3