Don't do post-method-probe error reporting steps if we're in a sugges… · rust-lang/rust@2e4c90c (original) (raw)

`@@ -90,6 +90,11 @@ pub(crate) struct ProbeContext<'a, 'tcx> {

`

90

90

`>,

`

91

91

``

92

92

`scope_expr_id: HirId,

`

``

93

+

``

94

`+

/// Is this probe being done for a diagnostic? This will skip some error reporting

`

``

95

`+

/// machinery, since we don't particularly care about, for example, similarly named

`

``

96

`+

/// candidates if we're reporting similarly named candidates.

`

``

97

`+

is_suggestion: IsSuggestion,

`

93

98

`}

`

94

99

``

95

100

`impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {

`

`@@ -220,7 +225,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

220

225

`/// would use to decide if a method is a plausible fit for

`

221

226

`/// ambiguity purposes).

`

222

227

`#[instrument(level = "debug", skip(self, candidate_filter))]

`

223

``

`-

pub fn probe_for_return_type(

`

``

228

`+

pub fn probe_for_return_type_for_diagnostic(

`

224

229

`&self,

`

225

230

`span: Span,

`

226

231

`mode: Mode,

`

`@@ -459,6 +464,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {

`

459

464

`&orig_values,

`

460

465

` steps.steps,

`

461

466

` scope_expr_id,

`

``

467

`+

is_suggestion,

`

462

468

`);

`

463

469

``

464

470

` probe_cx.assemble_inherent_candidates();

`

`@@ -553,6 +559,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

`

553

559

`orig_steps_var_values: &'a OriginalQueryValues<'tcx>,

`

554

560

`steps: &'tcx [CandidateStep<'tcx>],

`

555

561

`scope_expr_id: HirId,

`

``

562

`+

is_suggestion: IsSuggestion,

`

556

563

`) -> ProbeContext<'a, 'tcx> {

`

557

564

`ProbeContext {

`

558

565

` fcx,

`

`@@ -570,6 +577,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

`

570

577

`static_candidates: RefCell::new(Vec::new()),

`

571

578

`unsatisfied_predicates: RefCell::new(Vec::new()),

`

572

579

` scope_expr_id,

`

``

580

`+

is_suggestion,

`

573

581

`}

`

574

582

`}

`

575

583

``

`@@ -944,6 +952,18 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

`

944

952

`return r;

`

945

953

`}

`

946

954

``

``

955

`` +

// If it's a lookup_probe_for_diagnostic, then quit early. No need to

``

``

956

`+

// probe for other candidates.

`

``

957

`+

if self.is_suggestion.0 {

`

``

958

`+

return Err(MethodError::NoMatch(NoMatchData {

`

``

959

`+

static_candidates: vec![],

`

``

960

`+

unsatisfied_predicates: vec![],

`

``

961

`+

out_of_scope_traits: vec![],

`

``

962

`+

similar_candidate: None,

`

``

963

`+

mode: self.mode,

`

``

964

`+

}));

`

``

965

`+

}

`

``

966

+

947

967

`debug!("pick: actual search failed, assemble diagnostics");

`

948

968

``

949

969

`let static_candidates = std::mem::take(self.static_candidates.get_mut());

`

`@@ -1631,6 +1651,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {

`

1631

1651

`self.orig_steps_var_values,

`

1632

1652

`self.steps,

`

1633

1653

`self.scope_expr_id,

`

``

1654

`+

IsSuggestion(true),

`

1634

1655

`);

`

1635

1656

` pcx.allow_similar_names = true;

`

1636

1657

` pcx.assemble_inherent_candidates();

`