Skip to content

Commit 061004a

Browse files
committed
Auto merge of rust-lang#13469 - nyurik:apply-ref-option, r=llogiq
Convert `&Option<T>` to `Option<&T>` Run `ref_option` (rust-lang#13336) on the Clippy's own code, quiet a few hits. Per mentioned video, this may actually improve performance as well. Switch lint to `pedantic` ---- changelog: [`ref_option`]: upgrade lint to `pedantic`
2 parents 7b566c2 + f7d5d9d commit 061004a

File tree

7 files changed

+122
-83
lines changed

7 files changed

+122
-83
lines changed

clippy_lints/src/cargo/common_metadata.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,27 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata, ignore_publish: b
1010
// only run the lint if publish is `None` (`publish = true` or skipped entirely)
1111
// or if the vector isn't empty (`publish = ["something"]`)
1212
if package.publish.as_ref().filter(|publish| publish.is_empty()).is_none() || ignore_publish {
13-
if is_empty_str(&package.description) {
13+
if is_empty_str(package.description.as_ref()) {
1414
missing_warning(cx, package, "package.description");
1515
}
1616

17-
if is_empty_str(&package.license) && is_empty_str(&package.license_file) {
17+
if is_empty_str(package.license.as_ref()) && is_empty_str(package.license_file.as_ref()) {
1818
missing_warning(cx, package, "either package.license or package.license_file");
1919
}
2020

21-
if is_empty_str(&package.repository) {
21+
if is_empty_str(package.repository.as_ref()) {
2222
missing_warning(cx, package, "package.repository");
2323
}
2424

25-
if is_empty_str(&package.readme) {
25+
if is_empty_str(package.readme.as_ref()) {
2626
missing_warning(cx, package, "package.readme");
2727
}
2828

29-
if is_empty_vec(&package.keywords) {
29+
if is_empty_vec(package.keywords.as_ref()) {
3030
missing_warning(cx, package, "package.keywords");
3131
}
3232

33-
if is_empty_vec(&package.categories) {
33+
if is_empty_vec(package.categories.as_ref()) {
3434
missing_warning(cx, package, "package.categories");
3535
}
3636
}
@@ -42,8 +42,8 @@ fn missing_warning(cx: &LateContext<'_>, package: &cargo_metadata::Package, fiel
4242
span_lint(cx, CARGO_COMMON_METADATA, DUMMY_SP, message);
4343
}
4444

45-
fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: &Option<T>) -> bool {
46-
value.as_ref().map_or(true, |s| s.as_ref().is_empty())
45+
fn is_empty_str<T: AsRef<std::ffi::OsStr>>(value: Option<&T>) -> bool {
46+
value.map_or(true, |s| s.as_ref().is_empty())
4747
}
4848

4949
fn is_empty_vec(value: &[String]) -> bool {

clippy_lints/src/functions/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ declare_clippy_lint! {
443443
/// ```
444444
#[clippy::version = "1.82.0"]
445445
pub REF_OPTION,
446-
nursery,
446+
pedantic,
447447
"function signature uses `&Option<T>` instead of `Option<&T>`"
448448
}
449449

clippy_lints/src/unnested_or_patterns.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -275,12 +275,15 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
275275
|k, ps1, idx| matches!(
276276
k,
277277
TupleStruct(qself2, path2, ps2)
278-
if eq_maybe_qself(qself1, qself2) && eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx)
278+
if eq_maybe_qself(qself1.as_ref(), qself2.as_ref())
279+
&& eq_path(path1, path2) && eq_pre_post(ps1, ps2, idx)
279280
),
280281
|k| always_pat!(k, TupleStruct(_, _, ps) => ps),
281282
),
282283
// Transform a record pattern `S { fp_0, ..., fp_n }`.
283-
Struct(qself1, path1, fps1, rest1) => extend_with_struct_pat(qself1, path1, fps1, *rest1, start, alternatives),
284+
Struct(qself1, path1, fps1, rest1) => {
285+
extend_with_struct_pat(qself1.as_ref(), path1, fps1, *rest1, start, alternatives)
286+
},
284287
};
285288

286289
alternatives[focus_idx].kind = focus_kind;
@@ -292,7 +295,7 @@ fn transform_with_focus_on_idx(alternatives: &mut ThinVec<P<Pat>>, focus_idx: us
292295
/// So when we fixate on some `ident_k: pat_k`, we try to find `ident_k` in the other pattern
293296
/// and check that all `fp_i` where `i ∈ ((0...n) \ k)` between two patterns are equal.
294297
fn extend_with_struct_pat(
295-
qself1: &Option<P<ast::QSelf>>,
298+
qself1: Option<&P<ast::QSelf>>,
296299
path1: &ast::Path,
297300
fps1: &mut [ast::PatField],
298301
rest1: ast::PatFieldsRest,
@@ -307,7 +310,7 @@ fn extend_with_struct_pat(
307310
|k| {
308311
matches!(k, Struct(qself2, path2, fps2, rest2)
309312
if rest1 == *rest2 // If one struct pattern has `..` so must the other.
310-
&& eq_maybe_qself(qself1, qself2)
313+
&& eq_maybe_qself(qself1, qself2.as_ref())
311314
&& eq_path(path1, path2)
312315
&& fps1.len() == fps2.len()
313316
&& fps1.iter().enumerate().all(|(idx_1, fp1)| {

0 commit comments

Comments
 (0)