@@ -1911,8 +1911,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
1911
1911
// `Invalid` represents the empty string and matches that.
1912
1912
const TRANSMUTE_PATH : & [ Symbol ] =
1913
1913
& [ 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] ;
1914
1918
1915
1919
if let hir:: ExprKind :: Call ( ref path_expr, ref args) = expr. kind {
1920
+ // Find calls to `mem::{uninitialized,zeroed}` methods.
1916
1921
if let hir:: ExprKind :: Path ( ref qpath) = path_expr. kind {
1917
1922
let def_id = cx. tables . qpath_res ( qpath, path_expr. hir_id ) . opt_def_id ( ) ?;
1918
1923
@@ -1927,8 +1932,22 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InvalidValue {
1927
1932
return Some ( InitKind :: Zeroed ) ;
1928
1933
}
1929
1934
}
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
+ }
1932
1951
}
1933
1952
}
1934
1953
0 commit comments