@@ -2478,14 +2478,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
2478
2478
// Find calls to `mem::{uninitialized,zeroed}` methods.
2479
2479
if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
2480
2480
let def_id = cx. qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
2481
-
2482
- if cx. tcx . is_diagnostic_item ( sym:: mem_zeroed, def_id) {
2483
- return Some ( InitKind :: Zeroed ) ;
2484
- } else if cx. tcx . is_diagnostic_item ( sym:: mem_uninitialized, def_id) {
2485
- return Some ( InitKind :: Uninit ) ;
2486
- } else if cx. tcx . is_diagnostic_item ( sym:: transmute, def_id) && is_zero ( & args[ 0 ] )
2487
- {
2488
- return Some ( InitKind :: Zeroed ) ;
2481
+ match cx. tcx . get_diagnostic_name ( def_id) {
2482
+ Some ( sym:: mem_zeroed) => return Some ( InitKind :: Zeroed ) ,
2483
+ Some ( sym:: mem_uninitialized) => return Some ( InitKind :: Uninit ) ,
2484
+ Some ( sym:: transmute) if is_zero ( & args[ 0 ] ) => return Some ( InitKind :: Zeroed ) ,
2485
+ _ => { }
2489
2486
}
2490
2487
}
2491
2488
} else if let hir:: ExprKind :: MethodCall ( _, _, ref args, _) = expr. kind {
@@ -2497,11 +2494,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
2497
2494
if let hir:: ExprKind :: Call ( ref path_expr, _) = args[ 0 ] . kind {
2498
2495
if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
2499
2496
let def_id = cx. qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
2500
-
2501
- if cx. tcx . is_diagnostic_item ( sym:: maybe_uninit_zeroed, def_id) {
2502
- return Some ( InitKind :: Zeroed ) ;
2503
- } else if cx. tcx . is_diagnostic_item ( sym:: maybe_uninit_uninit, def_id) {
2504
- return Some ( InitKind :: Uninit ) ;
2497
+ match cx. tcx . get_diagnostic_name ( def_id) {
2498
+ Some ( sym:: maybe_uninit_zeroed) => return Some ( InitKind :: Zeroed ) ,
2499
+ Some ( sym:: maybe_uninit_uninit) => return Some ( InitKind :: Uninit ) ,
2500
+ _ => { }
2505
2501
}
2506
2502
}
2507
2503
}
@@ -3091,8 +3087,10 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
3091
3087
rustc_hir:: ExprKind :: Call ( ref path, _) => {
3092
3088
if let rustc_hir:: ExprKind :: Path ( ref qpath) = path. kind {
3093
3089
if let Some ( def_id) = cx. qpath_res ( qpath, path. hir_id ) . opt_def_id ( ) {
3094
- return cx. tcx . is_diagnostic_item ( sym:: ptr_null, def_id)
3095
- || cx. tcx . is_diagnostic_item ( sym:: ptr_null_mut, def_id) ;
3090
+ return matches ! (
3091
+ cx. tcx. get_diagnostic_name( def_id) ,
3092
+ Some ( sym:: ptr_null | sym:: ptr_null_mut)
3093
+ ) ;
3096
3094
}
3097
3095
}
3098
3096
}
0 commit comments