Convert &Option<T> to Option<&T>
This commit is contained in:
parent
7b566c214e
commit
f7d5d9d892
7 changed files with 122 additions and 83 deletions
|
|
@ -10,27 +10,27 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: b
|
|||
// only run the lint if publish is `None` (`publish = true` or skipped entirely)
|
||||
// or if the vector isn't empty (`publish = ["something"]`)
|
||||
if package.publish.as_ref().filter(|publish| publish.is_empty()).is_none() || ignore_publish {
|
||||
if is_empty_str(&package.description) {
|
||||
if is_empty_str(package.description.as_ref()) {
|
||||
missing_warning(cx, package, "package.description");
|
||||
}
|
||||
|
||||
if is_empty_str(&package.license) && is_empty_str(&package.license_file) {
|
||||
if is_empty_str(package.license.as_ref()) && is_empty_str(package.license_file.as_ref()) {
|
||||
missing_warning(cx, package, "either package.license or package.license_file");
|
||||
}
|
||||
|
||||
if is_empty_str(&package.repository) {
|
||||
if is_empty_str(package.repository.as_ref()) {
|
||||
missing_warning(cx, package, "package.repository");
|
||||
}
|
||||
|
||||
if is_empty_str(&package.readme) {
|
||||
if is_empty_str(package.readme.as_ref()) {
|
||||
missing_warning(cx, package, "package.readme");
|
||||
}
|
||||
|
||||
if is_empty_vec(&package.keywords) {
|
||||
if is_empty_vec(package.keywords.as_ref()) {
|
||||
missing_warning(cx, package, "package.keywords");
|
||||
}
|
||||
|
||||
if is_empty_vec(&package.categories) {
|
||||
if is_empty_vec(package.categories.as_ref()) {
|
||||
missing_warning(cx, package, "package.categories");
|
||||
}
|
||||
}
|
||||
|
|
@ -42,8 +42,8 @@ fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, fiel
|
|||
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
|
||||
}
|
||||
|
||||
fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: &Option<T>) -> bool {
|
||||
value.as_ref().map_or(true, |s| s.as_ref().is_empty())
|
||||
fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: Option<&T>) -> bool {
|
||||
value.map_or(true, |s| s.as_ref().is_empty())
|
||||
}
|
||||
|
||||
fn is_empty_vec(value: &[String]) -> bool {
|
||||
|
|
|
|||
|
|
@ -443,7 +443,7 @@ declare_clippy_lint! {
|
|||
/// ```
|
||||
#[clippy::version = "1.82.0"]
|
||||
pub REF_OPTION,
|
||||
nursery,
|
||||
pedantic,
|
||||
"function signature uses `&Option<T>` instead of `Option<&T>`"
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -275,12 +275,15 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
|
|||
|k, ps1, idx| matches!(
|
||||
k,
|
||||
TupleStruct(qself2, path2, ps2)
|
||||
if eq_maybe_qself(qself1, qself2) && eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx)
|
||||
if eq_maybe_qself(qself1.as_ref(), qself2.as_ref())
|
||||
&& eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx)
|
||||
),
|
||||
|k| always_pat!(k, TupleStruct(_, _, ps) => ps),
|
||||
),
|
||||
// Transform a record pattern `S { fp_0, ..., fp_n }`.
|
||||
Struct(qself1, path1, fps1, rest1) => extend_with_struct_pat(qself1, path1, fps1, *rest1, start, alternatives),
|
||||
Struct(qself1, path1, fps1, rest1) => {
|
||||
extend_with_struct_pat(qself1.as_ref(), path1, fps1, *rest1, start, alternatives)
|
||||
},
|
||||
};
|
||||
|
||||
alternatives[focus_idx].kind = focus_kind;
|
||||
|
|
@ -292,7 +295,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
|
|||
/// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern
|
||||
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
|
||||
fn extend_with_struct_pat(
|
||||
qself1: &Option<P<ast::QSelf>>,
|
||||
qself1: Option<&P<ast::QSelf>>,
|
||||
path1: &ast::Path,
|
||||
fps1: &mut [ast::PatField],
|
||||
rest1: ast::PatFieldsRest,
|
||||
|
|
@ -307,7 +310,7 @@ fn extend_with_struct_pat(
|
|||
|k| {
|
||||
matches!(k, Struct(qself2, path2, fps2, rest2)
|
||||
if rest1 == *rest2 // If one struct pattern has `..` so must the other.
|
||||
&& eq_maybe_qself(qself1, qself2)
|
||||
&& eq_maybe_qself(qself1, qself2.as_ref())
|
||||
&& eq_path(path1, path2)
|
||||
&& fps1.len() == fps2.len()
|
||||
&& fps1.iter().enumerate().all(|(idx_1, fp1)| {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue