From 88d2fbc9a8d0e7666badcc4a95f62dcffa2844e8 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Mon, 7 Oct 2024 16:49:36 +0200 Subject: [PATCH] Don't crash on GATs in trait solving --- frontend/exporter/src/traits.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/frontend/exporter/src/traits.rs b/frontend/exporter/src/traits.rs index 5ab9c943d..6553fe247 100644 --- a/frontend/exporter/src/traits.rs +++ b/frontend/exporter/src/traits.rs @@ -236,6 +236,7 @@ pub mod rustc { // FIXME: this has visibility `pub(crate)` only because of https://github.com/rust-lang/rust/issues/83049 pub(crate) mod search_clause { use super::{AnnotatedTraitPred, Path, PathChunk}; + use itertools::Itertools; use rustc_hir::def_id::DefId; use rustc_middle::ty::*; @@ -423,18 +424,14 @@ pub mod rustc { if let TyKind::Alias(AliasTyKind::Projection, alias_ty) = target.self_ty().skip_binder().kind() { - let (trait_ref, _gat_args) = alias_ty.trait_ref_and_own_args(tcx); - let trait_ref = target.self_ty().rebind(trait_ref); + let trait_ref = target.rebind(alias_ty.trait_ref(tcx)); // Recursively look up the trait ref inside `self`. let trait_candidate = self.lookup(trait_ref)?.clone(); let item_bounds = tcx + // TODO: `item_bounds` can contain parent traits, we don't want them .item_bounds(alias_ty.def_id) - // This `skip_binder` is for GATs. TODO: instantiate properly - .skip_binder() + .instantiate(tcx, alias_ty.args) .iter() - // Substitute with the `trait_ref` args so that the clause makes sense in - // the current context. - .map(|clause| clause.instantiate_supertrait(tcx, trait_ref)) .filter_map(|pred| pred.as_trait_clause()) .enumerate(); // Add all the bounds on the corresponding associated item. @@ -453,6 +450,13 @@ pub mod rustc { })); } + tracing::trace!( + "Looking for {target:?} in: [\n{}\n]", + self.candidates + .iter() + .map(|c| format!(" {c:?}\n")) + .join("") + ); for candidate in &self.candidates { if predicate_equality(tcx, candidate.pred, target, self.param_env) { return Some(candidate);