mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 12:36:47 +00:00
Allow let () = ..
as type inference for let_unit_value
This commit is contained in:
parent
196174ddad
commit
2872b7e0a4
@ -18,20 +18,23 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>) {
|
||||
&& !in_external_macro(cx.sess(), local.span)
|
||||
&& cx.typeck_results().pat_ty(local.pat).is_unit()
|
||||
{
|
||||
if local.ty.is_some() && expr_needs_inferred_result(cx, init) {
|
||||
if !matches!(local.pat.kind, PatKind::Wild) {
|
||||
if (local.ty.map_or(false, |ty| !matches!(ty.kind, TyKind::Infer))
|
||||
|| matches!(local.pat.kind, PatKind::Tuple([], None)))
|
||||
&& expr_needs_inferred_result(cx, init)
|
||||
{
|
||||
if !matches!(local.pat.kind, PatKind::Wild | PatKind::Tuple([], None)) {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
LET_UNIT_VALUE,
|
||||
local.span,
|
||||
"this let-binding has unit value",
|
||||
|diag| {
|
||||
diag.span_suggestion(
|
||||
local.pat.span,
|
||||
"use a wild (`_`) binding",
|
||||
"_",
|
||||
Applicability::MaybeIncorrect, // snippet
|
||||
);
|
||||
diag.span_suggestion(
|
||||
local.pat.span,
|
||||
"use a wild (`_`) binding",
|
||||
"_",
|
||||
Applicability::MaybeIncorrect, // snippet
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
@ -163,6 +163,8 @@ fn _returns_generic() {
|
||||
let _: () = opt;
|
||||
}
|
||||
}
|
||||
|
||||
let () = f();
|
||||
}
|
||||
|
||||
fn attributes() {
|
||||
|
@ -163,6 +163,8 @@ fn _returns_generic() {
|
||||
let _: () = opt;
|
||||
}
|
||||
}
|
||||
|
||||
let () = f();
|
||||
}
|
||||
|
||||
fn attributes() {
|
||||
|
Loading…
Reference in New Issue
Block a user