]>
Commit | Line | Data |
---|---|---|
cdc7bbd5 | 1 | use clippy_utils::diagnostics::span_lint; |
3c0e092e | 2 | use clippy_utils::{is_expr_path_def_path, paths, ty::is_uninit_value_valid_for_ty}; |
f20569fa XL |
3 | use if_chain::if_chain; |
4 | use rustc_hir as hir; | |
5 | use rustc_lint::LateContext; | |
f20569fa XL |
6 | |
7 | use super::UNINIT_ASSUMED_INIT; | |
8 | ||
9 | /// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter) | |
cdc7bbd5 | 10 | pub(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 | } |