summaryrefslogtreecommitdiffstats
path: root/src/test/ui/confuse-field-and-method
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/confuse-field-and-method
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/confuse-field-and-method')
-rw-r--r--src/test/ui/confuse-field-and-method/issue-18343.rs9
-rw-r--r--src/test/ui/confuse-field-and-method/issue-18343.stderr17
-rw-r--r--src/test/ui/confuse-field-and-method/issue-2392.rs69
-rw-r--r--src/test/ui/confuse-field-and-method/issue-2392.stderr151
-rw-r--r--src/test/ui/confuse-field-and-method/issue-32128.rs15
-rw-r--r--src/test/ui/confuse-field-and-method/issue-32128.stderr17
-rw-r--r--src/test/ui/confuse-field-and-method/issue-33784.rs33
-rw-r--r--src/test/ui/confuse-field-and-method/issue-33784.stderr36
-rw-r--r--src/test/ui/confuse-field-and-method/private-field.rs19
-rw-r--r--src/test/ui/confuse-field-and-method/private-field.stderr12
10 files changed, 378 insertions, 0 deletions
diff --git a/src/test/ui/confuse-field-and-method/issue-18343.rs b/src/test/ui/confuse-field-and-method/issue-18343.rs
new file mode 100644
index 000000000..bc2d73fae
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-18343.rs
@@ -0,0 +1,9 @@
+struct Obj<F> where F: FnMut() -> u32 {
+ closure: F,
+}
+
+fn main() {
+ let o = Obj { closure: || 42 };
+ o.closure();
+ //~^ ERROR no method named `closure` found
+}
diff --git a/src/test/ui/confuse-field-and-method/issue-18343.stderr b/src/test/ui/confuse-field-and-method/issue-18343.stderr
new file mode 100644
index 000000000..1c9a6847c
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-18343.stderr
@@ -0,0 +1,17 @@
+error[E0599]: no method named `closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-18343.rs:7:7
+ |
+LL | struct Obj<F> where F: FnMut() -> u32 {
+ | ------------- method `closure` not found for this struct
+...
+LL | o.closure();
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `closure`, surround the field access with parentheses
+ |
+LL | (o.closure)();
+ | + +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
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<FuncContainer>
+}
+
+struct Obj<F> where F: FnOnce() -> u32 {
+ closure: F,
+ not_closure: usize,
+}
+
+struct BoxedObj {
+ boxed_closure: Box<dyn FnOnce() -> u32>,
+}
+
+struct Wrapper<F> where F: FnMut() -> u32 {
+ wrap: Obj<F>,
+}
+
+fn func() -> u32 {
+ 0
+}
+
+fn check_expression() -> Obj<Box<dyn FnOnce() -> u32>> {
+ Obj { closure: Box::new(|| 42_u32) as Box<dyn FnOnce() -> 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<dyn FnOnce() -> 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
+ }
+ }
+}
diff --git a/src/test/ui/confuse-field-and-method/issue-2392.stderr b/src/test/ui/confuse-field-and-method/issue-2392.stderr
new file mode 100644
index 000000000..440fbb27c
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-2392.stderr
@@ -0,0 +1,151 @@
+error[E0599]: no method named `closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-2392.rs:36:15
+ |
+LL | struct Obj<F> where F: FnOnce() -> u32 {
+ | ------------- method `closure` not found for this struct
+...
+LL | o_closure.closure();
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `closure`, surround the field access with parentheses
+ |
+LL | (o_closure.closure)();
+ | + +
+
+error[E0599]: no method named `not_closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-2392.rs:38:15
+ |
+LL | struct Obj<F> where F: FnOnce() -> u32 {
+ | ------------- method `not_closure` not found for this struct
+...
+LL | o_closure.not_closure();
+ | ^^^^^^^^^^^-- help: remove the arguments
+ | |
+ | field, not a method
+
+error[E0599]: no method named `closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-2392.rs:42:12
+ |
+LL | struct Obj<F> where F: FnOnce() -> u32 {
+ | ------------- method `closure` not found for this struct
+...
+LL | o_func.closure();
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `closure`, surround the field access with parentheses
+ |
+LL | (o_func.closure)();
+ | + +
+
+error[E0599]: no method named `boxed_closure` found for struct `BoxedObj` in the current scope
+ --> $DIR/issue-2392.rs:45:14
+ |
+LL | struct BoxedObj {
+ | --------------- method `boxed_closure` not found for this struct
+...
+LL | boxed_fn.boxed_closure();
+ | ^^^^^^^^^^^^^ field, not a method
+ |
+help: to call the function stored in `boxed_closure`, surround the field access with parentheses
+ |
+LL | (boxed_fn.boxed_closure)();
+ | + +
+
+error[E0599]: no method named `boxed_closure` found for struct `BoxedObj` in the current scope
+ --> $DIR/issue-2392.rs:48:19
+ |
+LL | struct BoxedObj {
+ | --------------- method `boxed_closure` not found for this struct
+...
+LL | boxed_closure.boxed_closure();
+ | ^^^^^^^^^^^^^ field, not a method
+ |
+help: to call the function stored in `boxed_closure`, surround the field access with parentheses
+ |
+LL | (boxed_closure.boxed_closure)();
+ | + +
+
+error[E0599]: no method named `closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-2392.rs:53:12
+ |
+LL | struct Obj<F> where F: FnOnce() -> u32 {
+ | ------------- method `closure` not found for this struct
+...
+LL | w.wrap.closure();
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `closure`, surround the field access with parentheses
+ |
+LL | (w.wrap.closure)();
+ | + +
+
+error[E0599]: no method named `not_closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-2392.rs:55:12
+ |
+LL | struct Obj<F> where F: FnOnce() -> u32 {
+ | ------------- method `not_closure` not found for this struct
+...
+LL | w.wrap.not_closure();
+ | ^^^^^^^^^^^-- help: remove the arguments
+ | |
+ | field, not a method
+
+error[E0599]: no method named `closure` found for struct `Obj` in the current scope
+ --> $DIR/issue-2392.rs:58:24
+ |
+LL | struct Obj<F> where F: FnOnce() -> u32 {
+ | ------------- method `closure` not found for this struct
+...
+LL | check_expression().closure();
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `closure`, surround the field access with parentheses
+ |
+LL | (check_expression().closure)();
+ | + +
+
+error[E0599]: no method named `f1` found for struct `FuncContainer` in the current scope
+ --> $DIR/issue-2392.rs:64:31
+ |
+LL | struct FuncContainer {
+ | -------------------- method `f1` not found for this struct
+...
+LL | (*self.container).f1(1);
+ | ^^ field, not a method
+ |
+help: to call the function stored in `f1`, surround the field access with parentheses
+ |
+LL | ((*self.container).f1)(1);
+ | + +
+
+error[E0599]: no method named `f2` found for struct `FuncContainer` in the current scope
+ --> $DIR/issue-2392.rs:65:31
+ |
+LL | struct FuncContainer {
+ | -------------------- method `f2` not found for this struct
+...
+LL | (*self.container).f2(1);
+ | ^^ field, not a method
+ |
+help: to call the function stored in `f2`, surround the field access with parentheses
+ |
+LL | ((*self.container).f2)(1);
+ | + +
+
+error[E0599]: no method named `f3` found for struct `FuncContainer` in the current scope
+ --> $DIR/issue-2392.rs:66:31
+ |
+LL | struct FuncContainer {
+ | -------------------- method `f3` not found for this struct
+...
+LL | (*self.container).f3(1);
+ | ^^ field, not a method
+ |
+help: to call the function stored in `f3`, surround the field access with parentheses
+ |
+LL | ((*self.container).f3)(1);
+ | + +
+
+error: aborting due to 11 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/confuse-field-and-method/issue-32128.rs b/src/test/ui/confuse-field-and-method/issue-32128.rs
new file mode 100644
index 000000000..5a024aa4b
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-32128.rs
@@ -0,0 +1,15 @@
+struct Example {
+ example: Box<dyn Fn(i32) -> i32>
+}
+
+fn main() {
+ let demo = Example {
+ example: Box::new(|x| {
+ x + 1
+ })
+ };
+
+ demo.example(1);
+ //~^ ERROR no method named `example`
+ // (demo.example)(1);
+}
diff --git a/src/test/ui/confuse-field-and-method/issue-32128.stderr b/src/test/ui/confuse-field-and-method/issue-32128.stderr
new file mode 100644
index 000000000..4b96bce8d
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-32128.stderr
@@ -0,0 +1,17 @@
+error[E0599]: no method named `example` found for struct `Example` in the current scope
+ --> $DIR/issue-32128.rs:12:10
+ |
+LL | struct Example {
+ | -------------- method `example` not found for this struct
+...
+LL | demo.example(1);
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `example`, surround the field access with parentheses
+ |
+LL | (demo.example)(1);
+ | + +
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/confuse-field-and-method/issue-33784.rs b/src/test/ui/confuse-field-and-method/issue-33784.rs
new file mode 100644
index 000000000..e9bb1f9fb
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-33784.rs
@@ -0,0 +1,33 @@
+use std::ops::Deref;
+
+struct Obj<F> where F: FnMut() -> u32 {
+ fn_ptr: fn() -> (),
+ closure: F,
+}
+
+struct C {
+ c_fn_ptr: fn() -> (),
+}
+
+struct D(C);
+
+impl Deref for D {
+ type Target = C;
+ fn deref(&self) -> &C {
+ &self.0
+ }
+}
+
+
+fn empty() {}
+
+fn main() {
+ let o = Obj { fn_ptr: empty, closure: || 42 };
+ let p = &o;
+ p.closure(); //~ ERROR no method named `closure` found
+ let q = &p;
+ q.fn_ptr(); //~ ERROR no method named `fn_ptr` found
+ let r = D(C { c_fn_ptr: empty });
+ let s = &r;
+ s.c_fn_ptr(); //~ ERROR no method named `c_fn_ptr` found
+}
diff --git a/src/test/ui/confuse-field-and-method/issue-33784.stderr b/src/test/ui/confuse-field-and-method/issue-33784.stderr
new file mode 100644
index 000000000..34debb683
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/issue-33784.stderr
@@ -0,0 +1,36 @@
+error[E0599]: no method named `closure` found for reference `&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope
+ --> $DIR/issue-33784.rs:27:7
+ |
+LL | p.closure();
+ | ^^^^^^^ field, not a method
+ |
+help: to call the function stored in `closure`, surround the field access with parentheses
+ |
+LL | (p.closure)();
+ | + +
+
+error[E0599]: no method named `fn_ptr` found for reference `&&Obj<[closure@$DIR/issue-33784.rs:25:43: 25:45]>` in the current scope
+ --> $DIR/issue-33784.rs:29:7
+ |
+LL | q.fn_ptr();
+ | ^^^^^^ field, not a method
+ |
+help: to call the function stored in `fn_ptr`, surround the field access with parentheses
+ |
+LL | (q.fn_ptr)();
+ | + +
+
+error[E0599]: no method named `c_fn_ptr` found for reference `&D` in the current scope
+ --> $DIR/issue-33784.rs:32:7
+ |
+LL | s.c_fn_ptr();
+ | ^^^^^^^^ field, not a method
+ |
+help: to call the function stored in `c_fn_ptr`, surround the field access with parentheses
+ |
+LL | (s.c_fn_ptr)();
+ | + +
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0599`.
diff --git a/src/test/ui/confuse-field-and-method/private-field.rs b/src/test/ui/confuse-field-and-method/private-field.rs
new file mode 100644
index 000000000..28b8935ac
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/private-field.rs
@@ -0,0 +1,19 @@
+pub mod animal {
+ pub struct Dog {
+ pub age: usize,
+ dog_age: usize,
+ }
+
+ impl Dog {
+ pub fn new(age: usize) -> Dog {
+ Dog { age: age, dog_age: age * 7 }
+ }
+ }
+}
+
+fn main() {
+ let dog = animal::Dog::new(3);
+ let dog_age = dog.dog_age(); //~ ERROR no method
+ //let dog_age = dog.dog_age;
+ println!("{}", dog_age);
+}
diff --git a/src/test/ui/confuse-field-and-method/private-field.stderr b/src/test/ui/confuse-field-and-method/private-field.stderr
new file mode 100644
index 000000000..783378f8d
--- /dev/null
+++ b/src/test/ui/confuse-field-and-method/private-field.stderr
@@ -0,0 +1,12 @@
+error[E0599]: no method named `dog_age` found for struct `Dog` in the current scope
+ --> $DIR/private-field.rs:16:23
+ |
+LL | pub struct Dog {
+ | -------------- method `dog_age` not found for this struct
+...
+LL | let dog_age = dog.dog_age();
+ | ^^^^^^^ private field, not a method
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0599`.