@@ -30,6 +30,7 @@ enum Target {
3030 ForeignMod ,
3131 Expression ,
3232 Statement ,
33+ Closure ,
3334 Other ,
3435}
3536
@@ -103,14 +104,14 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
103104 self . check_repr ( item, target) ;
104105 }
105106
106- /// Check if an `#[inline]` is applied to a function.
107+ /// Check if an `#[inline]` is applied to a function or a closure .
107108 fn check_inline ( & self , attr : & hir:: Attribute , span : & Span , target : Target ) {
108- if target != Target :: Fn {
109+ if target != Target :: Fn && target != Target :: Closure {
109110 struct_span_err ! ( self . tcx. sess,
110111 attr. span,
111112 E0518 ,
112- "attribute should be applied to function" )
113- . span_label ( * span, "not a function" )
113+ "attribute should be applied to function or closure " )
114+ . span_label ( * span, "not a function or closure " )
114115 . emit ( ) ;
115116 }
116117 }
@@ -286,9 +287,13 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> {
286287 }
287288
288289 fn check_expr_attributes ( & self , expr : & hir:: Expr ) {
290+ let target = match expr. node {
291+ hir:: ExprClosure ( ..) => Target :: Closure ,
292+ _ => Target :: Expression ,
293+ } ;
289294 for attr in expr. attrs . iter ( ) {
290295 if attr. check_name ( "inline" ) {
291- self . check_inline ( attr, & expr. span , Target :: Expression ) ;
296+ self . check_inline ( attr, & expr. span , target ) ;
292297 }
293298 if attr. check_name ( "repr" ) {
294299 self . emit_repr_error (
0 commit comments