about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2022-08-14 12:06:50 +0000
committerbors <bors@rust-lang.org>2022-08-14 12:06:50 +0000
commit4c5665583815a0f0f3e22516441efb43ea6dede2 (patch)
treed63a94dc1432882fa5856a412d0c28d40e978cfd /src/test/ui
parent2fbc08e2ce64dee45a29cb6133da6b32366268aa (diff)
parent9de9786ef84f09b367d99bcce6e59a4ed75acd64 (diff)
downloadrust-4c5665583815a0f0f3e22516441efb43ea6dede2.tar.gz
rust-4c5665583815a0f0f3e22516441efb43ea6dede2.zip
Auto merge of #100525 - Dylan-DPC:rollup-4cp6nu0, r=Dylan-DPC
Rollup of 6 pull requests

Successful merges:

 - #99582 (Delay a span bug if we see ty/const generic params during writeback)
 - #99861 (orphan check: rationalize our handling of constants)
 - #100026 (Add `Iterator::array_chunks` (take N+1))
 - #100115 (Suggest removing `let` if `const let` or `let const` is used)
 - #100126 (rustc_target: Update some old naming around self contained linking)
 - #100487 (`assert_{inhabited,zero_valid,uninit_valid}` intrinsics are safe)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/closures/binder/disallow-const.rs6
