about summary refs log tree commit diff
path: root/tests/ui/consts/const_constructor/const-construct-call.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-01-11 11:17:22 +0000
committerbors <bors@rust-lang.org>2023-01-11 11:17:22 +0000
commitb22c152958eade17a71d899b29a2d39bcc77aa48 (patch)
treeec6da75dc598a0a4086c0cc032c86d7241be1bc1 /tests/ui/consts/const_constructor/const-construct-call.rs
parent8ecaad85f61375b18e1667b51a3ef350121d2ca0 (diff)
parent40ba0e84d53f605ccf01836e9c2d27892728ae81 (diff)
downloadrust-b22c152958eade17a71d899b29a2d39bcc77aa48.tar.gz
rust-b22c152958eade17a71d899b29a2d39bcc77aa48.zip
Auto merge of #106458 - albertlarsan68:move-tests, r=jyn514
Move src/test to the root

See MCP at rust-lang/compiler-team#573

There may be more changes needed.

The first commit is just the move of the files:
You can check that the first commit did not do anything else than renames by running
```
git diff --diff-filter=r -M100% <rust-lang remote>/master <first commit hash>
```
The output should be empty, because the filter excludes renames, and the match threshold for qualifying a rename is 100%.

The second one is mostly a "find and replace" of `src/test` to `tests` and whatever is needed to make CI pass.

What is left to do:
---

- [x] Move directory
- [ ] Change references to `src/test`
    - [x] Change references in-tree
    - [ ] Change references in submodules / out-of-tree docs
- [x] Make CI pass:
    - [x] Fix tidy
    - [x] Fix tests
    - [x] Bless tests if needed (shouldn't normally)
- [ ] Merge it !
Diffstat (limited to 'tests/ui/consts/const_constructor/const-construct-call.rs')
-rw-r--r--tests/ui/consts/const_constructor/const-construct-call.rs110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/ui/consts/const_constructor/const-construct-call.rs b/tests/ui/consts/const_constructor/const-construct-call.rs
new file mode 100644
index 00000000000..cb735d7b305
--- /dev/null
+++ b/tests/ui/consts/const_constructor/const-construct-call.rs
@@ -0,0 +1,110 @@
+// Test that constructors are considered to be const fns
+
+// run-pass
+
+// Ctor(..) is transformed to Ctor { 0: ... } in THIR lowering, so directly
+// calling constructors doesn't require them to be const.
+
+type ExternalType = std::panic::AssertUnwindSafe<(Option<i32>, Result<i32, bool>)>;
+
+const fn call_external_constructors_in_local_vars() -> ExternalType {
+    let f = Some;
+    let g = Err;
+    let h = std::panic::AssertUnwindSafe;
+    let x = f(5);
+    let y = g(false);
+    let z = h((x, y));
+    z
+}
+
+const CALL_EXTERNAL_CONSTRUCTORS_IN_LOCAL_VARS: ExternalType = {
+    let f = Some;
+    let g = Err;
+    let h = std::panic::AssertUnwindSafe;
+    let x = f(5);
+    let y = g(false);
+    let z = h((x, y));
+    z
+};
+
+const fn call_external_constructors_in_temps() -> ExternalType {
+    let x = { Some }(5);
+    let y = (*&Err)(false);
+    let z = [std::panic::AssertUnwindSafe][0]((x, y));
+    z
+}
+
+const CALL_EXTERNAL_CONSTRUCTORS_IN_TEMPS: ExternalType = {
+    let x = { Some }(5);
+    let y = (*&Err)(false);
+    let z = [std::panic::AssertUnwindSafe][0]((x, y));
+    z
+};
+
+#[derive(Debug, PartialEq)]
+enum LocalOption<T> {
+    Some(T),
+    _None,
+}
+
+#[derive(Debug, PartialEq)]
+enum LocalResult<T, E> {
+    _Ok(T),
+    Err(E),
+}
+
+#[derive(Debug, PartialEq)]
+struct LocalAssertUnwindSafe<T>(T);
+
+type LocalType = LocalAssertUnwindSafe<(LocalOption<i32>, LocalResult<i32, bool>)>;
+
+const fn call_local_constructors_in_local_vars() -> LocalType {
+    let f = LocalOption::Some;
+    let g = LocalResult::Err;
+    let h = LocalAssertUnwindSafe;
+    let x = f(5);
+    let y = g(false);
+    let z = h((x, y));
+    z
+}
+
+const CALL_LOCAL_CONSTRUCTORS_IN_LOCAL_VARS: LocalType = {
+    let f = LocalOption::Some;
+    let g = LocalResult::Err;
+    let h = LocalAssertUnwindSafe;
+    let x = f(5);
+    let y = g(false);
+    let z = h((x, y));
+    z
+};
+
+const fn call_local_constructors_in_temps() -> LocalType {
+    let x = { LocalOption::Some }(5);
+    let y = (*&LocalResult::Err)(false);
+    let z = [LocalAssertUnwindSafe][0]((x, y));
+    z
+}
+
+const CALL_LOCAL_CONSTRUCTORS_IN_TEMPS: LocalType = {
+    let x = { LocalOption::Some }(5);
+    let y = (*&LocalResult::Err)(false);
+    let z = [LocalAssertUnwindSafe][0]((x, y));
+    z
+};
+
+fn main() {
+    assert_eq!(
+        (
+            call_external_constructors_in_local_vars().0,
+            call_external_constructors_in_temps().0,
+            call_local_constructors_in_local_vars(),
+            call_local_constructors_in_temps(),
+        ),
+        (
+            CALL_EXTERNAL_CONSTRUCTORS_IN_LOCAL_VARS.0,
+            CALL_EXTERNAL_CONSTRUCTORS_IN_TEMPS.0,
+            CALL_LOCAL_CONSTRUCTORS_IN_LOCAL_VARS,
+            CALL_LOCAL_CONSTRUCTORS_IN_TEMPS,
+        )
+    );
+}