rust/compiler
bors 79611d90b6 Auto merge of #122551 - RayMuir:copy_fmt, r=saethlin
Added "copy" to Debug fmt for copy operands

In MIR's debug mode (--emit mir) the printing for Operands is slightly inconsistent.

The RValues - values on the right side of an Assign - are usually printed with their Operand when they are Places.

Example:
_2 = move _3

But for arguments, the operand is omitted.

_2 = _1

I propose a change be made, to display the place with the operand.

_2 = copy _1

Move and copy have different semantics, meaning this difference is important and helpful to the user. It also adds consistency to the pretty printing.

-- EDIT --

 Consider this example Rust program and its MIR output with the **updated pretty printer.**

This was generated with the arguments --emit mir --crate-type lib -Zmir-opt-level=0 (Otherwise, it's optimised away since it's a junk program).

```rust
fn main(foo: i32) {
    let v = 10;

    if v == 20 {
        foo;
    }
    else {
        v;
    }
}
```

```MIR
// WARNING: This output format is intended for human consumers only
// and is subject to change without notice. Knock yourself out.
fn main(_1: i32) -> () {
    debug foo => _1;
    let mut _0: ();
    let _2: i32;
    let mut _3: bool;
    let mut _4: i32;
    let _5: i32;
    let _6: i32;
    scope 1 {
        debug v => _2;
    }

    bb0: {
        StorageLive(_2);
        _2 = const 10_i32;
        StorageLive(_3);
        StorageLive(_4);
        _4 = copy _2;
        _3 = Eq(move _4, const 20_i32);
        switchInt(move _3) -> [0: bb2, otherwise: bb1];
    }

    bb1: {
        StorageDead(_4);
        StorageLive(_5);
        _5 = copy _1;
        StorageDead(_5);
        _0 = const ();
        goto -> bb3;
    }

    bb2: {
        StorageDead(_4);
        StorageLive(_6);
        _6 = copy _2;
        StorageDead(_6);
        _0 = const ();
        goto -> bb3;
    }

    bb3: {
        StorageDead(_3);
        StorageDead(_2);
        return;
    }
}
```

In this example program, we can see that when we move a place, it is preceded by "move". e.g. ``` _3 = Eq(move _4, const 20_i32);```. However, when we copy a place such as ```_5 = _1;```, it is not preceded by the operand in the original printout. I propose to change the print to include the copy ```_5 = copy _1``` as in this example.

