diff options
| author | Amanieu d'Antras <amanieu@gmail.com> | 2018-04-27 07:20:46 +0200 |
|---|---|---|
| committer | Amanieu d'Antras <amanieu@gmail.com> | 2018-04-27 12:34:01 +0200 |
| commit | 5f2c111165371b1e59fec9cd90e364ccf08b68ef (patch) | |
| tree | cb2778e11461f77953bac15924e43630af62682b /src/librustc | |
| parent | 9822b5709ca78d6398e9ae609de0181116e8b0db (diff) | |
Allow #[inline] on closures
Fixes #49632
Diffstat (limited to 'src/librustc')
| -rw-r--r-- | src/librustc/hir/check_attr.rs | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/librustc/hir/check_attr.rs b/src/librustc/hir/check_attr.rs index 956cd17f38f..19f8d15662d 100644 --- a/src/librustc/hir/check_attr.rs +++ b/src/librustc/hir/check_attr.rs @@ -30,6 +30,7 @@ enum Target { ForeignMod, Expression, Statement, + Closure, Other, } @@ -103,14 +104,14 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { self.check_repr(item, target); } - /// Check if an `#[inline]` is applied to a function. + /// Check if an `#[inline]` is applied to a function or a closure. fn check_inline(&self, attr: &hir::Attribute, span: &Span, target: Target) { - if target != Target::Fn { + if target != Target::Fn && target != Target::Closure { struct_span_err!(self.tcx.sess, attr.span, E0518, - "attribute should be applied to function") - .span_label(*span, "not a function") + "attribute should be applied to function or closure") + .span_label(*span, "not a function or closure") .emit(); } } @@ -286,9 +287,13 @@ impl<'a, 'tcx> CheckAttrVisitor<'a, 'tcx> { } fn check_expr_attributes(&self, expr: &hir::Expr) { + let target = match expr.node { + hir::ExprClosure(..) => Target::Closure, + _ => Target::Expression, + }; for attr in expr.attrs.iter() { if attr.check_name("inline") { - self.check_inline(attr, &expr.span, Target::Expression); + self.check_inline(attr, &expr.span, target); } if attr.check_name("repr") { self.emit_repr_error( |
