about summary refs log tree commit diff
path: root/tests/ui/methods
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-06-12 18:29:22 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-06-28 16:24:17 +0500
commitaac948b702737e8ead5e800bd9f5dd03b5b6b534 (patch)
treea49fccae1c21e5d7b11203c1d4f338d5429cb2ca /tests/ui/methods
parentfd50e1012f79eb93f661adc6f276335e4cfb34ea (diff)
downloadrust-aac948b702737e8ead5e800bd9f5dd03b5b6b534.tar.gz
rust-aac948b702737e8ead5e800bd9f5dd03b5b6b534.zip
cleaned up some tests
Diffstat (limited to 'tests/ui/methods')
-rw-r--r--tests/ui/methods/method-missing-call.rs30
-rw-r--r--tests/ui/methods/method-missing-call.stderr25
-rw-r--r--tests/ui/methods/method-value-without-call.rs33
-rw-r--r--tests/ui/methods/method-value-without-call.stderr36
4 files changed, 69 insertions, 55 deletions
diff --git a/tests/ui/methods/method-missing-call.rs b/tests/ui/methods/method-missing-call.rs
deleted file mode 100644
index 7ce1e9a4f1b..00000000000
--- a/tests/ui/methods/method-missing-call.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Tests to make sure that parens are needed for method calls without arguments.
-// outputs text to make sure either an anonymous function is provided or
-// open-close '()' parens are given
-
-
-struct Point {
-    x: isize,
-    y: isize
-}
-impl Point {
-    fn new() -> Point {
-        Point{x:0, y:0}
-    }
-    fn get_x(&self) -> isize {
-        self.x
-    }
-}
-
-fn main() {
-    let point: Point = Point::new();
-    let px: isize =  point
-                        .get_x;//~ ERROR attempted to take value of method `get_x` on type `Point`
-
-    // Ensure the span is useful
-    let ys = &[1,2,3,4,5,6,7];
-    let a = ys.iter()
-              .map(|x| x)
-              .filter(|&&x| x == 1)
-              .filter_map; //~ ERROR attempted to take value of method `filter_map` on type
-}
diff --git a/tests/ui/methods/method-missing-call.stderr b/tests/ui/methods/method-missing-call.stderr
deleted file mode 100644
index bc508461b69..00000000000
--- a/tests/ui/methods/method-missing-call.stderr
+++ /dev/null
@@ -1,25 +0,0 @@
-error[E0615]: attempted to take value of method `get_x` on type `Point`
-  --> $DIR/method-missing-call.rs:22:26
-   |
-LL |                         .get_x;
-   |                          ^^^^^ method, not a field
-   |
-help: use parentheses to call the method
-   |
-LL |                         .get_x();
-   |                               ++
-
-error[E0615]: attempted to take value of method `filter_map` on type `Filter<Map<std::slice::Iter<'_, {integer}>, {closure@$DIR/method-missing-call.rs:27:20: 27:23}>, {closure@$DIR/method-missing-call.rs:28:23: 28:28}>`
-  --> $DIR/method-missing-call.rs:29:16
-   |
-LL |               .filter_map;
-   |                ^^^^^^^^^^ method, not a field
-   |
-help: use parentheses to call the method
-   |
-LL |               .filter_map(_);
-   |                          +++
-
-error: aborting due to 2 previous errors
-
-For more information about this error, try `rustc --explain E0615`.
diff --git a/tests/ui/methods/method-value-without-call.rs b/tests/ui/methods/method-value-without-call.rs
new file mode 100644
index 00000000000..43bee4864b4
--- /dev/null
+++ b/tests/ui/methods/method-value-without-call.rs
@@ -0,0 +1,33 @@
+//! Test taking a method value without parentheses
+
+struct Point {
+    x: isize,
+    y: isize,
+}
+
+impl Point {
+    fn new() -> Point {
+        Point { x: 0, y: 0 }
+    }
+
+    fn get_x(&self) -> isize {
+        self.x
+    }
+}
+
+fn main() {
+    // Test with primitive type method
+    let _f = 10i32.abs; //~ ERROR attempted to take value of method
+
+    // Test with custom type method
+    let point: Point = Point::new();
+    let px: isize = point.get_x; //~ ERROR attempted to take value of method `get_x` on type `Point`
+
+    // Test with method chains - ensure the span is useful
+    let ys = &[1, 2, 3, 4, 5, 6, 7];
+    let a = ys
+        .iter()
+        .map(|x| x)
+        .filter(|&&x| x == 1)
+        .filter_map; //~ ERROR attempted to take value of method `filter_map` on type
+}
diff --git a/tests/ui/methods/method-value-without-call.stderr b/tests/ui/methods/method-value-without-call.stderr
new file mode 100644
index 00000000000..0c3870e2868
--- /dev/null
+++ b/tests/ui/methods/method-value-without-call.stderr
@@ -0,0 +1,36 @@
+error[E0615]: attempted to take value of method `abs` on type `i32`
+  --> $DIR/method-value-without-call.rs:20:20
+   |
+LL |     let _f = 10i32.abs;
+   |                    ^^^ method, not a field
+   |
+help: use parentheses to call the method
+   |
+LL |     let _f = 10i32.abs();
+   |                       ++
+
+error[E0615]: attempted to take value of method `get_x` on type `Point`
+  --> $DIR/method-value-without-call.rs:24:27
+   |
+LL |     let px: isize = point.get_x;
+   |                           ^^^^^ method, not a field
+   |
+help: use parentheses to call the method
+   |
+LL |     let px: isize = point.get_x();
+   |                                ++
+
+error[E0615]: attempted to take value of method `filter_map` on type `Filter<Map<std::slice::Iter<'_, {integer}>, {closure@$DIR/method-value-without-call.rs:30:14: 30:17}>, {closure@$DIR/method-value-without-call.rs:31:17: 31:22}>`
+  --> $DIR/method-value-without-call.rs:32:10
+   |
+LL |         .filter_map;
+   |          ^^^^^^^^^^ method, not a field
+   |
+help: use parentheses to call the method
+   |
+LL |         .filter_map(_);
+   |                    +++
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0615`.