Skip to content

Commit 43436a8

Browse files
committed
PR Feedback; find alternate way to get the appropriate span
1 parent 5b99636 commit 43436a8

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2975,7 +2975,6 @@ 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,
29792978
TraitsInScope,
29802979
|mut ctxt| ctxt.probe_for_similar_candidate(),
29812980
)

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

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

compiler/rustc_hir_typeck/src/method/mod.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
104104
self_ty,
105105
call_expr_id,
106106
ProbeScope::TraitsInScope,
107-
None,
108107
) {
109108
Ok(pick) => {
110109
pick.maybe_emit_unstable_name_collision_hint(
@@ -189,7 +188,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
189188
ProbeScope::TraitsInScope
190189
};
191190

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

194193
self.lint_edition_dependent_dot_call(
195194
self_ty, segment, span, call_expr, self_expr, &pick, args,
@@ -216,7 +215,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
216215
segment.ident,
217216
trait_type,
218217
call_expr,
219-
self_expr,
220218
ProbeScope::TraitsInScope,
221219
) {
222220
Ok(ref new_pick) if pick.differs_from(new_pick) => {
@@ -285,7 +283,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
285283
method_name: Ident,
286284
self_ty: Ty<'tcx>,
287285
call_expr: &hir::Expr<'_>,
288-
self_expr: &hir::Expr<'_>,
289286
scope: ProbeScope,
290287
) -> probe::PickResult<'tcx> {
291288
let pick = self.probe_for_name(
@@ -296,7 +293,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296293
self_ty,
297294
call_expr.hir_id,
298295
scope,
299-
Some(self_expr.span),
300296
)?;
301297

302298
pick.maybe_emit_unstable_name_collision_hint(self.tcx, method_name.span, call_expr.hir_id);
@@ -319,7 +315,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
319315
self_ty,
320316
call_expr.hir_id,
321317
scope,
322-
None,
323318
)?;
324319
Ok(pick)
325320
}
@@ -539,7 +534,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
539534
self_ty,
540535
expr_id,
541536
ProbeScope::TraitsInScope,
542-
Some(self_ty_span),
543537
);
544538
let pick = match (pick, struct_variant) {
545539
// Fall back to a resolution that will produce an error later.

compiler/rustc_hir_typeck/src/method/probe.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ use rustc_attr_parsing::is_doc_alias_attrs_contain_symbol;
77
use rustc_data_structures::fx::FxHashSet;
88
use rustc_data_structures::sso::SsoHashSet;
99
use rustc_errors::Applicability;
10-
use rustc_hir as hir;
11-
use rustc_hir::HirId;
1210
use rustc_hir::def::DefKind;
11+
use rustc_hir::{self as hir, ExprKind, HirId, Node};
1312
use rustc_hir_analysis::autoderef::{self, Autoderef};
1413
use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
1514
use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
@@ -296,7 +295,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
296295
IsSuggestion(true),
297296
self_ty,
298297
scope_expr_id,
299-
None,
300298
ProbeScope::AllTraits,
301299
|probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
302300
)
@@ -312,7 +310,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
312310
IsSuggestion(true),
313311
self_ty,
314312
scope_expr_id,
315-
None,
316313
ProbeScope::AllTraits,
317314
|probe_cx| probe_cx.pick(),
318315
)
@@ -332,7 +329,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
332329
self_ty: Ty<'tcx>,
333330
scope_expr_id: HirId,
334331
scope: ProbeScope,
335-
self_expr_span: Option<Span>,
336332
) -> PickResult<'tcx> {
337333
self.probe_op(
338334
item_name.span,
@@ -342,7 +338,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
342338
is_suggestion,
343339
self_ty,
344340
scope_expr_id,
345-
self_expr_span,
346341
scope,
347342
|probe_cx| probe_cx.pick(),
348343
)
@@ -367,7 +362,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
367362
is_suggestion,
368363
self_ty,
369364
scope_expr_id,
370-
None,
371365
scope,
372366
|probe_cx| {
373367
Ok(probe_cx
@@ -388,7 +382,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
388382
is_suggestion: IsSuggestion,
389383
self_ty: Ty<'tcx>,
390384
scope_expr_id: HirId,
391-
self_expr: Option<Span>,
392385
scope: ProbeScope,
393386
op: OP,
394387
) -> Result<R, MethodError<'tcx>>
@@ -492,12 +485,25 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
492485
let ty = self.resolve_vars_if_possible(ty.value);
493486
let guar = match *ty.kind() {
494487
ty::Infer(ty::TyVar(_)) => {
488+
// We want to get the variable name that the method
489+
// is being called on. If it is a method call.
490+
let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
491+
(
492+
Mode::MethodCall,
493+
Node::Expr(hir::Expr {
494+
kind: ExprKind::MethodCall(_, recv, ..),
495+
..
496+
}),
497+
) => recv.span,
498+
_ => span,
499+
};
500+
495501
let raw_ptr_call = bad_ty.reached_raw_pointer
496502
&& !self.tcx.features().arbitrary_self_types();
497503

498504
let mut err = self.err_ctxt().emit_inference_failure_err(
499505
self.body_id,
500-
self_expr.unwrap_or(span),
506+
err_span,
501507
ty.into(),
502508
TypeAnnotationNeeded::E0282,
503509
!raw_ptr_call,

compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,7 +2114,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
21142114
rcvr_ty,
21152115
expr_id,
21162116
ProbeScope::TraitsInScope,
2117-
None,
21182117
)
21192118
.is_ok()
21202119
})
@@ -3177,7 +3176,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
31773176
deref_ty,
31783177
ty.hir_id,
31793178
ProbeScope::TraitsInScope,
3180-
None,
31813179
) {
31823180
if deref_ty.is_suggestable(self.tcx, true)
31833181
// If this method receives `&self`, then the provided

0 commit comments

Comments
 (0)