@@ -61,7 +61,10 @@ impl ReturnPass {
61
61
match expr. node {
62
62
// simple return is always "bad"
63
63
ast:: ExprKind :: Ret ( Some ( ref inner) ) => {
64
- self . emit_return_lint ( cx, span. expect ( "`else return` is not possible" ) , inner. span ) ;
64
+ // allow `#[cfg(a)] return a; #[cfg(b)] return b;`
65
+ if !expr. attrs . iter ( ) . any ( attr_is_cfg) {
66
+ self . emit_return_lint ( cx, span. expect ( "`else return` is not possible" ) , inner. span ) ;
67
+ }
65
68
}
66
69
// a whole block? check it!
67
70
ast:: ExprKind :: Block ( ref block) => {
@@ -105,6 +108,7 @@ impl ReturnPass {
105
108
let ast:: StmtKind :: Expr ( ref retexpr) = retexpr. node,
106
109
let Some ( stmt) = it. next_back( ) ,
107
110
let ast:: StmtKind :: Local ( ref local) = stmt. node,
111
+ !local. attrs. iter( ) . any( attr_is_cfg) ,
108
112
let Some ( ref initexpr) = local. init,
109
113
let ast:: PatKind :: Ident ( _, Spanned { node: id, .. } , _) = local. pat. node,
110
114
let ast:: ExprKind :: Path ( _, ref path) = retexpr. node,
@@ -140,3 +144,12 @@ impl EarlyLintPass for ReturnPass {
140
144
self . check_let_return ( cx, block) ;
141
145
}
142
146
}
147
+
148
+ fn attr_is_cfg ( attr : & ast:: Attribute ) -> bool {
149
+ if let ast:: MetaItemKind :: List ( ref key, _) = attr. node . value . node {
150
+ * key == "cfg"
151
+ } else {
152
+ false
153
+ }
154
+ }
155
+
0 commit comments