@@ -17,7 +17,7 @@ use rustc_hir::{
17
17
use rustc_lint:: { EarlyContext , EarlyLintPass , LateContext , LateLintPass , Level , LintContext } ;
18
18
use rustc_middle:: lint:: in_external_macro;
19
19
use rustc_middle:: ty;
20
- use rustc_session:: { declare_lint_pass, declare_tool_lint , impl_lint_pass} ;
20
+ use rustc_session:: { declare_lint_pass, impl_lint_pass} ;
21
21
use rustc_span:: symbol:: Symbol ;
22
22
use rustc_span:: { sym, Span , DUMMY_SP } ;
23
23
use semver:: Version ;
@@ -120,7 +120,8 @@ declare_clippy_lint! {
120
120
declare_clippy_lint ! {
121
121
/// ### What it does
122
122
/// Checks for `#[deprecated]` annotations with a `since`
123
- /// field that is not a valid semantic version.
123
+ /// field that is not a valid semantic version. Also allows "TBD" to signal
124
+ /// future deprecation.
124
125
///
125
126
/// ### Why is this bad?
126
127
/// For checking the version of the deprecation, it must be
@@ -405,20 +406,26 @@ declare_clippy_lint! {
405
406
/// Checks for `#[cfg(features = "...")]` and suggests to replace it with
406
407
/// `#[cfg(feature = "...")]`.
407
408
///
409
+ /// It also checks if `cfg(test)` was misspelled.
410
+ ///
408
411
/// ### Why is this bad?
409
- /// Misspelling `feature` as `features` can be sometimes hard to spot. It
412
+ /// Misspelling `feature` as `features` or `test` as `tests` can be sometimes hard to spot. It
410
413
/// may cause conditional compilation not work quietly.
411
414
///
412
415
/// ### Example
413
416
/// ```no_run
414
417
/// #[cfg(features = "some-feature")]
415
418
/// fn conditional() { }
419
+ /// #[cfg(tests)]
420
+ /// mod tests { }
416
421
/// ```
417
422
///
418
423
/// Use instead:
419
424
/// ```no_run
420
425
/// #[cfg(feature = "some-feature")]
421
426
/// fn conditional() { }
427
+ /// #[cfg(test)]
428
+ /// mod tests { }
422
429
/// ```
423
430
#[ clippy:: version = "1.69.0" ]
424
431
pub MAYBE_MISUSED_CFG ,
@@ -473,7 +480,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
473
480
&& let MetaItemKind :: NameValue ( lit) = & mi. kind
474
481
&& mi. has_name ( sym:: since)
475
482
{
476
- check_semver ( cx, item. span ( ) , lit) ;
483
+ check_deprecated_since ( cx, item. span ( ) , lit) ;
477
484
}
478
485
}
479
486
}
@@ -754,9 +761,9 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut
754
761
}
755
762
}
756
763
757
- fn check_semver ( cx : & LateContext < ' _ > , span : Span , lit : & MetaItemLit ) {
764
+ fn check_deprecated_since ( cx : & LateContext < ' _ > , span : Span , lit : & MetaItemLit ) {
758
765
if let LitKind :: Str ( is, _) = lit. kind {
759
- if Version :: parse ( is. as_str ( ) ) . is_ok ( ) {
766
+ if is . as_str ( ) == "TBD" || Version :: parse ( is. as_str ( ) ) . is_ok ( ) {
760
767
return ;
761
768
}
762
769
}
@@ -923,21 +930,35 @@ fn check_nested_cfg(cx: &EarlyContext<'_>, items: &[NestedMetaItem]) {
923
930
fn check_nested_misused_cfg ( cx : & EarlyContext < ' _ > , items : & [ NestedMetaItem ] ) {
924
931
for item in items {
925
932
if let NestedMetaItem :: MetaItem ( meta) = item {
926
- if meta. has_name ( sym ! ( features) )
933
+ if let Some ( ident) = meta. ident ( )
934
+ && ident. name . as_str ( ) == "features"
927
935
&& let Some ( val) = meta. value_str ( )
928
936
{
929
937
span_lint_and_sugg (
930
938
cx,
931
939
MAYBE_MISUSED_CFG ,
932
940
meta. span ,
933
- "feature may misspelled as features" ,
934
- "use " ,
941
+ "' feature' may be misspelled as ' features' " ,
942
+ "did you mean " ,
935
943
format ! ( "feature = \" {val}\" " ) ,
936
944
Applicability :: MaybeIncorrect ,
937
945
) ;
938
946
}
939
947
if let MetaItemKind :: List ( list) = & meta. kind {
940
948
check_nested_misused_cfg ( cx, list) ;
949
+ // If this is not a list, then we check for `cfg(test)`.
950
+ } else if let Some ( ident) = meta. ident ( )
951
+ && matches ! ( ident. name. as_str( ) , "tests" | "Test" )
952
+ {
953
+ span_lint_and_sugg (
954
+ cx,
955
+ MAYBE_MISUSED_CFG ,
956
+ meta. span ,
957
+ & format ! ( "'test' may be misspelled as '{}'" , ident. name. as_str( ) ) ,
958
+ "did you mean" ,
959
+ "test" . to_string ( ) ,
960
+ Applicability :: MaybeIncorrect ,
961
+ ) ;
941
962
}
942
963
}
943
964
}
0 commit comments