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