]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/clippy_lints/src/methods/uninit_assumed_init.rs
New upstream version 1.58.1+dfsg1
[rustc.git] / src / tools / clippy / clippy_lints / src / methods / uninit_assumed_init.rs
CommitLineData
cdc7bbd5 1use clippy_utils::diagnostics::span_lint;
3c0e092e 2use clippy_utils::{is_expr_path_def_path, paths, ty::is_uninit_value_valid_for_ty};
f20569fa
XL
3use if_chain::if_chain;
4use rustc_hir as hir;
5use rustc_lint::LateContext;
f20569fa
XL
6
7use super::UNINIT_ASSUMED_INIT;
8
9/// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter)
cdc7bbd5 10pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
f20569fa 11 if_chain! {
cdc7bbd5 12 if let hir::ExprKind::Call(callee, args) = recv.kind;
f20569fa 13 if args.is_empty();
cdc7bbd5 14 if is_expr_path_def_path(cx, callee, &paths::MEM_MAYBEUNINIT_UNINIT);
3c0e092e 15 if !is_uninit_value_valid_for_ty(cx, cx.typeck_results().expr_ty_adjusted(expr));
f20569fa
XL
16 then {
17 span_lint(
18 cx,
19 UNINIT_ASSUMED_INIT,
cdc7bbd5 20 expr.span,
f20569fa
XL
21 "this call for this type may be undefined behavior"
22 );
23 }
24 }
25}