Auto merge of #9835 - koka831:fix/9035, r=Alexendoo
Avoid linting unsized mutable reference fix https://github.com/rust-lang/rust-clippy/issues/9035 changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
This commit is contained in:
commit
9f283c97e1
@ -68,7 +68,8 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
|||||||
expr.span,
|
expr.span,
|
||||||
"generally you want to avoid `&mut &mut _` if possible",
|
"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() {
|
} 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(
|
span_lint(
|
||||||
self.cx,
|
self.cx,
|
||||||
MUT_MUT,
|
MUT_MUT,
|
||||||
@ -78,6 +79,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'_>) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
fn visit_ty(&mut self, ty: &'tcx hir::Ty<'_>) {
|
||||||
if in_external_macro(self.cx.sess(), ty.span) {
|
if in_external_macro(self.cx.sess(), ty.span) {
|
||||||
|
@ -57,3 +57,20 @@ fn issue6922() {
|
|||||||
// do not lint from an external macro
|
// do not lint from an external macro
|
||||||
mut_mut!();
|
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 New Issue
Block a user