mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 21:23:56 +00:00
Avoid lint to unsized mutable reference
This commit is contained in:
parent
cad0d3d6da
commit
93edc127a0
2 changed files with 26 additions and 7 deletions
|
@ -68,13 +68,15 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
|
|||
expr.span,
|
||||
"generally you want to avoid `&mut &mut _` if possible",
|
||||
);
|
||||
} else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() {
|
||||
span_lint(
|
||||
self.cx,
|
||||
MUT_MUT,
|
||||
expr.span,
|
||||
"this expression mutably borrows a mutable reference. Consider reborrowing",
|
||||
);
|
||||
} else if let ty::Ref(_, ty, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() {
|
||||
if ty.peel_refs().is_sized(self.cx.tcx.at(expr.span), self.cx.param_env) {
|
||||
span_lint(
|
||||
self.cx,
|
||||
MUT_MUT,
|
||||
expr.span,
|
||||
"this expression mutably borrows a mutable reference. Consider reborrowing",
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,3 +57,20 @@ fn issue6922() {
|
|||
// do not lint from an external macro
|
||||
mut_mut!();
|
||||
}
|
||||
|
||||
mod issue9035 {
|
||||
use std::fmt::Display;
|
||||
|
||||
struct Foo<'a> {
|
||||
inner: &'a mut dyn Display,
|
||||
}
|
||||
|
||||
impl Foo<'_> {
|
||||
fn foo(&mut self) {
|
||||
let hlp = &mut self.inner;
|
||||
bar(hlp);
|
||||
}
|
||||
}
|
||||
|
||||
fn bar(_: &mut impl Display) {}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue