about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-04-27 19:01:05 +0400
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-07-26 15:38:10 +0400
commitd65fa276f3f2a239805f8458e210fb92fcfdca24 (patch)
tree9772f6696e32fe2051eecb7573949a66ca48d963 /src
parent9015a5110fd7b887dafaa1007afc02da90963f2a (diff)
downloadrust-d65fa276f3f2a239805f8458e210fb92fcfdca24.tar.gz
rust-d65fa276f3f2a239805f8458e210fb92fcfdca24.zip
Add tests for `#[rustc_default_body_unstable]`
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/stability-attribute/auxiliary/default_body.rs29
-rw-r--r--src/test/ui/stability-attribute/default-body-stability-err.rs19
-rw-r--r--src/test/ui/stability-attribute/default-body-stability-err.stderr32
-rw-r--r--src/test/ui/stability-attribute/default-body-stability-ok-enables.rs18
-rw-r--r--src/test/ui/stability-attribute/default-body-stability-ok-impls.rs21
5 files changed, 119 insertions, 0 deletions
diff --git a/src/test/ui/stability-attribute/auxiliary/default_body.rs b/src/test/ui/stability-attribute/auxiliary/default_body.rs
new file mode 100644
index 00000000000..3a177419d66
--- /dev/null
+++ b/src/test/ui/stability-attribute/auxiliary/default_body.rs
@@ -0,0 +1,29 @@
+#![crate_type = "lib"]
+#![feature(staged_api, rustc_attrs)]
+#![stable(feature = "stable_feature", since = "1.0.0")]
+
+#[stable(feature = "stable_feature", since = "1.0.0")]
+pub trait JustTrait {
+    #[stable(feature = "stable_feature", since = "1.0.0")]
+    #[rustc_default_body_unstable(feature = "constant_default_body", issue = "none")]
+    const CONSTANT: usize = 0;
+
+    #[rustc_default_body_unstable(feature = "fun_default_body", issue = "none")]
+    #[stable(feature = "stable_feature", since = "1.0.0")]
+    fn fun() {}
+}
+
+#[rustc_must_implement_one_of(eq, neq)]
+#[stable(feature = "stable_feature", since = "1.0.0")]
+pub trait Equal {
+    #[rustc_default_body_unstable(feature = "eq_default_body", issue = "none")]
+    #[stable(feature = "stable_feature", since = "1.0.0")]
+    fn eq(&self, other: &Self) -> bool {
+        !self.neq(other)
+    }
+
+    #[stable(feature = "stable_feature", since = "1.0.0")]
+    fn neq(&self, other: &Self) -> bool {
+        !self.eq(other)
+    }
+}
diff --git a/src/test/ui/stability-attribute/default-body-stability-err.rs b/src/test/ui/stability-attribute/default-body-stability-err.rs
new file mode 100644
index 00000000000..8f970d0c9f6
--- /dev/null
+++ b/src/test/ui/stability-attribute/default-body-stability-err.rs
@@ -0,0 +1,19 @@
+// aux-build:default_body.rs
+#![crate_type = "lib"]
+
+extern crate default_body;
+
+use default_body::{Equal, JustTrait};
+
+struct Type;
+
+impl JustTrait for Type {}
+//~^ ERROR use of unstable library feature 'fun_default_body'
+//~| ERROR use of unstable library feature 'constant_default_body'
+
+impl Equal for Type {
+    //~^ ERROR use of unstable library feature 'eq_default_body'
+    fn neq(&self, other: &Self) -> bool {
+        false
+    }
+}
diff --git a/src/test/ui/stability-attribute/default-body-stability-err.stderr b/src/test/ui/stability-attribute/default-body-stability-err.stderr
new file mode 100644
index 00000000000..6abf68bbcae
--- /dev/null
+++ b/src/test/ui/stability-attribute/default-body-stability-err.stderr
@@ -0,0 +1,32 @@
+error[E0658]: use of unstable library feature 'constant_default_body'
+  --> $DIR/default-body-stability-err.rs:10:1
+   |
+LL | impl JustTrait for Type {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: add `#![feature(constant_default_body)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'fun_default_body'
+  --> $DIR/default-body-stability-err.rs:10:1
+   |
+LL | impl JustTrait for Type {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = help: add `#![feature(fun_default_body)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'eq_default_body'
+  --> $DIR/default-body-stability-err.rs:14:1
+   |
+LL | / impl Equal for Type {
+LL | |
+LL | |     fn neq(&self, other: &Self) -> bool {
+LL | |         false
+LL | |     }
+LL | | }
+   | |_^
+   |
+   = help: add `#![feature(eq_default_body)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/stability-attribute/default-body-stability-ok-enables.rs b/src/test/ui/stability-attribute/default-body-stability-ok-enables.rs
new file mode 100644
index 00000000000..bdc7522f48d
--- /dev/null
+++ b/src/test/ui/stability-attribute/default-body-stability-ok-enables.rs
@@ -0,0 +1,18 @@
+// check-pass
+// aux-build:default_body.rs
+#![crate_type = "lib"]
+#![feature(fun_default_body, eq_default_body, constant_default_body)]
+
+extern crate default_body;
+
+use default_body::{Equal, JustTrait};
+
+struct Type;
+
+impl JustTrait for Type {}
+
+impl Equal for Type {
+    fn neq(&self, other: &Self) -> bool {
+        false
+    }
+}
diff --git a/src/test/ui/stability-attribute/default-body-stability-ok-impls.rs b/src/test/ui/stability-attribute/default-body-stability-ok-impls.rs
new file mode 100644
index 00000000000..e1f5c017096
--- /dev/null
+++ b/src/test/ui/stability-attribute/default-body-stability-ok-impls.rs
@@ -0,0 +1,21 @@
+// check-pass
+// aux-build:default_body.rs
+#![crate_type = "lib"]
+
+extern crate default_body;
+
+use default_body::{Equal, JustTrait};
+
+struct Type;
+
+impl JustTrait for Type {
+    const CONSTANT: usize = 1;
+
+    fn fun() {}
+}
+
+impl Equal for Type {
+    fn eq(&self, other: &Self) -> bool {
+        false
+    }
+}