Don't lint exlipicit_auto_deref when other adjustments are needed

This commit is contained in:
Jason Newcomb 2022-07-17 11:12:25 -04:00
parent 84e03b6215
commit d602ab1445
3 changed files with 31 additions and 1 deletions

View file

@ -357,7 +357,11 @@ impl<'tcx> LateLintPass<'tcx> for Dereferencing {
}),
StateData { span: expr.span, hir_id: expr.hir_id, position },
));
} else if position.is_deref_stable() {
} else if position.is_deref_stable()
// Auto-deref doesn't combine with other adjustments
&& next_adjust.map_or(true, |a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
&& iter.all(|a| matches!(a.kind, Adjust::Deref(_) | Adjust::Borrow(_)))
{
self.state = Some((
State::Borrow { mutability },
StateData {

View file

@ -242,4 +242,17 @@ fn main() {
fn ret_any(x: &Box<dyn std::any::Any>) -> &dyn std::any::Any {
&**x
}
let x = String::new();
let _: *const str = &*x;
struct S7([u32; 1]);
impl core::ops::Deref for S7 {
type Target = [u32; 1];
fn deref(&self) -> &Self::Target {
&self.0
}
}
let x = S7([0]);
let _: &[u32] = &*x;
}

View file

@ -242,4 +242,17 @@ fn main() {
fn ret_any(x: &Box<dyn std::any::Any>) -> &dyn std::any::Any {
&**x
}
let x = String::new();
let _: *const str = &*x;
struct S7([u32; 1]);
impl core::ops::Deref for S7 {
type Target = [u32; 1];
fn deref(&self) -> &Self::Target {
&self.0
}
}
let x = S7([0]);
let _: &[u32] = &*x;
}