Skip to content

Commit

Permalink
Auto merge of rust-lang#10403 - smoelius:fix-107877, r=Jarcho
Browse files Browse the repository at this point in the history
Fix rust-lang#107877, etc.

Fix rust-lang#10009
Fix rust-lang#10387
Fix rust-lang#107877

The fix is to verify that the associated item's trait is implemented before trying to project the item's type.

r? `@Jarcho`

---

changelog: ICE: [`needless_borrow`]: No longer panics on ambiguous projections
[rust-lang#10403](rust-lang/rust-clippy#10403)
<!-- changelog_checked -->
  • Loading branch information
bors committed Mar 5, 2023
2 parents 78f0f78 + f95d9de commit 70e85d1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clippy_lints/src/dereference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,10 +1357,10 @@ fn replace_types<'tcx>(
&& let Some(term_ty) = projection_predicate.term.ty()
&& let ty::Param(term_param_ty) = term_ty.kind()
{
let item_def_id = projection_predicate.projection_ty.def_id;
let assoc_item = cx.tcx.associated_item(item_def_id);
let projection = cx.tcx
.mk_projection(assoc_item.def_id, cx.tcx.mk_substs_trait(new_ty, []));
let projection = cx.tcx.mk_ty(ty::Alias(
ty::Projection,
projection_predicate.projection_ty.with_self_ty(cx.tcx, new_ty),
));

if let Ok(projected_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, projection)
&& substs[term_param_ty.index as usize] != ty::GenericArg::from(projected_ty)
Expand Down
17 changes: 17 additions & 0 deletions tests/ui/crashes/ice-rust-107877.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#![allow(dead_code)]

struct Foo;

impl<'a> std::convert::TryFrom<&'a String> for Foo {
type Error = std::convert::Infallible;

fn try_from(_: &'a String) -> Result<Self, Self::Error> {
Ok(Foo)
}
}

fn find<E>(_: impl std::convert::TryInto<Foo, Error = E>) {}

fn main() {
find(&String::new());
}

0 comments on commit 70e85d1

Please sign in to comment.