Skip to content

Commit a615440

Browse files
smoeliusflip1995
authored andcommitted
Handle ambiguous projections
1 parent d0ae7cf commit a615440

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/tools/clippy/clippy_lints/src/dereference.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1357,10 +1357,10 @@ fn replace_types<'tcx>(
13571357
&& let Some(term_ty) = projection_predicate.term.ty()
13581358
&& let ty::Param(term_param_ty) = term_ty.kind()
13591359
{
1360-
let item_def_id = projection_predicate.projection_ty.def_id;
1361-
let assoc_item = cx.tcx.associated_item(item_def_id);
1362-
let projection = cx.tcx
1363-
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, []));
1360+
let projection = cx.tcx.mk_ty_from_kind(ty::Alias(
1361+
ty::Projection,
1362+
projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty),
1363+
));
13641364

13651365
if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
13661366
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#![allow(dead_code)]
2+
3+
struct Foo;
4+
5+
impl<'a> std::convert::TryFrom<&'a String> for Foo {
6+
type Error = std::convert::Infallible;
7+
8+
fn try_from(_: &'a String) -> Result<Self, Self::Error> {
9+
Ok(Foo)
10+
}
11+
}
12+
13+
fn find<E>(_: impl std::convert::TryInto<Foo, Error = E>) {}
14+
15+
fn main() {
16+
find(&String::new());
17+
}

0 commit comments

Comments
 (0)