Skip to content

Commit 5b1e445

Browse files
committed
Don't lint explicit_auto_deref when the target type is a projection containing a generic argument
1 parent 213003b commit 5b1e445

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

clippy_lints/src/dereference.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,7 @@ fn ty_auto_deref_stability<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>, precedenc
13621362
continue;
13631363
},
13641364
ty::Param(_) => TyPosition::new_deref_stable_for_result(precedence, ty),
1365+
ty::Projection(_) if ty.has_non_region_param() => TyPosition::new_deref_stable_for_result(precedence, ty),
13651366
ty::Infer(_) | ty::Error(_) | ty::Bound(..) | ty::Opaque(..) | ty::Placeholder(_) | ty::Dynamic(..) => {
13661367
Position::ReborrowStable(precedence).into()
13671368
},

tests/ui/explicit_auto_deref.fixed

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,15 @@ fn main() {
266266
}
267267
x
268268
};
269+
270+
trait WithAssoc {
271+
type Assoc: ?Sized;
272+
}
273+
impl WithAssoc for String {
274+
type Assoc = str;
275+
}
276+
fn takes_assoc<T: WithAssoc>(_: &T::Assoc) -> T {
277+
unimplemented!()
278+
}
279+
let _: String = takes_assoc(&*String::new());
269280
}

tests/ui/explicit_auto_deref.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,15 @@ fn main() {
266266
}
267267
*x
268268
};
269+
270+
trait WithAssoc {
271+
type Assoc: ?Sized;
272+
}
273+
impl WithAssoc for String {
274+
type Assoc = str;
275+
}
276+
fn takes_assoc<T: WithAssoc>(_: &T::Assoc) -> T {
277+
unimplemented!()
278+
}
279+
let _: String = takes_assoc(&*String::new());
269280
}

0 commit comments

Comments
 (0)