1
1
//! lint on missing cargo common metadata
2
2
3
- use std:: path:: PathBuf ;
4
-
5
3
use clippy_utils:: { diagnostics:: span_lint, is_lint_allowed} ;
6
4
use rustc_hir:: { hir_id:: CRATE_HIR_ID , Crate } ;
7
5
use rustc_lint:: { LateContext , LateLintPass } ;
@@ -69,12 +67,8 @@ fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, fiel
69
67
span_lint ( cx, CARGO_COMMON_METADATA , DUMMY_SP , & message) ;
70
68
}
71
69
72
- fn is_empty_str ( value : & Option < String > ) -> bool {
73
- value. as_ref ( ) . map_or ( true , String :: is_empty)
74
- }
75
-
76
- fn is_empty_path ( value : & Option < PathBuf > ) -> bool {
77
- value. as_ref ( ) . and_then ( |x| x. to_str ( ) ) . map_or ( true , str:: is_empty)
70
+ fn is_empty_str < T : AsRef < std:: ffi:: OsStr > > ( value : & Option < T > ) -> bool {
71
+ value. as_ref ( ) . map_or ( true , |s| s. as_ref ( ) . is_empty ( ) )
78
72
}
79
73
80
74
fn is_empty_vec ( value : & [ String ] ) -> bool {
@@ -98,15 +92,15 @@ impl LateLintPass<'_> for CargoCommonMetadata {
98
92
missing_warning ( cx, & package, "package.description" ) ;
99
93
}
100
94
101
- if is_empty_str ( & package. license ) && is_empty_path ( & package. license_file ) {
95
+ if is_empty_str ( & package. license ) && is_empty_str ( & package. license_file ) {
102
96
missing_warning ( cx, & package, "either package.license or package.license_file" ) ;
103
97
}
104
98
105
99
if is_empty_str ( & package. repository ) {
106
100
missing_warning ( cx, & package, "package.repository" ) ;
107
101
}
108
102
109
- if is_empty_path ( & package. readme ) {
103
+ if is_empty_str ( & package. readme ) {
110
104
missing_warning ( cx, & package, "package.readme" ) ;
111
105
}
112
106
0 commit comments