@@ -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) ]
2627pub ( 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 }
0 commit comments