lint: port path statement diagnostics

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-06-28 10:19:11 +01:00
parent 1999a4c421
commit 2829f519a0
2 changed files with 9 additions and 4 deletions

View file

@ -273,3 +273,8 @@ lint-unused-generator =
.note = generators are lazy and do nothing unless resumed
lint-unused-def = unused {$pre}`{$def}`{$post} that must be used
lint-path-statement-drop = path statement drops value
.suggestion = use `drop` to clarify the intent
lint-path-statement-no-effect = path statement with no effect

View file

@ -360,20 +360,20 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
let ty = cx.typeck_results().expr_ty(expr);
if ty.needs_drop(cx.tcx, cx.param_env) {
let mut lint = lint.build("path statement drops value");
let mut lint = lint.build(fluent::lint::path_statement_drop);
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) {
lint.span_suggestion(
s.span,
"use `drop` to clarify the intent",
fluent::lint::suggestion,
format!("drop({});", snippet),
Applicability::MachineApplicable,
);
} else {
lint.span_help(s.span, "use `drop` to clarify the intent");
lint.span_help(s.span, fluent::lint::suggestion);
}
lint.emit();
} else {
lint.build("path statement with no effect").emit();
lint.build(fluent::lint::path_statement_no_effect).emit();
}
});
}