lint: port unused allocation diagnostics

Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
David Wood 2022-06-28 10:43:38 +01:00
parent e24833869f
commit 4f7b10f484
2 changed files with 8 additions and 7 deletions

View File

@ -283,3 +283,6 @@ lint-unused-delim = unnecessary {$delim} around {$item}
.suggestion = remove these {$delim}
lint-unused-import-braces = braces around {$node} is unnecessary
lint-unused-allocation = unnecessary allocation, use `&` instead
lint-unused-allocation-mut = unnecessary allocation, use `&mut` instead

View File

@ -1169,15 +1169,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
for adj in cx.typeck_results().expr_adjustments(e) {
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
cx.struct_span_lint(UNUSED_ALLOCATION, e.span, |lint| {
let msg = match m {
adjustment::AutoBorrowMutability::Not => {
"unnecessary allocation, use `&` instead"
}
lint.build(match m {
adjustment::AutoBorrowMutability::Not => fluent::lint::unused_allocation,
adjustment::AutoBorrowMutability::Mut { .. } => {
"unnecessary allocation, use `&mut` instead"
fluent::lint::unused_allocation_mut
}
};
lint.build(msg).emit();
})
.emit();
});
}
}