9545ab8e12
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``` |
||
---|---|---|
.. | ||
aggregate_exprs.adt.built.after.mir | ||
aggregate_exprs.array.built.after.mir | ||
aggregate_exprs.rs | ||
aggregate_exprs.tuple.built.after.mir | ||
arbitrary_let.arbitrary_let.built.after.mir | ||
arbitrary_let.rs | ||
arrays.arrays.built.after.mir | ||
arrays.rs | ||
as_cast.float_to_int.built.after.mir | ||
as_cast.int_to_int.built.after.mir | ||
as_cast.int_to_ptr.built.after.mir | ||
as_cast.rs | ||
composite_return.rs | ||
composite_return.tuple.built.after.mir | ||
consts.consts.built.after.mir | ||
consts.rs | ||
consts.statics.built.after.mir | ||
enums.rs | ||
enums.set_discr_repr.built.after.mir | ||
enums.set_discr.built.after.mir | ||
enums.switch_bool.built.after.mir | ||
enums.switch_option_repr.built.after.mir | ||
enums.switch_option.built.after.mir | ||
operators.f.built.after.mir | ||
operators.rs | ||
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 | ||
simple_assign.simple_ref.built.after.mir | ||
simple_assign.simple.built.after.mir | ||
terminators.assert_nonzero.built.after.mir | ||
terminators.direct_call.built.after.mir | ||
terminators.drop_first.built.after.mir | ||
terminators.drop_second.built.after.mir | ||
terminators.indirect_call.built.after.mir | ||
terminators.rs |