summaryrefslogtreecommitdiffstats
path: root/src/test/ui/internal
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/internal')
-rw-r--r--src/test/ui/internal/auxiliary/internal_unstable.rs101
-rw-r--r--src/test/ui/internal/internal-unstable-const.rs13
-rw-r--r--src/test/ui/internal/internal-unstable-const.stderr17
-rw-r--r--src/test/ui/internal/internal-unstable-noallow.rs23
-rw-r--r--src/test/ui/internal/internal-unstable-noallow.stderr39
-rw-r--r--src/test/ui/internal/internal-unstable-thread-local.rs11
-rw-r--r--src/test/ui/internal/internal-unstable-thread-local.stderr11
-rw-r--r--src/test/ui/internal/internal-unstable.rs56
-rw-r--r--src/test/ui/internal/internal-unstable.stderr47
9 files changed, 318 insertions, 0 deletions
diff --git a/src/test/ui/internal/auxiliary/internal_unstable.rs b/src/test/ui/internal/auxiliary/internal_unstable.rs
new file mode 100644
index 000000000..eb4d6cb38
--- /dev/null
+++ b/src/test/ui/internal/auxiliary/internal_unstable.rs
@@ -0,0 +1,101 @@
+#![feature(staged_api, allow_internal_unstable)]
+#![stable(feature = "stable", since = "1.0.0")]
+
+#[unstable(feature = "function", issue = "none")]
+pub fn unstable() {}
+
+
+#[stable(feature = "stable", since = "1.0.0")]
+pub struct Foo {
+ #[unstable(feature = "struct_field", issue = "none")]
+ pub x: u8
+}
+
+impl Foo {
+ #[unstable(feature = "method", issue = "none")]
+ pub fn method(&self) {}
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+pub struct Bar {
+ #[unstable(feature = "struct2_field", issue = "none")]
+ pub x: u8
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[allow_internal_unstable(function)]
+#[macro_export]
+macro_rules! call_unstable_allow {
+ () => { $crate::unstable() }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[allow_internal_unstable(struct_field)]
+#[macro_export]
+macro_rules! construct_unstable_allow {
+ ($e: expr) => {
+ $crate::Foo { x: $e }
+ }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[allow_internal_unstable(method)]
+#[macro_export]
+macro_rules! call_method_allow {
+ ($e: expr) => { $e.method() }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[allow_internal_unstable(struct_field, struct2_field)]
+#[macro_export]
+macro_rules! access_field_allow {
+ ($e: expr) => { $e.x }
+}
+
+// regression test for #77088
+#[stable(feature = "stable", since = "1.0.0")]
+#[allow_internal_unstable(struct_field)]
+#[allow_internal_unstable(struct2_field)]
+#[macro_export]
+macro_rules! access_field_allow2 {
+ ($e: expr) => { $e.x }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[allow_internal_unstable()]
+#[macro_export]
+macro_rules! pass_through_allow {
+ ($e: expr) => { $e }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[macro_export]
+macro_rules! call_unstable_noallow {
+ () => { $crate::unstable() }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[macro_export]
+macro_rules! construct_unstable_noallow {
+ ($e: expr) => {
+ $crate::Foo { x: $e }
+ }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[macro_export]
+macro_rules! call_method_noallow {
+ ($e: expr) => { $e.method() }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[macro_export]
+macro_rules! access_field_noallow {
+ ($e: expr) => { $e.x }
+}
+
+#[stable(feature = "stable", since = "1.0.0")]
+#[macro_export]
+macro_rules! pass_through_noallow {
+ ($e: expr) => { $e }
+}
diff --git a/src/test/ui/internal/internal-unstable-const.rs b/src/test/ui/internal/internal-unstable-const.rs
new file mode 100644
index 000000000..4ec2426df
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable-const.rs
@@ -0,0 +1,13 @@
+// Don't allow unstable features in stable functions without `allow_internal_unstable`.
+
+#![stable(feature = "rust1", since = "1.0.0")]
+#![feature(staged_api)]
+#![feature(const_fn_floating_point_arithmetic)]
+
+#[stable(feature = "rust1", since = "1.0.0")]
+#[rustc_const_stable(feature = "rust1", since = "1.0.0")]
+pub const fn foo() -> f32 {
+ 1.0 + 1.0 //~ ERROR const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+}
+
+fn main() {}
diff --git a/src/test/ui/internal/internal-unstable-const.stderr b/src/test/ui/internal/internal-unstable-const.stderr
new file mode 100644
index 000000000..37d2ea6d2
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable-const.stderr
@@ -0,0 +1,17 @@
+error: const-stable function cannot use `#[feature(const_fn_floating_point_arithmetic)]`
+ --> $DIR/internal-unstable-const.rs:10:5
+ |
+LL | 1.0 + 1.0
+ | ^^^^^^^^^
+ |
+help: if it is not part of the public API, make this function unstably const
+ |
+LL | #[rustc_const_unstable(feature = "...", issue = "...")]
+ |
+help: otherwise `#[rustc_allow_const_fn_unstable]` can be used to bypass stability checks
+ |
+LL | #[rustc_allow_const_fn_unstable(const_fn_floating_point_arithmetic)]
+ |
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/internal/internal-unstable-noallow.rs b/src/test/ui/internal/internal-unstable-noallow.rs
new file mode 100644
index 000000000..616f6668d
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable-noallow.rs
@@ -0,0 +1,23 @@
+// this has to be separate to internal-unstable.rs because these tests
+// have error messages pointing deep into the internals of the
+// cross-crate macros, and hence need to use error-pattern instead of
+// the // ~ form.
+
+// aux-build:internal_unstable.rs
+// error-pattern:use of unstable library feature 'function'
+// error-pattern:use of unstable library feature 'struct_field'
+// error-pattern:use of unstable library feature 'method'
+// error-pattern:use of unstable library feature 'struct2_field'
+
+#[macro_use]
+extern crate internal_unstable;
+
+fn main() {
+ call_unstable_noallow!();
+
+ construct_unstable_noallow!(0);
+
+ |x: internal_unstable::Foo| { call_method_noallow!(x) };
+
+ |x: internal_unstable::Bar| { access_field_noallow!(x) };
+}
diff --git a/src/test/ui/internal/internal-unstable-noallow.stderr b/src/test/ui/internal/internal-unstable-noallow.stderr
new file mode 100644
index 000000000..b0ceae62a
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable-noallow.stderr
@@ -0,0 +1,39 @@
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable-noallow.rs:16:5
+ |
+LL | call_unstable_noallow!();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+ = note: this error originates in the macro `call_unstable_noallow` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0658]: use of unstable library feature 'struct_field'
+ --> $DIR/internal-unstable-noallow.rs:18:5
+ |
+LL | construct_unstable_noallow!(0);
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(struct_field)]` to the crate attributes to enable
+ = note: this error originates in the macro `construct_unstable_noallow` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0658]: use of unstable library feature 'method'
+ --> $DIR/internal-unstable-noallow.rs:20:35
+ |
+LL | |x: internal_unstable::Foo| { call_method_noallow!(x) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(method)]` to the crate attributes to enable
+ = note: this error originates in the macro `call_method_noallow` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error[E0658]: use of unstable library feature 'struct2_field'
+ --> $DIR/internal-unstable-noallow.rs:22:35
+ |
+LL | |x: internal_unstable::Bar| { access_field_noallow!(x) };
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(struct2_field)]` to the crate attributes to enable
+ = note: this error originates in the macro `access_field_noallow` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 4 previous errors
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/internal/internal-unstable-thread-local.rs b/src/test/ui/internal/internal-unstable-thread-local.rs
new file mode 100644
index 000000000..b9194c6b3
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable-thread-local.rs
@@ -0,0 +1,11 @@
+// aux-build:internal_unstable.rs
+
+#![allow(dead_code)]
+
+extern crate internal_unstable;
+
+
+thread_local!(static FOO: () = ());
+thread_local!(static BAR: () = internal_unstable::unstable()); //~ ERROR use of unstable
+
+fn main() {}
diff --git a/src/test/ui/internal/internal-unstable-thread-local.stderr b/src/test/ui/internal/internal-unstable-thread-local.stderr
new file mode 100644
index 000000000..558e3dbb7
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable-thread-local.stderr
@@ -0,0 +1,11 @@
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable-thread-local.rs:9:32
+ |
+LL | thread_local!(static BAR: () = internal_unstable::unstable());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/internal/internal-unstable.rs b/src/test/ui/internal/internal-unstable.rs
new file mode 100644
index 000000000..b8987d3e1
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable.rs
@@ -0,0 +1,56 @@
+// aux-build:internal_unstable.rs
+
+#![feature(allow_internal_unstable)]
+#[allow(dead_code)]
+
+#[macro_use]
+extern crate internal_unstable;
+
+struct Baz {
+ #[allow_internal_unstable]
+ //^ WARN `#[allow_internal_unstable]` is ignored on struct fields and match arms
+ baz: u8,
+}
+
+macro_rules! foo {
+ ($e: expr, $f: expr) => {{
+ $e;
+ $f;
+ internal_unstable::unstable(); //~ ERROR use of unstable
+ }}
+}
+
+#[allow_internal_unstable(function)]
+macro_rules! bar {
+ ($e: expr) => {{
+ foo!($e,
+ internal_unstable::unstable());
+ internal_unstable::unstable();
+ }}
+}
+
+fn main() {
+ // ok, the instability is contained.
+ call_unstable_allow!();
+ construct_unstable_allow!(0);
+ |x: internal_unstable::Foo| { call_method_allow!(x) };
+ |x: internal_unstable::Bar| { access_field_allow!(x) };
+ |x: internal_unstable::Bar| { access_field_allow2!(x) }; // regression test for #77088
+
+ // bad.
+ pass_through_allow!(internal_unstable::unstable()); //~ ERROR use of unstable
+
+ pass_through_noallow!(internal_unstable::unstable()); //~ ERROR use of unstable
+
+
+
+ println!("{:?}", internal_unstable::unstable()); //~ ERROR use of unstable
+
+ bar!(internal_unstable::unstable()); //~ ERROR use of unstable
+
+ match true {
+ #[allow_internal_unstable]
+ //^ WARN `#[allow_internal_unstable]` is ignored on struct fields and match arms
+ _ => {}
+ }
+}
diff --git a/src/test/ui/internal/internal-unstable.stderr b/src/test/ui/internal/internal-unstable.stderr
new file mode 100644
index 000000000..f0f9bfb8d
--- /dev/null
+++ b/src/test/ui/internal/internal-unstable.stderr
@@ -0,0 +1,47 @@
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable.rs:41:25
+ |
+LL | pass_through_allow!(internal_unstable::unstable());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable.rs:43:27
+ |
+LL | pass_through_noallow!(internal_unstable::unstable());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable.rs:47:22
+ |
+LL | println!("{:?}", internal_unstable::unstable());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable.rs:49:10
+ |
+LL | bar!(internal_unstable::unstable());
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+
+error[E0658]: use of unstable library feature 'function'
+ --> $DIR/internal-unstable.rs:19:9
+ |
+LL | internal_unstable::unstable();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | bar!(internal_unstable::unstable());
+ | ----------------------------------- in this macro invocation
+ |
+ = help: add `#![feature(function)]` to the crate attributes to enable
+ = note: this error originates in the macro `foo` which comes from the expansion of the macro `bar` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 5 previous errors
+
+For more information about this error, try `rustc --explain E0658`.