-rw-r--r--src/test/ui/closures/binder/disallow-const.stderr8
-rw-r--r--src/test/ui/closures/binder/disallow-ty.rs6
-rw-r--r--src/test/ui/closures/binder/disallow-ty.stderr8
-rw-r--r--src/test/ui/coherence/auxiliary/trait-with-const-param.rs1
-rw-r--r--src/test/ui/coherence/const-generics-orphan-check-ok.rs28
-rw-r--r--src/test/ui/consts/assert-type-intrinsics.rs4
-rw-r--r--src/test/ui/consts/assert-type-intrinsics.stderr8
-rw-r--r--src/test/ui/parser/issue-99910-const-let-mutually-exclusive.fixed8
-rw-r--r--src/test/ui/parser/issue-99910-const-let-mutually-exclusive.rs8
-rw-r--r--src/test/ui/parser/issue-99910-const-let-mutually-exclusive.stderr14
11 files changed, 93 insertions, 6 deletions
diff --git a/src/test/ui/closures/binder/disallow-const.rs b/src/test/ui/closures/binder/disallow-const.rs
new file mode 100644
index 00000000000..72ad6185d37
--- /dev/null
+++ b/src/test/ui/closures/binder/disallow-const.rs
@@ -0,0 +1,6 @@
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+    for<const N: i32> || -> () {};
+    //~^ ERROR only lifetime parameters can be used in this context
+}
diff --git a/src/test/ui/closures/binder/disallow-const.stderr b/src/test/ui/closures/binder/disallow-const.stderr
new file mode 100644
index 00000000000..3c3b43d8cf3
--- /dev/null
+++ b/src/test/ui/closures/binder/disallow-const.stderr
@@ -0,0 +1,8 @@
+error: only lifetime parameters can be used in this context
+  --> $DIR/disallow-const.rs:4:15
+   |
+LL |     for<const N: i32> || -> () {};
+   |               ^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/closures/binder/disallow-ty.rs b/src/test/ui/closures/binder/disallow-ty.rs
new file mode 100644
index 00000000000..bbe3d8488d9
--- /dev/null
+++ b/src/test/ui/closures/binder/disallow-ty.rs
@@ -0,0 +1,6 @@
+#![feature(closure_lifetime_binder)]
+
+fn main() {
+    for<T> || -> () {};
+    //~^ ERROR only lifetime parameters can be used in this context
+}
diff --git a/src/test/ui/closures/binder/disallow-ty.stderr b/src/test/ui/closures/binder/disallow-ty.stderr
new file mode 100644
index 00000000000..51b6773edea
--- /dev/null
+++ b/src/test/ui/closures/binder/disallow-ty.stderr
@@ -0,0 +1,8 @@
+error: only lifetime parameters can be used in this context
+  --> $DIR/disallow-ty.rs:4:9
+   |
+LL |     for<T> || -> () {};
+   |         ^
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/coherence/auxiliary/trait-with-const-param.rs b/src/test/ui/coherence/auxiliary/trait-with-const-param.rs
new file mode 100644
index 00000000000..a44eb14f8e4
--- /dev/null
+++ b/src/test/ui/coherence/auxiliary/trait-with-const-param.rs
@@ -0,0 +1 @@
+pub trait Trait<const N: usize, T> {}
diff --git a/src/test/ui/coherence/const-generics-orphan-check-ok.rs b/src/test/ui/coherence/const-generics-orphan-check-ok.rs
new file mode 100644
index 00000000000..217e8aed234
--- /dev/null
+++ b/src/test/ui/coherence/const-generics-orphan-check-ok.rs
@@ -0,0 +1,28 @@
+// check-pass
+// aux-build:trait-with-const-param.rs
+extern crate trait_with_const_param;
+use trait_with_const_param::*;
+
+// Trivial case, const param after local type.
+struct Local1;
+impl<const N: usize, T> Trait<N, T> for Local1 {}
+
+// Concrete consts behave the same as foreign types,
+// so this also trivially works.
+impl Trait<3, Local1> for i32 {}
+
+// This case isn't as trivial as we would forbid type
+// parameters here, we do allow const parameters though.
+//
+// The reason that type parameters are forbidden for
+// `impl<T> Trait<T, LocalInA> for i32 {}` is that another
+// downstream crate can add `impl<T> Trait<LocalInB, T> for i32`.
+// As these two impls would overlap we forbid any impls which
+// have a type parameter in front of a local type.
+//
+// With const parameters this issue does not exist as there are no
+// constants local to another downstream crate.
+struct Local2;
+impl<const N: usize> Trait<N, Local2> for i32 {}
+
+fn main() {}
diff --git a/src/test/ui/consts/assert-type-intrinsics.rs b/src/test/ui/consts/assert-type-intrinsics.rs
index 38e5c454edf..3ce3e1bdbac 100644
--- a/src/test/ui/consts/assert-type-intrinsics.rs
+++ b/src/test/ui/consts/assert-type-intrinsics.rs
@@ -13,10 +13,10 @@ fn main() {
     const _BAD1: () = unsafe {
         MaybeUninit::<!>::uninit().assume_init();
     };
-    const _BAD2: () = unsafe {
+    const _BAD2: () = {
         intrinsics::assert_uninit_valid::<bool>();
     };
-    const _BAD3: () = unsafe {
+    const _BAD3: () = {
         intrinsics::assert_zero_valid::<&'static i32>();
     };
 }
diff --git a/src/test/ui/consts/assert-type-intrinsics.stderr b/src/test/ui/consts/assert-type-intrinsics.stderr
index f3b9170d428..6eab10197b8 100644
--- a/src/test/ui/consts/assert-type-intrinsics.stderr
+++ b/src/test/ui/consts/assert-type-intrinsics.stderr
@@ -13,7 +13,7 @@ LL |         MaybeUninit::<!>::uninit().assume_init();
 error: any use of this value will cause an error
   --> $DIR/assert-type-intrinsics.rs:17:9
    |
-LL |     const _BAD2: () = unsafe {
+LL |     const _BAD2: () = {
    |     ---------------
 LL |         intrinsics::assert_uninit_valid::<bool>();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
@@ -24,7 +24,7 @@ LL |         intrinsics::assert_uninit_valid::<bool>();
 error: any use of this value will cause an error
   --> $DIR/assert-type-intrinsics.rs:20:9
    |
-LL |     const _BAD3: () = unsafe {
+LL |     const _BAD3: () = {
    |     ---------------
 LL |         intrinsics::assert_zero_valid::<&'static i32>();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
@@ -51,7 +51,7 @@ Future breakage diagnostic:
 error: any use of this value will cause an error
   --> $DIR/assert-type-intrinsics.rs:17:9
    |
-LL |     const _BAD2: () = unsafe {
+LL |     const _BAD2: () = {
    |     ---------------
 LL |         intrinsics::assert_uninit_valid::<bool>();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `bool` uninitialized, which is invalid
@@ -64,7 +64,7 @@ Future breakage diagnostic:
 error: any use of this value will cause an error
   --> $DIR/assert-type-intrinsics.rs:20:9
    |
-LL |     const _BAD3: () = unsafe {
+LL |     const _BAD3: () = {
    |     ---------------
 LL |         intrinsics::assert_zero_valid::<&'static i32>();
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
diff --git a/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.fixed b/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.fixed
new file mode 100644
index 00000000000..64ab6f62b77
--- /dev/null
+++ b/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.fixed
@@ -0,0 +1,8 @@
+// run-rustfix
+
+fn main() {
+    const _FOO: i32 = 123;
+    //~^ ERROR const` and `let` are mutually exclusive
+    const _BAR: i32 = 123;
+    //~^ ERROR `const` and `let` are mutually exclusive
+}
diff --git a/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.rs b/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.rs
new file mode 100644
index 00000000000..50520971ffb
--- /dev/null
+++ b/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.rs
@@ -0,0 +1,8 @@
+// run-rustfix
+
+fn main() {
+    const let _FOO: i32 = 123;
+    //~^ ERROR const` and `let` are mutually exclusive
+    let const _BAR: i32 = 123;
+    //~^ ERROR `const` and `let` are mutually exclusive
+}
diff --git a/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.stderr b/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.stderr
new file mode 100644
index 00000000000..72377fc379c
--- /dev/null
+++ b/src/test/ui/parser/issue-99910-const-let-mutually-exclusive.stderr
@@ -0,0 +1,14 @@
+error: `const` and `let` are mutually exclusive
+  --> $DIR/issue-99910-const-let-mutually-exclusive.rs:4:5
+   |
+LL |     const let _FOO: i32 = 123;
+   |     ^^^^^^^^^ help: remove `let`: `const`
+
+error: `const` and `let` are mutually exclusive
+  --> $DIR/issue-99910-const-let-mutually-exclusive.rs:6:5
+   |
+LL |     let const _BAR: i32 = 123;
+   |     ^^^^^^^^^ help: remove `let`: `const`
+
+error: aborting due to 2 previous errors
+