lint: port unused allocation diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
This commit is contained in:
parent
e24833869f
commit
4f7b10f484
2 changed files with 8 additions and 7 deletions
|
@ -283,3 +283,6 @@ lint-unused-delim = unnecessary {$delim} around {$item}
|
||||||
.suggestion = remove these {$delim}
|
.suggestion = remove these {$delim}
|
||||||
|
|
||||||
lint-unused-import-braces = braces around {$node} is unnecessary
|
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
|
||||||
|
|
|
@ -1169,15 +1169,13 @@ impl<'tcx> LateLintPass<'tcx> for UnusedAllocation {
|
||||||
for adj in cx.typeck_results().expr_adjustments(e) {
|
for adj in cx.typeck_results().expr_adjustments(e) {
|
||||||
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
|
if let adjustment::Adjust::Borrow(adjustment::AutoBorrow::Ref(_, m)) = adj.kind {
|
||||||
cx.struct_span_lint(UNUSED_ALLOCATION, e.span, |lint| {
|
cx.struct_span_lint(UNUSED_ALLOCATION, e.span, |lint| {
|
||||||
let msg = match m {
|
lint.build(match m {
|
||||||
adjustment::AutoBorrowMutability::Not => {
|
adjustment::AutoBorrowMutability::Not => fluent::lint::unused_allocation,
|
||||||
"unnecessary allocation, use `&` instead"
|
|
||||||
}
|
|
||||||
adjustment::AutoBorrowMutability::Mut { .. } => {
|
adjustment::AutoBorrowMutability::Mut { .. } => {
|
||||||
"unnecessary allocation, use `&mut` instead"
|
fluent::lint::unused_allocation_mut
|
||||||
}
|
}
|
||||||
};
|
})
|
||||||
lint.build(msg).emit();
|
.emit();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue