11//! lint on missing cargo common metadata
22
3- use std:: path:: PathBuf ;
4-
53use clippy_utils:: { diagnostics:: span_lint, is_lint_allowed} ;
64use rustc_hir:: { hir_id:: CRATE_HIR_ID , Crate } ;
75use rustc_lint:: { LateContext , LateLintPass } ;
@@ -69,12 +67,8 @@ fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, fiel
6967 span_lint ( cx, CARGO_COMMON_METADATA , DUMMY_SP , & message) ;
7068}
7169
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 ( ) )
7872}
7973
8074fn is_empty_vec ( value : & [ String ] ) -> bool {
@@ -98,15 +92,15 @@ impl LateLintPass<'_> for CargoCommonMetadata {
9892 missing_warning ( cx, & package, "package.description" ) ;
9993 }
10094
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 ) {
10296 missing_warning ( cx, & package, "either package.license or package.license_file" ) ;
10397 }
10498
10599 if is_empty_str ( & package. repository ) {
106100 missing_warning ( cx, & package, "package.repository" ) ;
107101 }
108102
109- if is_empty_path ( & package. readme ) {
103+ if is_empty_str ( & package. readme ) {
110104 missing_warning ( cx, & package, "package.readme" ) ;
111105 }
112106
0 commit comments