@@ -2478,14 +2478,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24782478 // Find calls to `mem::{uninitialized,zeroed}` methods.
24792479 if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
24802480 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+ _ => { }
24892486 }
24902487 }
24912488 } else if let hir:: ExprKind :: MethodCall ( _, _, ref args, _) = expr. kind {
@@ -2497,11 +2494,10 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
24972494 if let hir:: ExprKind :: Call ( ref path_expr, _) = args[ 0 ] . kind {
24982495 if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
24992496 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+ _ => { }
25052501 }
25062502 }
25072503 }
@@ -3091,8 +3087,10 @@ impl<'tcx> LateLintPass<'tcx> for DerefNullPtr {
30913087 rustc_hir:: ExprKind :: Call ( ref path, _) => {
30923088 if let rustc_hir:: ExprKind :: Path ( ref qpath) = path. kind {
30933089 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+ ) ;
30963094 }
30973095 }
30983096 }
0 commit comments