Skip to content

Commit f801657

Browse files
authored
Merge pull request rust-lang#19675 from Veykril/push-uuluymsosttr
fix: Fix type argument mismatch incorrectly triggering on inferred trait args
2 parents eed0fd4 + de08212 commit f801657

File tree

5 files changed

+29
-12
lines changed

5 files changed

+29
-12
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/infer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1675,7 +1675,7 @@ impl<'a> InferenceContext<'a> {
16751675
// `lower_partly_resolved_path()` returns `None` as type namespace unless
16761676
// `remaining_segments` is empty, which is never the case here. We don't know
16771677
// which namespace the new `ty` is in until normalized anyway.
1678-
(ty, _) = path_ctx.lower_partly_resolved_path(resolution, false);
1678+
(ty, _) = path_ctx.lower_partly_resolved_path(resolution, true);
16791679
tried_resolving_once = true;
16801680

16811681
ty = self.table.insert_type_vars(ty);

src/tools/rust-analyzer/crates/hir-ty/src/infer/path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl InferenceContext<'_> {
177177
let ty = self.table.normalize_associated_types_in(ty);
178178

179179
path_ctx.ignore_last_segment();
180-
let (ty, _) = path_ctx.lower_ty_relative_path(ty, orig_ns);
180+
let (ty, _) = path_ctx.lower_ty_relative_path(ty, orig_ns, true);
181181
drop_ctx(ctx, no_diagnostics);
182182
let ty = self.table.insert_type_vars(ty);
183183
let ty = self.table.normalize_associated_types_in(ty);
@@ -207,7 +207,7 @@ impl InferenceContext<'_> {
207207
(TypeNs::TraitId(trait_), true) => {
208208
let self_ty = self.table.new_type_var();
209209
let trait_ref =
210-
path_ctx.lower_trait_ref_from_resolved_path(trait_, self_ty);
210+
path_ctx.lower_trait_ref_from_resolved_path(trait_, self_ty, true);
211211
drop_ctx(ctx, no_diagnostics);
212212
self.resolve_trait_assoc_item(trait_ref, last_segment, id)
213213
}

src/tools/rust-analyzer/crates/hir-ty/src/lower.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ impl<'a> TyLoweringContext<'a> {
506506
if let Some(type_ref) = path.type_anchor() {
507507
let (ty, res) = self.lower_ty_ext(type_ref);
508508
let mut ctx = self.at_path(path_id);
509-
return ctx.lower_ty_relative_path(ty, res);
509+
return ctx.lower_ty_relative_path(ty, res, false);
510510
}
511511

512512
let mut ctx = self.at_path(path_id);
@@ -536,7 +536,7 @@ impl<'a> TyLoweringContext<'a> {
536536
TypeNs::TraitId(tr) => tr,
537537
_ => return None,
538538
};
539-
Some((ctx.lower_trait_ref_from_resolved_path(resolved, explicit_self_ty), ctx))
539+
Some((ctx.lower_trait_ref_from_resolved_path(resolved, explicit_self_ty, false), ctx))
540540
}
541541

542542
fn lower_trait_ref(

src/tools/rust-analyzer/crates/hir-ty/src/lower/path.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,13 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
137137
ty: Ty,
138138
// We need the original resolution to lower `Self::AssocTy` correctly
139139
res: Option<TypeNs>,
140+
infer_args: bool,
140141
) -> (Ty, Option<TypeNs>) {
141142
match self.segments.len() - self.current_segment_idx {
142143
0 => (ty, res),
143144
1 => {
144145
// resolve unselected assoc types
145-
(self.select_associated_type(res), None)
146+
(self.select_associated_type(res, infer_args), None)
146147
}
147148
_ => {
148149
// FIXME report error (ambiguous associated type)
@@ -166,6 +167,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
166167
let trait_ref = self.lower_trait_ref_from_resolved_path(
167168
trait_,
168169
TyKind::Error.intern(Interner),
170+
infer_args,
169171
);
170172

171173
self.skip_resolved_segment();
@@ -181,7 +183,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
181183
// this point (`trait_ref.substitution`).
182184
let substitution = self.substs_from_path_segment(
183185
associated_ty.into(),
184-
false,
186+
infer_args,
185187
None,
186188
true,
187189
);
@@ -276,7 +278,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
276278
};
277279

278280
self.skip_resolved_segment();
279-
self.lower_ty_relative_path(ty, Some(resolution))
281+
self.lower_ty_relative_path(ty, Some(resolution), infer_args)
280282
}
281283

282284
fn handle_type_ns_resolution(&mut self, resolution: &TypeNs) {
@@ -472,7 +474,7 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
472474
Some(res)
473475
}
474476

475-
fn select_associated_type(&mut self, res: Option<TypeNs>) -> Ty {
477+
fn select_associated_type(&mut self, res: Option<TypeNs>, infer_args: bool) -> Ty {
476478
let Some(res) = res else {
477479
return TyKind::Error.intern(Interner);
478480
};
@@ -506,7 +508,8 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
506508
// generic params. It's inefficient to splice the `Substitution`s, so we may want
507509
// that method to optionally take parent `Substitution` as we already know them at
508510
// this point (`t.substitution`).
509-
let substs = self.substs_from_path_segment(associated_ty.into(), false, None, true);
511+
let substs =
512+
self.substs_from_path_segment(associated_ty.into(), infer_args, None, true);
510513

511514
let substs = Substitution::from_iter(
512515
Interner,
@@ -830,17 +833,19 @@ impl<'a, 'b> PathLoweringContext<'a, 'b> {
830833
&mut self,
831834
resolved: TraitId,
832835
explicit_self_ty: Ty,
836+
infer_args: bool,
833837
) -> TraitRef {
834-
let substs = self.trait_ref_substs_from_path(resolved, explicit_self_ty);
838+
let substs = self.trait_ref_substs_from_path(resolved, explicit_self_ty, infer_args);
835839
TraitRef { trait_id: to_chalk_trait_id(resolved), substitution: substs }
836840
}
837841

838842
fn trait_ref_substs_from_path(
839843
&mut self,
840844
resolved: TraitId,
841845
explicit_self_ty: Ty,
846+
infer_args: bool,
842847
) -> Substitution {
843-
self.substs_from_path_segment(resolved.into(), false, Some(explicit_self_ty), false)
848+
self.substs_from_path_segment(resolved.into(), infer_args, Some(explicit_self_ty), false)
844849
}
845850

846851
pub(super) fn assoc_type_bindings_from_type_bound<'c>(

src/tools/rust-analyzer/crates/ide-diagnostics/src/handlers/incorrect_generics_len.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,16 @@ fn foo<T: Trait<Assoc<i32> = bool>>() {}
172172
"#,
173173
);
174174
}
175+
176+
#[test]
177+
fn regression_19669() {
178+
check_diagnostics(
179+
r#"
180+
//- minicore: from
181+
fn main() {
182+
let _: i32 = Into::into(0);
183+
}
184+
"#,
185+
);
186+
}
175187
}

0 commit comments

Comments
 (0)