Skip to content

Commit 892cb18

Browse files
committed
clean-up
1 parent ca168c0 commit 892cb18

File tree

5 files changed

+27
-25
lines changed

5 files changed

+27
-25
lines changed

clippy_lints/src/matches/manual_filter.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ fn peels_blocks_incl_unsafe<'a>(expr: &'a Expr<'a>) -> &'a Expr<'a> {
5252
peels_blocks_incl_unsafe_opt(expr).unwrap_or(expr)
5353
}
5454

55-
// function called for each <expr> expression:
55+
/// Checks whether <expr> resolves to `Some(target)`
56+
// NOTE: called for each <expr> expression:
5657
// Some(x) => if <cond> {
5758
// <expr>
5859
// } else {
5960
// <expr>
6061
// }
61-
// Returns true if <expr> resolves to `Some(x)`, `false` otherwise
6262
fn is_some_expr(cx: &LateContext<'_>, target: HirId, ctxt: SyntaxContext, expr: &Expr<'_>) -> bool {
6363
if let Some(inner_expr) = peels_blocks_incl_unsafe_opt(expr)
6464
// there can be not statements in the block as they would be removed when switching to `.filter`

clippy_lints/src/matches/manual_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub(super) fn try_parse_pattern<'tcx>(
281281
f(cx, pat, 0, ctxt)
282282
}
283283

284-
// Checks for the `None` value.
284+
/// Checks for the `None` value, possibly in a block.
285285
fn is_none_expr(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
286286
peel_blocks(expr).res(cx).ctor_parent(cx).is_lang_item(cx, OptionNone)
287287
}

clippy_lints/src/methods/unnecessary_literal_unwrap.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn get_ty_from_args<'a>(args: Option<&'a [hir::GenericArg<'a>]>, index: usize) -
2323
}
2424
}
2525

26+
#[expect(clippy::too_many_lines)]
2627
pub(super) fn check(
2728
cx: &LateContext<'_>,
2829
expr: &hir::Expr<'_>,
@@ -38,19 +39,20 @@ pub(super) fn check(
3839
}
3940

4041
let (constructor, call_args, ty) = if let hir::ExprKind::Call(call, call_args) = init.kind {
41-
let Some((qpath, hir_id)) = call.opt_qpath() else {
42-
return;
43-
};
44-
45-
let args = last_path_segment(qpath).args.map(|args| args.args);
46-
let res = cx.qpath_res(qpath, hir_id);
47-
48-
if res.ctor_parent(cx).is_lang_item(cx, hir::LangItem::OptionSome) {
49-
(sym::Some, call_args, get_ty_from_args(args, 0))
50-
} else if res.ctor_parent(cx).is_lang_item(cx, hir::LangItem::ResultOk) {
51-
(sym::Ok, call_args, get_ty_from_args(args, 0))
52-
} else if res.ctor_parent(cx).is_lang_item(cx, hir::LangItem::ResultErr) {
53-
(sym::Err, call_args, get_ty_from_args(args, 1))
42+
if let Some((qpath, hir_id)) = call.opt_qpath()
43+
&& let args = last_path_segment(qpath).args.map(|args| args.args)
44+
&& let Some(did) = cx.qpath_res(qpath, hir_id).ctor_parent(cx).opt_def_id()
45+
{
46+
let lang_items = cx.tcx.lang_items();
47+
if Some(did) == lang_items.option_some_variant() {
48+
(sym::Some, call_args, get_ty_from_args(args, 0))
49+
} else if Some(did) == lang_items.result_ok_variant() {
50+
(sym::Ok, call_args, get_ty_from_args(args, 0))
51+
} else if Some(did) == lang_items.result_err_variant() {
52+
(sym::Err, call_args, get_ty_from_args(args, 1))
53+
} else {
54+
return;
55+
}
5456
} else {
5557
return;
5658
}

clippy_lints/src/non_canonical_impls.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -354,10 +354,7 @@ fn self_cmp_call<'tcx>(
354354
needs_fully_qualified: &mut bool,
355355
) -> bool {
356356
match cmp_expr.kind {
357-
ExprKind::Call(path, [_, _]) => path
358-
.res(typeck)
359-
.opt_def_id()
360-
.is_some_and(|def_id| cx.tcx.is_diagnostic_item(sym::ord_cmp_method, def_id)),
357+
ExprKind::Call(path, [_, _]) => path.res(typeck).is_diag_item(cx, sym::ord_cmp_method),
361358
ExprKind::MethodCall(_, recv, [_], ..) => {
362359
let ExprKind::Path(path) = recv.kind else {
363360
return false;

clippy_lints/src/option_if_let_else.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use clippy_utils::{
1010
};
1111
use rustc_data_structures::fx::FxHashSet;
1212
use rustc_errors::Applicability;
13-
use rustc_hir::LangItem::{OptionNone, OptionSome, ResultErr, ResultOk};
13+
use rustc_hir::LangItem::{OptionNone, ResultErr};
1414
use rustc_hir::def::Res;
1515
use rustc_hir::intravisit::{Visitor, walk_expr, walk_path};
1616
use rustc_hir::{
@@ -313,11 +313,14 @@ impl<'tcx> Visitor<'tcx> for ReferenceVisitor<'_, 'tcx> {
313313
}
314314

315315
fn try_get_inner_pat_and_is_result<'tcx>(cx: &LateContext<'tcx>, pat: &Pat<'tcx>) -> Option<(&'tcx Pat<'tcx>, bool)> {
316-
if let PatKind::TupleStruct(ref qpath, [inner_pat], ..) = pat.kind {
317-
let res = cx.qpath_res(qpath, pat.hir_id);
318-
if res.ctor_parent(cx).is_lang_item(cx, OptionSome) {
316+
if let PatKind::TupleStruct(ref qpath, [inner_pat], ..) = pat.kind
317+
&& let res = cx.qpath_res(qpath, pat.hir_id)
318+
&& let Some(did) = res.ctor_parent(cx).opt_def_id()
319+
{
320+
let lang_items = cx.tcx.lang_items();
321+
if Some(did) == lang_items.option_some_variant() {
319322
return Some((inner_pat, false));
320-
} else if res.ctor_parent(cx).is_lang_item(cx, ResultOk) {
323+
} else if Some(did) == lang_items.result_ok_variant() {
321324
return Some((inner_pat, true));
322325
}
323326
}

0 commit comments

Comments
 (0)