Skip to content

Commit 5b99636

Browse files
committed
Fix; correct placement of type inference error for method calls
1 parent 1a3cdd3 commit 5b99636

22 files changed

+56
-44
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2975,6 +2975,7 @@ impl<'a, 'b, 'tcx> ArgsCtxt<'a, 'b, 'tcx> {
29752975
IsSuggestion(true),
29762976
callee_ty.peel_refs(),
29772977
self.call_ctxt.callee_expr.unwrap().hir_id,
2978+
None,
29782979
TraitsInScope,
29792980
|mut ctxt| ctxt.probe_for_similar_candidate(),
29802981
)

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,6 +1794,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17941794
self_ty,
17951795
expr.hir_id,
17961796
ProbeScope::TraitsInScope,
1797+
Some(expr.span),
17971798
)
17981799
{
17991800
(pick.item, segment)

compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
104104
self_ty,
105105
call_expr_id,
106106
ProbeScope::TraitsInScope,
107+
None,
107108
) {
108109
Ok(pick) => {
109110
pick.maybe_emit_unstable_name_collision_hint(
@@ -188,7 +189,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
188189
ProbeScope::TraitsInScope
189190
};
190191

191-
let pick = self.lookup_probe(segment.ident, self_ty, call_expr, scope)?;
192+
let pick = self.lookup_probe(segment.ident, self_ty, call_expr, self_expr, scope)?;
192193

193194
self.lint_edition_dependent_dot_call(
194195
self_ty, segment, span, call_expr, self_expr, &pick, args,
@@ -215,6 +216,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
215216
segment.ident,
216217
trait_type,
217218
call_expr,
219+
self_expr,
218220
ProbeScope::TraitsInScope,
219221
) {
220222
Ok(ref new_pick) if pick.differs_from(new_pick) => {
@@ -283,6 +285,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
283285
method_name: Ident,
284286
self_ty: Ty<'tcx>,
285287
call_expr: &hir::Expr<'_>,
288+
self_expr: &hir::Expr<'_>,
286289
scope: ProbeScope,
287290
) -> probe::PickResult<'tcx> {
288291
let pick = self.probe_for_name(
@@ -293,7 +296,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
293296
self_ty,
294297
call_expr.hir_id,
295298
scope,
299+
Some(self_expr.span),
296300
)?;
301+
297302
pick.maybe_emit_unstable_name_collision_hint(self.tcx, method_name.span, call_expr.hir_id);
298303
Ok(pick)
299304
}
@@ -314,6 +319,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
314319
self_ty,
315320
call_expr.hir_id,
316321
scope,
322+
None,
317323
)?;
318324
Ok(pick)
319325
}
@@ -533,6 +539,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
533539
self_ty,
534540
expr_id,
535541
ProbeScope::TraitsInScope,
542+
Some(self_ty_span),
536543
);
537544
let pick = match (pick, struct_variant) {
538545
// Fall back to a resolution that will produce an error later.

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296296
IsSuggestion(true),
297297
self_ty,
298298
scope_expr_id,
299+
None,
299300
ProbeScope::AllTraits,
300301
|probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
301302
)
@@ -311,6 +312,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
311312
IsSuggestion(true),
312313
self_ty,
313314
scope_expr_id,
315+
None,
314316
ProbeScope::AllTraits,
315317
|probe_cx| probe_cx.pick(),
316318
)
@@ -330,6 +332,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
330332
self_ty: Ty<'tcx>,
331333
scope_expr_id: HirId,
332334
scope: ProbeScope,
335+
self_expr_span: Option<Span>,
333336
) -> PickResult<'tcx> {
334337
self.probe_op(
335338
item_name.span,
@@ -339,6 +342,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339342
is_suggestion,
340343
self_ty,
341344
scope_expr_id,
345+
self_expr_span,
342346
scope,
343347
|probe_cx| probe_cx.pick(),
344348
)
@@ -363,6 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
363367
is_suggestion,
364368
self_ty,
365369
scope_expr_id,
370+
None,
366371
scope,
367372
|probe_cx| {
368373
Ok(probe_cx
@@ -383,6 +388,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
383388
is_suggestion: IsSuggestion,
384389
self_ty: Ty<'tcx>,
385390
scope_expr_id: HirId,
391+
self_expr: Option<Span>,
386392
scope: ProbeScope,
387393
op: OP,
388394
) -> Result<R, MethodError<'tcx>>
@@ -488,11 +494,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
488494
ty::Infer(ty::TyVar(_)) => {
489495
let raw_ptr_call = bad_ty.reached_raw_pointer
490496
&& !self.tcx.features().arbitrary_self_types();
491-
// FIXME: Ideally we'd use the span of the self-expr here,
492-
// not of the method path.
497+
493498
let mut err = self.err_ctxt().emit_inference_failure_err(
494499
self.body_id,
495-
span,
500+
self_expr.unwrap_or(span),
496501
ty.into(),
497502
TypeAnnotationNeeded::E0282,
498503
!raw_ptr_call,

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21142114
rcvr_ty,
21152115
expr_id,
21162116
ProbeScope::TraitsInScope,
2117+
None,
21172118
)
21182119
.is_ok()
21192120
})
@@ -3176,6 +3177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31763177
deref_ty,
31773178
ty.hir_id,
31783179
ProbeScope::TraitsInScope,
3180+
None,
31793181
) {
31803182
if deref_ty.is_suggestable(self.tcx, true)
31813183
// If this method receives `&self`, then the provided

tests/ui/autoref-autoderef/deref-ambiguity-becomes-nonambiguous.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let var_fn = Value::wrap();
55
| ^^^^^^
66
...
77
LL | let _ = var_fn.clone();
8-
| ----- type must be known at this point
8+
| ------ type must be known at this point
99
|
1010
help: consider giving `var_fn` an explicit type, where the placeholders `_` are specified
1111
|

tests/ui/closures/deduce-signature/obligation-with-leaking-placeholders.next.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | needs_foo(|x| {
55
| ^
66
...
77
LL | x.to_string();
8-
| --------- type must be known at this point
8+
| - type must be known at this point
99
|
1010
help: consider giving this closure parameter an explicit type
1111
|

tests/ui/impl-trait/hidden-type-is-opaque-2.default.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| {
55
| ^^^^^^^^
66
LL |
77
LL | cont.reify_as();
8-
| -------- type must be known at this point
8+
| ---- type must be known at this point
99
|
1010
help: consider giving this closure parameter an explicit type
1111
|
@@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| {
1919
| ^^^^^^^^
2020
LL |
2121
LL | cont.reify_as();
22-
| -------- type must be known at this point
22+
| ---- type must be known at this point
2323
|
2424
help: consider giving this closure parameter an explicit type
2525
|

tests/ui/impl-trait/hidden-type-is-opaque-2.next.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | Thunk::new(|mut cont| {
55
| ^^^^^^^^
66
LL |
77
LL | cont.reify_as();
8-
| -------- type must be known at this point
8+
| ---- type must be known at this point
99
|
1010
help: consider giving this closure parameter an explicit type
1111
|
@@ -19,7 +19,7 @@ LL | Thunk::new(|mut cont| {
1919
| ^^^^^^^^
2020
LL |
2121
LL | cont.reify_as();
22-
| -------- type must be known at this point
22+
| ---- type must be known at this point
2323
|
2424
help: consider giving this closure parameter an explicit type
2525
|

tests/ui/inference/need_type_info/incompat-call-after-qualified-path-0.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0282]: type annotations needed
22
--> $DIR/incompat-call-after-qualified-path-0.rs:21:6
33
|
44
LL | f(|a, b| a.cmp(b));
5-
| ^ --- type must be known at this point
5+
| ^ - type must be known at this point
66
|
77
help: consider giving this closure parameter an explicit type
88
|

0 commit comments

Comments
 (0)