lint: port path statement diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
1999a4c421
commit
2829f519a0
2 changed files with 9 additions and 4 deletions
|
@ -273,3 +273,8 @@ lint-unused-generator =
|
||||||
.note = generators are lazy and do nothing unless resumed
|
.note = generators are lazy and do nothing unless resumed
|
||||||
|
|
||||||
lint-unused-def = unused {$pre}`{$def}`{$post} that must be used
|
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
|
||||||
|
|
|
@ -360,20 +360,20 @@ impl<'tcx> LateLintPass<'tcx> for PathStatements {
|
||||||
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
|
cx.struct_span_lint(PATH_STATEMENTS, s.span, |lint| {
|
||||||
let ty = cx.typeck_results().expr_ty(expr);
|
let ty = cx.typeck_results().expr_ty(expr);
|
||||||
if ty.needs_drop(cx.tcx, cx.param_env) {
|
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) {
|
if let Ok(snippet) = cx.sess().source_map().span_to_snippet(expr.span) {
|
||||||
lint.span_suggestion(
|
lint.span_suggestion(
|
||||||
s.span,
|
s.span,
|
||||||
"use `drop` to clarify the intent",
|
fluent::lint::suggestion,
|
||||||
format!("drop({});", snippet),
|
format!("drop({});", snippet),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
lint.span_help(s.span, "use `drop` to clarify the intent");
|
lint.span_help(s.span, fluent::lint::suggestion);
|
||||||
}
|
}
|
||||||
lint.emit();
|
lint.emit();
|
||||||
} else {
|
} else {
|
||||||
lint.build("path statement with no effect").emit();
|
lint.build(fluent::lint::path_statement_no_effect).emit();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue