Skip to content

Commit

Permalink
Auto merge of rust-lang#125912 - nnethercote:rustfmt-tests-mir-opt, r…
Browse files Browse the repository at this point in the history
…=oli-obk

rustfmt `tests/mir-opt`

Continuing the work started in rust-lang#125759. Details in individual commit log messages.

r? `@oli-obk`
  • Loading branch information
bors committed Jun 3, 2024
2 parents 1d52972 + c9c80d2 commit 8768db9
Show file tree
Hide file tree
Showing 112 changed files with 630 additions and 563 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_mir_transform/src/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ use std::fmt;
///
/// ```text
// fn drop_term<T>(t: &mut T) {
// mir!(
// mir! {
// {
// Drop(*t, exit)
// }
// exit = {
// Return()
// }
// )
// }
// }
/// ```
pub struct ElaborateDrops;
Expand Down
58 changes: 32 additions & 26 deletions library/core/src/intrinsics/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! #[custom_mir(dialect = "built")]
//! pub fn simple(x: i32) -> i32 {
//! mir!(
//! mir! {
//! let temp2: i32;
//!
//! {
Expand All @@ -33,7 +33,7 @@
//! RET = temp2;
//! Return()
//! }
//! )
//! }
//! }
//! ```
//!
Expand Down Expand Up @@ -71,7 +71,7 @@
//!
//! #[custom_mir(dialect = "built")]
//! pub fn choose_load(a: &i32, b: &i32, c: bool) -> i32 {
//! mir!(
//! mir! {
//! {
//! match c {
//! true => t,
Expand All @@ -93,20 +93,22 @@
//! RET = *temp;
//! Return()
//! }
//! )
//! }
//! }
//!
//! #[custom_mir(dialect = "built")]
//! fn unwrap_unchecked<T>(opt: Option<T>) -> T {
//! mir!({
//! RET = Move(Field(Variant(opt, 1), 0));
//! Return()
//! })
//! mir! {
//! {
//! RET = Move(Field(Variant(opt, 1), 0));
//! Return()
//! }
//! }
//! }
//!
//! #[custom_mir(dialect = "runtime", phase = "optimized")]
//! fn push_and_pop<T>(v: &mut Vec<T>, value: T) {
//! mir!(
//! mir! {
//! let _unused;
//! let popped;
//!
Expand All @@ -125,19 +127,19 @@
//! ret = {
//! Return()
//! }
//! )
//! }
//! }
//!
//! #[custom_mir(dialect = "runtime", phase = "optimized")]
//! fn annotated_return_type() -> (i32, bool) {
//! mir!(
//! mir! {
//! type RET = (i32, bool);
//! {
//! RET.0 = 1;
//! RET.1 = true;
//! Return()
//! }
//! )
//! }
//! }
//! ```
//!
Expand All @@ -152,7 +154,7 @@
//!
//! #[custom_mir(dialect = "built")]
//! fn borrow_error(should_init: bool) -> i32 {
//! mir!(
//! mir! {
//! let temp: i32;
//!
//! {
Expand All @@ -171,15 +173,15 @@
//! RET = temp;
//! Return()
//! }
//! )
//! }
//! }
//! ```
//!
//! ```text
//! error[E0381]: used binding is possibly-uninitialized
//! --> test.rs:24:13
//! |
//! 8 | / mir!(
//! 8 | / mir! {
//! 9 | | let temp: i32;
//! 10 | |
//! 11 | | {
Expand All @@ -191,7 +193,7 @@
//! | | ^^^^^^^^^^ value used here but it is possibly-uninitialized
//! 25 | | Return()
//! 26 | | }
//! 27 | | )
//! 27 | | }
//! | |_____- binding declared here but left uninitialized
//!
//! error: aborting due to 1 previous error
Expand Down Expand Up @@ -407,18 +409,22 @@ define!(
///
/// #[custom_mir(dialect = "built")]
/// fn unwrap_deref(opt: Option<&i32>) -> i32 {
/// mir!({
/// RET = *Field::<&i32>(Variant(opt, 1), 0);
/// Return()
/// })
/// mir! {
/// {
/// RET = *Field::<&i32>(Variant(opt, 1), 0);
/// Return()
/// }
/// }
/// }
///
/// #[custom_mir(dialect = "built")]
/// fn set(opt: &mut Option<i32>) {
/// mir!({
/// place!(Field(Variant(*opt, 1), 0)) = 5;
/// Return()
/// })
/// mir! {
/// {
/// place!(Field(Variant(*opt, 1), 0)) = 5;
/// Return()
/// }
/// }
/// }
/// ```
fn Field<F>(place: (), field: u32) -> F
Expand Down Expand Up @@ -455,7 +461,7 @@ define!(
/// your MIR into something that is easier to parse in the compiler.
#[rustc_macro_transparency = "transparent"]
pub macro mir {
(
{
$(type RET = $ret_ty:ty ;)?
$(let $local_decl:ident $(: $local_decl_ty:ty)? ;)*
$(debug $dbg_name:ident => $dbg_data:expr ;)*
Expand All @@ -469,7 +475,7 @@ pub macro mir {
$($block:tt)*
}
)*
) => {{
} => {{
// First, we declare all basic blocks.
__internal_declare_basic_blocks!($(
$block_name $(($block_cleanup))?
Expand Down
14 changes: 5 additions & 9 deletions rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,13 @@ ignore = [
"/build-*/",
"/vendor/",

# Some tests are not formatted, for multiple reasons:
# - some contain syntax errors that cause rustfmt to give an error
# - some UI tests are broken by different formatting
# - some require special comments in a particular position (e.g. `EMIT_MIR` comments)
# Some tests are not formatted, for various reasons.
"/tests/codegen/simd-intrinsic/", # Many types like `u8x64` are better hand-formatted.
"/tests/crashes/", # Many tests contain syntax errors.
"/tests/debuginfo/", # Tests are somewhat sensitive to source code layout.
"/tests/incremental/", # Tests are somewhat sensitive to source code layout.
"/tests/mir-opt/",
"/tests/crashes/", # Many of these tests contain syntax errors.
"/tests/debuginfo/", # These tests are somewhat sensitive to source code layout.
"/tests/incremental/", # These tests are somewhat sensitive to source code layout.
"/tests/pretty/",
"/tests/run-make/translation/test.rs", # Contains syntax errors.
"/tests/run-make/translation/test.rs", # This test contains syntax errors.
"/tests/run-make-fulldeps/",
"/tests/run-pass-valgrind/",
"/tests/rustdoc/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use std::intrinsics::mir::*;

#[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
mir!({
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
})
mir! {
{
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
}
}
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_slice_data.rs:LL:CC
|
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use std::intrinsics::mir::*;

#[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const [i32]) -> usize {
mir!({
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
})
mir! {
{
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
}
}
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ LL | (*p.as_mut_ptr().cast::<[*const i32; 2]>())[0] = 4 as *const i32;
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_slice_len.rs:LL:CC
|
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
10 changes: 6 additions & 4 deletions src/tools/miri/tests/fail/intrinsics/ptr_metadata_uninit_thin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ use std::intrinsics::mir::*;

#[custom_mir(dialect = "runtime")]
pub unsafe fn deref_meta(p: *const *const i32) -> () {
mir!({
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
})
mir! {
{
RET = PtrMetadata(*p); //~ ERROR: Undefined Behavior: using uninitialized data
Return()
}
}
}

fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
error: Undefined Behavior: using uninitialized data, but this operation requires initialized memory
--> $DIR/ptr_metadata_uninit_thin.rs:LL:CC
|
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
LL | RET = PtrMetadata(*p);
| ^^^^^^^^^^^^^^^^^^^^^ using uninitialized data, but this operation requires initialized memory
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
Expand Down
2 changes: 1 addition & 1 deletion tests/mir-opt/address_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ fn address_of_reborrow() {
y as *const [i32; 10];
y as *const dyn Send;
y as *const [i32];
y as *const i32; // This is a cast, not a coercion
y as *const i32; // This is a cast, not a coercion

let p: *const _ = y;
let p: *const [i32; 10] = y;
Expand Down
1 change: 0 additions & 1 deletion tests/mir-opt/array_index_is_temporary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ unsafe fn foo(z: *mut usize) -> u32 {
99
}


// EMIT_MIR array_index_is_temporary.main.SimplifyCfg-pre-optimizations.after.mir
fn main() {
// CHECK-LABEL: fn main(
Expand Down
12 changes: 6 additions & 6 deletions tests/mir-opt/building/custom/aggregate_exprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ use core::intrinsics::mir::*;
// EMIT_MIR aggregate_exprs.tuple.built.after.mir
#[custom_mir(dialect = "built")]
fn tuple() -> (i32, bool) {
mir!(
mir! {
{
RET = (1, true);
Return()
}
)
}
}

// EMIT_MIR aggregate_exprs.array.built.after.mir
#[custom_mir(dialect = "built")]
fn array() -> [i32; 2] {
mir!(
mir! {
let x: [i32; 2];
let one: i32;
{
Expand All @@ -28,7 +28,7 @@ fn array() -> [i32; 2] {
RET = Move(x);
Return()
}
)
}
}

struct Foo {
Expand All @@ -48,7 +48,7 @@ union Onion {
// EMIT_MIR aggregate_exprs.adt.built.after.mir
#[custom_mir(dialect = "built")]
fn adt() -> Onion {
mir!(
mir! {
let one: i32;
let x: Foo;
let y: Bar;
Expand All @@ -62,7 +62,7 @@ fn adt() -> Onion {
RET = Onion { neon: Field(Variant(y, 0), 1) };
Return()
}
)
}
}

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions tests/mir-opt/building/custom/arbitrary_let.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use core::ptr::{addr_of, addr_of_mut};
// EMIT_MIR arbitrary_let.arbitrary_let.built.after.mir
#[custom_mir(dialect = "built")]
fn arbitrary_let(x: i32) -> i32 {
mir!(
mir! {
{
let y = x;
Goto(second)
Expand All @@ -21,7 +21,7 @@ fn arbitrary_let(x: i32) -> i32 {
let z = y;
Goto(third)
}
)
}
}

fn main() {
Expand Down
14 changes: 8 additions & 6 deletions tests/mir-opt/building/custom/arrays.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ use core::intrinsics::mir::*;
// EMIT_MIR arrays.arrays.built.after.mir
#[custom_mir(dialect = "built")]
fn arrays<const C: usize>() -> usize {
mir!({
let x = [5_i32; C];
let c = Len(x);
RET = c;
Return()
})
mir! {
{
let x = [5_i32; C];
let c = Len(x);
RET = c;
Return()
}
}
}

fn main() {
Expand Down
Loading

0 comments on commit 8768db9

Please sign in to comment.