]> git.lizzy.rs Git - rust.git/commitdiff
Split const trait method test and impl `ops::Add`
authorDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 5 Feb 2020 17:35:32 +0000 (09:35 -0800)
committerDylan MacKenzie <ecstaticmorse@gmail.com>
Wed, 19 Feb 2020 05:03:28 +0000 (21:03 -0800)
src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs [new file with mode: 0644]
src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr [new file with mode: 0644]
src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs [new file with mode: 0644]
src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method.rs [deleted file]
src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method.stderr [deleted file]

diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.rs
new file mode 100644 (file)
index 0000000..8e6ef12
--- /dev/null
@@ -0,0 +1,30 @@
+#![allow(incomplete_features)]
+#![feature(const_trait_impl)]
+#![feature(const_fn)]
+
+pub trait Plus {
+    fn plus(self, rhs: Self) -> Self;
+}
+
+impl const Plus for i32 {
+    fn plus(self, rhs: Self) -> Self {
+        self + rhs
+    }
+}
+
+impl Plus for u32 {
+    fn plus(self, rhs: Self) -> Self {
+        self + rhs
+    }
+}
+
+pub const fn add_i32(a: i32, b: i32) -> i32 {
+    a.plus(b) // ok
+}
+
+pub const fn add_u32(a: u32, b: u32) -> u32 {
+    a.plus(b)
+    //~^ ERROR calls in constant functions are limited to constant functions
+}
+
+fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-fail.stderr
new file mode 100644 (file)
index 0000000..0c320d5
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
+  --> $DIR/call-const-trait-method-fail.rs:26:5
+   |
+LL |     a.plus(b)
+   |     ^^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0015`.
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method-pass.rs
new file mode 100644 (file)
index 0000000..6a2112e
--- /dev/null
@@ -0,0 +1,41 @@
+// run-pass
+
+#![allow(incomplete_features)]
+#![feature(const_trait_impl)]
+#![feature(const_fn)]
+
+struct Int(i32);
+
+impl const std::ops::Add for Int {
+    type Output = Int;
+
+    fn add(self, rhs: Self) -> Self {
+        Int(self.0.plus(rhs.0))
+    }
+}
+
+impl const PartialEq for Int {
+    fn eq(&self, rhs: &Self) -> bool {
+        self.0 == rhs.0
+    }
+}
+
+pub trait Plus {
+    fn plus(self, rhs: Self) -> Self;
+}
+
+impl const Plus for i32 {
+    fn plus(self, rhs: Self) -> Self {
+        self + rhs
+    }
+}
+
+pub const fn add_i32(a: i32, b: i32) -> i32 {
+    a.plus(b)
+}
+
+const ADD_INT: Int = Int(1i32) + Int(2i32);
+
+fn main() {
+    assert!(ADD_INT == Int(3i32));
+}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method.rs b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method.rs
deleted file mode 100644 (file)
index ed6c07e..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-#![allow(incomplete_features)]
-#![feature(const_trait_impl)]
-#![feature(const_fn)]
-
-pub trait Plus {
-    fn plus(self, rhs: Self) -> Self;
-}
-
-impl const Plus for i32 {
-    fn plus(self, rhs: Self) -> Self {
-        self + rhs
-    }
-}
-
-impl Plus for u32 {
-    fn plus(self, rhs: Self) -> Self {
-        self + rhs
-    }
-}
-
-pub const fn add_i32(a: i32, b: i32) -> i32 {
-    a.plus(b)
-}
-
-pub const fn add_u32(a: u32, b: u32) -> u32 {
-    a.plus(b)
-    //~^ ERROR calls in constant functions are limited to constant functions
-}
-
-fn main() {}
diff --git a/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method.stderr b/src/test/ui/rfc-2632-const-trait-impl/call-const-trait-method.stderr
deleted file mode 100644 (file)
index 7216876..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
-  --> $DIR/call-const-trait-method.rs:26:5
-   |
-LL |     a.plus(b)
-   |     ^^^^^^^^^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0015`.