Skip to content

Commit 9da1da9

Browse files
committed
Allow optional RET type annotation
1 parent ab9bb3e commit 9da1da9

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

library/core/src/intrinsics/mir.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ define!(
342342
#[rustc_macro_transparency = "transparent"]
343343
pub macro mir {
344344
(
345+
$(type RET = $ret_ty:ty ;)?
345346
$(let $local_decl:ident $(: $local_decl_ty:ty)? ;)*
346347

347348
{
@@ -362,7 +363,7 @@ pub macro mir {
362363
{
363364
// Now all locals
364365
#[allow(non_snake_case)]
365-
let RET;
366+
let RET $(: $ret_ty)?;
366367
$(
367368
let $local_decl $(: $local_decl_ty)? ;
368369
)*
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![feature(custom_mir, core_intrinsics)]
2+
3+
extern crate core;
4+
use core::intrinsics::mir::*;
5+
6+
// EMIT_MIR composite_return.tuple.built.after.mir
7+
#[custom_mir(dialect = "runtime", phase = "optimized")]
8+
fn tuple() -> (i32, bool) {
9+
mir!(
10+
type RET = (i32, bool);
11+
{
12+
RET.0 = 1;
13+
RET.1 = true;
14+
Return()
15+
}
16+
)
17+
}
18+
19+
fn main() {
20+
assert_eq!(tuple(), (1, true));
21+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// MIR for `tuple` after built
2+
3+
fn tuple() -> (i32, bool) {
4+
let mut _0: (i32, bool); // return place in scope 0 at $DIR/composite_return.rs:+0:15: +0:26
5+
6+
bb0: {
7+
(_0.0: i32) = const 1_i32; // scope 0 at $DIR/composite_return.rs:+4:13: +4:22
8+
(_0.1: bool) = const true; // scope 0 at $DIR/composite_return.rs:+5:13: +5:25
9+
return; // scope 0 at $DIR/composite_return.rs:+6:13: +6:21
10+
}
11+
}

0 commit comments

Comments
 (0)