Last active
February 20, 2020 18:45
-
-
Save Amanieu/fb36f459ec3bbab0f18e67c5c02425c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn check_expr_asm_operand(&self, expr: &'tcx hir::Expr<'tcx>, is_input: bool) { | |
// TODO: add proper checks instead of reusing those of assign and call | |
let ty = | |
self.check_expr_with_needs(expr, if is_input { Needs::None } else { Needs::MutPlace }); | |
self.require_type_is_sized(ty, expr.span, traits::SizedArgumentType); | |
if !is_input { | |
self.check_lhs_assignable(expr, "E0070", &expr.span); | |
} | |
if is_input { | |
let ty = self.resolve_vars_if_possible(&ty); | |
match ty.kind { | |
ty::FnDef(..) => { | |
let fnptr_ty = self.tcx.mk_fn_ptr(ty.fn_sig(self.tcx)); | |
let _ = self.try_coerce(expr, ty, fnptr_ty, AllowTwoPhase::No); | |
// Coercion failures will be caught by the later type validation pass | |
} | |
_ => {} | |
} | |
} | |
} | |
fn check_expr_asm(&self, asm: &'tcx hir::InlineAsm<'tcx>) -> Ty<'tcx> { | |
for (op, _) in asm.operands { | |
match op { | |
hir::InlineAsmOperand::In { expr, .. } | hir::InlineAsmOperand::Const { expr } => { | |
self.check_expr_asm_operand(expr, true); | |
} | |
hir::InlineAsmOperand::Out { expr, .. } => { | |
if let Some(expr) = expr { | |
self.check_expr_asm_operand(expr, false); | |
} | |
} | |
hir::InlineAsmOperand::InOut { expr, .. } => { | |
self.check_expr_asm_operand(expr, false); | |
} | |
hir::InlineAsmOperand::SplitInOut { in_expr, out_expr, .. } => { | |
self.check_expr_asm_operand(in_expr, true); | |
if let Some(out_expr) = out_expr { | |
self.check_expr_asm_operand(out_expr, false); | |
} | |
} | |
hir::InlineAsmOperand::Sym { .. } => unimplemented!(), | |
} | |
} | |
if asm.options.contains(InlineAsmOptions::NORETURN) { | |
self.tcx.types.never | |
} else { | |
self.tcx.mk_unit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment