Skip to content

Custom MIR: Parse ExprKind::Use correctly #109160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> {
let cast_kind = mir_cast_kind(source_ty, expr.ty);
Ok(Rvalue::Cast(cast_kind, source, expr.ty))
},
ExprKind::Use { source } => Ok(
Rvalue::Use(self.parse_operand(*source)?)
),
_ => self.parse_operand(expr_id).map(Rvalue::Use),
)
}
Expand Down
10 changes: 10 additions & 0 deletions tests/mir-opt/building/custom/as_cast.identity.built.after.mir
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// MIR for `identity` after built

fn identity(_1: i32) -> i32 {
let mut _0: i32; // return place in scope 0 at $DIR/as_cast.rs:+0:24: +0:27

bb0: {
_0 = _1; // scope 0 at $DIR/as_cast.rs:+3:13: +3:27
return; // scope 0 at $DIR/as_cast.rs:+4:13: +4:21
}
}
12 changes: 12 additions & 0 deletions tests/mir-opt/building/custom/as_cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,20 @@ fn int_to_ptr(x: usize) -> *const i32 {
)
}

// EMIT_MIR as_cast.identity.built.after.mir
#[custom_mir(dialect = "built")]
fn identity(x: i32) -> i32 {
mir!(
{
RET = x as i32;
Return()
}
)
}

fn main() {
assert_eq!(int_to_int(5), 5);
assert_eq!(float_to_int(5.), 5);
assert_eq!(int_to_ptr(0), std::ptr::null());
assert_eq!(identity(5), 5);
}