diff options
| author | Yuki Okushi <jtitor@2k36.org> | 2023-03-07 23:06:25 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-07 23:06:25 +0900 |
| commit | fddd861a7d00a183548633bfd65d885205ca5cad (patch) | |
| tree | d8a8dad13c38fb692eaebd32f4c6160c702afe04 /compiler | |
| parent | b866e1ee0ac86ca24c41231d53792aa79e9775d1 (diff) | |
| parent | 7281cd0c215ef8005adfb83e13ff075df32a0ebd (diff) | |
| download | rust-fddd861a7d00a183548633bfd65d885205ca5cad.tar.gz rust-fddd861a7d00a183548633bfd65d885205ca5cad.zip | |
Rollup merge of #108855 - cbeuw:mir-cast, r=tmiasko
Custom MIR: Support `as` casts Small changes to support this low hanging fruit r? `@oli-obk` or `@tmiasko` or `@JakobDegen`
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_mir_build/src/build/custom/parse/instruction.rs | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs index dbba529aef7..09d2eb96d0f 100644 --- a/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs +++ b/compiler/rustc_mir_build/src/build/custom/parse/instruction.rs @@ -1,5 +1,6 @@ use rustc_middle::mir::interpret::{ConstValue, Scalar}; use rustc_middle::mir::tcx::PlaceTy; +use rustc_middle::ty::cast::mir_cast_kind; use rustc_middle::{mir::*, thir::*, ty}; use rustc_span::Span; use rustc_target::abi::VariantIdx; @@ -142,7 +143,7 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { } fn parse_rvalue(&self, expr_id: ExprId) -> PResult<Rvalue<'tcx>> { - parse_by_kind!(self, expr_id, _, "rvalue", + parse_by_kind!(self, expr_id, expr, "rvalue", @call("mir_discriminant", args) => self.parse_place(args[0]).map(Rvalue::Discriminant), @call("mir_checked", args) => { parse_by_kind!(self, args[0], _, "binary op", @@ -167,6 +168,12 @@ impl<'tcx, 'body> ParseCtxt<'tcx, 'body> { ExprKind::Repeat { value, count } => Ok( Rvalue::Repeat(self.parse_operand(*value)?, *count) ), + ExprKind::Cast { source } => { + let source = self.parse_operand(*source)?; + let source_ty = source.ty(self.body.local_decls(), self.tcx); + let cast_kind = mir_cast_kind(source_ty, expr.ty); + Ok(Rvalue::Cast(cast_kind, source, expr.ty)) + }, _ => self.parse_operand(expr_id).map(Rvalue::Use), ) } |
