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