@@ -251,11 +251,7 @@ pub fn is_lang_ctor(cx: &LateContext<'_>, qpath: &QPath<'_>, lang_item: LangItem
251251/// Returns `true` if this `span` was expanded by any macro.
252252#[ must_use]
253253pub 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 ( ..) )
259255}
260256
261257pub fn is_unit_expr ( expr : & Expr < ' _ > ) -> bool {
@@ -1285,10 +1281,9 @@ pub fn is_integer_const(cx: &LateContext<'_>, e: &Expr<'_>, value: u128) -> bool
12851281 }
12861282 let enclosing_body = cx. tcx . hir ( ) . local_def_id ( cx. tcx . hir ( ) . enclosing_body_owner ( e. hir_id ) ) ;
12871283 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;
12911285 }
1286+ false
12921287}
12931288
12941289/// 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 {
13151310
13161311/// Returns the pre-expansion span if is this comes from an expansion of the
13171312/// macro `name`.
1318- /// See also `is_direct_expn_of`.
1313+ /// See also [ `is_direct_expn_of`] .
13191314#[ must_use]
13201315pub fn is_expn_of ( mut span : Span , name : & str ) -> Option < Span > {
13211316 loop {
@@ -1338,13 +1333,13 @@ pub fn is_expn_of(mut span: Span, name: &str) -> Option<Span> {
13381333
13391334/// Returns the pre-expansion span if the span directly comes from an expansion
13401335/// 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 } }
13431339/// foo!(bar!(42));
13441340/// ```
13451341/// `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`.
13481343#[ must_use]
13491344pub fn is_direct_expn_of ( span : Span , name : & str ) -> Option < Span > {
13501345 if span. from_expansion ( ) {
@@ -1467,11 +1462,9 @@ pub fn is_self(slf: &Param<'_>) -> bool {
14671462}
14681463
14691464pub 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 ;
14751468 }
14761469 }
14771470 false
@@ -2063,15 +2056,12 @@ macro_rules! unwrap_cargo_metadata {
20632056}
20642057
20652058pub 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) ;
20732062 }
20742063 }
2064+ false
20752065}
20762066
20772067/// 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 {
20832073 }
20842074 }
20852075
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 ")
20872077}
20882078
20892079macro_rules! op_utils {
0 commit comments