2021-03-16 00:55:45 +00:00
|
|
|
use clippy_utils::diagnostics::span_lint;
|
2022-08-18 17:25:02 +00:00
|
|
|
use clippy_utils::{is_path_diagnostic_item, ty::is_uninit_value_valid_for_ty};
|
2021-03-02 16:03:47 +00:00
|
|
|
use if_chain::if_chain;
|
|
|
|
use rustc_hir as hir;
|
|
|
|
use rustc_lint::LateContext;
|
2022-02-25 15:38:06 +00:00
|
|
|
use rustc_span::sym;
|
2021-03-02 16:03:47 +00:00
|
|
|
|
|
|
|
use super::UNINIT_ASSUMED_INIT;
|
|
|
|
|
|
|
|
/// lint for `MaybeUninit::uninit().assume_init()` (we already have the latter)
|
2021-03-11 05:40:20 +00:00
|
|
|
pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr<'_>) {
|
2021-03-02 16:03:47 +00:00
|
|
|
if_chain! {
|
2021-04-02 21:35:32 +00:00
|
|
|
if let hir::ExprKind::Call(callee, args) = recv.kind;
|
2021-03-02 16:03:47 +00:00
|
|
|
if args.is_empty();
|
2022-08-18 17:25:02 +00:00
|
|
|
if is_path_diagnostic_item(cx, callee, sym::maybe_uninit_uninit);
|
2021-09-17 18:42:32 +00:00
|
|
|
if !is_uninit_value_valid_for_ty(cx, cx.typeck_results().expr_ty_adjusted(expr));
|
2021-03-02 16:03:47 +00:00
|
|
|
then {
|
|
|
|
span_lint(
|
|
|
|
cx,
|
|
|
|
UNINIT_ASSUMED_INIT,
|
2021-03-11 05:40:20 +00:00
|
|
|
expr.span,
|
2021-03-02 16:03:47 +00:00
|
|
|
"this call for this type may be undefined behavior"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|