@@ -1836,9 +1836,9 @@ fn lint_expect_fun_call(
18361836 }
18371837
18381838 let receiver_type = cx. tables . expr_ty_adjusted ( & args[ 0 ] ) ;
1839- let closure_args = if match_type ( cx, receiver_type, & paths :: OPTION ) {
1839+ let closure_args = if is_type_diagnostic_item ( cx, receiver_type, sym ! ( option_type ) ) {
18401840 "||"
1841- } else if match_type ( cx, receiver_type, & paths :: RESULT ) {
1841+ } else if is_type_diagnostic_item ( cx, receiver_type, sym ! ( result_type ) ) {
18421842 "|_|"
18431843 } else {
18441844 return ;
@@ -2067,7 +2067,7 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &
20672067 if_chain ! {
20682068 let source_type = cx. tables. expr_ty( source) ;
20692069 if let ty:: Adt ( def, substs) = source_type. kind;
2070- if match_def_path ( cx , def. did, & paths :: RESULT ) ;
2070+ if cx . tcx . is_diagnostic_item ( sym! ( result_type ) , def. did) ;
20712071 if match_type( cx, substs. type_at( 0 ) , & paths:: CSTRING ) ;
20722072 then {
20732073 span_lint_and_then(
@@ -2395,9 +2395,9 @@ fn derefs_to_slice<'a, 'tcx>(
23952395fn lint_unwrap ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , unwrap_args : & [ hir:: Expr < ' _ > ] ) {
23962396 let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & unwrap_args[ 0 ] ) ) ;
23972397
2398- let mess = if match_type ( cx, obj_ty, & paths :: OPTION ) {
2398+ let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type ) ) {
23992399 Some ( ( OPTION_UNWRAP_USED , "an Option" , "None" ) )
2400- } else if match_type ( cx, obj_ty, & paths :: RESULT ) {
2400+ } else if is_type_diagnostic_item ( cx, obj_ty, sym ! ( result_type ) ) {
24012401 Some ( ( RESULT_UNWRAP_USED , "a Result" , "Err" ) )
24022402 } else {
24032403 None
@@ -2422,9 +2422,9 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
24222422fn lint_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , expect_args : & [ hir:: Expr < ' _ > ] ) {
24232423 let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & expect_args[ 0 ] ) ) ;
24242424
2425- let mess = if match_type ( cx, obj_ty, & paths :: OPTION ) {
2425+ let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type ) ) {
24262426 Some ( ( OPTION_EXPECT_USED , "an Option" , "None" ) )
2427- } else if match_type ( cx, obj_ty, & paths :: RESULT ) {
2427+ } else if is_type_diagnostic_item ( cx, obj_ty, sym ! ( result_type ) ) {
24282428 Some ( ( RESULT_EXPECT_USED , "a Result" , "Err" ) )
24292429 } else {
24302430 None
@@ -2445,7 +2445,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
24452445fn lint_ok_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , ok_args : & [ hir:: Expr < ' _ > ] ) {
24462446 if_chain ! {
24472447 // lint if the caller of `ok()` is a `Result`
2448- if match_type ( cx, cx. tables. expr_ty( & ok_args[ 0 ] ) , & paths :: RESULT ) ;
2448+ if is_type_diagnostic_item ( cx, cx. tables. expr_ty( & ok_args[ 0 ] ) , sym! ( result_type ) ) ;
24492449 let result_type = cx. tables. expr_ty( & ok_args[ 0 ] ) ;
24502450 if let Some ( error_type) = get_error_type( cx, result_type) ;
24512451 if has_debug_impl( error_type, cx) ;
@@ -2491,8 +2491,8 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
24912491 unwrap_args : & ' tcx [ hir:: Expr < ' _ > ] ,
24922492) {
24932493 // lint if the caller of `map()` is an `Option`
2494- let is_option = match_type ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , & paths :: OPTION ) ;
2495- let is_result = match_type ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , & paths :: RESULT ) ;
2494+ let is_option = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , sym ! ( option_type ) ) ;
2495+ let is_result = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , sym ! ( result_type ) ) ;
24962496
24972497 if is_option || is_result {
24982498 // Don't make a suggestion that may fail to compile due to mutably borrowing
@@ -2559,8 +2559,8 @@ fn lint_map_or_none<'a, 'tcx>(
25592559 expr : & ' tcx hir:: Expr < ' _ > ,
25602560 map_or_args : & ' tcx [ hir:: Expr < ' _ > ] ,
25612561) {
2562- let is_option = match_type ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , & paths :: OPTION ) ;
2563- let is_result = match_type ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , & paths :: RESULT ) ;
2562+ let is_option = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , sym ! ( option_type ) ) ;
2563+ let is_result = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , sym ! ( result_type ) ) ;
25642564
25652565 // There are two variants of this `map_or` lint:
25662566 // (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
@@ -3210,7 +3210,6 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
32103210 ty:: Array ( ref component, _) => is_maybe_uninit_ty_valid ( cx, component) ,
32113211 ty:: Tuple ( ref types) => types. types ( ) . all ( |ty| is_maybe_uninit_ty_valid ( cx, ty) ) ,
32123212 ty:: Adt ( ref adt, _) => {
3213- // needs to be a MaybeUninit
32143213 match_def_path ( cx, adt. did , & paths:: MEM_MAYBEUNINIT )
32153214 } ,
32163215 _ => false ,
@@ -3326,7 +3325,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
33263325/// Given a `Result<T, E>` type, return its error type (`E`).
33273326fn get_error_type < ' a > ( cx : & LateContext < ' _ , ' _ > , ty : Ty < ' a > ) -> Option < Ty < ' a > > {
33283327 match ty. kind {
3329- ty:: Adt ( _, substs) if match_type ( cx, ty, & paths :: RESULT ) => substs. types ( ) . nth ( 1 ) ,
3328+ ty:: Adt ( _, substs) if is_type_diagnostic_item ( cx, ty, sym ! ( result_type ) ) => substs. types ( ) . nth ( 1 ) ,
33303329 _ => None ,
33313330 }
33323331}
0 commit comments