rust/tests/mir-opt/building/custom
Matthias Krüger 9545ab8e12
Rollup merge of #109392 - cbeuw:composite-ret, r=JakobDegen
Custom MIR: Allow optional RET type annotation

This currently doesn't compile because the type of `RET` is inferred, which fails if RET is a composite type and fields are initialised separately.
```rust
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "optimized")]
fn fn0() -> (i32, bool) {
    mir! ({
        RET.0 = 0;
        RET.1 = true;
        Return()
    })
}
```
```
error[E0282]: type annotations needed
 --> src/lib.rs:8:9
  |
8 |         RET.0 = 0;
  |         ^^^ cannot infer type

For more information about this error, try `rustc --explain E0282`.
```

This PR allows the user to manually specify the return type with `type RET = ...;` if required:

```rust
#[custom_mir(dialect = "runtime", phase = "optimized")]
fn fn0() -> (i32, bool) {
    mir! (
        type RET = (i32, bool);
        {
            RET.0 = 0;
            RET.1 = true;
            Return()
        }
    )
}
```

The syntax is not optimal, I'm happy to see other suggestions. Ideally I wanted it to be a normal type annotation like `let RET: ...;`, but this runs into the multiple parsing options error during macro expansion, as it can be parsed as a normal `let` declaration as well.

r? ```@oli-obk``` or ```@tmiasko``` or ```@JakobDegen```
2023-03-22 20:08:01 +01:00
..
aggregate_exprs.adt.built.after.mir Support aggregate expressions 2023-03-20 15:25:11 +01:00
aggregate_exprs.array.built.after.mir Support aggregate expressions 2023-03-20 15:25:11 +01:00
aggregate_exprs.rs Support aggregate expressions 2023-03-20 15:25:11 +01:00
aggregate_exprs.tuple.built.after.mir Support aggregate expressions 2023-03-20 15:25:11 +01:00
arbitrary_let.arbitrary_let.built.after.mir
arbitrary_let.rs
arrays.arrays.built.after.mir Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
arrays.rs Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
as_cast.float_to_int.built.after.mir Custom MIR: Support as casts 2023-03-07 11:42:34 +01:00
as_cast.int_to_int.built.after.mir Custom MIR: Support as casts 2023-03-07 11:42:34 +01:00
as_cast.int_to_ptr.built.after.mir Custom MIR: Support as casts 2023-03-07 11:42:34 +01:00
as_cast.rs Custom MIR: Support as casts 2023-03-07 11:42:34 +01:00
composite_return.rs Allow optional RET type annotation 2023-03-20 12:21:19 +01:00
composite_return.tuple.built.after.mir Allow optional RET type annotation 2023-03-20 12:21:19 +01:00
consts.consts.built.after.mir
consts.rs
consts.statics.built.after.mir
enums.rs Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
enums.set_discr_repr.built.after.mir
enums.set_discr.built.after.mir Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
enums.switch_bool.built.after.mir
enums.switch_option_repr.built.after.mir
enums.switch_option.built.after.mir
operators.f.built.after.mir Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
operators.rs Custom mir: Add support for some remaining, easy to support constructs 2023-01-26 03:29:28 -08:00
projections.rs
projections.set.built.after.mir
projections.simple_index.built.after.mir
projections.tuples.built.after.mir
projections.unions.built.after.mir
projections.unwrap_deref.built.after.mir
projections.unwrap.built.after.mir
references.immut_ref.built.after.mir
references.mut_ref.built.after.mir
references.raw_pointer.built.after.mir
references.rs
simple_assign.rs Custom MIR: Support storage statements 2023-01-19 11:53:33 +01:00
simple_assign.simple_ref.built.after.mir
simple_assign.simple.built.after.mir Custom MIR: Support storage statements 2023-01-19 11:53:33 +01:00
terminators.assert_nonzero.built.after.mir
terminators.direct_call.built.after.mir
terminators.drop_first.built.after.mir Remove DropAndReplace terminator 2023-03-07 14:25:22 +01:00
terminators.drop_second.built.after.mir
terminators.indirect_call.built.after.mir
terminators.rs Remove DropAndReplace terminator 2023-03-07 14:25:22 +01:00