Skip to content

Commit 58dfe26

Browse files
committed
CandidateSource::XCandidate -> CandidateSource::X
1 parent ec667fb commit 58dfe26

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;
@@ -692,7 +692,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
692692
for item in self.impl_or_trait_item(impl_def_id) {
693693
if !self.has_applicable_self(&item) {
694694
// No receiver declared. Not a candidate.
695-
self.record_static_candidate(ImplSource(impl_def_id));
695+
self.record_static_candidate(CandidateSource::Impl(impl_def_id));
696696
continue;
697697
}
698698

@@ -846,7 +846,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
846846
debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
847847
for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
848848
if !self.has_applicable_self(&item) {
849-
self.record_static_candidate(TraitSource(bound_trait_ref.def_id()));
849+
self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
850850
} else {
851851
mk_cand(self, bound_trait_ref, item);
852852
}
@@ -944,7 +944,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
944944
// Check whether `trait_def_id` defines a method with suitable name.
945945
if !self.has_applicable_self(&item) {
946946
debug!("method has inapplicable self");
947-
self.record_static_candidate(TraitSource(trait_def_id));
947+
self.record_static_candidate(CandidateSource::Trait(trait_def_id));
948948
continue;
949949
}
950950

@@ -1016,8 +1016,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
10161016
Some(Err(MethodError::Ambiguity(v))) => v
10171017
.into_iter()
10181018
.map(|source| match source {
1019-
TraitSource(id) => id,
1020-
ImplSource(impl_id) => match tcx.trait_id_of_impl(impl_id) {
1019+
CandidateSource::Trait(id) => id,
1020+
CandidateSource::Impl(impl_id) => match tcx.trait_id_of_impl(impl_id) {
10211021
Some(id) => id,
10221022
None => span_bug!(span, "found inherent method when looking at traits"),
10231023
},
@@ -1415,8 +1415,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14151415

14161416
fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
14171417
match candidate.kind {
1418-
InherentImplCandidate(..) => ImplSource(candidate.item.container.id()),
1419-
ObjectCandidate | WhereClauseCandidate(_) => TraitSource(candidate.item.container.id()),
1418+
InherentImplCandidate(..) => CandidateSource::Impl(candidate.item.container.id()),
1419+
ObjectCandidate | WhereClauseCandidate(_) => {
1420+
CandidateSource::Trait(candidate.item.container.id())
1421+
}
14201422
TraitCandidate(trait_ref) => self.probe(|_| {
14211423
let _ = self
14221424
.at(&ObligationCause::dummy(), self.param_env)
@@ -1426,9 +1428,9 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
14261428
Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
14271429
// If only a single impl matches, make the error message point
14281430
// to that impl.
1429-
ImplSource(impl_data.impl_def_id)
1431+
CandidateSource::Impl(impl_data.impl_def_id)
14301432
}
1431-
_ => TraitSource(candidate.item.container.id()),
1433+
_ => CandidateSource::Trait(candidate.item.container.id()),
14321434
}
14331435
}),
14341436
}

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)