@@ -252,11 +252,7 @@ pub fn is_lang_ctor(cx: &LateContext<'_>, qpath: &QPath<'_>, lang_item: LangItem
252
252
/// Returns `true` if this `span` was expanded by any macro.
253
253
#[ must_use]
254
254
pub fn in_macro ( span : Span ) -> bool {
255
- if span. from_expansion ( ) {
256
- !matches ! ( span. ctxt( ) . outer_expn_data( ) . kind, ExpnKind :: Desugaring ( ..) )
257
- } else {
258
- false
259
- }
255
+ span. from_expansion ( ) && !matches ! ( span. ctxt( ) . outer_expn_data( ) . kind, ExpnKind :: Desugaring ( ..) )
260
256
}
261
257
262
258
pub fn is_unit_expr ( expr : & Expr < ' _ > ) -> bool {
@@ -1286,10 +1282,9 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
1286
1282
}
1287
1283
let enclosing_body = cx. tcx . hir ( ) . local_def_id ( cx. tcx . hir ( ) . enclosing_body_owner ( e. hir_id ) ) ;
1288
1284
if let Some ( ( Constant :: Int ( v) , _) ) = constant ( cx, cx. tcx . typeck ( enclosing_body) , e) {
1289
- value == v
1290
- } else {
1291
- false
1285
+ return value == v;
1292
1286
}
1287
+ false
1293
1288
}
1294
1289
1295
1290
/// Checks whether the given expression is a constant literal of the given value.
@@ -1316,7 +1311,7 @@ pub fn is_adjusted(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
1316
1311
1317
1312
/// Returns the pre-expansion span if is this comes from an expansion of the
1318
1313
/// macro `name`.
1319
- /// See also `is_direct_expn_of`.
1314
+ /// See also [ `is_direct_expn_of`] .
1320
1315
#[ must_use]
1321
1316
pub fn is_expn_of ( mut span : Span , name : & str ) -> Option < Span > {
1322
1317
loop {
@@ -1339,13 +1334,13 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
1339
1334
1340
1335
/// Returns the pre-expansion span if the span directly comes from an expansion
1341
1336
/// of the macro `name`.
1342
- /// The difference with `is_expn_of` is that in
1343
- /// ```rust,ignore
1337
+ /// The difference with [`is_expn_of`] is that in
1338
+ /// ```rust
1339
+ /// # macro_rules! foo { ($e:tt) => { $e } }; macro_rules! bar { ($e:expr) => { $e } }
1344
1340
/// foo!(bar!(42));
1345
1341
/// ```
1346
1342
/// `42` is considered expanded from `foo!` and `bar!` by `is_expn_of` but only
1347
- /// `bar!` by
1348
- /// `is_direct_expn_of`.
1343
+ /// from `bar!` by `is_direct_expn_of`.
1349
1344
#[ must_use]
1350
1345
pub fn is_direct_expn_of ( span : Span , name : & str ) -> Option < Span > {
1351
1346
if span. from_expansion ( ) {
@@ -1468,11 +1463,9 @@ pub fn is_self(slf: &Param<'_>) -> bool {
1468
1463
}
1469
1464
1470
1465
pub fn is_self_ty ( slf : & hir:: Ty < ' _ > ) -> bool {
1471
- if_chain ! {
1472
- if let TyKind :: Path ( QPath :: Resolved ( None , path) ) = slf. kind;
1473
- if let Res :: SelfTy ( ..) = path. res;
1474
- then {
1475
- return true
1466
+ if let TyKind :: Path ( QPath :: Resolved ( None , path) ) = slf. kind {
1467
+ if let Res :: SelfTy ( ..) = path. res {
1468
+ return true ;
1476
1469
}
1477
1470
}
1478
1471
false
@@ -2064,15 +2057,12 @@ macro_rules! unwrap_cargo_metadata {
2064
2057
}
2065
2058
2066
2059
pub fn is_hir_ty_cfg_dependant ( cx : & LateContext < ' _ > , ty : & hir:: Ty < ' _ > ) -> bool {
2067
- if_chain ! {
2068
- if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = ty. kind;
2069
- if let Res :: Def ( _, def_id) = path. res;
2070
- then {
2071
- cx. tcx. has_attr( def_id, sym:: cfg) || cx. tcx. has_attr( def_id, sym:: cfg_attr)
2072
- } else {
2073
- false
2060
+ if let TyKind :: Path ( QPath :: Resolved ( _, path) ) = ty. kind {
2061
+ if let Res :: Def ( _, def_id) = path. res {
2062
+ return cx. tcx . has_attr ( def_id, sym:: cfg) || cx. tcx . has_attr ( def_id, sym:: cfg_attr) ;
2074
2063
}
2075
2064
}
2065
+ false
2076
2066
}
2077
2067
2078
2068
/// Checks whether item either has `test` attribute applied, or
@@ -2084,7 +2074,7 @@ pub fn is_test_module_or_function(tcx: TyCtxt<'_>, item: &Item<'_>) -> bool {
2084
2074
}
2085
2075
}
2086
2076
2087
- matches ! ( item. kind, ItemKind :: Mod ( ..) ) && item. ident . name . as_str ( ) . contains ( "test" )
2077
+ matches ! ( item. kind, ItemKind :: Mod ( ..) ) && item. ident . name . as_str ( ) . split ( '_' ) . any ( |a| a == "test" || a == "tests ")
2088
2078
}
2089
2079
2090
2080
macro_rules! op_utils {
0 commit comments