1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::debug_assert_matches;
4use std::ops::Deref;
5
6use rustc_data_structures::fx::FxHashSet;
7use rustc_data_structures::sso::SsoHashSet;
8use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
9use rustc_hir::def::DefKind;
10use rustc_hir::{self as hir, ExprKind, HirId, Node, find_attr};
11use rustc_hir_analysis::autoderef::{self, Autoderef};
12use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
13use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
14use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
15use rustc_lint::builtin::METHOD_CALL_ON_DIVERGING_INFER_VAR;
16use rustc_macros::Diagnostic;
17use rustc_middle::middle::stability;
18use rustc_middle::ty::elaborate::supertrait_def_ids;
19use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
20use rustc_middle::ty::{
21 self, AssocContainer, AssocItem, GenericArgs, GenericArgsRef, GenericParamDefKind, ParamEnvAnd,
22 Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
23};
24use rustc_middle::{bug, span_bug};
25use rustc_session::lint;
26use rustc_span::def_id::{DefId, LocalDefId};
27use rustc_span::edit_distance::{
28 edit_distance_with_substrings, find_best_match_for_name_with_substrings,
29};
30use rustc_span::{DUMMY_SP, Ident, Span, Symbol};
31use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
32use rustc_trait_selection::infer::InferCtxtExt as _;
33use rustc_trait_selection::solve::Goal;
34use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
35use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
36use rustc_trait_selection::traits::query::method_autoderef::{
37 CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
38};
39use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
40use smallvec::SmallVec;
41use tracing::{debug, instrument};
42
43use self::CandidateKind::*;
44pub(crate) use self::PickKind::*;
45use super::{CandidateSource, MethodError, NoMatchData, suggest};
46use crate::FnCtxt;
47
48#[derive(#[automatically_derived]
impl ::core::clone::Clone for IsSuggestion {
#[inline]
fn clone(&self) -> IsSuggestion {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IsSuggestion { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for IsSuggestion {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "IsSuggestion",
&&self.0)
}
}Debug)]
51pub(crate) struct IsSuggestion(pub bool);
52
53pub(crate) struct ProbeContext<'a, 'tcx> {
54 fcx: &'a FnCtxt<'a, 'tcx>,
55 span: Span,
56 mode: Mode,
57 method_name: Option<Ident>,
58 return_type: Option<Ty<'tcx>>,
59
60 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
63 steps: &'tcx [CandidateStep<'tcx>],
64
65 inherent_candidates: Vec<Candidate<'tcx>>,
66 extension_candidates: Vec<Candidate<'tcx>>,
67 impl_dups: FxHashSet<DefId>,
68
69 allow_similar_names: bool,
72
73 private_candidates: Vec<Candidate<'tcx>>,
76
77 private_candidate: Cell<Option<(DefKind, DefId)>>,
79
80 static_candidates: RefCell<Vec<CandidateSource>>,
83
84 scope_expr_id: HirId,
85
86 is_suggestion: IsSuggestion,
90
91 self_ty_override: Option<Ty<'tcx>>,
99}
100
101impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
102 type Target = FnCtxt<'a, 'tcx>;
103 fn deref(&self) -> &Self::Target {
104 self.fcx
105 }
106}
107
108#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Candidate<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "Candidate",
"item", &self.item, "kind", &self.kind, "import_ids",
&&self.import_ids)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Candidate<'tcx> {
#[inline]
fn clone(&self) -> Candidate<'tcx> {
Candidate {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
}
}
}Clone)]
109pub(crate) struct Candidate<'tcx> {
110 pub(crate) item: ty::AssocItem,
111 pub(crate) kind: CandidateKind<'tcx>,
112 pub(crate) import_ids: &'tcx [LocalDefId],
113}
114
115#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CandidateKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
CandidateKind::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InherentImplCandidate", "impl_def_id", __self_0,
"receiver_steps", &__self_1),
CandidateKind::ObjectCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ObjectCandidate", &__self_0),
CandidateKind::TraitCandidate(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"TraitCandidate", __self_0, &__self_1),
CandidateKind::WhereClauseCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WhereClauseCandidate", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for CandidateKind<'tcx> {
#[inline]
fn clone(&self) -> CandidateKind<'tcx> {
match self {
CandidateKind::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
CandidateKind::InherentImplCandidate {
impl_def_id: ::core::clone::Clone::clone(__self_0),
receiver_steps: ::core::clone::Clone::clone(__self_1),
},
CandidateKind::ObjectCandidate(__self_0) =>
CandidateKind::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
CandidateKind::TraitCandidate(__self_0, __self_1) =>
CandidateKind::TraitCandidate(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1)),
CandidateKind::WhereClauseCandidate(__self_0) =>
CandidateKind::WhereClauseCandidate(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
116pub(crate) enum CandidateKind<'tcx> {
117 InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
118 ObjectCandidate(ty::PolyTraitRef<'tcx>),
119 TraitCandidate(ty::PolyTraitRef<'tcx>, bool ),
120 WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
121}
122
123#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ProbeResult {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ProbeResult::NoMatch => "NoMatch",
ProbeResult::BadReturnType => "BadReturnType",
ProbeResult::Match => "Match",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for ProbeResult {
#[inline]
fn eq(&self, other: &ProbeResult) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ProbeResult {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for ProbeResult { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ProbeResult {
#[inline]
fn clone(&self) -> ProbeResult { *self }
}Clone)]
124enum ProbeResult {
125 NoMatch,
126 BadReturnType,
127 Match,
128}
129
130#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AutorefOrPtrAdjustment {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AutorefOrPtrAdjustment::Autoref {
mutbl: __self_0, unsize: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Autoref", "mutbl", __self_0, "unsize", &__self_1),
AutorefOrPtrAdjustment::ToConstPtr =>
::core::fmt::Formatter::write_str(f, "ToConstPtr"),
AutorefOrPtrAdjustment::ReborrowPin(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ReborrowPin", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for AutorefOrPtrAdjustment {
#[inline]
fn eq(&self, other: &AutorefOrPtrAdjustment) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AutorefOrPtrAdjustment::Autoref {
mutbl: __self_0, unsize: __self_1 },
AutorefOrPtrAdjustment::Autoref {
mutbl: __arg1_0, unsize: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(AutorefOrPtrAdjustment::ReborrowPin(__self_0),
AutorefOrPtrAdjustment::ReborrowPin(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::marker::Copy for AutorefOrPtrAdjustment { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AutorefOrPtrAdjustment {
#[inline]
fn clone(&self) -> AutorefOrPtrAdjustment {
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
*self
}
}Clone)]
143pub(crate) enum AutorefOrPtrAdjustment {
144 Autoref {
147 mutbl: hir::Mutability,
148
149 unsize: bool,
152 },
153 ToConstPtr,
155
156 ReborrowPin(hir::Mutability),
158}
159
160impl AutorefOrPtrAdjustment {
161 fn get_unsize(&self) -> bool {
162 match self {
163 AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
164 AutorefOrPtrAdjustment::ToConstPtr => false,
165 AutorefOrPtrAdjustment::ReborrowPin(_) => false,
166 }
167 }
168}
169
170#[derive(#[automatically_derived]
impl<'a, 'tcx> ::core::fmt::Debug for PickDiagHints<'a, 'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "PickDiagHints",
"unstable_candidates", &self.unstable_candidates,
"unsatisfied_predicates", &&self.unsatisfied_predicates)
}
}Debug)]
172struct PickDiagHints<'a, 'tcx> {
173 unstable_candidates: Option<Vec<(Candidate<'tcx>, Symbol)>>,
175
176 unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'tcx>,
179}
180
181pub(crate) type UnsatisfiedPredicates<'tcx> =
182 Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>;
183
184#[derive(#[automatically_derived]
impl ::core::fmt::Debug for PickConstraintsForShadowed {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f,
"PickConstraintsForShadowed", "autoderefs", &self.autoderefs,
"receiver_steps", &self.receiver_steps, "def_id", &&self.def_id)
}
}Debug)]
188struct PickConstraintsForShadowed {
189 autoderefs: usize,
190 receiver_steps: Option<usize>,
191 def_id: DefId,
192}
193
194impl PickConstraintsForShadowed {
195 fn may_shadow_based_on_autoderefs(&self, autoderefs: usize) -> bool {
196 autoderefs == self.autoderefs
197 }
198
199 fn candidate_may_shadow(&self, candidate: &Candidate<'_>) -> bool {
200 candidate.item.def_id != self.def_id
202 && match candidate.kind {
206 CandidateKind::InherentImplCandidate { receiver_steps, .. } => match self.receiver_steps {
207 Some(shadowed_receiver_steps) => receiver_steps > shadowed_receiver_steps,
208 _ => false
209 },
210 _ => false
211 }
212 }
213}
214
215#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Pick<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["item", "kind", "import_ids", "autoderefs",
"autoref_or_ptr_adjustment", "self_ty",
"unstable_candidates", "receiver_steps",
"shadowed_candidates"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.item, &self.kind, &self.import_ids, &self.autoderefs,
&self.autoref_or_ptr_adjustment, &self.self_ty,
&self.unstable_candidates, &self.receiver_steps,
&&self.shadowed_candidates];
::core::fmt::Formatter::debug_struct_fields_finish(f, "Pick", names,
values)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Pick<'tcx> {
#[inline]
fn clone(&self) -> Pick<'tcx> {
Pick {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
autoderefs: ::core::clone::Clone::clone(&self.autoderefs),
autoref_or_ptr_adjustment: ::core::clone::Clone::clone(&self.autoref_or_ptr_adjustment),
self_ty: ::core::clone::Clone::clone(&self.self_ty),
unstable_candidates: ::core::clone::Clone::clone(&self.unstable_candidates),
receiver_steps: ::core::clone::Clone::clone(&self.receiver_steps),
shadowed_candidates: ::core::clone::Clone::clone(&self.shadowed_candidates),
}
}
}Clone)]
216pub(crate) struct Pick<'tcx> {
217 pub item: ty::AssocItem,
218 pub kind: PickKind<'tcx>,
219 pub import_ids: &'tcx [LocalDefId],
220
221 pub autoderefs: usize,
226
227 pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
230 pub self_ty: Ty<'tcx>,
231
232 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
234
235 pub receiver_steps: Option<usize>,
239
240 pub shadowed_candidates: Vec<ty::AssocItem>,
242}
243
244#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for PickKind<'tcx> {
#[inline]
fn clone(&self) -> PickKind<'tcx> {
match self {
PickKind::InherentImplPick => PickKind::InherentImplPick,
PickKind::ObjectPick => PickKind::ObjectPick,
PickKind::TraitPick(__self_0) =>
PickKind::TraitPick(::core::clone::Clone::clone(__self_0)),
PickKind::WhereClausePick(__self_0) =>
PickKind::WhereClausePick(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PickKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
PickKind::InherentImplPick =>
::core::fmt::Formatter::write_str(f, "InherentImplPick"),
PickKind::ObjectPick =>
::core::fmt::Formatter::write_str(f, "ObjectPick"),
PickKind::TraitPick(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TraitPick", &__self_0),
PickKind::WhereClausePick(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WhereClausePick", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for PickKind<'tcx> {
#[inline]
fn eq(&self, other: &PickKind<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(PickKind::TraitPick(__self_0), PickKind::TraitPick(__arg1_0))
=> __self_0 == __arg1_0,
(PickKind::WhereClausePick(__self_0),
PickKind::WhereClausePick(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for PickKind<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitRef<'tcx>>;
}
}Eq)]
245pub(crate) enum PickKind<'tcx> {
246 InherentImplPick,
247 ObjectPick,
248 TraitPick(
249 bool,
251 ),
252 WhereClausePick(
253 ty::PolyTraitRef<'tcx>,
255 ),
256}
257
258pub(crate) type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
259
260#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for Mode {
#[inline]
fn eq(&self, other: &Mode) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Mode {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for Mode { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Mode {
#[inline]
fn clone(&self) -> Mode { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Mode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Mode::MethodCall => "MethodCall",
Mode::Path => "Path",
})
}
}Debug)]
261pub(crate) enum Mode {
262 MethodCall,
266 Path,
270}
271
272#[derive(#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ProbeScope<'tcx> {
#[inline]
fn eq(&self, other: &ProbeScope<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ProbeScope::Single(__self_0, __self_1),
ProbeScope::Single(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ProbeScope<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProbeScope<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ProbeScope::Single(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Single",
__self_0, &__self_1),
ProbeScope::TraitsInScope =>
::core::fmt::Formatter::write_str(f, "TraitsInScope"),
ProbeScope::AllTraits =>
::core::fmt::Formatter::write_str(f, "AllTraits"),
}
}
}Debug)]
273pub(crate) enum ProbeScope<'tcx> {
274 Single(DefId, Option<Ty<'tcx>> ),
276
277 TraitsInScope,
279
280 AllTraits,
282}
283
284impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
285 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_return_type_for_diagnostic",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(291u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("span")
}> =
::tracing::__macro_support::FieldName::new("span");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mode")
}> =
::tracing::__macro_support::FieldName::new("mode");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return_type")
}> =
::tracing::__macro_support::FieldName::new("return_type");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope_expr_id")
}> =
::tracing::__macro_support::FieldName::new("scope_expr_id");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Vec<ty::AssocItem> = loop {};
return __tracing_attr_fake_return;
}
{
let method_names =
self.probe_op(span, mode, None, Some(return_type),
IsSuggestion(true), self_ty, scope_expr_id,
ProbeScope::AllTraits,
|probe_cx|
Ok(probe_cx.candidate_method_names(candidate_filter))).unwrap_or_default();
method_names.iter().flat_map(|&method_name|
{
self.probe_op(span, mode, Some(method_name),
Some(return_type), IsSuggestion(true), self_ty,
scope_expr_id, ProbeScope::AllTraits,
|probe_cx| probe_cx.pick()).ok().map(|pick| pick.item)
}).collect()
}
}
}#[instrument(level = "debug", skip(self, candidate_filter))]
292 pub(crate) fn probe_for_return_type_for_diagnostic(
293 &self,
294 span: Span,
295 mode: Mode,
296 return_type: Ty<'tcx>,
297 self_ty: Ty<'tcx>,
298 scope_expr_id: HirId,
299 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
300 ) -> Vec<ty::AssocItem> {
301 let method_names = self
302 .probe_op(
303 span,
304 mode,
305 None,
306 Some(return_type),
307 IsSuggestion(true),
308 self_ty,
309 scope_expr_id,
310 ProbeScope::AllTraits,
311 |probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
312 )
313 .unwrap_or_default();
314 method_names
315 .iter()
316 .flat_map(|&method_name| {
317 self.probe_op(
318 span,
319 mode,
320 Some(method_name),
321 Some(return_type),
322 IsSuggestion(true),
323 self_ty,
324 scope_expr_id,
325 ProbeScope::AllTraits,
326 |probe_cx| probe_cx.pick(),
327 )
328 .ok()
329 .map(|pick| pick.item)
330 })
331 .collect()
332 }
333
334 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_name",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(334u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mode")
}> =
::tracing::__macro_support::FieldName::new("mode");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_name")
}> =
::tracing::__macro_support::FieldName::new("item_name");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return_type")
}> =
::tracing::__macro_support::FieldName::new("return_type");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_suggestion")
}> =
::tracing::__macro_support::FieldName::new("is_suggestion");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope_expr_id")
}> =
::tracing::__macro_support::FieldName::new("scope_expr_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope")
}> =
::tracing::__macro_support::FieldName::new("scope");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: PickResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
self.probe_op(item_name.span, mode, Some(item_name), return_type,
is_suggestion, self_ty, scope_expr_id, scope,
|probe_cx| probe_cx.pick())
}
}
}#[instrument(level = "debug", skip(self))]
335 pub(crate) fn probe_for_name(
336 &self,
337 mode: Mode,
338 item_name: Ident,
339 return_type: Option<Ty<'tcx>>,
340 is_suggestion: IsSuggestion,
341 self_ty: Ty<'tcx>,
342 scope_expr_id: HirId,
343 scope: ProbeScope<'tcx>,
344 ) -> PickResult<'tcx> {
345 self.probe_op(
346 item_name.span,
347 mode,
348 Some(item_name),
349 return_type,
350 is_suggestion,
351 self_ty,
352 scope_expr_id,
353 scope,
354 |probe_cx| probe_cx.pick(),
355 )
356 }
357
358 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_name_many",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(358u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mode")
}> =
::tracing::__macro_support::FieldName::new("mode");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_name")
}> =
::tracing::__macro_support::FieldName::new("item_name");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return_type")
}> =
::tracing::__macro_support::FieldName::new("return_type");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_suggestion")
}> =
::tracing::__macro_support::FieldName::new("is_suggestion");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope_expr_id")
}> =
::tracing::__macro_support::FieldName::new("scope_expr_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope")
}> =
::tracing::__macro_support::FieldName::new("scope");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
self.probe_op(item_name.span, mode, Some(item_name), return_type,
is_suggestion, self_ty, scope_expr_id, scope,
|probe_cx|
{
Ok(probe_cx.inherent_candidates.into_iter().chain(probe_cx.extension_candidates).collect())
})
}
}
}#[instrument(level = "debug", skip(self))]
359 pub(crate) fn probe_for_name_many(
360 &self,
361 mode: Mode,
362 item_name: Ident,
363 return_type: Option<Ty<'tcx>>,
364 is_suggestion: IsSuggestion,
365 self_ty: Ty<'tcx>,
366 scope_expr_id: HirId,
367 scope: ProbeScope<'tcx>,
368 ) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
369 self.probe_op(
370 item_name.span,
371 mode,
372 Some(item_name),
373 return_type,
374 is_suggestion,
375 self_ty,
376 scope_expr_id,
377 scope,
378 |probe_cx| {
379 Ok(probe_cx
380 .inherent_candidates
381 .into_iter()
382 .chain(probe_cx.extension_candidates)
383 .collect())
384 },
385 )
386 }
387
388 pub(crate) fn probe_op<OP, R>(
389 &'a self,
390 span: Span,
391 mode: Mode,
392 method_name: Option<Ident>,
393 return_type: Option<Ty<'tcx>>,
394 is_suggestion: IsSuggestion,
395 self_ty: Ty<'tcx>,
396 scope_expr_id: HirId,
397 scope: ProbeScope<'tcx>,
398 op: OP,
399 ) -> Result<R, MethodError<'tcx>>
400 where
401 OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
402 {
403 #[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MissingTypeAnnot where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MissingTypeAnnot => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type annotations needed")));
;
diag
}
}
}
}
};Diagnostic)]
404 #[diag("type annotations needed")]
405 struct MissingTypeAnnot;
406
407 #[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MethodCallOnDivergingInferenceVariable where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MethodCallOnDivergingInferenceVariable => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method call on a diverging inference variable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider providing a type annotation")));
;
diag
}
}
}
}
};Diagnostic)]
408 #[diag("method call on a diverging inference variable")]
409 #[help("consider providing a type annotation")]
410 struct MethodCallOnDivergingInferenceVariable;
411
412 let mut orig_values = OriginalQueryValues::default();
413 let predefined_opaques_in_body = if self.next_trait_solver() {
414 self.tcx.mk_predefined_opaques_in_body_from_iter(
415 self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
416 )
417 } else {
418 ty::List::empty()
419 };
420 let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
421 let query_input = self
422 .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
423
424 let steps = match mode {
425 Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
426 Mode::Path => self.probe(|_| {
427 let infcx = &self.infcx;
433 let (ParamEnvAnd { param_env: _, value }, var_values) =
434 infcx.instantiate_canonical(span, &query_input.canonical);
435 let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
436 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:436",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(436u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("query_input")
}> =
::tracing::__macro_support::FieldName::new("query_input");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("probe_op: Mode::Path")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_input)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
437 let prev_opaque_entries = self.inner.borrow_mut().opaque_types().num_entries();
438 MethodAutoderefStepsResult {
439 steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
440 self_ty: self.make_query_response_ignoring_pending_obligations(
441 var_values,
442 self_ty,
443 prev_opaque_entries,
444 ),
445 self_ty_is_opaque: false,
446 autoderefs: 0,
447 from_unsafe_deref: false,
448 unsize: false,
449 reachable_via_deref: true,
450 }]),
451 opt_bad_ty: None,
452 reached_recursion_limit: false,
453 }
454 }),
455 };
456
457 if steps.reached_recursion_limit && !is_suggestion.0 {
461 self.probe(|_| {
462 let ty = &steps
463 .steps
464 .last()
465 .unwrap_or_else(|| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("reached the recursion limit in 0 steps?"))span_bug!(span, "reached the recursion limit in 0 steps?"))
466 .self_ty;
467 let ty = self
468 .probe_instantiate_query_response(span, &orig_values, ty)
469 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
470 autoderef::report_autoderef_recursion_limit_error(self.tcx, span, ty.value);
471 });
472 }
473
474 if let Some(bad_ty) = &steps.opt_bad_ty {
477 let ty = &bad_ty.ty;
481 let ty = self
482 .probe_instantiate_query_response(span, &orig_values, ty)
483 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
484 let ty = ty.value;
485
486 if is_suggestion.0 {
487 return Err(MethodError::NoMatch(NoMatchData {
490 static_candidates: Vec::new(),
491 unsatisfied_predicates: Vec::new(),
492 out_of_scope_traits: Vec::new(),
493 similar_candidate: None,
494 mode,
495 }));
496 } else if bad_ty.reached_raw_pointer
497 && !self.tcx.features().arbitrary_self_types_pointers()
498 && !self.tcx.sess.at_least_rust_2018()
499 {
500 self.tcx.emit_node_span_lint(
504 lint::builtin::TYVAR_BEHIND_RAW_POINTER,
505 scope_expr_id,
506 span,
507 MissingTypeAnnot,
508 );
509 } else if let ty::Infer(ty::TyVar(ty_id)) = *ty.kind()
513 && let ty_id = self.sub_unification_table_root_var(ty_id)
514 && self
515 .diverging_type_vars
516 .borrow()
517 .iter()
518 .any(|&candidate_id| self.sub_unification_table_root_var(candidate_id) == ty_id)
519 {
520 self.tcx.emit_node_span_lint(
521 METHOD_CALL_ON_DIVERGING_INFER_VAR,
522 scope_expr_id,
523 span,
524 MethodCallOnDivergingInferenceVariable,
525 );
526 let root_ty = Ty::new_var(self.tcx, ty_id);
527 self.demand_eqtype(span, root_ty, self.tcx.types.never);
528 } else {
529 let guar = match *ty.kind() {
530 _ if let Some(guar) = self.tainted_by_errors() => guar,
531 ty::Infer(ty::TyVar(_)) => {
532 let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
535 (
536 Mode::MethodCall,
537 Node::Expr(hir::Expr {
538 kind: ExprKind::MethodCall(_, recv, ..),
539 ..
540 }),
541 ) => recv.span,
542 _ => span,
543 };
544
545 let raw_ptr_call = bad_ty.reached_raw_pointer
546 && !self.tcx.features().arbitrary_self_types();
547
548 let mut err = self.err_ctxt().emit_inference_failure_err(
549 self.body_def_id,
550 err_span,
551 ty.into(),
552 TypeAnnotationNeeded::E0282,
553 !raw_ptr_call,
554 );
555 if raw_ptr_call {
556 err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
557 }
558 err.emit()
559 }
560 ty::Error(guar) => guar,
561 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected bad final type in method autoderef"))bug!("unexpected bad final type in method autoderef"),
562 };
563 self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
564 return Err(MethodError::ErrorReported(guar));
565 }
566 }
567
568 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:568",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(568u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ProbeContext: steps for self_ty={0:?} are {1:?}",
self_ty, steps) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("ProbeContext: steps for self_ty={:?} are {:?}", self_ty, steps);
569
570 self.probe(|_| {
573 let mut probe_cx = ProbeContext::new(
574 self,
575 span,
576 mode,
577 method_name,
578 return_type,
579 &orig_values,
580 steps.steps,
581 scope_expr_id,
582 is_suggestion,
583 );
584
585 match scope {
586 ProbeScope::TraitsInScope => {
587 probe_cx.assemble_inherent_candidates();
588 probe_cx.assemble_extension_candidates_for_traits_in_scope();
589 }
590 ProbeScope::AllTraits => {
591 probe_cx.assemble_inherent_candidates();
592 probe_cx.assemble_extension_candidates_for_all_traits();
593 }
594 ProbeScope::Single(def_id, self_ty_override) => {
595 let item = self.tcx.associated_item(def_id);
596 {
match (&item.container, &AssocContainer::Trait) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};assert_eq!(item.container, AssocContainer::Trait);
598
599 let trait_def_id = self.tcx.parent(def_id);
600 let trait_span = self.tcx.def_span(trait_def_id);
601
602 let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
603 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
604
605 probe_cx.self_ty_override = self_ty_override;
606 probe_cx.push_candidate(
607 Candidate {
608 item,
609 kind: CandidateKind::TraitCandidate(
610 ty::Binder::dummy(trait_ref),
611 false,
612 ),
613 import_ids: &[],
614 },
615 false,
616 );
617 }
618 };
619 op(probe_cx)
620 })
621 }
622}
623
624pub(crate) fn method_autoderef_steps<'tcx>(
625 tcx: TyCtxt<'tcx>,
626 goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
627) -> MethodAutoderefStepsResult<'tcx> {
628 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:628",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(628u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps({0:?})",
goal) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("method_autoderef_steps({:?})", goal);
629
630 let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
631 let ParamEnvAnd {
632 param_env,
633 value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
634 } = goal;
635 for (key, ty) in predefined_opaques_in_body {
636 let prev = infcx
637 .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
638 if let Some(prev) = prev {
650 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:650",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(650u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("key")
}> =
::tracing::__macro_support::FieldName::new("key");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("prev")
}> =
::tracing::__macro_support::FieldName::new("prev");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&key)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
651 }
652 }
653 let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
654
655 let self_ty_is_opaque = |ty: Ty<'_>| {
659 if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
660 infcx.has_opaques_with_sub_unified_hidden_type(vid)
661 } else {
662 false
663 }
664 };
665
666 let mut autoderef_via_deref =
676 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
677 .include_raw_pointers()
678 .silence_errors();
679
680 let mut reached_raw_pointer = false;
681 let arbitrary_self_types_enabled =
682 tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
683 let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
684 let reachable_via_deref =
685 autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
686
687 let mut autoderef_via_receiver =
688 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
689 .include_raw_pointers()
690 .use_receiver_trait()
691 .silence_errors();
692 let steps = autoderef_via_receiver
693 .by_ref()
694 .zip(reachable_via_deref)
695 .map(|((ty, d), reachable_via_deref)| {
696 let step = CandidateStep {
697 self_ty: infcx.make_query_response_ignoring_pending_obligations(
698 inference_vars,
699 ty,
700 prev_opaque_entries,
701 ),
702 self_ty_is_opaque: self_ty_is_opaque(ty),
703 autoderefs: d,
704 from_unsafe_deref: reached_raw_pointer,
705 unsize: false,
706 reachable_via_deref,
707 };
708 if ty.is_raw_ptr() {
709 reached_raw_pointer = true;
711 }
712 step
713 })
714 .collect();
715 (steps, autoderef_via_receiver.reached_recursion_limit())
716 } else {
717 let steps = autoderef_via_deref
718 .by_ref()
719 .map(|(ty, d)| {
720 let step = CandidateStep {
721 self_ty: infcx.make_query_response_ignoring_pending_obligations(
722 inference_vars,
723 ty,
724 prev_opaque_entries,
725 ),
726 self_ty_is_opaque: self_ty_is_opaque(ty),
727 autoderefs: d,
728 from_unsafe_deref: reached_raw_pointer,
729 unsize: false,
730 reachable_via_deref: true,
731 };
732 if ty.is_raw_ptr() {
733 reached_raw_pointer = true;
735 }
736 step
737 })
738 .collect();
739 (steps, autoderef_via_deref.reached_recursion_limit())
740 };
741 let final_ty = autoderef_via_deref.final_ty();
742 let opt_bad_ty = match final_ty.kind() {
743 ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
744 reached_raw_pointer,
745 ty: infcx.make_query_response_ignoring_pending_obligations(
746 inference_vars,
747 final_ty,
748 prev_opaque_entries,
749 ),
750 }),
751 ty::Error(_) => Some(MethodAutoderefBadTy {
752 reached_raw_pointer,
753 ty: infcx.make_query_response_ignoring_pending_obligations(
754 inference_vars,
755 final_ty,
756 prev_opaque_entries,
757 ),
758 }),
759 ty::Array(elem_ty, _) => {
760 let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
761 steps.push(CandidateStep {
762 self_ty: infcx.make_query_response_ignoring_pending_obligations(
763 inference_vars,
764 Ty::new_slice(infcx.tcx, *elem_ty),
765 prev_opaque_entries,
766 ),
767 self_ty_is_opaque: false,
768 autoderefs,
769 from_unsafe_deref: reached_raw_pointer,
772 unsize: true,
773 reachable_via_deref: true, });
776
777 None
778 }
779 _ => None,
780 };
781
782 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:782",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(782u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps: steps={0:?} opt_bad_ty={1:?}",
steps, opt_bad_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("method_autoderef_steps: steps={:?} opt_bad_ty={:?}", steps, opt_bad_ty);
783 let _ = infcx.take_opaque_types();
785 MethodAutoderefStepsResult {
786 steps: tcx.arena.alloc_from_iter(steps),
787 opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
788 reached_recursion_limit,
789 }
790}
791
792impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
793 fn new(
794 fcx: &'a FnCtxt<'a, 'tcx>,
795 span: Span,
796 mode: Mode,
797 method_name: Option<Ident>,
798 return_type: Option<Ty<'tcx>>,
799 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
800 steps: &'tcx [CandidateStep<'tcx>],
801 scope_expr_id: HirId,
802 is_suggestion: IsSuggestion,
803 ) -> ProbeContext<'a, 'tcx> {
804 ProbeContext {
805 fcx,
806 span,
807 mode,
808 method_name,
809 return_type,
810 inherent_candidates: Vec::new(),
811 extension_candidates: Vec::new(),
812 impl_dups: FxHashSet::default(),
813 orig_steps_var_values,
814 steps,
815 allow_similar_names: false,
816 private_candidates: Vec::new(),
817 private_candidate: Cell::new(None),
818 static_candidates: RefCell::new(Vec::new()),
819 scope_expr_id,
820 is_suggestion,
821 self_ty_override: None,
822 }
823 }
824
825 fn reset(&mut self) {
826 self.inherent_candidates.clear();
827 self.extension_candidates.clear();
828 self.impl_dups.clear();
829 self.private_candidates.clear();
830 self.private_candidate.set(None);
831 self.static_candidates.borrow_mut().clear();
832 }
833
834 fn variance(&self) -> ty::Variance {
838 match self.mode {
839 Mode::MethodCall => ty::Covariant,
840 Mode::Path => ty::Invariant,
841 }
842 }
843
844 fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
848 let is_accessible = if let Some(name) = self.method_name {
849 let item = candidate.item;
850 let container_id = item.container_id(self.tcx);
851 let def_scope =
852 self.tcx.adjust_ident_and_get_scope(name, container_id, self.body_def_id).1;
853 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
854 } else {
855 true
856 };
857 if is_accessible {
858 if is_inherent {
859 self.inherent_candidates.push(candidate);
860 } else {
861 self.extension_candidates.push(candidate);
862 }
863 } else {
864 self.private_candidates.push(candidate);
865 }
866 }
867
868 fn assemble_inherent_candidates(&mut self) {
869 for step in self.steps.iter() {
870 self.assemble_probe(&step.self_ty, step.autoderefs);
871 }
872 }
873
874 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_probe",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(874u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("receiver_steps")
}> =
::tracing::__macro_support::FieldName::new("receiver_steps");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&receiver_steps as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let raw_self_ty = self_ty.value.value;
match *raw_self_ty.kind() {
ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
let (QueryResponse { value: generalized_self_ty, .. },
_ignored_var_values) =
self.fcx.instantiate_canonical(self.span, self_ty);
self.assemble_inherent_candidates_from_object(generalized_self_ty);
self.assemble_inherent_impl_candidates_for_type(p.def_id(),
receiver_steps);
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps);
}
ty::Adt(def, _) => {
let def_id = def.did();
self.assemble_inherent_impl_candidates_for_type(def_id,
receiver_steps);
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps);
}
ty::Foreign(did) => {
self.assemble_inherent_impl_candidates_for_type(did,
receiver_steps);
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps);
}
ty::Param(_) => {
self.assemble_inherent_candidates_from_param(raw_self_ty);
}
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_)
| ty::Str | ty::Array(..) | ty::Slice(_) | ty::RawPtr(_, _)
| ty::Ref(..) | ty::Never | ty::Tuple(..) => {
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps)
}
ty::Alias(..) | ty::Bound(..) | ty::Closure(..) |
ty::Coroutine(..) | ty::CoroutineClosure(..) |
ty::CoroutineWitness(..) | ty::Dynamic(..) | ty::Error(..) |
ty::FnDef(..) | ty::FnPtr(..) | ty::Infer(..) | ty::Pat(..)
| ty::Placeholder(..) | ty::UnsafeBinder(..) => {}
}
}
}
}#[instrument(level = "debug", skip(self))]
875 fn assemble_probe(
876 &mut self,
877 self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
878 receiver_steps: usize,
879 ) {
880 let raw_self_ty = self_ty.value.value;
881 match *raw_self_ty.kind() {
882 ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
883 let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
901 self.fcx.instantiate_canonical(self.span, self_ty);
902
903 self.assemble_inherent_candidates_from_object(generalized_self_ty);
904 self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
905 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
906 }
907 ty::Adt(def, _) => {
908 let def_id = def.did();
909 self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
910 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
911 }
912 ty::Foreign(did) => {
913 self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
914 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
915 }
916 ty::Param(_) => {
917 self.assemble_inherent_candidates_from_param(raw_self_ty);
918 }
919 ty::Bool
920 | ty::Char
921 | ty::Int(_)
922 | ty::Uint(_)
923 | ty::Float(_)
924 | ty::Str
925 | ty::Array(..)
926 | ty::Slice(_)
927 | ty::RawPtr(_, _)
928 | ty::Ref(..)
929 | ty::Never
930 | ty::Tuple(..) => {
931 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
932 }
933 ty::Alias(..)
934 | ty::Bound(..)
935 | ty::Closure(..)
936 | ty::Coroutine(..)
937 | ty::CoroutineClosure(..)
938 | ty::CoroutineWitness(..)
939 | ty::Dynamic(..)
940 | ty::Error(..)
941 | ty::FnDef(..)
942 | ty::FnPtr(..)
943 | ty::Infer(..)
944 | ty::Pat(..)
945 | ty::Placeholder(..)
946 | ty::UnsafeBinder(..) => {}
947 }
948 }
949
950 fn assemble_inherent_candidates_for_incoherent_ty(
951 &mut self,
952 self_ty: Ty<'tcx>,
953 receiver_steps: usize,
954 ) {
955 let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
956 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected incoherent type: {0:?}",
self_ty))bug!("unexpected incoherent type: {:?}", self_ty)
957 };
958 for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
959 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
960 }
961 }
962
963 fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
964 let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
965 for &impl_def_id in impl_def_ids {
966 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
967 }
968 }
969
970 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_impl_probe",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(970u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_def_id")
}> =
::tracing::__macro_support::FieldName::new("impl_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("receiver_steps")
}> =
::tracing::__macro_support::FieldName::new("receiver_steps");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&receiver_steps as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if !self.impl_dups.insert(impl_def_id) { return; }
for item in self.impl_or_trait_item(impl_def_id) {
if !self.has_applicable_self(&item) {
self.record_static_candidate(CandidateSource::Impl(impl_def_id));
continue;
}
self.push_candidate(Candidate {
item,
kind: InherentImplCandidate { impl_def_id, receiver_steps },
import_ids: &[],
}, true);
}
}
}
}#[instrument(level = "debug", skip(self))]
971 fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
972 if !self.impl_dups.insert(impl_def_id) {
973 return; }
975
976 for item in self.impl_or_trait_item(impl_def_id) {
977 if !self.has_applicable_self(&item) {
978 self.record_static_candidate(CandidateSource::Impl(impl_def_id));
980 continue;
981 }
982 self.push_candidate(
983 Candidate {
984 item,
985 kind: InherentImplCandidate { impl_def_id, receiver_steps },
986 import_ids: &[],
987 },
988 true,
989 );
990 }
991 }
992
993 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_candidates_from_object",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(993u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let principal =
match self_ty.kind() {
ty::Dynamic(data, ..) => Some(data),
_ => None,
}.and_then(|data|
data.principal()).unwrap_or_else(||
{
::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("non-object {0:?} in assemble_inherent_candidates_from_object",
self_ty))
});
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.assemble_candidates_for_bounds(traits::supertraits(self.tcx,
trait_ref),
|this, new_trait_ref, item|
{
this.push_candidate(Candidate {
item,
kind: ObjectCandidate(new_trait_ref),
import_ids: &[],
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
994 fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
995 let principal = match self_ty.kind() {
996 ty::Dynamic(data, ..) => Some(data),
997 _ => None,
998 }
999 .and_then(|data| data.principal())
1000 .unwrap_or_else(|| {
1001 span_bug!(
1002 self.span,
1003 "non-object {:?} in assemble_inherent_candidates_from_object",
1004 self_ty
1005 )
1006 });
1007
1008 let trait_ref = principal.with_self_ty(self.tcx, self_ty);
1015 self.assemble_candidates_for_bounds(
1016 traits::supertraits(self.tcx, trait_ref),
1017 |this, new_trait_ref, item| {
1018 this.push_candidate(
1019 Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
1020 true,
1021 );
1022 },
1023 );
1024 }
1025
1026 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_candidates_from_param",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1026u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("param_ty")
}> =
::tracing::__macro_support::FieldName::new("param_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if true {
{
match param_ty.kind() {
ty::Param(_) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"ty::Param(_)", ::core::option::Option::None);
}
}
};
};
let tcx = self.tcx;
let bounds =
self.param_env.caller_bounds().iter().filter_map(|clause|
{
let bound_clause = clause.kind();
match bound_clause.skip_binder() {
ty::ClauseKind::Trait(trait_predicate) =>
DeepRejectCtxt::relate_rigid_rigid(tcx).types_may_unify(param_ty,
trait_predicate.trait_ref.self_ty()).then(||
bound_clause.rebind(trait_predicate.trait_ref)),
ty::ClauseKind::RegionOutlives(_) |
ty::ClauseKind::TypeOutlives(_) |
ty::ClauseKind::Projection(_) |
ty::ClauseKind::ConstArgHasType(_, _) |
ty::ClauseKind::WellFormed(_) |
ty::ClauseKind::ConstEvaluatable(_) |
ty::ClauseKind::UnstableFeature(_) |
ty::ClauseKind::HostEffect(..) => None,
}
});
self.assemble_candidates_for_bounds(bounds,
|this, poly_trait_ref, item|
{
this.push_candidate(Candidate {
item,
kind: WhereClauseCandidate(poly_trait_ref),
import_ids: &[],
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
1027 fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
1028 debug_assert_matches!(param_ty.kind(), ty::Param(_));
1029
1030 let tcx = self.tcx;
1031
1032 let bounds = self.param_env.caller_bounds().iter().filter_map(|clause| {
1036 let bound_clause = clause.kind();
1037 match bound_clause.skip_binder() {
1038 ty::ClauseKind::Trait(trait_predicate) => DeepRejectCtxt::relate_rigid_rigid(tcx)
1039 .types_may_unify(param_ty, trait_predicate.trait_ref.self_ty())
1040 .then(|| bound_clause.rebind(trait_predicate.trait_ref)),
1041 ty::ClauseKind::RegionOutlives(_)
1042 | ty::ClauseKind::TypeOutlives(_)
1043 | ty::ClauseKind::Projection(_)
1044 | ty::ClauseKind::ConstArgHasType(_, _)
1045 | ty::ClauseKind::WellFormed(_)
1046 | ty::ClauseKind::ConstEvaluatable(_)
1047 | ty::ClauseKind::UnstableFeature(_)
1048 | ty::ClauseKind::HostEffect(..) => None,
1049 }
1050 });
1051
1052 self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1053 this.push_candidate(
1054 Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
1055 true,
1056 );
1057 });
1058 }
1059
1060 fn assemble_candidates_for_bounds<F>(
1063 &mut self,
1064 bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1065 mut mk_cand: F,
1066 ) where
1067 F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1068 {
1069 for bound_trait_ref in bounds {
1070 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1070",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1070u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("elaborate_bounds(bound_trait_ref={0:?})",
bound_trait_ref) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
1071 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1072 if !self.has_applicable_self(&item) {
1073 self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1074 } else {
1075 mk_cand(self, bound_trait_ref, item);
1076 }
1077 }
1078 }
1079 }
1080
1081 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_traits_in_scope",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1081u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut duplicates = FxHashSet::default();
let opt_applicable_traits =
self.tcx.in_scope_traits(self.scope_expr_id);
if let Some(applicable_traits) = opt_applicable_traits {
for trait_candidate in applicable_traits.iter() {
let trait_did = trait_candidate.def_id;
if duplicates.insert(trait_did) {
self.assemble_extension_candidates_for_trait(&trait_candidate.import_ids,
trait_did, trait_candidate.lint_ambiguous);
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1082 fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1083 let mut duplicates = FxHashSet::default();
1084 let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1085 if let Some(applicable_traits) = opt_applicable_traits {
1086 for trait_candidate in applicable_traits.iter() {
1087 let trait_did = trait_candidate.def_id;
1088 if duplicates.insert(trait_did) {
1089 self.assemble_extension_candidates_for_trait(
1090 &trait_candidate.import_ids,
1091 trait_did,
1092 trait_candidate.lint_ambiguous,
1093 );
1094 }
1095 }
1096 }
1097 }
1098
1099 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_all_traits",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1099u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut duplicates = FxHashSet::default();
for trait_info in suggest::all_traits(self.tcx) {
if duplicates.insert(trait_info.def_id) {
self.assemble_extension_candidates_for_trait(&[],
trait_info.def_id, false);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1100 fn assemble_extension_candidates_for_all_traits(&mut self) {
1101 let mut duplicates = FxHashSet::default();
1102 for trait_info in suggest::all_traits(self.tcx) {
1103 if duplicates.insert(trait_info.def_id) {
1104 self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
1105 }
1106 }
1107 }
1108
1109 fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1110 match method.kind {
1111 ty::AssocKind::Fn { .. } => self.probe(|_| {
1112 let args = self.fresh_args_for_item(self.span, method.def_id);
1113 let fty =
1114 self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args).skip_norm_wip();
1115 let fty = self.instantiate_binder_with_fresh_vars(
1116 self.span,
1117 BoundRegionConversionTime::FnCall,
1118 fty,
1119 );
1120 self.can_eq(self.param_env, fty.output(), expected)
1121 }),
1122 _ => false,
1123 }
1124 }
1125
1126 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_trait",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1126u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("import_ids")
}> =
::tracing::__macro_support::FieldName::new("import_ids");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("trait_def_id")
}> =
::tracing::__macro_support::FieldName::new("trait_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("lint_ambiguous")
}> =
::tracing::__macro_support::FieldName::new("lint_ambiguous");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&import_ids)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&lint_ambiguous as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let trait_args =
self.fresh_args_for_item(self.span, trait_def_id);
let trait_ref =
ty::TraitRef::new_from_args(self.tcx, trait_def_id,
trait_args);
if self.tcx.is_trait_alias(trait_def_id) {
for (bound_trait_pred, _) in
traits::expand_trait_aliases(self.tcx,
[(trait_ref.upcast(self.tcx), self.span)]).0 {
{
match (&bound_trait_pred.polarity(),
&ty::PredicatePolarity::Positive) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
let bound_trait_ref =
bound_trait_pred.map_bound(|pred| pred.trait_ref);
for item in
self.impl_or_trait_item(bound_trait_ref.def_id()) {
if !self.has_applicable_self(&item) {
self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
} else {
self.push_candidate(Candidate {
item,
import_ids,
kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
}, false);
}
}
}
} else {
if true {
if !self.tcx.is_trait(trait_def_id) {
::core::panicking::panic("assertion failed: self.tcx.is_trait(trait_def_id)")
};
};
if self.tcx.trait_is_auto(trait_def_id) { return; }
for item in self.impl_or_trait_item(trait_def_id) {
if !self.has_applicable_self(&item) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1168",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1168u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method has inapplicable self")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.record_static_candidate(CandidateSource::Trait(trait_def_id));
continue;
}
self.push_candidate(Candidate {
item,
import_ids,
kind: TraitCandidate(ty::Binder::dummy(trait_ref),
lint_ambiguous),
}, false);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1127 fn assemble_extension_candidates_for_trait(
1128 &mut self,
1129 import_ids: &'tcx [LocalDefId],
1130 trait_def_id: DefId,
1131 lint_ambiguous: bool,
1132 ) {
1133 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1134 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1135
1136 if self.tcx.is_trait_alias(trait_def_id) {
1137 for (bound_trait_pred, _) in
1139 traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1140 {
1141 assert_eq!(bound_trait_pred.polarity(), ty::PredicatePolarity::Positive);
1142 let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1143 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1144 if !self.has_applicable_self(&item) {
1145 self.record_static_candidate(CandidateSource::Trait(
1146 bound_trait_ref.def_id(),
1147 ));
1148 } else {
1149 self.push_candidate(
1150 Candidate {
1151 item,
1152 import_ids,
1153 kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
1154 },
1155 false,
1156 );
1157 }
1158 }
1159 }
1160 } else {
1161 debug_assert!(self.tcx.is_trait(trait_def_id));
1162 if self.tcx.trait_is_auto(trait_def_id) {
1163 return;
1164 }
1165 for item in self.impl_or_trait_item(trait_def_id) {
1166 if !self.has_applicable_self(&item) {
1168 debug!("method has inapplicable self");
1169 self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1170 continue;
1171 }
1172 self.push_candidate(
1173 Candidate {
1174 item,
1175 import_ids,
1176 kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
1177 },
1178 false,
1179 );
1180 }
1181 }
1182 }
1183
1184 fn candidate_method_names(
1185 &self,
1186 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1187 ) -> Vec<Ident> {
1188 let mut set = FxHashSet::default();
1189 let mut names: Vec<_> = self
1190 .inherent_candidates
1191 .iter()
1192 .chain(&self.extension_candidates)
1193 .filter(|candidate| candidate_filter(&candidate.item))
1194 .filter(|candidate| {
1195 if let Some(return_ty) = self.return_type {
1196 self.matches_return_type(candidate.item, return_ty)
1197 } else {
1198 true
1199 }
1200 })
1201 .filter(|candidate| {
1203 !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
None, DUMMY_SP, None) {
stability::EvalResult::Deny { .. } => true,
_ => false,
}matches!(
1206 self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1207 stability::EvalResult::Deny { .. }
1208 )
1209 })
1210 .map(|candidate| candidate.item.ident(self.tcx))
1211 .filter(|&name| set.insert(name))
1212 .collect();
1213
1214 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1216 names
1217 }
1218
1219 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("pick",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1222u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: PickResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
if !self.method_name.is_some() {
::core::panicking::panic("assertion failed: self.method_name.is_some()")
};
let mut unsatisfied_predicates = Vec::new();
if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
return r;
}
if self.is_suggestion.0 {
return Err(MethodError::NoMatch(NoMatchData {
static_candidates: ::alloc::vec::Vec::new(),
unsatisfied_predicates: ::alloc::vec::Vec::new(),
out_of_scope_traits: ::alloc::vec::Vec::new(),
similar_candidate: None,
mode: self.mode,
}));
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1244",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1244u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pick: actual search failed, assemble diagnostics")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let static_candidates =
std::mem::take(self.static_candidates.get_mut());
let private_candidate = self.private_candidate.take();
self.reset();
self.assemble_extension_candidates_for_all_traits();
let out_of_scope_traits =
match self.pick_core(&mut Vec::new()) {
Some(Ok(p)) =>
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[p.item.container_id(self.tcx)])),
Some(Err(MethodError::Ambiguity(v))) =>
v.into_iter().map(|source|
match source {
CandidateSource::Trait(id) => id,
CandidateSource::Impl(impl_id) =>
self.tcx.impl_trait_id(impl_id),
}).collect(),
Some(Err(MethodError::NoMatch(NoMatchData {
out_of_scope_traits: others, .. }))) => {
if !others.is_empty() {
::core::panicking::panic("assertion failed: others.is_empty()")
};
::alloc::vec::Vec::new()
}
_ => ::alloc::vec::Vec::new(),
};
if let Some((kind, def_id)) = private_candidate {
return Err(MethodError::PrivateMatch(kind, def_id,
out_of_scope_traits));
}
let similar_candidate = self.probe_for_similar_candidate()?;
Err(MethodError::NoMatch(NoMatchData {
static_candidates,
unsatisfied_predicates,
out_of_scope_traits,
similar_candidate,
mode: self.mode,
}))
}
}
}#[instrument(level = "debug", skip(self))]
1223 fn pick(mut self) -> PickResult<'tcx> {
1224 assert!(self.method_name.is_some());
1225
1226 let mut unsatisfied_predicates = Vec::new();
1227
1228 if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1229 return r;
1230 }
1231
1232 if self.is_suggestion.0 {
1235 return Err(MethodError::NoMatch(NoMatchData {
1236 static_candidates: vec![],
1237 unsatisfied_predicates: vec![],
1238 out_of_scope_traits: vec![],
1239 similar_candidate: None,
1240 mode: self.mode,
1241 }));
1242 }
1243
1244 debug!("pick: actual search failed, assemble diagnostics");
1245
1246 let static_candidates = std::mem::take(self.static_candidates.get_mut());
1247 let private_candidate = self.private_candidate.take();
1248
1249 self.reset();
1251
1252 self.assemble_extension_candidates_for_all_traits();
1253
1254 let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1255 Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1256 Some(Err(MethodError::Ambiguity(v))) => v
1257 .into_iter()
1258 .map(|source| match source {
1259 CandidateSource::Trait(id) => id,
1260 CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1261 })
1262 .collect(),
1263 Some(Err(MethodError::NoMatch(NoMatchData {
1264 out_of_scope_traits: others, ..
1265 }))) => {
1266 assert!(others.is_empty());
1267 vec![]
1268 }
1269 _ => vec![],
1270 };
1271
1272 if let Some((kind, def_id)) = private_candidate {
1273 return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1274 }
1275 let similar_candidate = self.probe_for_similar_candidate()?;
1276
1277 Err(MethodError::NoMatch(NoMatchData {
1278 static_candidates,
1279 unsatisfied_predicates,
1280 out_of_scope_traits,
1281 similar_candidate,
1282 mode: self.mode,
1283 }))
1284 }
1285
1286 fn pick_core(
1287 &self,
1288 unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1289 ) -> Option<PickResult<'tcx>> {
1290 self.pick_all_method(&mut PickDiagHints {
1292 unstable_candidates: Some(Vec::new()),
1295 unsatisfied_predicates,
1298 })
1299 .or_else(|| {
1300 self.pick_all_method(&mut PickDiagHints {
1301 unstable_candidates: None,
1306 unsatisfied_predicates: &mut Vec::new(),
1309 })
1310 })
1311 }
1312
1313 fn pick_all_method<'b>(
1314 &self,
1315 pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1316 ) -> Option<PickResult<'tcx>> {
1317 let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1318 self.steps
1319 .iter()
1320 .filter(|step| step.reachable_via_deref)
1324 .filter(|step| {
1325 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1325",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1325u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pick_all_method: step={0:?}",
step) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pick_all_method: step={:?}", step);
1326 !step.self_ty.value.references_error() && !step.from_unsafe_deref
1329 })
1330 .find_map(|step| {
1331 let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1332 .fcx
1333 .probe_instantiate_query_response(
1334 self.span,
1335 self.orig_steps_var_values,
1336 &step.self_ty,
1337 )
1338 .unwrap_or_else(|_| {
1339 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("{0:?} was applicable but now isn\'t?", step.self_ty))span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
1340 });
1341
1342 let by_value_pick = self.pick_by_value_method(
1343 step,
1344 self_ty,
1345 &instantiate_self_ty_obligations,
1346 pick_diag_hints,
1347 );
1348
1349 if let Some(by_value_pick) = by_value_pick {
1351 if let Ok(by_value_pick) = by_value_pick.as_ref() {
1352 if by_value_pick.kind == PickKind::InherentImplPick {
1353 for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1354 if let Err(e) = self.check_for_shadowed_autorefd_method(
1355 by_value_pick,
1356 step,
1357 self_ty,
1358 &instantiate_self_ty_obligations,
1359 mutbl,
1360 track_unstable_candidates,
1361 ) {
1362 return Some(Err(e));
1363 }
1364 }
1365 }
1366 }
1367 return Some(by_value_pick);
1368 }
1369
1370 let autoref_pick = self.pick_autorefd_method(
1371 step,
1372 self_ty,
1373 &instantiate_self_ty_obligations,
1374 hir::Mutability::Not,
1375 pick_diag_hints,
1376 None,
1377 );
1378 if let Some(autoref_pick) = autoref_pick {
1380 if let Ok(autoref_pick) = autoref_pick.as_ref() {
1381 if autoref_pick.kind == PickKind::InherentImplPick {
1383 if let Err(e) = self.check_for_shadowed_autorefd_method(
1384 autoref_pick,
1385 step,
1386 self_ty,
1387 &instantiate_self_ty_obligations,
1388 hir::Mutability::Mut,
1389 track_unstable_candidates,
1390 ) {
1391 return Some(Err(e));
1392 }
1393 }
1394 }
1395 return Some(autoref_pick);
1396 }
1397
1398 self.pick_autorefd_method(
1422 step,
1423 self_ty,
1424 &instantiate_self_ty_obligations,
1425 hir::Mutability::Mut,
1426 pick_diag_hints,
1427 None,
1428 )
1429 .or_else(|| {
1430 self.pick_const_ptr_method(
1431 step,
1432 self_ty,
1433 &instantiate_self_ty_obligations,
1434 pick_diag_hints,
1435 )
1436 })
1437 .or_else(|| {
1438 self.pick_reborrow_pin_method(
1439 step,
1440 self_ty,
1441 &instantiate_self_ty_obligations,
1442 pick_diag_hints,
1443 )
1444 })
1445 })
1446 }
1447
1448 fn check_for_shadowed_autorefd_method(
1464 &self,
1465 possible_shadower: &Pick<'tcx>,
1466 step: &CandidateStep<'tcx>,
1467 self_ty: Ty<'tcx>,
1468 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1469 mutbl: hir::Mutability,
1470 track_unstable_candidates: bool,
1471 ) -> Result<(), MethodError<'tcx>> {
1472 if !self.tcx.features().arbitrary_self_types()
1476 && !self.tcx.features().arbitrary_self_types_pointers()
1477 {
1478 return Ok(());
1479 }
1480
1481 let mut pick_diag_hints = PickDiagHints {
1486 unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1487 unsatisfied_predicates: &mut Vec::new(),
1488 };
1489 let pick_constraints = PickConstraintsForShadowed {
1491 autoderefs: possible_shadower.autoderefs,
1493 receiver_steps: possible_shadower.receiver_steps,
1497 def_id: possible_shadower.item.def_id,
1500 };
1501 let potentially_shadowed_pick = self.pick_autorefd_method(
1531 step,
1532 self_ty,
1533 instantiate_self_ty_obligations,
1534 mutbl,
1535 &mut pick_diag_hints,
1536 Some(&pick_constraints),
1537 );
1538 if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1541 let sources = [possible_shadower, possible_shadowed]
1542 .into_iter()
1543 .map(|p| self.candidate_source_from_pick(p))
1544 .collect();
1545 return Err(MethodError::Ambiguity(sources));
1546 }
1547 Ok(())
1548 }
1549
1550 fn pick_by_value_method(
1557 &self,
1558 step: &CandidateStep<'tcx>,
1559 self_ty: Ty<'tcx>,
1560 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1561 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1562 ) -> Option<PickResult<'tcx>> {
1563 if step.unsize {
1564 return None;
1565 }
1566
1567 self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1568 r.map(|mut pick| {
1569 pick.autoderefs = step.autoderefs;
1570
1571 match *step.self_ty.value.value.kind() {
1572 ty::Ref(_, _, mutbl) => {
1574 pick.autoderefs += 1;
1575 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1576 mutbl,
1577 unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1578 })
1579 }
1580
1581 ty::Adt(def, args)
1582 if self.tcx.features().pin_ergonomics()
1583 && self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) =>
1584 {
1585 if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1587 pick.autoref_or_ptr_adjustment =
1588 Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1589 }
1590 }
1591
1592 _ => (),
1593 }
1594
1595 pick
1596 })
1597 })
1598 }
1599
1600 fn pick_autorefd_method(
1601 &self,
1602 step: &CandidateStep<'tcx>,
1603 self_ty: Ty<'tcx>,
1604 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1605 mutbl: hir::Mutability,
1606 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1607 pick_constraints: Option<&PickConstraintsForShadowed>,
1608 ) -> Option<PickResult<'tcx>> {
1609 let tcx = self.tcx;
1610
1611 if let Some(pick_constraints) = pick_constraints {
1612 if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1613 return None;
1614 }
1615 }
1616
1617 let region = tcx.lifetimes.re_erased;
1619
1620 let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1621 self.pick_method(
1622 autoref_ty,
1623 instantiate_self_ty_obligations,
1624 pick_diag_hints,
1625 pick_constraints,
1626 )
1627 .map(|r| {
1628 r.map(|mut pick| {
1629 pick.autoderefs = step.autoderefs;
1630 pick.autoref_or_ptr_adjustment =
1631 Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1632 pick
1633 })
1634 })
1635 }
1636
1637 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("pick_reborrow_pin_method",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1638u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("instantiate_self_ty_obligations")
}> =
::tracing::__macro_support::FieldName::new("instantiate_self_ty_obligations");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instantiate_self_ty_obligations)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<PickResult<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
if !self.tcx.features().pin_ergonomics() { return None; }
let inner_ty =
match self_ty.kind() {
ty::Adt(def, args) if
self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => {
match args[0].expect_ty().kind() {
ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
_ => { return None; }
}
}
_ => return None,
};
let region = self.tcx.lifetimes.re_erased;
let autopin_ty =
Ty::new_pinned_ref(self.tcx, region, inner_ty,
hir::Mutability::Not);
self.pick_method(autopin_ty, instantiate_self_ty_obligations,
pick_diag_hints,
None).map(|r|
{
r.map(|mut pick|
{
pick.autoderefs = step.autoderefs;
pick.autoref_or_ptr_adjustment =
Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
pick
})
})
}
}
}#[instrument(level = "debug", skip(self, step, pick_diag_hints))]
1639 fn pick_reborrow_pin_method(
1640 &self,
1641 step: &CandidateStep<'tcx>,
1642 self_ty: Ty<'tcx>,
1643 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1644 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1645 ) -> Option<PickResult<'tcx>> {
1646 if !self.tcx.features().pin_ergonomics() {
1647 return None;
1648 }
1649
1650 let inner_ty = match self_ty.kind() {
1652 ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => {
1653 match args[0].expect_ty().kind() {
1654 ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1655 _ => {
1656 return None;
1657 }
1658 }
1659 }
1660 _ => return None,
1661 };
1662
1663 let region = self.tcx.lifetimes.re_erased;
1664 let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1665 self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1666 |r| {
1667 r.map(|mut pick| {
1668 pick.autoderefs = step.autoderefs;
1669 pick.autoref_or_ptr_adjustment =
1670 Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1671 pick
1672 })
1673 },
1674 )
1675 }
1676
1677 fn pick_const_ptr_method(
1681 &self,
1682 step: &CandidateStep<'tcx>,
1683 self_ty: Ty<'tcx>,
1684 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1685 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1686 ) -> Option<PickResult<'tcx>> {
1687 if step.unsize {
1689 return None;
1690 }
1691
1692 let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1693 return None;
1694 };
1695
1696 let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1697 self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1698 |r| {
1699 r.map(|mut pick| {
1700 pick.autoderefs = step.autoderefs;
1701 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1702 pick
1703 })
1704 },
1705 )
1706 }
1707
1708 fn pick_method(
1709 &self,
1710 self_ty: Ty<'tcx>,
1711 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1712 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1713 pick_constraints: Option<&PickConstraintsForShadowed>,
1714 ) -> Option<PickResult<'tcx>> {
1715 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1715",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1715u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("pick_method(self_ty={0})",
self.ty_to_string(self_ty)) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("pick_method(self_ty={})", self.ty_to_string(self_ty));
1716
1717 for (kind, candidates) in
1718 [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1719 {
1720 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1720",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1720u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("searching {0} candidates",
kind) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("searching {} candidates", kind);
1721 let res = self.consider_candidates(
1722 self_ty,
1723 instantiate_self_ty_obligations,
1724 candidates,
1725 pick_diag_hints,
1726 pick_constraints,
1727 );
1728 if let Some(pick) = res {
1729 return Some(pick);
1730 }
1731 }
1732
1733 if self.private_candidate.get().is_none() {
1734 if let Some(Ok(pick)) = self.consider_candidates(
1735 self_ty,
1736 instantiate_self_ty_obligations,
1737 &self.private_candidates,
1738 &mut PickDiagHints {
1739 unstable_candidates: None,
1740 unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1741 },
1742 None,
1743 ) {
1744 self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1745 }
1746 }
1747 None
1748 }
1749
1750 fn consider_candidates(
1751 &self,
1752 self_ty: Ty<'tcx>,
1753 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1754 candidates: &[Candidate<'tcx>],
1755 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1756 pick_constraints: Option<&PickConstraintsForShadowed>,
1757 ) -> Option<PickResult<'tcx>> {
1758 let mut applicable_candidates: Vec<_> = candidates
1759 .iter()
1760 .filter(|candidate| {
1761 pick_constraints
1762 .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1763 .unwrap_or(true)
1764 })
1765 .map(|probe| {
1766 (
1767 probe,
1768 self.consider_probe(
1769 self_ty,
1770 instantiate_self_ty_obligations,
1771 probe,
1772 &mut pick_diag_hints.unsatisfied_predicates,
1773 ),
1774 )
1775 })
1776 .filter(|&(_, status)| status != ProbeResult::NoMatch)
1777 .collect();
1778
1779 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1779",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1779u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("applicable_candidates: {0:?}",
applicable_candidates) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("applicable_candidates: {:?}", applicable_candidates);
1780
1781 if applicable_candidates.len() > 1 {
1782 if let Some(pick) =
1783 self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1784 {
1785 return Some(Ok(pick));
1786 }
1787 }
1788
1789 if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1790 applicable_candidates.retain(|&(candidate, _)| {
1791 if let stability::EvalResult::Deny { feature, .. } =
1792 self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1793 {
1794 uc.push((candidate.clone(), feature));
1795 return false;
1796 }
1797 true
1798 });
1799 }
1800
1801 if applicable_candidates.len() > 1 {
1802 if self.tcx.features().supertrait_item_shadowing() {
1806 if let Some(pick) =
1807 self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1808 {
1809 return Some(Ok(pick));
1810 }
1811 }
1812
1813 let sources =
1814 applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1815 return Some(Err(MethodError::Ambiguity(sources)));
1816 }
1817
1818 applicable_candidates.pop().map(|(probe, status)| match status {
1819 ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1820 self_ty,
1821 pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1822 )),
1823 ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1824 })
1825 }
1826}
1827
1828impl<'tcx> Pick<'tcx> {
1829 pub(crate) fn differs_from(&self, other: &Self) -> bool {
1834 let Self {
1835 item: AssocItem { def_id, kind: _, container: _ },
1836 kind: _,
1837 import_ids: _,
1838 autoderefs: _,
1839 autoref_or_ptr_adjustment: _,
1840 self_ty,
1841 unstable_candidates: _,
1842 receiver_steps: _,
1843 shadowed_candidates: _,
1844 } = *self;
1845 self_ty != other.self_ty || def_id != other.item.def_id
1846 }
1847
1848 pub(crate) fn maybe_emit_unstable_name_collision_hint(
1850 &self,
1851 tcx: TyCtxt<'tcx>,
1852 span: Span,
1853 scope_expr_id: HirId,
1854 ) {
1855 struct ItemMaybeBeAddedToStd<'a, 'tcx> {
1856 this: &'a Pick<'tcx>,
1857 tcx: TyCtxt<'tcx>,
1858 span: Span,
1859 }
1860
1861 impl<'a, 'b, 'tcx> Diagnostic<'a, ()> for ItemMaybeBeAddedToStd<'b, 'tcx> {
1862 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
1863 let Self { this, tcx, span } = self;
1864 let def_kind = this.item.as_def_kind();
1865 let mut lint = Diag::new(
1866 dcx,
1867 level,
1868 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("{0} {1} with this name may be added to the standard library in the future",
tcx.def_kind_descr_article(def_kind, this.item.def_id),
tcx.def_kind_descr(def_kind, this.item.def_id)))
})format!(
1869 "{} {} with this name may be added to the standard library in the future",
1870 tcx.def_kind_descr_article(def_kind, this.item.def_id),
1871 tcx.def_kind_descr(def_kind, this.item.def_id),
1872 ),
1873 );
1874
1875 match (this.item.kind, this.item.container) {
1876 (ty::AssocKind::Fn { .. }, _) => {
1877 lint.help(::alloc::__export::must_use({
::alloc::fmt::format(format_args!("call with fully qualified syntax `{0}(...)` to keep using the current method",
tcx.def_path_str(this.item.def_id)))
})format!(
1882 "call with fully qualified syntax `{}(...)` to keep using the current \
1883 method",
1884 tcx.def_path_str(this.item.def_id),
1885 ));
1886 }
1887 (ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
1888 let def_id = this.item.container_id(tcx);
1889 lint.span_suggestion(
1890 span,
1891 "use the fully qualified path to the associated const",
1892 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0} as {1}>::{2}", this.self_ty,
tcx.def_path_str(def_id), name))
})format!("<{} as {}>::{}", this.self_ty, tcx.def_path_str(def_id), name),
1893 Applicability::MachineApplicable,
1894 );
1895 }
1896 _ => {}
1897 }
1898 tcx.disabled_nightly_features(
1899 &mut lint,
1900 this.unstable_candidates.iter().map(|(candidate, feature)| {
1901 (::alloc::__export::must_use({
::alloc::fmt::format(format_args!(" `{0}`",
tcx.def_path_str(candidate.item.def_id)))
})format!(" `{}`", tcx.def_path_str(candidate.item.def_id)), *feature)
1902 }),
1903 );
1904 lint
1905 }
1906 }
1907
1908 if self.unstable_candidates.is_empty() {
1909 return;
1910 }
1911 tcx.emit_node_span_lint(
1912 lint::builtin::UNSTABLE_NAME_COLLISIONS,
1913 scope_expr_id,
1914 span,
1915 ItemMaybeBeAddedToStd { this: self, tcx, span },
1916 );
1917 }
1918}
1919
1920impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1921 fn select_trait_candidate_for_diagnostics(
1922 &self,
1923 trait_ref: ty::TraitRef<'tcx>,
1924 ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1925 let obligation =
1926 traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1927 let candidate = traits::SelectionContext::new(self).select(&obligation);
1928 if let Ok(Some(traits::ImplSource::UserDefined(impl_source_user_defined_data))) = &candidate
1929 && self.infcx.tcx.do_not_recommend_impl(impl_source_user_defined_data.impl_def_id)
1930 {
1931 return Err(traits::SelectionError::Unimplemented);
1932 }
1933 candidate
1934 }
1935
1936 fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1939 match candidate.kind {
1940 InherentImplCandidate { .. } => {
1941 CandidateSource::Impl(candidate.item.container_id(self.tcx))
1942 }
1943 ObjectCandidate(_) | WhereClauseCandidate(_) => {
1944 CandidateSource::Trait(candidate.item.container_id(self.tcx))
1945 }
1946 TraitCandidate(trait_ref, _) => self.probe(|_| {
1947 let trait_ref = self.instantiate_binder_with_fresh_vars(
1948 self.span,
1949 BoundRegionConversionTime::FnCall,
1950 trait_ref,
1951 );
1952 let (xform_self_ty, _) =
1953 self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1954 let _ = self.at(&ObligationCause::dummy(), self.param_env).sup(
1957 DefineOpaqueTypes::Yes,
1958 xform_self_ty,
1959 self_ty,
1960 );
1961 match self.select_trait_candidate_for_diagnostics(trait_ref) {
1962 Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
1963 CandidateSource::Impl(impl_data.impl_def_id)
1966 }
1967 _ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
1968 }
1969 }),
1970 }
1971 }
1972
1973 fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
1974 match pick.kind {
1975 InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1976 ObjectPick | WhereClausePick(_) | TraitPick(_) => {
1977 CandidateSource::Trait(pick.item.container_id(self.tcx))
1978 }
1979 }
1980 }
1981
1982 fn consider_probe(
1983 &self,
1984 self_ty: Ty<'tcx>,
1985 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1986 probe: &Candidate<'tcx>,
1987 possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1988 ) -> ProbeResult {
1989 self.probe(|snapshot| {
1990 let outer_universe = self.universe();
1991
1992 let mut result = ProbeResult::Match;
1993 let cause = &self.misc(self.span);
1994 let ocx = ObligationCtxt::new_with_diagnostics(self);
1995
1996 if self.next_trait_solver() {
2004 ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
2005 let errors = ocx.try_evaluate_obligations();
2006 if !errors.is_empty() {
2007 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected autoderef error {0:?}", errors)));
};unreachable!("unexpected autoderef error {errors:?}");
2008 }
2009 }
2010
2011 let mut trait_predicate = None;
2012 let (mut xform_self_ty, mut xform_ret_ty);
2013
2014 match probe.kind {
2015 InherentImplCandidate { impl_def_id, .. } => {
2016 let impl_args = self.fresh_args_for_item(self.span, impl_def_id);
2017 let impl_ty = self
2018 .tcx
2019 .type_of(impl_def_id)
2020 .instantiate(self.tcx, impl_args)
2021 .skip_norm_wip();
2022 (xform_self_ty, xform_ret_ty) =
2023 self.xform_self_ty(probe.item, impl_ty, impl_args);
2024 xform_self_ty =
2025 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2026 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2027 {
2028 Ok(()) => {}
2029 Err(err) => {
2030 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2030",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2030u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> cannot relate self-types {0:?}",
err) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("--> cannot relate self-types {:?}", err);
2031 return ProbeResult::NoMatch;
2032 }
2033 }
2034 xform_ret_ty =
2036 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2037 let impl_def_id = probe.item.container_id(self.tcx);
2039 let impl_bounds =
2040 self.tcx.clauses_of(impl_def_id).instantiate(self.tcx, impl_args);
2041 ocx.register_obligations(traits::predicates_for_generics(
2043 |idx, span| {
2044 let code = ObligationCauseCode::WhereClauseInExpr(
2045 impl_def_id,
2046 span,
2047 self.scope_expr_id,
2048 idx,
2049 );
2050 self.cause(self.span, code)
2051 },
2052 |clause| ocx.normalize(cause, self.param_env, clause),
2053 self.param_env,
2054 impl_bounds,
2055 ));
2056 }
2057 TraitCandidate(poly_trait_ref, _) => {
2058 if let Some(method_name) = self.method_name {
2061 if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
2062 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2063 if trait_def.skip_array_during_method_dispatch {
2064 return ProbeResult::NoMatch;
2065 }
2066 }
2067
2068 if self_ty.boxed_ty().is_some_and(Ty::is_slice)
2071 && !method_name.span.at_least_rust_2024()
2072 {
2073 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2074 if trait_def.skip_boxed_slice_during_method_dispatch {
2075 return ProbeResult::NoMatch;
2076 }
2077 }
2078 }
2079
2080 let trait_ref = self.instantiate_binder_with_fresh_vars(
2081 self.span,
2082 BoundRegionConversionTime::FnCall,
2083 poly_trait_ref,
2084 );
2085 let trait_ref =
2086 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(trait_ref));
2087 (xform_self_ty, xform_ret_ty) =
2088 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2089 xform_self_ty =
2090 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2091 match self_ty.kind() {
2092 &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })
2096 if !self.next_trait_solver()
2097 && self.infcx.can_define_opaque_ty(def_id)
2098 && !xform_self_ty.is_ty_var() =>
2099 {
2100 return ProbeResult::NoMatch;
2101 }
2102 _ => match ocx.relate(
2103 cause,
2104 self.param_env,
2105 self.variance(),
2106 self_ty,
2107 xform_self_ty,
2108 ) {
2109 Ok(()) => {}
2110 Err(err) => {
2111 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2111",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2111u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> cannot relate self-types {0:?}",
err) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("--> cannot relate self-types {:?}", err);
2112 return ProbeResult::NoMatch;
2113 }
2114 },
2115 }
2116 let obligation = traits::Obligation::new(
2117 self.tcx,
2118 cause.clone(),
2119 self.param_env,
2120 ty::Binder::dummy(trait_ref),
2121 );
2122
2123 if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
2125 {
2126 ocx.register_obligation(obligation);
2127 } else {
2128 result = ProbeResult::NoMatch;
2129 if let Ok(Some(candidate)) =
2130 self.select_trait_candidate_for_diagnostics(trait_ref)
2131 {
2132 for nested_obligation in candidate.nested_obligations() {
2133 if !self.infcx.predicate_may_hold(&nested_obligation) {
2134 possibly_unsatisfied_predicates.push((
2135 self.resolve_vars_if_possible(nested_obligation.predicate),
2136 Some(self.resolve_vars_if_possible(obligation.predicate)),
2137 Some(nested_obligation.cause),
2138 ));
2139 }
2140 }
2141 }
2142 }
2143
2144 trait_predicate = Some(trait_ref.upcast(self.tcx));
2145 }
2146 ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
2147 let trait_ref = self.instantiate_binder_with_fresh_vars(
2148 self.span,
2149 BoundRegionConversionTime::FnCall,
2150 poly_trait_ref,
2151 );
2152 (xform_self_ty, xform_ret_ty) =
2153 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2154
2155 if #[allow(non_exhaustive_omitted_patterns)] match probe.kind {
WhereClauseCandidate(_) => true,
_ => false,
}matches!(probe.kind, WhereClauseCandidate(_)) {
2156 let ty = ocx.normalize(
2160 cause,
2161 self.param_env,
2162 Unnormalized::new_wip(trait_ref.self_ty()),
2163 );
2164 if !#[allow(non_exhaustive_omitted_patterns)] match ty.kind() {
ty::Param(_) => true,
_ => false,
}matches!(ty.kind(), ty::Param(_)) {
2165 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2165",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2165u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> not a param ty: {0:?}",
xform_self_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("--> not a param ty: {xform_self_ty:?}");
2166 return ProbeResult::NoMatch;
2167 }
2168 }
2169
2170 xform_self_ty =
2171 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2172 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2173 {
2174 Ok(()) => {}
2175 Err(err) => {
2176 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2176",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2176u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("--> cannot relate self-types {0:?}",
err) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("--> cannot relate self-types {:?}", err);
2177 return ProbeResult::NoMatch;
2178 }
2179 }
2180 }
2181 }
2182
2183 if let Some(xform_ret_ty) = xform_ret_ty
2195 && self.infcx.next_trait_solver()
2196 {
2197 ocx.register_obligation(traits::Obligation::new(
2198 self.tcx,
2199 cause.clone(),
2200 self.param_env,
2201 ty::ClauseKind::WellFormed(xform_ret_ty.into()),
2202 ));
2203 }
2204
2205 for error in ocx.try_evaluate_obligations() {
2207 result = ProbeResult::NoMatch;
2208 let nested_predicate = self.resolve_vars_if_possible(error.obligation.predicate);
2209 if let Some(trait_predicate) = trait_predicate
2210 && nested_predicate == self.resolve_vars_if_possible(trait_predicate)
2211 {
2212 } else {
2216 possibly_unsatisfied_predicates.push((
2217 nested_predicate,
2218 Some(self.resolve_vars_if_possible(error.root_obligation.predicate))
2219 .filter(|root_predicate| *root_predicate != nested_predicate),
2220 Some(error.obligation.cause),
2221 ));
2222 }
2223 }
2224
2225 if let ProbeResult::Match = result
2226 && let Some(return_ty) = self.return_type
2227 && let Some(mut xform_ret_ty) = xform_ret_ty
2228 {
2229 if !#[allow(non_exhaustive_omitted_patterns)] match probe.kind {
InherentImplCandidate { .. } => true,
_ => false,
}matches!(probe.kind, InherentImplCandidate { .. }) {
2234 xform_ret_ty =
2235 ocx.normalize(&cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2236 }
2237
2238 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2238",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2238u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("comparing return_ty {0:?} with xform ret ty {1:?}",
return_ty, xform_ret_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("comparing return_ty {:?} with xform ret ty {:?}", return_ty, xform_ret_ty);
2239 match ocx.relate(cause, self.param_env, self.variance(), xform_ret_ty, return_ty) {
2240 Ok(()) => {}
2241 Err(_) => {
2242 result = ProbeResult::BadReturnType;
2243 }
2244 }
2245
2246 for error in ocx.try_evaluate_obligations() {
2248 result = ProbeResult::NoMatch;
2249 possibly_unsatisfied_predicates.push((
2250 error.obligation.predicate,
2251 Some(error.root_obligation.predicate)
2252 .filter(|predicate| *predicate != error.obligation.predicate),
2253 Some(error.root_obligation.cause),
2254 ));
2255 }
2256 }
2257
2258 if self.infcx.next_trait_solver() {
2259 if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
2260 result = ProbeResult::NoMatch;
2261 }
2262 }
2263
2264 if let Err(_) = self.leak_check(outer_universe, Some(snapshot)) {
2270 result = ProbeResult::NoMatch;
2271 }
2272
2273 result
2274 })
2275 }
2276
2277 x;#[instrument(level = "debug", skip(self), ret)]
2292 fn should_reject_candidate_due_to_opaque_treated_as_rigid(
2293 &self,
2294 trait_predicate: Option<ty::Predicate<'tcx>>,
2295 ) -> bool {
2296 if let Some(predicate) = trait_predicate {
2308 let goal = Goal { param_env: self.param_env, predicate };
2309 if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
2310 return true;
2311 }
2312 }
2313
2314 for step in self.steps {
2317 if step.self_ty_is_opaque {
2318 debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
2319 let constrained_opaque = self.probe(|_| {
2320 let Ok(ok) = self.fcx.probe_instantiate_query_response(
2325 self.span,
2326 self.orig_steps_var_values,
2327 &step.self_ty,
2328 ) else {
2329 debug!("failed to instantiate self_ty");
2330 return false;
2331 };
2332 let ocx = ObligationCtxt::new(self);
2333 let self_ty = ocx.register_infer_ok_obligations(ok);
2334 if !ocx.try_evaluate_obligations().is_empty() {
2335 debug!("failed to prove instantiate self_ty obligations");
2336 return false;
2337 }
2338
2339 !self.resolve_vars_if_possible(self_ty).is_ty_var()
2340 });
2341 if constrained_opaque {
2342 debug!("opaque type has been constrained");
2343 return true;
2344 }
2345 }
2346 }
2347
2348 false
2349 }
2350
2351 fn collapse_candidates_to_trait_pick(
2369 &self,
2370 self_ty: Ty<'tcx>,
2371 probes: &[(&Candidate<'tcx>, ProbeResult)],
2372 ) -> Option<Pick<'tcx>> {
2373 let container = probes[0].0.item.trait_container(self.tcx)?;
2375 for (p, _) in &probes[1..] {
2376 let p_container = p.item.trait_container(self.tcx)?;
2377 if p_container != container {
2378 return None;
2379 }
2380 }
2381
2382 let lint_ambiguous = match probes[0].0.kind {
2383 TraitCandidate(_, lint) => lint,
2384 _ => false,
2385 };
2386
2387 Some(Pick {
2390 item: probes[0].0.item,
2391 kind: TraitPick(lint_ambiguous),
2392 import_ids: probes[0].0.import_ids,
2393 autoderefs: 0,
2394 autoref_or_ptr_adjustment: None,
2395 self_ty,
2396 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2397 receiver_steps: None,
2398 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2399 })
2400 }
2401
2402 fn collapse_candidates_to_subtrait_pick(
2412 &self,
2413 self_ty: Ty<'tcx>,
2414 probes: &[(&Candidate<'tcx>, ProbeResult)],
2415 ) -> Option<Pick<'tcx>> {
2416 let mut child_candidate = probes[0].0;
2417 let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2418 let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2419
2420 let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2421 while !remaining_candidates.is_empty() {
2422 let mut made_progress = false;
2423 let mut next_round = ::alloc::vec::Vec::new()vec![];
2424
2425 for remaining_candidate in remaining_candidates {
2426 let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2427 if supertraits.contains(&remaining_trait) {
2428 made_progress = true;
2429 continue;
2430 }
2431
2432 let remaining_trait_supertraits: SsoHashSet<_> =
2438 supertrait_def_ids(self.tcx, remaining_trait).collect();
2439 if remaining_trait_supertraits.contains(&child_trait) {
2440 child_candidate = remaining_candidate;
2441 child_trait = remaining_trait;
2442 supertraits = remaining_trait_supertraits;
2443 made_progress = true;
2444 continue;
2445 }
2446
2447 next_round.push(remaining_candidate);
2454 }
2455
2456 if made_progress {
2457 remaining_candidates = next_round;
2459 } else {
2460 return None;
2463 }
2464 }
2465
2466 let lint_ambiguous = match probes[0].0.kind {
2467 TraitCandidate(_, lint) => lint,
2468 _ => false,
2469 };
2470
2471 Some(Pick {
2472 item: child_candidate.item,
2473 kind: TraitPick(lint_ambiguous),
2474 import_ids: child_candidate.import_ids,
2475 autoderefs: 0,
2476 autoref_or_ptr_adjustment: None,
2477 self_ty,
2478 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2479 shadowed_candidates: probes
2480 .iter()
2481 .map(|(c, _)| c.item)
2482 .filter(|item| item.def_id != child_candidate.item.def_id)
2483 .collect(),
2484 receiver_steps: None,
2485 })
2486 }
2487
2488 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_similar_candidate",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2491u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Option<ty::AssocItem>, MethodError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2495",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2495u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("probing for method names similar to {0:?}",
self.method_name) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
self.probe(|_|
{
let mut pcx =
ProbeContext::new(self.fcx, self.span, self.mode,
self.method_name, self.return_type,
self.orig_steps_var_values, self.steps, self.scope_expr_id,
IsSuggestion(true));
pcx.allow_similar_names = true;
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_all_traits();
let method_names = pcx.candidate_method_names(|_| true);
pcx.allow_similar_names = false;
let applicable_close_candidates: Vec<ty::AssocItem> =
method_names.iter().filter_map(|&method_name|
{
pcx.reset();
pcx.method_name = Some(method_name);
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_all_traits();
pcx.pick_core(&mut Vec::new()).and_then(|pick|
pick.ok()).map(|pick| pick.item)
}).collect();
if applicable_close_candidates.is_empty() {
Ok(None)
} else {
let best_name =
{
let names =
applicable_close_candidates.iter().map(|cand|
cand.name()).collect::<Vec<Symbol>>();
find_best_match_for_name_with_substrings(&names,
self.method_name.unwrap().name, None)
}.or_else(||
{
applicable_close_candidates.iter().find(|cand|
self.matches_by_doc_alias(cand.def_id)).map(|cand|
cand.name())
});
Ok(best_name.and_then(|best_name|
{
applicable_close_candidates.into_iter().find(|method|
method.name() == best_name)
}))
}
})
}
}
}#[instrument(level = "debug", skip(self))]
2492 pub(crate) fn probe_for_similar_candidate(
2493 &mut self,
2494 ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2495 debug!("probing for method names similar to {:?}", self.method_name);
2496
2497 self.probe(|_| {
2498 let mut pcx = ProbeContext::new(
2499 self.fcx,
2500 self.span,
2501 self.mode,
2502 self.method_name,
2503 self.return_type,
2504 self.orig_steps_var_values,
2505 self.steps,
2506 self.scope_expr_id,
2507 IsSuggestion(true),
2508 );
2509 pcx.allow_similar_names = true;
2510 pcx.assemble_inherent_candidates();
2511 pcx.assemble_extension_candidates_for_all_traits();
2512
2513 let method_names = pcx.candidate_method_names(|_| true);
2514 pcx.allow_similar_names = false;
2515 let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2516 .iter()
2517 .filter_map(|&method_name| {
2518 pcx.reset();
2519 pcx.method_name = Some(method_name);
2520 pcx.assemble_inherent_candidates();
2521 pcx.assemble_extension_candidates_for_all_traits();
2522 pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2523 })
2524 .collect();
2525
2526 if applicable_close_candidates.is_empty() {
2527 Ok(None)
2528 } else {
2529 let best_name = {
2530 let names = applicable_close_candidates
2531 .iter()
2532 .map(|cand| cand.name())
2533 .collect::<Vec<Symbol>>();
2534 find_best_match_for_name_with_substrings(
2535 &names,
2536 self.method_name.unwrap().name,
2537 None,
2538 )
2539 }
2540 .or_else(|| {
2541 applicable_close_candidates
2542 .iter()
2543 .find(|cand| self.matches_by_doc_alias(cand.def_id))
2544 .map(|cand| cand.name())
2545 });
2546 Ok(best_name.and_then(|best_name| {
2547 applicable_close_candidates
2548 .into_iter()
2549 .find(|method| method.name() == best_name)
2550 }))
2551 }
2552 })
2553 }
2554
2555 fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2558 match self.mode {
2564 Mode::MethodCall => item.is_method(),
2565 Mode::Path => match item.kind {
2566 ty::AssocKind::Type { .. } => false,
2567 ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2568 },
2569 }
2570 }
2577
2578 fn record_static_candidate(&self, source: CandidateSource) {
2579 self.static_candidates.borrow_mut().push(source);
2580 }
2581
2582 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("xform_self_ty",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2582u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item")
}> =
::tracing::__macro_support::FieldName::new("item");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_ty")
}> =
::tracing::__macro_support::FieldName::new("impl_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: (Ty<'tcx>, Option<Ty<'tcx>>) =
loop {};
return __tracing_attr_fake_return;
}
{
if item.is_fn() && self.mode == Mode::MethodCall {
let sig = self.xform_method_sig(item.def_id, args);
(self.self_ty_override.unwrap_or(sig.inputs()[0]),
Some(sig.output()))
} else { (impl_ty, None) }
}
}
}#[instrument(level = "debug", skip(self))]
2583 fn xform_self_ty(
2584 &self,
2585 item: ty::AssocItem,
2586 impl_ty: Ty<'tcx>,
2587 args: GenericArgsRef<'tcx>,
2588 ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2589 if item.is_fn() && self.mode == Mode::MethodCall {
2590 let sig = self.xform_method_sig(item.def_id, args);
2591 (self.self_ty_override.unwrap_or(sig.inputs()[0]), Some(sig.output()))
2592 } else {
2593 (impl_ty, None)
2594 }
2595 }
2596
2597 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("xform_method_sig",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2597u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("method")
}> =
::tracing::__macro_support::FieldName::new("method");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::FnSig<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let fn_sig = self.tcx.fn_sig(method);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2600",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2600u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_sig")
}> =
::tracing::__macro_support::FieldName::new("fn_sig");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_sig)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if !!args.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !args.has_escaping_bound_vars()")
};
let generics = self.tcx.generics_of(method);
{
match (&args.len(), &generics.parent_count) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
let xform_fn_sig =
if generics.is_own_empty() {
fn_sig.instantiate(self.tcx, args).skip_norm_wip()
} else {
let args =
GenericArgs::for_item(self.tcx, method,
|param, _|
{
let i = param.index as usize;
if i < args.len() {
args[i]
} else {
match param.kind {
GenericParamDefKind::Lifetime => {
self.tcx.lifetimes.re_erased.into()
}
GenericParamDefKind::Type { .. } |
GenericParamDefKind::Const { .. } => {
self.var_for_def(self.span, param)
}
}
}
});
fn_sig.instantiate(self.tcx, args).skip_norm_wip()
};
self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
}
}
}#[instrument(level = "debug", skip(self))]
2598 fn xform_method_sig(&self, method: DefId, args: GenericArgsRef<'tcx>) -> ty::FnSig<'tcx> {
2599 let fn_sig = self.tcx.fn_sig(method);
2600 debug!(?fn_sig);
2601
2602 assert!(!args.has_escaping_bound_vars());
2603
2604 let generics = self.tcx.generics_of(method);
2610 assert_eq!(args.len(), generics.parent_count);
2611
2612 let xform_fn_sig = if generics.is_own_empty() {
2613 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2614 } else {
2615 let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2616 let i = param.index as usize;
2617 if i < args.len() {
2618 args[i]
2619 } else {
2620 match param.kind {
2621 GenericParamDefKind::Lifetime => {
2622 self.tcx.lifetimes.re_erased.into()
2624 }
2625 GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2626 self.var_for_def(self.span, param)
2627 }
2628 }
2629 }
2630 });
2631 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2632 };
2633
2634 self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2635 }
2636
2637 fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2639 match (self.mode, kind) {
2640 (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2641 (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2642 _ => false,
2643 }
2644 }
2645
2646 fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2649 let Some(method) = self.method_name else {
2650 return false;
2651 };
2652
2653 if let Some(d) = {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use ::rustc_hir::attrs::AttributeKind::*;
let i: &::rustc_hir::Attribute = i;
match i {
::rustc_hir::Attribute::Parsed(Doc(d)) => {
break 'done Some(d);
}
::rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, Doc(d) => d)
2654 && d.aliases.contains_key(&method.name)
2655 {
2656 return true;
2657 }
2658
2659 if let Some(confusables) =
2660 {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use ::rustc_hir::attrs::AttributeKind::*;
let i: &::rustc_hir::Attribute = i;
match i {
::rustc_hir::Attribute::Parsed(RustcConfusables {
confusables }) => {
break 'done Some(confusables);
}
::rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, RustcConfusables{ confusables } => confusables)
2661 && confusables.contains(&method.name)
2662 {
2663 return true;
2664 }
2665
2666 false
2667 }
2668
2669 fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2674 if let Some(name) = self.method_name {
2675 if self.allow_similar_names {
2676 let max_dist = max(name.as_str().len(), 3) / 3;
2677 self.tcx
2678 .associated_items(def_id)
2679 .in_definition_order()
2680 .filter(|x| {
2681 if !self.is_relevant_kind_for_mode(x.kind) {
2682 return false;
2683 }
2684 if let Some(d) = edit_distance_with_substrings(
2685 name.as_str(),
2686 x.name().as_str(),
2687 max_dist,
2688 ) {
2689 return d > 0;
2690 }
2691 self.matches_by_doc_alias(x.def_id)
2692 })
2693 .copied()
2694 .collect()
2695 } else {
2696 self.fcx
2697 .associated_value(def_id, name)
2698 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2699 .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2700 }
2701 } else {
2702 self.tcx
2703 .associated_items(def_id)
2704 .in_definition_order()
2705 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2706 .copied()
2707 .collect()
2708 }
2709 }
2710}
2711
2712impl<'tcx> Candidate<'tcx> {
2713 fn to_unadjusted_pick(
2714 &self,
2715 self_ty: Ty<'tcx>,
2716 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2717 ) -> Pick<'tcx> {
2718 Pick {
2719 item: self.item,
2720 kind: match self.kind {
2721 InherentImplCandidate { .. } => InherentImplPick,
2722 ObjectCandidate(_) => ObjectPick,
2723 TraitCandidate(_, lint_ambiguous) => TraitPick(lint_ambiguous),
2724 WhereClauseCandidate(trait_ref) => {
2725 if !(!trait_ref.skip_binder().args.has_infer() &&
!trait_ref.skip_binder().args.has_placeholders()) {
::core::panicking::panic("assertion failed: !trait_ref.skip_binder().args.has_infer() &&\n !trait_ref.skip_binder().args.has_placeholders()")
};assert!(
2731 !trait_ref.skip_binder().args.has_infer()
2732 && !trait_ref.skip_binder().args.has_placeholders()
2733 );
2734
2735 WhereClausePick(trait_ref)
2736 }
2737 },
2738 import_ids: self.import_ids,
2739 autoderefs: 0,
2740 autoref_or_ptr_adjustment: None,
2741 self_ty,
2742 unstable_candidates,
2743 receiver_steps: match self.kind {
2744 InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2745 _ => None,
2746 },
2747 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2748 }
2749 }
2750}