fix: Fix type argument mismatch incorrectly triggering on inferred trait args

This commit is contained in:
Lukas Wirth 2025-04-24 07:34:04 +02:00
parent 8fb2dcc947
commit dce59ad8fb
4 changed files with 19 additions and 4 deletions

View file

@ -207,7 +207,7 @@ impl InferenceContext<'_> {
(TypeNs::TraitId(trait_), true) => { (TypeNs::TraitId(trait_), true) => {
let self_ty = self.table.new_type_var(); let self_ty = self.table.new_type_var();
let trait_ref = let trait_ref =
path_ctx.lower_trait_ref_from_resolved_path(trait_, self_ty); path_ctx.lower_trait_ref_from_resolved_path(trait_, self_ty, true);
drop_ctx(ctx, no_diagnostics); drop_ctx(ctx, no_diagnostics);
self.resolve_trait_assoc_item(trait_ref, last_segment, id) self.resolve_trait_assoc_item(trait_ref, last_segment, id)
} }

View file

@ -538,7 +538,7 @@ impl<'a> TyLoweringContext<'a> {
TypeNs::TraitId(tr) => tr, TypeNs::TraitId(tr) => tr,
_ => return None, _ => return None,
}; };
Some((ctx.lower_trait_ref_from_resolved_path(resolved, explicit_self_ty), ctx)) Some((ctx.lower_trait_ref_from_resolved_path(resolved, explicit_self_ty, false), ctx))
} }
fn lower_trait_ref( fn lower_trait_ref(

View file

@ -166,6 +166,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
let trait_ref = self.lower_trait_ref_from_resolved_path( let trait_ref = self.lower_trait_ref_from_resolved_path(
trait_, trait_,
TyKind::Error.intern(Interner), TyKind::Error.intern(Interner),
infer_args,
); );
self.skip_resolved_segment(); self.skip_resolved_segment();
@ -830,8 +831,9 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
&mut self, &mut self,
resolved: TraitId, resolved: TraitId,
explicit_self_ty: Ty, explicit_self_ty: Ty,
infer_args: bool,
) -> TraitRef { ) -> TraitRef {
let substs = self.trait_ref_substs_from_path(resolved, explicit_self_ty); let substs = self.trait_ref_substs_from_path(resolved, explicit_self_ty, infer_args);
TraitRef { trait_id: to_chalk_trait_id(resolved), substitution: substs } TraitRef { trait_id: to_chalk_trait_id(resolved), substitution: substs }
} }
@ -839,8 +841,9 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
&mut self, &mut self,
resolved: TraitId, resolved: TraitId,
explicit_self_ty: Ty, explicit_self_ty: Ty,
infer_args: bool,
) -> Substitution { ) -> Substitution {
self.substs_from_path_segment(resolved.into(), false, Some(explicit_self_ty), false) self.substs_from_path_segment(resolved.into(), infer_args, Some(explicit_self_ty), false)
} }
pub(super) fn assoc_type_bindings_from_type_bound<'c>( pub(super) fn assoc_type_bindings_from_type_bound<'c>(

View file

@ -172,4 +172,16 @@ fn foo<T: Trait<Assoc<i32> = bool>>() {}
"#, "#,
); );
} }
#[test]
fn regression_19669() {
check_diagnostics(
r#"
//- minicore: from
fn main() {
let _: i32 = Into::into(0);
}
"#,
);
}
} }