@@ -11,24 +11,24 @@ use rustc_target::asm::{InlineAsmReg, InlineAsmRegClass, InlineAsmRegOrRegClass,
1111pub struct InlineAsmCtxt < ' a , ' tcx > {
1212 tcx : TyCtxt < ' tcx > ,
1313 param_env : ty:: ParamEnv < ' tcx > ,
14- get_operand_ty : Box < dyn Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a > ,
14+ get_expr_ty : Box < dyn Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a > ,
1515}
1616
1717impl < ' a , ' tcx > InlineAsmCtxt < ' a , ' tcx > {
1818 pub fn new_global_asm ( tcx : TyCtxt < ' tcx > ) -> Self {
1919 InlineAsmCtxt {
2020 tcx,
2121 param_env : ty:: ParamEnv :: empty ( ) ,
22- get_operand_ty : Box :: new ( |e| bug ! ( "asm operand in global asm: {e:?}" ) ) ,
22+ get_expr_ty : Box :: new ( |e| bug ! ( "asm operand in global asm: {e:?}" ) ) ,
2323 }
2424 }
2525
2626 pub fn new_in_fn (
2727 tcx : TyCtxt < ' tcx > ,
2828 param_env : ty:: ParamEnv < ' tcx > ,
29- get_operand_ty : impl Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a ,
29+ get_expr_ty : impl Fn ( & ' tcx hir:: Expr < ' tcx > ) -> Ty < ' tcx > + ' a ,
3030 ) -> Self {
31- InlineAsmCtxt { tcx, param_env, get_operand_ty : Box :: new ( get_operand_ty ) }
31+ InlineAsmCtxt { tcx, param_env, get_expr_ty : Box :: new ( get_expr_ty ) }
3232 }
3333
3434 // FIXME(compiler-errors): This could use `<$ty as Pointee>::Metadata == ()`
@@ -124,7 +124,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
124124 tied_input : Option < ( & ' tcx hir:: Expr < ' tcx > , Option < InlineAsmType > ) > ,
125125 target_features : & FxIndexSet < Symbol > ,
126126 ) -> Option < InlineAsmType > {
127- let ty = ( self . get_operand_ty ) ( expr) ;
127+ let ty = ( self . get_expr_ty ) ( expr) ;
128128 if ty. has_non_region_infer ( ) {
129129 bug ! ( "inference variable in asm operand ty: {:?} {:?}" , expr, ty) ;
130130 }
@@ -178,7 +178,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
178178 let msg = "incompatible types for asm inout argument" ;
179179 let mut err = self . tcx . sess . struct_span_err ( vec ! [ in_expr. span, expr. span] , msg) ;
180180
181- let in_expr_ty = ( self . get_operand_ty ) ( in_expr) ;
181+ let in_expr_ty = ( self . get_expr_ty ) ( in_expr) ;
182182 err. span_label ( in_expr. span , format ! ( "type `{in_expr_ty}`" ) ) ;
183183 err. span_label ( expr. span , format ! ( "type `{ty}`" ) ) ;
184184 err. note (
@@ -437,7 +437,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
437437 hir:: InlineAsmOperand :: Const { .. } | hir:: InlineAsmOperand :: SymStatic { .. } => { }
438438 // Check that sym actually points to a function. Later passes
439439 // depend on this.
440- hir:: InlineAsmOperand :: SymFn { anon_const } => {
440+ hir:: InlineAsmOperand :: SymFnInGlobal { anon_const } => {
441441 let ty = self . tcx . type_of ( anon_const. def_id ) . instantiate_identity ( ) ;
442442 match ty. kind ( ) {
443443 ty:: Never | ty:: Error ( _) => { }
@@ -454,6 +454,23 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
454454 }
455455 } ;
456456 }
457+ hir:: InlineAsmOperand :: SymFnInInline { expr } => {
458+ let ty = ( self . get_expr_ty ) ( expr) ;
459+ match ty. kind ( ) {
460+ ty:: Never | ty:: Error ( _) => { }
461+ ty:: FnDef ( ..) => { }
462+ _ => {
463+ let mut err =
464+ self . tcx . sess . struct_span_err ( * op_sp, "invalid `sym` operand" ) ;
465+ err. span_label (
466+ expr. span ,
467+ format ! ( "is {} `{}`" , ty. kind( ) . article( ) , ty) ,
468+ ) ;
469+ err. help ( "`sym` operands must refer to either a function or a static" ) ;
470+ err. emit ( ) ;
471+ }
472+ } ;
473+ }
457474 }
458475 }
459476 }
0 commit comments