Skip to content

Commit b3c3eda

Browse files
authored
Rollup merge of #95642 - lcnr:probe-smol, r=compiler-errors
`CandidateSource::XCandidate` -> `CandidateSource::X`
2 parents 5b8ac2d + 58dfe26 commit b3c3eda

File tree

3 files changed

+33
-33
lines changed

3 files changed

+33
-33
lines changed

compiler/rustc_typeck/src/check/method/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ pub mod probe;
88
mod suggest;
99

1010
pub use self::suggest::SelfSource;
11-
pub use self::CandidateSource::*;
1211
pub use self::MethodError::*;
1312

1413
use crate::check::FnCtxt;
@@ -82,8 +81,8 @@ pub struct NoMatchData<'tcx> {
8281
// candidate can arise. Used for error reporting only.
8382
#[derive(Copy, Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
8483
pub enum CandidateSource {
85-
ImplSource(DefId),
86-
TraitSource(DefId /* trait id */),
84+
Impl(DefId),
85+
Trait(DefId /* trait id */),
8786
}
8887

8988
impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
@@ -237,8 +236,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
237236
match *source {
238237
// Note: this cannot come from an inherent impl,
239238
// because the first probing succeeded.
240-
ImplSource(def) => self.tcx.trait_id_of_impl(def),
241-
TraitSource(_) => None,
239+
CandidateSource::Impl(def) => self.tcx.trait_id_of_impl(def),
240+
CandidateSource::Trait(_) => None,
242241
}
243242
})
244243
.collect(),

compiler/rustc_typeck/src/check/method/probe.rs

+12-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::suggest;
2+
use super::CandidateSource;
23
use super::MethodError;
34
use super::NoMatchData;
4-
use super::{CandidateSource, ImplSource, TraitSource};
55

66
use crate::check::FnCtxt;
77
use crate::errors::MethodCallOnUnknownType;
@@ -694,7 +694,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
694694
for item in self.impl_or_trait_item(impl_def_id) {
695695
if !self.has_applicable_self(&item) {
696696
// No receiver declared. Not a candidate.
697-
self.record_static_candidate(ImplSource(impl_def_id));
697+
self.record_static_candidate(CandidateSource::Impl(impl_def_id));
698698
continue;
699699
}
700700

@@ -848,7 +848,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
848848
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
849849
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
850850
if !self.has_applicable_self(&item) {
851-
self.record_static_candidate(TraitSource(bound_trait_ref.def_id()));
851+
self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
852852
} else {
853853
mk_cand(self, bound_trait_ref, item);
854854
}
@@ -946,7 +946,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
946946
// Check whether `trait_def_id` defines a method with suitable name.
947947
if !self.has_applicable_self(&item) {
948948
debug!("method has inapplicable self");
949-
self.record_static_candidate(TraitSource(trait_def_id));
949+
self.record_static_candidate(CandidateSource::Trait(trait_def_id));
950950
continue;
951951
}
952952

@@ -1018,8 +1018,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10181018
Some(Err(MethodError::Ambiguity(v))) => v
10191019
.into_iter()
10201020
.map(|source| match source {
1021-
TraitSource(id) => id,
1022-
ImplSource(impl_id) => match tcx.trait_id_of_impl(impl_id) {
1021+
CandidateSource::Trait(id) => id,
1022+
CandidateSource::Impl(impl_id) => match tcx.trait_id_of_impl(impl_id) {
10231023
Some(id) => id,
10241024
None => span_bug!(span, "found inherent method when looking at traits"),
10251025
},
@@ -1417,8 +1417,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14171417

14181418
fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
14191419
match candidate.kind {
1420-
InherentImplCandidate(..) => ImplSource(candidate.item.container.id()),
1421-
ObjectCandidate | WhereClauseCandidate(_) => TraitSource(candidate.item.container.id()),
1420+
InherentImplCandidate(..) => CandidateSource::Impl(candidate.item.container.id()),
1421+
ObjectCandidate | WhereClauseCandidate(_) => {
1422+
CandidateSource::Trait(candidate.item.container.id())
1423+
}
14221424
TraitCandidate(trait_ref) => self.probe(|_| {
14231425
let _ = self
14241426
.at(&ObligationCause::dummy(), self.param_env)
@@ -1428,9 +1430,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14281430
Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
14291431
// If only a single impl matches, make the error message point
14301432
// to that impl.
1431-
ImplSource(impl_data.impl_def_id)
1433+
CandidateSource::Impl(impl_data.impl_def_id)
14321434
}
1433-
_ => TraitSource(candidate.item.container.id()),
1435+
_ => CandidateSource::Trait(candidate.item.container.id()),
14341436
}
14351437
}),
14361438
}

compiler/rustc_typeck/src/check/method/suggest.rs

+17-18
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
110110

111111
for (idx, source) in sources.iter().take(limit).enumerate() {
112112
match *source {
113-
CandidateSource::ImplSource(impl_did) => {
113+
CandidateSource::Impl(impl_did) => {
114114
// Provide the best span we can. Use the item, if local to crate, else
115115
// the impl, if local to crate (item may be defaulted), else nothing.
116116
let Some(item) = self.associated_value(impl_did, item_name).or_else(|| {
@@ -193,7 +193,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
193193
);
194194
}
195195
}
196-
CandidateSource::TraitSource(trait_did) => {
196+
CandidateSource::Trait(trait_did) => {
197197
let Some(item) = self.associated_value(trait_did, item_name) else { continue };
198198
let item_span = self
199199
.tcx
@@ -515,23 +515,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
515515
custom_span_label = true;
516516
}
517517
if static_sources.len() == 1 {
518-
let ty_str = if let Some(CandidateSource::ImplSource(impl_did)) =
519-
static_sources.get(0)
520-
{
521-
// When the "method" is resolved through dereferencing, we really want the
522-
// original type that has the associated function for accurate suggestions.
523-
// (#61411)
524-
let ty = tcx.at(span).type_of(*impl_did);
525-
match (&ty.peel_refs().kind(), &actual.peel_refs().kind()) {
526-
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
527-
// Use `actual` as it will have more `substs` filled in.
528-
self.ty_to_value_string(actual.peel_refs())
518+
let ty_str =
519+
if let Some(CandidateSource::Impl(impl_did)) = static_sources.get(0) {
520+
// When the "method" is resolved through dereferencing, we really want the
521+
// original type that has the associated function for accurate suggestions.
522+
// (#61411)
523+
let ty = tcx.at(span).type_of(*impl_did);
524+
match (&ty.peel_refs().kind(), &actual.peel_refs().kind()) {
525+
(ty::Adt(def, _), ty::Adt(def_actual, _)) if def == def_actual => {
526+
// Use `actual` as it will have more `substs` filled in.
527+
self.ty_to_value_string(actual.peel_refs())
528+
}
529+
_ => self.ty_to_value_string(ty.peel_refs()),
529530
}
530-
_ => self.ty_to_value_string(ty.peel_refs()),
531-
}
532-
} else {
533-
self.ty_to_value_string(actual.peel_refs())
534-
};
531+
} else {
532+
self.ty_to_value_string(actual.peel_refs())
533+
};
535534
if let SelfSource::MethodCall(expr) = source {
536535
err.span_suggestion(
537536
expr.span.to(span),

0 commit comments

Comments
 (0)