@@ -1836,9 +1836,9 @@ fn lint_expect_fun_call(
1836
1836
}
1837
1837
1838
1838
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 ) ) {
1840
1840
"||"
1841
- } else if match_type ( cx, receiver_type, & paths :: RESULT ) {
1841
+ } else if is_type_diagnostic_item ( cx, receiver_type, sym ! ( result_type ) ) {
1842
1842
"|_|"
1843
1843
} else {
1844
1844
return ;
@@ -2067,7 +2067,7 @@ fn lint_cstring_as_ptr(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, source: &
2067
2067
if_chain ! {
2068
2068
let source_type = cx. tables. expr_ty( source) ;
2069
2069
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) ;
2071
2071
if match_type( cx, substs. type_at( 0 ) , & paths:: CSTRING ) ;
2072
2072
then {
2073
2073
span_lint_and_then(
@@ -2395,9 +2395,9 @@ fn derefs_to_slice<'a, 'tcx>(
2395
2395
fn lint_unwrap ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , unwrap_args : & [ hir:: Expr < ' _ > ] ) {
2396
2396
let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & unwrap_args[ 0 ] ) ) ;
2397
2397
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 ) ) {
2399
2399
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 ) ) {
2401
2401
Some ( ( RESULT_UNWRAP_USED , "a Result" , "Err" ) )
2402
2402
} else {
2403
2403
None
@@ -2422,9 +2422,9 @@ fn lint_unwrap(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, unwrap_args: &[hi
2422
2422
fn lint_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , expect_args : & [ hir:: Expr < ' _ > ] ) {
2423
2423
let obj_ty = walk_ptrs_ty ( cx. tables . expr_ty ( & expect_args[ 0 ] ) ) ;
2424
2424
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 ) ) {
2426
2426
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 ) ) {
2428
2428
Some ( ( RESULT_EXPECT_USED , "a Result" , "Err" ) )
2429
2429
} else {
2430
2430
None
@@ -2445,7 +2445,7 @@ fn lint_expect(cx: &LateContext<'_, '_>, expr: &hir::Expr<'_>, expect_args: &[hi
2445
2445
fn lint_ok_expect ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr < ' _ > , ok_args : & [ hir:: Expr < ' _ > ] ) {
2446
2446
if_chain ! {
2447
2447
// 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 ) ) ;
2449
2449
let result_type = cx. tables. expr_ty( & ok_args[ 0 ] ) ;
2450
2450
if let Some ( error_type) = get_error_type( cx, result_type) ;
2451
2451
if has_debug_impl( error_type, cx) ;
@@ -2491,8 +2491,8 @@ fn lint_map_unwrap_or_else<'a, 'tcx>(
2491
2491
unwrap_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2492
2492
) {
2493
2493
// 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 ) ) ;
2496
2496
2497
2497
if is_option || is_result {
2498
2498
// 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>(
2559
2559
expr : & ' tcx hir:: Expr < ' _ > ,
2560
2560
map_or_args : & ' tcx [ hir:: Expr < ' _ > ] ,
2561
2561
) {
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 ) ) ;
2564
2564
2565
2565
// There are two variants of this `map_or` lint:
2566
2566
// (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 {
3210
3210
ty:: Array ( ref component, _) => is_maybe_uninit_ty_valid ( cx, component) ,
3211
3211
ty:: Tuple ( ref types) => types. types ( ) . all ( |ty| is_maybe_uninit_ty_valid ( cx, ty) ) ,
3212
3212
ty:: Adt ( ref adt, _) => {
3213
- // needs to be a MaybeUninit
3214
3213
match_def_path ( cx, adt. did , & paths:: MEM_MAYBEUNINIT )
3215
3214
} ,
3216
3215
_ => false ,
@@ -3326,7 +3325,7 @@ fn lint_option_as_ref_deref<'a, 'tcx>(
3326
3325
/// Given a `Result<T, E>` type, return its error type (`E`).
3327
3326
fn get_error_type < ' a > ( cx : & LateContext < ' _ , ' _ > , ty : Ty < ' a > ) -> Option < Ty < ' a > > {
3328
3327
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 ) ,
3330
3329
_ => None ,
3331
3330
}
3332
3331
}
0 commit comments