Skip to content

Commit 157edad

Browse files
committed
Auto merge of #4518 - imp:4517_license-file, r=phansch
clippy::cargo_common_metadata: check for license-file When license property is missing in Cargo.toml check for license-file as it may be used instead of the former. The check implemented here is very naive as it only verifies that the field is present and is not empty. More scrutiny can be applied by verifying the file is actually present. Fixes #4517 changelog: clippy::cargo_common_metadata now checks for license-file when license is missing
2 parents dbb1bde + 4c881d1 commit 157edad

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

clippy_lints/src/cargo_common_metadata.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! lint on missing cargo common metadata
22
3+
use std::path::PathBuf;
4+
35
use crate::utils::span_lint;
46
use rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
57
use rustc::{declare_lint_pass, declare_tool_lint};
@@ -47,6 +49,10 @@ fn is_empty_str(value: &Option<String>) -> bool {
4749
value.as_ref().map_or(true, String::is_empty)
4850
}
4951

52+
fn is_empty_path(value: &Option<PathBuf>) -> bool {
53+
value.as_ref().and_then(|x| x.to_str()).map_or(true, str::is_empty)
54+
}
55+
5056
fn is_empty_vec(value: &[String]) -> bool {
5157
// This works because empty iterators return true
5258
value.iter().all(std::string::String::is_empty)
@@ -72,8 +78,8 @@ impl EarlyLintPass for CargoCommonMetadata {
7278
missing_warning(cx, &package, "package.description");
7379
}
7480

75-
if is_empty_str(&package.license) {
76-
missing_warning(cx, &package, "package.license");
81+
if is_empty_str(&package.license) && is_empty_path(&package.license_file) {
82+
missing_warning(cx, &package, "either package.license or package.license_file");
7783
}
7884

7985
if is_empty_str(&package.repository) {

0 commit comments

Comments
 (0)