]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/clippy_lints/src/methods/uninit_assumed_init.rs
Rollup merge of #89876 - AlexApps99:const_ops, r=oli-obk
[rust.git] / src / tools / clippy / clippy_lints / src / methods / uninit_assumed_init.rs
1 use clippy_utils::diagnostics::span_lint;
2 use clippy_utils::{is_expr_path_def_path, paths, ty::is_uninit_value_valid_for_ty};
3 use if_chain::if_chain;
4 use rustc_hir as hir;
5 use rustc_lint::LateContext;
6
7 use super::UNINIT_ASSUMED_INIT;
8
9 /// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter)
10 pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
11     if_chain! {
12         if let hir::ExprKind::Call(callee, args) = recv.kind;
13         if args.is_empty();
14         if is_expr_path_def_path(cx, callee, &paths::MEM_MAYBEUNINIT_UNINIT);
15         if !is_uninit_value_valid_for_ty(cx, cx.typeck_results().expr_ty_adjusted(expr));
16         then {
17             span_lint(
18                 cx,
19                 UNINIT_ASSUMED_INIT,
20                 expr.span,
21                 "this call for this type may be undefined behavior"
22             );
23         }
24     }
25 }