@@ -1911,8 +1911,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
19111911 // `Invalid` represents the empty string and matches that.
19121912 const TRANSMUTE_PATH : & [ Symbol ] =
19131913 & [ sym:: core, sym:: intrinsics, kw:: Invalid , sym:: transmute] ;
1914+ const MU_ZEROED_PATH : & [ Symbol ] =
1915+ & [ sym:: core, sym:: mem, sym:: maybe_uninit, sym:: MaybeUninit , sym:: zeroed] ;
1916+ const MU_UNINIT_PATH : & [ Symbol ] =
1917+ & [ sym:: core, sym:: mem, sym:: maybe_uninit, sym:: MaybeUninit , sym:: uninit] ;
19141918
19151919 if let hir:: ExprKind :: Call ( ref path_expr, ref args) = expr. kind {
1920+ // Find calls to `mem::{uninitialized,zeroed}` methods.
19161921 if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
19171922 let def_id = cx. tables . qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
19181923
@@ -1927,8 +1932,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
19271932 return Some ( InitKind :: Zeroed ) ;
19281933 }
19291934 }
1930- // FIXME: Also detect `MaybeUninit::zeroed().assume_init()` and
1931- // `MaybeUninit::uninit().assume_init()`.
1935+ }
1936+ } else if let hir:: ExprKind :: MethodCall ( ref path, _, ref args) = expr. kind {
1937+ // Find problematic calls to `MaybeUninit::assume_init`.
1938+ if path. ident . name == sym:: assume_init {
1939+ // This is a call to *some* method named `assume_init`.
1940+ // See if the `self` parameter is one of the dangerous constructors.
1941+ if let hir:: ExprKind :: Call ( ref path_expr, _) = args[ 0 ] . kind {
1942+ if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
1943+ let def_id = cx. tables . qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
1944+ if cx. match_def_path ( def_id, MU_ZEROED_PATH ) {
1945+ return Some ( InitKind :: Zeroed ) ;
1946+ } else if cx. match_def_path ( def_id, MU_UNINIT_PATH ) {
1947+ return Some ( InitKind :: Uninit ) ;
1948+ }
1949+ }
1950+ }
19321951 }
19331952 }
19341953
0 commit comments