Skip to content

Commit 9f283c9

Browse files
committed
Auto merge of #9835 - koka831:fix/9035, r=Alexendoo
Avoid linting unsized mutable reference fix #9035 changelog: [`mut_mut`] avoid suggesting to reborrow unsized mutable reference
2 parents bb326e7 + 93edc12 commit 9f283c9

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

clippy_lints/src/mut_mut.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for MutVisitor<'a, 'tcx> {
6868
expr.span,
6969
"generally you want to avoid `&mut &mut _` if possible",
7070
);
71-
} else if let ty::Ref(_, _, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() {
72-
span_lint(
73-
self.cx,
74-
MUT_MUT,
75-
expr.span,
76-
"this expression mutably borrows a mutable reference. Consider reborrowing",
77-
);
71+
} else if let ty::Ref(_, ty, hir::Mutability::Mut) = self.cx.typeck_results().expr_ty(e).kind() {
72+
if ty.peel_refs().is_sized(self.cx.tcx.at(expr.span), self.cx.param_env) {
73+
span_lint(
74+
self.cx,
75+
MUT_MUT,
76+
expr.span,
77+
"this expression mutably borrows a mutable reference. Consider reborrowing",
78+
);
79+
}
7880
}
7981
}
8082
}

tests/ui/mut_mut.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,20 @@ fn issue6922() {
5757
// do not lint from an external macro
5858
mut_mut!();
5959
}
60+
61+
mod issue9035 {
62+
use std::fmt::Display;
63+
64+
struct Foo<'a> {
65+
inner: &'a mut dyn Display,
66+
}
67+
68+
impl Foo<'_> {
69+
fn foo(&mut self) {
70+
let hlp = &mut self.inner;
71+
bar(hlp);
72+
}
73+
}
74+
75+
fn bar(_: &mut impl Display) {}
76+
}

0 commit comments

Comments
 (0)