Correctly set infer_args = true in more places

Previously this being incorrect wasn't a problem, it just meant we put an error type that then changed to infer type, so exactly what rustc does at the end. But now there is a diagnostic.
This commit is contained in:
Chayim Refael Friedman 2025-04-24 09:06:04 +03:00 committed by Lukas Wirth
parent cd064e764d
commit de082127d8
4 changed files with 10 additions and 8 deletions

View file

@ -1675,7 +1675,7 @@ impl<'a> InferenceContext<'a> {
// `lower_partly_resolved_path()` returns `None` as type namespace unless
// `remaining_segments` is empty, which is never the case here. We don't know
// which namespace the new `ty` is in until normalized anyway.
(ty, _) = path_ctx.lower_partly_resolved_path(resolution, false);
(ty, _) = path_ctx.lower_partly_resolved_path(resolution, true);
tried_resolving_once = true;
ty = self.table.insert_type_vars(ty);

View file

@ -177,7 +177,7 @@ impl InferenceContext<'_> {
let ty = self.table.normalize_associated_types_in(ty);
path_ctx.ignore_last_segment();
let (ty, _) = path_ctx.lower_ty_relative_path(ty, orig_ns);
let (ty, _) = path_ctx.lower_ty_relative_path(ty, orig_ns, true);
drop_ctx(ctx, no_diagnostics);
let ty = self.table.insert_type_vars(ty);
let ty = self.table.normalize_associated_types_in(ty);

View file

@ -508,7 +508,7 @@ impl<'a> TyLoweringContext<'a> {
if let Some(type_ref) = path.type_anchor() {
let (ty, res) = self.lower_ty_ext(type_ref);
let mut ctx = self.at_path(path_id);
return ctx.lower_ty_relative_path(ty, res);
return ctx.lower_ty_relative_path(ty, res, false);
}
let mut ctx = self.at_path(path_id);

View file

@ -137,12 +137,13 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
ty: Ty,
// We need the original resolution to lower `Self::AssocTy` correctly
res: Option<TypeNs>,
infer_args: bool,
) -> (Ty, Option<TypeNs>) {
match self.segments.len() - self.current_segment_idx {
0 => (ty, res),
1 => {
// resolve unselected assoc types
(self.select_associated_type(res), None)
(self.select_associated_type(res, infer_args), None)
}
_ => {
// FIXME report error (ambiguous associated type)
@ -182,7 +183,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
// this point (`trait_ref.substitution`).
let substitution = self.substs_from_path_segment(
associated_ty.into(),
false,
infer_args,
None,
true,
);
@ -277,7 +278,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
};
self.skip_resolved_segment();
self.lower_ty_relative_path(ty, Some(resolution))
self.lower_ty_relative_path(ty, Some(resolution), infer_args)
}
fn handle_type_ns_resolution(&mut self, resolution: &TypeNs) {
@ -473,7 +474,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
Some(res)
}
fn select_associated_type(&mut self, res: Option<TypeNs>) -> Ty {
fn select_associated_type(&mut self, res: Option<TypeNs>, infer_args: bool) -> Ty {
let Some(res) = res else {
return TyKind::Error.intern(Interner);
};
@ -507,7 +508,8 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
// generic params. It's inefficient to splice the `Substitution`s, so we may want
// that method to optionally take parent `Substitution` as we already know them at
// this point (`t.substitution`).
let substs = self.substs_from_path_segment(associated_ty.into(), false, None, true);
let substs =
self.substs_from_path_segment(associated_ty.into(), infer_args, None, true);
let substs = Substitution::from_iter(
Interner,