@@ -1858,9 +1858,9 @@ fn lint_expect_fun_call(
1858
1858
}
1859
1859
1860
1860
let receiver_type = cx. tables . expr_ty_adjusted ( & args[ 0 ] ) ;
1861
- let closure_args = if match_type ( cx, receiver_type, & paths :: OPTION ) {
1861
+ let closure_args = if is_type_diagnostic_item ( cx, receiver_type, sym ! ( option_type ) ) {
1862
1862
"||"
1863
- } else if match_type ( cx, receiver_type, & paths :: RESULT ) {
1863
+ } else if is_type_diagnostic_item ( cx, receiver_type, sym ! ( result_type ) ) {
1864
1864
"|_|"
1865
1865
} else {
1866
1866
return ;
@@ -2020,9 +2020,9 @@ fn lint_clone_on_ref_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, arg: &h
2020
2020
let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( arg) ) ;
2021
2021
2022
2022
if let ty:: Adt ( _, subst) = obj_ty. kind {
2023
- let caller_type = if match_type ( cx, obj_ty, & paths :: RC ) {
2023
+ let caller_type = if is_type_diagnostic_item ( cx, obj_ty, sym :: Rc ) {
2024
2024
"Rc"
2025
- } else if match_type ( cx, obj_ty, & paths :: ARC ) {
2025
+ } else if is_type_diagnostic_item ( cx, obj_ty, sym :: Arc ) {
2026
2026
"Arc"
2027
2027
} else if match_type ( cx, obj_ty, & paths:: WEAK_RC ) || match_type ( cx, obj_ty, & paths:: WEAK_ARC ) {
2028
2028
"Weak"
@@ -2089,7 +2089,7 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &
2089
2089
if_chain ! {
2090
2090
let source_type = cx. tables. expr_ty( source) ;
2091
2091
if let ty:: Adt ( def, substs) = source_type. kind;
2092
- if match_def_path ( cx , def. did, & paths :: RESULT ) ;
2092
+ if cx . tcx . is_diagnostic_item ( sym! ( result_type ) , def. did) ;
2093
2093
if match_type( cx, substs. type_at( 0 ) , & paths:: CSTRING ) ;
2094
2094
then {
2095
2095
span_lint_and_then(
@@ -2417,9 +2417,9 @@ fn derefs_to_slice<'a, 'tcx>(
2417
2417
fn lint_unwrap ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , unwrap_args : & [ hir:: Expr < ' _ > ] ) {
2418
2418
let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & unwrap_args[ 0 ] ) ) ;
2419
2419
2420
- let mess = if match_type ( cx, obj_ty, & paths :: OPTION ) {
2420
+ let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type ) ) {
2421
2421
Some ( ( OPTION_UNWRAP_USED , "an Option" , "None" ) )
2422
- } else if match_type ( cx, obj_ty, & paths :: RESULT ) {
2422
+ } else if is_type_diagnostic_item ( cx, obj_ty, sym ! ( result_type ) ) {
2423
2423
Some ( ( RESULT_UNWRAP_USED , "a Result" , "Err" ) )
2424
2424
} else {
2425
2425
None
@@ -2444,9 +2444,9 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
2444
2444
fn lint_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , expect_args : & [ hir:: Expr < ' _ > ] ) {
2445
2445
let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & expect_args[ 0 ] ) ) ;
2446
2446
2447
- let mess = if match_type ( cx, obj_ty, & paths :: OPTION ) {
2447
+ let mess = if is_type_diagnostic_item ( cx, obj_ty, sym ! ( option_type ) ) {
2448
2448
Some ( ( OPTION_EXPECT_USED , "an Option" , "None" ) )
2449
- } else if match_type ( cx, obj_ty, & paths :: RESULT ) {
2449
+ } else if is_type_diagnostic_item ( cx, obj_ty, sym ! ( result_type ) ) {
2450
2450
Some ( ( RESULT_EXPECT_USED , "a Result" , "Err" ) )
2451
2451
} else {
2452
2452
None
@@ -2467,7 +2467,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
2467
2467
fn lint_ok_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , ok_args : & [ hir:: Expr < ' _ > ] ) {
2468
2468
if_chain ! {
2469
2469
// lint if the caller of `ok()` is a `Result`
2470
- if match_type ( cx, cx. tables. expr_ty( & ok_args[ 0 ] ) , & paths :: RESULT ) ;
2470
+ if is_type_diagnostic_item ( cx, cx. tables. expr_ty( & ok_args[ 0 ] ) , sym! ( result_type ) ) ;
2471
2471
let result_type = cx. tables. expr_ty( & ok_args[ 0 ] ) ;
2472
2472
if let Some ( error_type) = get_error_type( cx, result_type) ;
2473
2473
if has_debug_impl( error_type, cx) ;
@@ -2513,8 +2513,8 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
2513
2513
unwrap_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2514
2514
) {
2515
2515
// lint if the caller of `map()` is an `Option`
2516
- let is_option = match_type ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , & paths :: OPTION ) ;
2517
- let is_result = match_type ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , & paths :: RESULT ) ;
2516
+ let is_option = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , sym ! ( option_type ) ) ;
2517
+ let is_result = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_args[ 0 ] ) , sym ! ( result_type ) ) ;
2518
2518
2519
2519
if is_option || is_result {
2520
2520
// Don't make a suggestion that may fail to compile due to mutably borrowing
@@ -2581,8 +2581,8 @@ fn lint_map_or_none<'a, 'tcx>(
2581
2581
expr : & ' tcx hir:: Expr < ' _ > ,
2582
2582
map_or_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2583
2583
) {
2584
- let is_option = match_type ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , & paths :: OPTION ) ;
2585
- let is_result = match_type ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , & paths :: RESULT ) ;
2584
+ let is_option = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , sym ! ( option_type ) ) ;
2585
+ let is_result = is_type_diagnostic_item ( cx, cx. tables . expr_ty ( & map_or_args[ 0 ] ) , sym ! ( result_type ) ) ;
2586
2586
2587
2587
// There are two variants of this `map_or` lint:
2588
2588
// (1) using `map_or` as an adapter from `Result<T,E>` to `Option<T>`
@@ -3231,10 +3231,7 @@ fn is_maybe_uninit_ty_valid(cx: &LateContext<'_, '_>, ty: Ty<'_>) -> bool {
3231
3231
match ty. kind {
3232
3232
ty:: Array ( ref component, _) => is_maybe_uninit_ty_valid ( cx, component) ,
3233
3233
ty:: Tuple ( ref types) => types. types ( ) . all ( |ty| is_maybe_uninit_ty_valid ( cx, ty) ) ,
3234
- ty:: Adt ( ref adt, _) => {
3235
- // needs to be a MaybeUninit
3236
- match_def_path ( cx, adt. did , & paths:: MEM_MAYBEUNINIT )
3237
- } ,
3234
+ ty:: Adt ( ref adt, _) => match_def_path ( cx, adt. did , & paths:: MEM_MAYBEUNINIT ) ,
3238
3235
_ => false ,
3239
3236
}
3240
3237
}
@@ -3348,7 +3345,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
3348
3345
/// Given a `Result<T, E>` type, return its error type (`E`).
3349
3346
fn get_error_type < ' a > ( cx : & LateContext < ' _ , ' _ > , ty : Ty < ' a > ) -> Option < Ty < ' a > > {
3350
3347
match ty. kind {
3351
- ty:: Adt ( _, substs) if match_type ( cx, ty, & paths :: RESULT ) => substs. types ( ) . nth ( 1 ) ,
3348
+ ty:: Adt ( _, substs) if is_type_diagnostic_item ( cx, ty, sym ! ( result_type ) ) => substs. types ( ) . nth ( 1 ) ,
3352
3349
_ => None ,
3353
3350
}
3354
3351
}
0 commit comments