Fix substitution bug

This commit is contained in:
León Orell Valerian Liehr 2023-02-17 18:42:47 +01:00
parent 6065867a7e
commit 77ea90ec71
No known key found for this signature in database
GPG key ID: D17A07215F68E713
7 changed files with 67 additions and 19 deletions

View file

@ -225,7 +225,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
pub(crate) fn complain_about_ambiguous_inherent_assoc_type(
&self,
name: Ident,
candidates: Vec<(DefId, DefId)>,
candidates: Vec<DefId>,
span: Span,
) -> ErrorGuaranteed {
let mut err = struct_span_err!(
@ -243,7 +243,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
fn note_ambiguous_inherent_assoc_type(
&self,
err: &mut Diagnostic,
candidates: Vec<(DefId, DefId)>,
candidates: Vec<DefId>,
span: Span,
) {
let tcx = self.tcx();
@ -251,11 +251,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// Dynamic limit to avoid hiding just one candidate, which is silly.
let limit = if candidates.len() == 5 { 5 } else { 4 };
for (index, &(assoc_item, _)) in candidates.iter().take(limit).enumerate() {
let impl_ = tcx.impl_of_method(assoc_item).unwrap();
for (index, &item) in candidates.iter().take(limit).enumerate() {
let impl_ = tcx.impl_of_method(item).unwrap();
let note_span = if assoc_item.is_local() {
Some(tcx.def_span(assoc_item))
let note_span = if item.is_local() {
Some(tcx.def_span(item))
} else if impl_.is_local() {
Some(tcx.def_span(impl_))
} else {

View file

@ -2267,7 +2267,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
return None;
}
Some((assoc_item, def_scope))
// FIXME(fmease): Unsolved vars can escape this InferCtxt snapshot.
Some((assoc_item, def_scope, infcx.resolve_vars_if_possible(impl_substs)))
})
})
.collect();
@ -2275,23 +2276,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
if applicable_candidates.len() > 1 {
return Err(self.complain_about_ambiguous_inherent_assoc_type(
name,
applicable_candidates,
applicable_candidates.into_iter().map(|(candidate, ..)| candidate).collect(),
span,
));
}
if let Some((assoc_item, def_scope)) = applicable_candidates.pop() {
if let Some((assoc_item, def_scope, impl_substs)) = applicable_candidates.pop() {
self.check_assoc_ty(assoc_item, name, def_scope, block, span);
let ty::Adt(_, adt_substs) = self_ty.kind() else {
bug!("unreachable: `lookup_inherent_assoc_ty` is only called on ADTs");
};
// FIXME(inherent_associated_types): To fully *confirm* the *probed* candidate,
// we still need to register region obligations for regionck to prove/disprove.
let item_substs = self.create_substs_for_associated_item(
span, assoc_item, segment,
// FIXME(fmease, #107468, #105305): Don't use `adt_substs` here but `impl_substs`.
adt_substs,
);
let item_substs =
self.create_substs_for_associated_item(span, assoc_item, segment, impl_substs);
// FIXME(fmease, #106722): Check if the bounds on the parameters of the
// associated type hold, if any.