about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codegen-units/item-collection/closures.rs12
-rw-r--r--tests/codegen-units/item-collection/non-generic-closures.rs7
-rw-r--r--tests/codegen/min-function-alignment.rs43
-rw-r--r--tests/codegen/naked-fn/min-function-alignment.rs44
-rw-r--r--tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs15
-rw-r--r--tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr13
6 files changed, 131 insertions, 3 deletions
diff --git a/tests/codegen-units/item-collection/closures.rs b/tests/codegen-units/item-collection/closures.rs
new file mode 100644
index 00000000000..5fc80230925
--- /dev/null
+++ b/tests/codegen-units/item-collection/closures.rs
@@ -0,0 +1,12 @@
+//@ edition: 2021
+//@ compile-flags: -Zprint-mono-items=eager --crate-type=lib
+
+//~ MONO_ITEM fn async_fn @@
+//~ MONO_ITEM fn async_fn::{closure#0} @@
+pub async fn async_fn() {}
+
+//~ MONO_ITEM fn closure @@
+//~ MONO_ITEM fn closure::{closure#0} @@
+pub fn closure() {
+    let _ = || {};
+}
diff --git a/tests/codegen-units/item-collection/non-generic-closures.rs b/tests/codegen-units/item-collection/non-generic-closures.rs
index dc0846f2cd3..8847a249b1e 100644
--- a/tests/codegen-units/item-collection/non-generic-closures.rs
+++ b/tests/codegen-units/item-collection/non-generic-closures.rs
@@ -13,6 +13,7 @@ fn temporary() {
 
 //~ MONO_ITEM fn assigned_to_variable_but_not_executed @@ non_generic_closures-cgu.0[Internal]
 fn assigned_to_variable_but_not_executed() {
+    //~ MONO_ITEM fn assigned_to_variable_but_not_executed::{closure#0}
     let _x = |a: i16| {
         let _ = a + 1;
     };
@@ -21,9 +22,9 @@ fn assigned_to_variable_but_not_executed() {
 //~ MONO_ITEM fn assigned_to_variable_executed_indirectly @@ non_generic_closures-cgu.0[Internal]
 fn assigned_to_variable_executed_indirectly() {
     //~ MONO_ITEM fn assigned_to_variable_executed_indirectly::{closure#0} @@ non_generic_closures-cgu.0[Internal]
-    //~ MONO_ITEM fn <{closure@TEST_PATH:27:13: 27:21} as std::ops::FnOnce<(i32,)>>::call_once - shim @@ non_generic_closures-cgu.0[Internal]
-    //~ MONO_ITEM fn <{closure@TEST_PATH:27:13: 27:21} as std::ops::FnOnce<(i32,)>>::call_once - shim(vtable) @@ non_generic_closures-cgu.0[Internal]
-    //~ MONO_ITEM fn std::ptr::drop_in_place::<{closure@TEST_PATH:27:13: 27:21}> - shim(None) @@ non_generic_closures-cgu.0[Internal]
+    //~ MONO_ITEM fn <{closure@TEST_PATH:28:13: 28:21} as std::ops::FnOnce<(i32,)>>::call_once - shim @@ non_generic_closures-cgu.0[Internal]
+    //~ MONO_ITEM fn <{closure@TEST_PATH:28:13: 28:21} as std::ops::FnOnce<(i32,)>>::call_once - shim(vtable) @@ non_generic_closures-cgu.0[Internal]
+    //~ MONO_ITEM fn std::ptr::drop_in_place::<{closure@TEST_PATH:28:13: 28:21}> - shim(None) @@ non_generic_closures-cgu.0[Internal]
     let f = |a: i32| {
         let _ = a + 2;
     };
diff --git a/tests/codegen/min-function-alignment.rs b/tests/codegen/min-function-alignment.rs
new file mode 100644
index 00000000000..7c0ad12402a
--- /dev/null
+++ b/tests/codegen/min-function-alignment.rs
@@ -0,0 +1,43 @@
+//@ revisions: align16 align1024
+//@ compile-flags: -C no-prepopulate-passes -Z mir-opt-level=0
+//@ [align16] compile-flags: -Zmin-function-alignment=16
+//@ [align1024] compile-flags: -Zmin-function-alignment=1024
+
+#![crate_type = "lib"]
+#![feature(fn_align)]
+
+// functions without explicit alignment use the global minimum
+//
+// CHECK-LABEL: @no_explicit_align
+// align16: align 16
+// align1024: align 1024
+#[no_mangle]
+pub fn no_explicit_align() {}
+
+// CHECK-LABEL: @lower_align
+// align16: align 16
+// align1024: align 1024
+#[no_mangle]
+#[repr(align(8))]
+pub fn lower_align() {}
+
+// the higher value of min-function-alignment and repr(align) wins out
+//
+// CHECK-LABEL: @higher_align
+// align16: align 32
+// align1024: align 1024
+#[no_mangle]
+#[repr(align(32))]
+pub fn higher_align() {}
+
+// cold functions follow the same rules as other functions
+//
+// in GCC, the `-falign-functions` does not apply to cold functions, but
+// `-Zmin-function-alignment` applies to all functions.
+//
+// CHECK-LABEL: @no_explicit_align_cold
+// align16: align 16
+// align1024: align 1024
+#[no_mangle]
+#[cold]
+pub fn no_explicit_align_cold() {}
diff --git a/tests/codegen/naked-fn/min-function-alignment.rs b/tests/codegen/naked-fn/min-function-alignment.rs
new file mode 100644
index 00000000000..1330d796d39
--- /dev/null
+++ b/tests/codegen/naked-fn/min-function-alignment.rs
@@ -0,0 +1,44 @@
+//@ compile-flags: -C no-prepopulate-passes -Copt-level=0 -Zmin-function-alignment=16
+//@ needs-asm-support
+//@ ignore-arm no "ret" mnemonic
+
+#![feature(naked_functions, fn_align)]
+#![crate_type = "lib"]
+
+// functions without explicit alignment use the global minimum
+//
+// CHECK: .balign 16
+#[no_mangle]
+#[naked]
+pub unsafe extern "C" fn naked_no_explicit_align() {
+    core::arch::naked_asm!("ret")
+}
+
+// CHECK: .balign 16
+#[no_mangle]
+#[repr(align(8))]
+#[naked]
+pub unsafe extern "C" fn naked_lower_align() {
+    core::arch::naked_asm!("ret")
+}
+
+// CHECK: .balign 32
+#[no_mangle]
+#[repr(align(32))]
+#[naked]
+pub unsafe extern "C" fn naked_higher_align() {
+    core::arch::naked_asm!("ret")
+}
+
+// cold functions follow the same rules as other functions
+//
+// in GCC, the `-falign-functions` does not apply to cold functions, but
+// `-Zmin-function-alignment` applies to all functions.
+//
+// CHECK: .balign 16
+#[no_mangle]
+#[cold]
+#[naked]
+pub unsafe extern "C" fn no_explicit_align_cold() {
+    core::arch::naked_asm!("ret")
+}
diff --git a/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs
new file mode 100644
index 00000000000..e5d095fd617
--- /dev/null
+++ b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.rs
@@ -0,0 +1,15 @@
+#![feature(structural_match)]
+impl<T: ?Sized> std::marker::StructuralPartialEq for O<T> { }
+
+enum O<T: ?Sized> {
+    Some(*const T),
+    None,
+}
+
+const C: O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)> = O::None;
+
+fn main() {
+    match O::None {
+        C => (), //~ ERROR constant of non-structural type
+    }
+}
diff --git a/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
new file mode 100644
index 00000000000..371be9982f7
--- /dev/null
+++ b/tests/ui/consts/const_in_pattern/non_structural_with_escaping_bounds.stderr
@@ -0,0 +1,13 @@
+error: constant of non-structural type `O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)>` in a pattern
+  --> $DIR/non_structural_with_escaping_bounds.rs:13:9
+   |
+LL | const C: O<dyn for<'a> Fn(Box<dyn Fn(&'a u8)>)> = O::None;
+   | ----------------------------------------------- constant defined here
+...
+LL |         C => (),
+   |         ^ constant of non-structural type
+   |
+   = note: see https://doc.rust-lang.org/stable/std/marker/trait.StructuralPartialEq.html for details
+
+error: aborting due to 1 previous error
+