diff options
| author | Samuel Moelius <sam@moeli.us> | 2023-02-25 15:54:31 -0500 |
|---|---|---|
| committer | Philipp Krones <hello@philkrones.com> | 2023-04-13 11:18:44 +0200 |
| commit | a615440643f7dc1816926d637f0f43cdf9fc38b6 (patch) | |
| tree | 5bec6df1656f37a579097f18f179f9bcf24dba03 | |
| parent | d0ae7cf62d540027e6e6289c61ed2f8452bbd3ba (diff) | |
| download | rust-a615440643f7dc1816926d637f0f43cdf9fc38b6.tar.gz rust-a615440643f7dc1816926d637f0f43cdf9fc38b6.zip | |
Handle ambiguous projections
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/dereference.rs | 8 | ||||
| -rw-r--r-- | src/tools/clippy/tests/ui/crashes/ice-rust-107877.rs | 17 |
2 files changed, 21 insertions, 4 deletions
diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 47501980e66..7f3f26bed7c 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -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_from_kind(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) diff --git a/src/tools/clippy/tests/ui/crashes/ice-rust-107877.rs b/src/tools/clippy/tests/ui/crashes/ice-rust-107877.rs new file mode 100644 index 00000000000..7f5bae60d55 --- /dev/null +++ b/src/tools/clippy/tests/ui/crashes/ice-rust-107877.rs @@ -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()); +} |
