about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-07-08 18:30:34 +0200
committerGitHub <noreply@github.com>2021-07-08 18:30:34 +0200
commitd85718ad01124abcb6a7cd2f958bae2285c933f1 (patch)
treee99e6e50e92ffc5d54e2613037e2e5ada83a2c7b /src
parentff4bf73a4274623e302fcde1f7914d6cf8da40e7 (diff)
parent07f903e0e0816821c41a19774f029086b557738b (diff)
downloadrust-d85718ad01124abcb6a7cd2f958bae2285c933f1.tar.gz
rust-d85718ad01124abcb6a7cd2f958bae2285c933f1.zip
Rollup merge of #86838 - lambinoo:I-69630-rust_const_unstable_check_const, r=oli-obk
Checking that function is const if marked with rustc_const_unstable

Fixes #69630

This one is still missing tests to check the behavior but I checked by hand and it seemed to work.
I would not mind some direction for writing those unit tests!
Diffstat (limited to 'src')
-rw-r--r--src/test/ui/consts/rustc-const-stability-require-const.rs47
-rw-r--r--src/test/ui/consts/rustc-const-stability-require-const.stderr86
-rw-r--r--src/test/ui/consts/rustc-impl-const-stability.rs21
3 files changed, 154 insertions, 0 deletions
diff --git a/src/test/ui/consts/rustc-const-stability-require-const.rs b/src/test/ui/consts/rustc-const-stability-require-const.rs
new file mode 100644
index 00000000000..4fb259b335c
--- /dev/null
+++ b/src/test/ui/consts/rustc-const-stability-require-const.rs
@@ -0,0 +1,47 @@
+#![crate_type = "lib"]
+#![feature(staged_api)]
+#![stable(feature = "foo", since = "1.0.0")]
+
+#[stable(feature = "foo", since = "1.0.0")]
+#[rustc_const_unstable(feature = "const_foo", issue = "none")]
+pub fn foo() {}
+//~^ ERROR attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+
+#[stable(feature = "bar", since = "1.0.0")]
+#[rustc_const_stable(feature = "const_bar", since = "1.0.0")]
+pub fn bar() {}
+//~^ ERROR attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+
+#[stable(feature = "potato", since = "1.0.0")]
+pub struct Potato;
+
+impl Potato {
+    #[stable(feature = "salad", since = "1.0.0")]
+    #[rustc_const_unstable(feature = "const_salad", issue = "none")]
+    pub fn salad(&self) -> &'static str { "mmmmmm" }
+    //~^ ERROR attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+
+    #[stable(feature = "roasted", since = "1.0.0")]
+    #[rustc_const_unstable(feature = "const_roasted", issue = "none")]
+    pub fn roasted(&self) -> &'static str { "mmmmmmmmmm" }
+    //~^ ERROR attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+}
+
+#[stable(feature = "bar", since = "1.0.0")]
+#[rustc_const_stable(feature = "const_bar", since = "1.0.0")]
+pub extern "C" fn bar_c() {}
+//~^ ERROR attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+
+#[stable(feature = "foo", since = "1.0.0")]
+#[rustc_const_unstable(feature = "const_foo", issue = "none")]
+pub extern "C" fn foo_c() {}
+//~^ ERROR attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+
+
+#[stable(feature = "foobar", since = "1.0.0")]
+#[rustc_const_unstable(feature = "foobar_const", issue = "none")]
+pub const fn foobar() {}
+
+#[stable(feature = "barfoo", since = "1.0.0")]
+#[rustc_const_stable(feature = "barfoo_const", since = "1.0.0")]
+pub const fn barfoo() {}
diff --git a/src/test/ui/consts/rustc-const-stability-require-const.stderr b/src/test/ui/consts/rustc-const-stability-require-const.stderr
new file mode 100644
index 00000000000..1027b9311b7
--- /dev/null
+++ b/src/test/ui/consts/rustc-const-stability-require-const.stderr
@@ -0,0 +1,86 @@
+error: attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+  --> $DIR/rustc-const-stability-require-const.rs:7:1
+   |
+LL | #[rustc_const_unstable(feature = "const_foo", issue = "none")]
+   | -------------------------------------------------------------- attribute specified here
+LL | pub fn foo() {}
+   | ^^^^^^^^^^^^
+   |
+help: make the function or method const
+  --> $DIR/rustc-const-stability-require-const.rs:7:1
+   |
+LL | pub fn foo() {}
+   | ^^^^^^^^^^^^
+
+error: attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+  --> $DIR/rustc-const-stability-require-const.rs:12:1
+   |
+LL | #[rustc_const_stable(feature = "const_bar", since = "1.0.0")]
+   | ------------------------------------------------------------- attribute specified here
+LL | pub fn bar() {}
+   | ^^^^^^^^^^^^
+   |
+help: make the function or method const
+  --> $DIR/rustc-const-stability-require-const.rs:12:1
+   |
+LL | pub fn bar() {}
+   | ^^^^^^^^^^^^
+
+error: attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+  --> $DIR/rustc-const-stability-require-const.rs:21:5
+   |
+LL |     #[rustc_const_unstable(feature = "const_salad", issue = "none")]
+   |     ---------------------------------------------------------------- attribute specified here
+LL |     pub fn salad(&self) -> &'static str { "mmmmmm" }
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: make the function or method const
+  --> $DIR/rustc-const-stability-require-const.rs:21:5
+   |
+LL |     pub fn salad(&self) -> &'static str { "mmmmmm" }
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+  --> $DIR/rustc-const-stability-require-const.rs:26:5
+   |
+LL |     #[rustc_const_unstable(feature = "const_roasted", issue = "none")]
+   |     ------------------------------------------------------------------ attribute specified here
+LL |     pub fn roasted(&self) -> &'static str { "mmmmmmmmmm" }
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: make the function or method const
+  --> $DIR/rustc-const-stability-require-const.rs:26:5
+   |
+LL |     pub fn roasted(&self) -> &'static str { "mmmmmmmmmm" }
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+  --> $DIR/rustc-const-stability-require-const.rs:32:1
+   |
+LL | #[rustc_const_stable(feature = "const_bar", since = "1.0.0")]
+   | ------------------------------------------------------------- attribute specified here
+LL | pub extern "C" fn bar_c() {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: make the function or method const
+  --> $DIR/rustc-const-stability-require-const.rs:32:1
+   |
+LL | pub extern "C" fn bar_c() {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: attributes `#[rustc_const_unstable]` and `#[rustc_const_stable]` require the function or method to be `const`
+  --> $DIR/rustc-const-stability-require-const.rs:37:1
+   |
+LL | #[rustc_const_unstable(feature = "const_foo", issue = "none")]
+   | -------------------------------------------------------------- attribute specified here
+LL | pub extern "C" fn foo_c() {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: make the function or method const
+  --> $DIR/rustc-const-stability-require-const.rs:37:1
+   |
+LL | pub extern "C" fn foo_c() {}
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 6 previous errors
+
diff --git a/src/test/ui/consts/rustc-impl-const-stability.rs b/src/test/ui/consts/rustc-impl-const-stability.rs
new file mode 100644
index 00000000000..01daa1c9cb4
--- /dev/null
+++ b/src/test/ui/consts/rustc-impl-const-stability.rs
@@ -0,0 +1,21 @@
+// build-pass
+
+#![crate_type = "lib"]
+#![allow(incomplete_features)]
+#![feature(staged_api)]
+#![feature(const_trait_impl)]
+#![stable(feature = "foo", since = "1.0.0")]
+
+
+#[stable(feature = "potato", since = "1.27.0")]
+pub struct Data {
+    _data: u128
+}
+
+#[stable(feature = "potato", since = "1.27.0")]
+impl const Default for Data {
+    #[rustc_const_unstable(feature = "data_foo", issue = "none")]
+    fn default() -> Data {
+        Data { _data: 42 }
+    }
+}