about summary refs log tree commit diff
path: root/tests/mir-opt/reference_prop.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-06-03 10:19:57 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2024-06-03 13:24:44 +1000
commitac242996366cd0d1ec48ff76638320969c65bed3 (patch)
treeb6d35de6f702417a55f23d2f8c50c93c077c7487 /tests/mir-opt/reference_prop.rs
parenta6416d8907bc94ef1a032d54cb0443cde963e455 (diff)
downloadrust-ac242996366cd0d1ec48ff76638320969c65bed3.tar.gz
rust-ac242996366cd0d1ec48ff76638320969c65bed3.zip
Reformat `mir!` macro invocations to use braces.
The `mir!` macro has multiple parts:
- An optional return type annotation.
- A sequence of zero or more local declarations.
- A mandatory starting anonymous basic block, which is brace-delimited.
- A sequence of zero of more additional named basic blocks.

Some `mir!` invocations use braces with a "block" style, like so:
```
mir! {
    let _unit: ();
    {
	let non_copy = S(42);
	let ptr = std::ptr::addr_of_mut!(non_copy);
	// Inside `callee`, the first argument and `*ptr` are basically
	// aliasing places!
	Call(_unit = callee(Move(*ptr), ptr), ReturnTo(after_call), UnwindContinue())
    }
    after_call = {
	Return()
    }
}
```
Some invocations use parens with a "block" style, like so:
```
mir!(
    let x: [i32; 2];
    let one: i32;
    {
	x = [42, 43];
	one = 1;
	x = [one, 2];
	RET = Move(x);
	Return()
    }
)
```
And some invocations uses parens with a "tighter" style, like so:
```
mir!({
    SetDiscriminant(*b, 0);
    Return()
})
```
This last style is generally used for cases where just the mandatory
starting basic block is present. Its braces are placed next to the
parens.

This commit changes all `mir!` invocations to use braces with a "block"
style. Why?

- Consistency is good.

- The contents of the invocation is a block of code, so it's odd to use
  parens. They are more normally used for function-like macros.

- Most importantly, the next commit will enable rustfmt for
  `tests/mir-opt/`. rustfmt is more aggressive about formatting macros
  that use parens than macros that use braces. Without this commit's
  changes, rustfmt would break a couple of `mir!` macro invocations that
  use braces within `tests/mir-opt` by inserting an extraneous comma.
  E.g.:
  ```
  mir!(type RET = (i32, bool);, { // extraneous comma after ';'
      RET.0 = 1;
      RET.1 = true;
      Return()
  })
  ```
  Switching those `mir!` invocations to use braces avoids that problem,
  resulting in this, which is nicer to read as well as being valid
  syntax:
  ```
  mir! {
      type RET = (i32, bool);
      {
	  RET.0 = 1;
	  RET.1 = true;
	  Return()
      }
  }
  ```
Diffstat (limited to 'tests/mir-opt/reference_prop.rs')
-rw-r--r--tests/mir-opt/reference_prop.rs16
1 files changed, 8 insertions, 8 deletions
diff --git a/tests/mir-opt/reference_prop.rs b/tests/mir-opt/reference_prop.rs
index e0b0d699420..678a7c81084 100644
--- a/tests/mir-opt/reference_prop.rs
+++ b/tests/mir-opt/reference_prop.rs
@@ -658,7 +658,7 @@ fn read_through_raw(x: &mut usize) -> usize {
     // CHECK-NEXT: return;
 
     use std::intrinsics::mir::*;
-    mir!(
+    mir! {
         let r1: &mut usize;
         let r2: &mut usize;
         let p1: *mut usize;
@@ -674,7 +674,7 @@ fn read_through_raw(x: &mut usize) -> usize {
             RET = *p2;
             Return()
         }
-    )
+    }
 }
 
 #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@@ -683,7 +683,7 @@ fn multiple_storage() {
     // CHECK: _3 = (*_2);
 
     use std::intrinsics::mir::*;
-    mir!(
+    mir! {
         let x: i32;
         {
             StorageLive(x);
@@ -700,7 +700,7 @@ fn multiple_storage() {
         retblock = {
             Return()
         }
-    )
+    }
 }
 
 #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@@ -709,7 +709,7 @@ fn dominate_storage() {
     // CHECK: _5 = (*_2);
 
     use std::intrinsics::mir::*;
-    mir!(
+    mir! {
         let x: i32;
         let r: &i32;
         let c: i32;
@@ -730,7 +730,7 @@ fn dominate_storage() {
             let d = true;
             match d { false => bb2, _ => bb0 }
         }
-    )
+    }
 }
 
 #[custom_mir(dialect = "runtime", phase = "post-cleanup")]
@@ -739,7 +739,7 @@ fn maybe_dead(m: bool) {
     // CHECK: (*_5) = const 7_i32;
 
     use std::intrinsics::mir::*;
-    mir!(
+    mir! {
         let x: i32;
         let y: i32;
         {
@@ -774,7 +774,7 @@ fn maybe_dead(m: bool) {
         retblock = {
             Return()
         }
-    )
+    }
 }
 
 fn mut_raw_then_mut_shr() -> (i32, i32) {