@@ -1903,29 +1903,23 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
1903
1903
1904
1904
/// Determine if this expression is a "dangerous initialization".
1905
1905
fn is_dangerous_init ( cx : & LateContext < ' _ , ' _ > , expr : & hir:: Expr ) -> Option < InitKind > {
1906
- const ZEROED_PATH : & [ Symbol ] = & [ sym:: core, sym:: mem, sym:: zeroed] ;
1907
- const UININIT_PATH : & [ Symbol ] = & [ sym:: core, sym:: mem, sym:: uninitialized] ;
1908
1906
// `transmute` is inside an anonymous module (the `extern` block?);
1909
1907
// `Invalid` represents the empty string and matches that.
1908
+ // FIXME(#66075): use diagnostic items. Somehow, that does not seem to work
1909
+ // on intrinsics right now.
1910
1910
const TRANSMUTE_PATH : & [ Symbol ] =
1911
1911
& [ sym:: core, sym:: intrinsics, kw:: Invalid , sym:: transmute] ;
1912
- const MU_ZEROED_PATH : & [ Symbol ] =
1913
- & [ sym:: core, sym:: mem, sym:: maybe_uninit, sym:: MaybeUninit , sym:: zeroed] ;
1914
- const MU_UNINIT_PATH : & [ Symbol ] =
1915
- & [ sym:: core, sym:: mem, sym:: maybe_uninit, sym:: MaybeUninit , sym:: uninit] ;
1916
1912
1917
1913
if let hir:: ExprKind :: Call ( ref path_expr, ref args) = expr. kind {
1918
1914
// Find calls to `mem::{uninitialized,zeroed}` methods.
1919
1915
if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
1920
1916
let def_id = cx. tables . qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
1921
1917
1922
- if cx. match_def_path ( def_id , ZEROED_PATH ) {
1918
+ if cx. tcx . is_diagnostic_item ( sym :: mem_zeroed , def_id ) {
1923
1919
return Some ( InitKind :: Zeroed ) ;
1924
- }
1925
- if cx. match_def_path ( def_id, UININIT_PATH ) {
1920
+ } else if cx. tcx . is_diagnostic_item ( sym:: mem_uninitialized, def_id) {
1926
1921
return Some ( InitKind :: Uninit ) ;
1927
- }
1928
- if cx. match_def_path ( def_id, TRANSMUTE_PATH ) {
1922
+ } else if cx. match_def_path ( def_id, TRANSMUTE_PATH ) {
1929
1923
if is_zero ( & args[ 0 ] ) {
1930
1924
return Some ( InitKind :: Zeroed ) ;
1931
1925
}
@@ -1940,9 +1934,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
1940
1934
if let hir:: ExprKind :: Call ( ref path_expr, _) = args[ 0 ] . kind {
1941
1935
if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
1942
1936
let def_id = cx. tables . qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
1943
- if cx. match_def_path ( def_id, MU_ZEROED_PATH ) {
1937
+
1938
+ if cx. tcx . is_diagnostic_item ( sym:: maybe_uninit_zeroed, def_id) {
1944
1939
return Some ( InitKind :: Zeroed ) ;
1945
- } else if cx. match_def_path ( def_id , MU_UNINIT_PATH ) {
1940
+ } else if cx. tcx . is_diagnostic_item ( sym :: maybe_uninit_uninit , def_id ) {
1946
1941
return Some ( InitKind :: Uninit ) ;
1947
1942
}
1948
1943
}
0 commit comments