Regarding the arguments part. When I originally submitted this PR, I was under the impression this only affected the print for arguments to a function, but actually, it affects anything that uses a copy. This is preferable anyway with regard to consistency. The PR is about making ```copy``` explicit.
2024-08-19 23:10:46 +00:00
..
rustc Link std statically in rustc_driver 2024-08-11 04:16:53 +02:00
rustc_abi interpret: simplify pointer arithmetic logic 2024-08-01 14:25:19 +02:00
rustc_arena Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_ast Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
rustc_ast_ir Use dep: for crate dependencies 2024-07-15 12:40:10 -04:00
rustc_ast_lowering Use FnSig instead of raw FnDecl for ForeignItemKind::Fn 2024-08-16 14:10:06 -04:00
rustc_ast_passes stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
rustc_ast_pretty Use more slice patterns inside the compiler 2024-08-07 13:37:52 +02:00
rustc_attr Rollup merge of #128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercote 2024-08-12 17:09:17 +02:00
rustc_baked_icu_data
rustc_borrowck rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_builtin_macros Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercote 2024-08-17 22:48:42 +00:00
rustc_codegen_cranelift rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_codegen_gcc stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
rustc_codegen_llvm Update some dependency versions that allow better licensing 2024-08-18 13:59:27 -05:00
rustc_codegen_ssa Auto merge of #128722 - tgross35:new-resolver-root, r=Mark-Simulacrum 2024-08-19 09:50:33 +00:00
rustc_const_eval rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_data_structures Update indexmap and use IndexMap::append 2024-08-13 16:16:57 -07:00
rustc_driver
rustc_driver_impl Rollup merge of #128762 - fmease:use-more-slice-pats, r=compiler-errors 2024-08-11 07:51:51 +02:00
rustc_error_codes stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
rustc_error_messages Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_errors Add | to make the html doc of Level rendered correctly 2024-08-14 13:38:03 +08:00
rustc_expand Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercote 2024-08-17 22:48:42 +00:00
rustc_feature stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
rustc_fluent_macro Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_fs_util Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_graphviz Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_hir Typo 2024-08-18 13:14:09 -04:00
rustc_hir_analysis Use FnSig instead of raw FnDecl for ForeignItemKind::Fn 2024-08-16 14:10:06 -04:00
rustc_hir_pretty Use FnSig instead of raw FnDecl for ForeignItemKind::Fn 2024-08-16 14:10:06 -04:00
rustc_hir_typeck Rollup merge of #129223 - wafarm:fix-129215, r=compiler-errors 2024-08-19 20:14:57 +02:00
rustc_incremental Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_index Add and use IndexVec::append 2024-08-13 13:40:05 -07:00
rustc_index_macros Remove usage of specialization from newtype_index! 2024-06-30 16:42:53 +00:00
rustc_infer Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors 2024-08-14 00:56:53 +00:00
rustc_interface Stabilize std:🧵:Builder::spawn_unchecked 2024-08-16 10:43:47 -07:00
rustc_lexer Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_lint Use FnSig instead of raw FnDecl for ForeignItemKind::Fn 2024-08-16 14:10:06 -04:00
rustc_lint_defs Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercote 2024-08-17 22:48:42 +00:00
rustc_llvm Auto merge of #128936 - bjorn3:fix_thin_archive_reading, r=jieyouxu 2024-08-15 14:13:52 +00:00
rustc_log Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_metadata Rollup merge of #128886 - GrigorenkoPV:untranslatable-diagnostic, r=nnethercote 2024-08-12 17:09:17 +02:00
rustc_middle Auto merge of #122551 - RayMuir:copy_fmt, r=saethlin 2024-08-19 23:10:46 +00:00
rustc_mir_build rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_mir_dataflow rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_mir_transform Rollup merge of #128628 - khuey:simply-cfg-erase-source-info, r=nnethercote 2024-08-18 23:41:47 -05:00
rustc_monomorphize Rollup merge of #129067 - cuviper:append, r=wesleywiser 2024-08-15 00:02:27 +02:00
rustc_next_trait_solver Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors 2024-08-14 21:43:07 +08:00
rustc_parse stabilize raw_ref_op 2024-08-18 19:46:53 +02:00
rustc_parse_format Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_passes Fix wording of misapplied must_not_suspend error 2024-08-18 20:32:04 +03:00
rustc_pattern_analysis Rollup merge of #128965 - Zalathar:no-pat, r=Nadrieril 2024-08-15 18:44:16 -07:00
rustc_privacy Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_query_impl Prevent double panic in query system, improve diagnostics 2024-08-19 17:42:42 +02:00
rustc_query_system Prevent double panic in query system, improve diagnostics 2024-08-19 17:42:42 +02:00
rustc_resolve Rollup merge of #128875 - bvanjoi:cleanup-import-used, r=petrochenkov 2024-08-11 07:51:52 +02:00
rustc_sanitizers Shrink TyKind::FnPtr. 2024-08-09 14:33:25 +10:00
rustc_serialize Reformat use declarations. 2024-07-29 08:26:52 +10:00
rustc_session Rollup merge of #128348 - dingxiangfei2009:allow-shadow-call-stack-sanitizer, r=tmandry 2024-08-15 19:32:35 +02:00
rustc_smir rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
rustc_span #[deprecated_safe_2024]: Also use the // TODO: hint in the compiler error 2024-08-13 11:32:47 +02:00
rustc_symbol_mangling Shrink TyKind::FnPtr. 2024-08-09 14:33:25 +10:00
rustc_target Auto merge of #125854 - beetrees:zst-arg-abi, r=estebank 2024-08-18 22:15:41 +00:00
rustc_trait_selection Rollup merge of #129217 - jswrenn:transmute-lifetimes, r=compiler-errors 2024-08-19 20:14:56 +02:00
rustc_traits Remove redundant type ops 2024-08-14 14:18:17 -04:00
rustc_transmute safe transmute: forbid reference lifetime extension 2024-08-18 18:31:06 +00:00
rustc_ty_utils Rollup merge of #127679 - RalfJung:raw_ref_op, r=jieyouxu 2024-08-18 23:41:46 -05:00
rustc_type_ir Rollup merge of #128828 - lcnr:search-graph-11, r=compiler-errors 2024-08-14 21:43:07 +08:00
rustc_type_ir_macros Reformat use declarations. 2024-07-29 08:26:52 +10:00
stable_mir Reformat use declarations. 2024-07-29 08:26:52 +10:00