1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::ops::Deref;
4use std::{assert_matches, debug_assert_matches};
5
6use rustc_attr_ir::find_attr;
7use rustc_attr_ir::lang_items::LangItem;
8use rustc_data_structures::fx::FxHashSet;
9use rustc_data_structures::sso::SsoHashSet;
10use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
11use rustc_hir::def::DefKind;
12use rustc_hir::{self as hir, ExprKind, HirId, Node};
13use rustc_hir_analysis::autoderef::{self, Autoderef};
14use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
15use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
16use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
17use rustc_lint_defs::builtin::{
18 METHOD_CALL_ON_DIVERGING_INFER_VAR, TYVAR_BEHIND_RAW_POINTER, UNSTABLE_NAME_COLLISIONS,
19};
20use rustc_macros::Diagnostic;
21use rustc_middle::middle::stability;
22use rustc_middle::ty::elaborate::supertrait_def_ids;
23use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
24use rustc_middle::ty::{
25 self, AssocContainer, AssocItem, CallerBoundsIterator, GenericArgs, GenericParamDefKind,
26 ParamEnvAnd, Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
27};
28use rustc_span::def_id::{DefId, LocalDefId};
29use rustc_span::edit_distance::{
30 edit_distance_with_substrings, find_best_match_for_name_with_substrings,
31};
32use rustc_span::{DUMMY_SP, Ident, Span, Symbol, bug, span_bug};
33use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
34use rustc_trait_selection::infer::InferCtxtExt as _;
35use rustc_trait_selection::solve::Goal;
36use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
37use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
38use rustc_trait_selection::traits::query::method_autoderef::{
39 CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
40};
41use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
42use smallvec::SmallVec;
43use tracing::{debug, instrument};
44
45use self::CandidateKind::*;
46pub(crate) use self::PickKind::*;
47use super::{CandidateSource, MethodError, NoMatchData, suggest};
48use crate::FnCtxt;
49
50#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for IsSuggestion {
}
#[automatically_derived]impl ::core::clone::Clone for IsSuggestion {
#[inline]
fn clone(&self) -> Self {
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_struct_field1_finish(f, "IsSuggestion",
&&self.0)
}
}Debug)]
53pub(crate) struct IsSuggestion(pub bool);
54
55pub(crate) struct ProbeContext<'a, 'tcx> {
56 fcx: &'a FnCtxt<'a, 'tcx>,
57 span: Span,
58 mode: Mode,
59 method_name: Option<Ident>,
60 return_type: Option<Ty<'tcx>>,
61
62 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
65 steps: &'tcx [CandidateStep<'tcx>],
66
67 inherent_candidates: Vec<Candidate<'tcx>>,
68 extension_candidates: Vec<Candidate<'tcx>>,
69 impl_dups: FxHashSet<DefId>,
70
71 allow_similar_names: bool,
74
75 private_candidates: Vec<Candidate<'tcx>>,
78
79 private_candidate: Cell<Option<(DefKind, DefId)>>,
81
82 static_candidates: RefCell<Vec<CandidateSource>>,
85
86 scope_expr_id: HirId,
87
88 is_suggestion: IsSuggestion,
92
93 self_ty_override: Option<Ty<'tcx>>,
101}
102
103impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
104 type Target = FnCtxt<'a, 'tcx>;
105 fn deref(&self) -> &Self::Target {
106 self.fcx
107 }
108}
109
110#[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 kind import_ids", &self.item, &self.kind,
&&self.import_ids)
}
}Debug, #[automatically_derived]impl<'tcx> ::core::clone::Clone for Candidate<'tcx> {
#[inline]
fn clone(&self) -> Self {
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)]
111pub(crate) struct Candidate<'tcx> {
112 pub(crate) item: ty::AssocItem,
113 pub(crate) kind: CandidateKind<'tcx>,
114 pub(crate) import_ids: &'tcx [LocalDefId],
115}
116
117#[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 {
Self::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InherentImplCandidate impl_def_id receiver_steps",
__self_0, &__self_1),
Self::ObjectCandidate(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ObjectCandidate", &__self_0),
Self::TraitCandidate {
trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"TraitCandidate trait_ref is_ambiguously_imported",
__self_0, &__self_1),
Self::WhereClauseCandidate(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"WhereClauseCandidate", &__self_0),
}
}
}Debug, #[automatically_derived]impl<'tcx> ::core::clone::Clone for
CandidateKind<'tcx> {
#[inline]
fn clone(&self) -> Self {
match self {
Self::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),
},
Self::ObjectCandidate(__self_0) =>
CandidateKind::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
Self::TraitCandidate {
trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
CandidateKind::TraitCandidate {
trait_ref: ::core::clone::Clone::clone(__self_0),
is_ambiguously_imported: ::core::clone::Clone::clone(__self_1),
},
Self::WhereClauseCandidate(__self_0) =>
CandidateKind::WhereClauseCandidate(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
118pub(crate) enum CandidateKind<'tcx> {
119 InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
120 ObjectCandidate(ty::PolyTraitRef<'tcx>),
121 TraitCandidate { trait_ref: ty::PolyTraitRef<'tcx>, is_ambiguously_imported: bool },
122 WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
123}
124
125#[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::marker::StructuralPartialEq for
ProbeResult {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ProbeResult {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ProbeResult { }Eq, #[automatically_derived]impl ::core::marker::Copy for ProbeResult { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ProbeResult {
}
#[automatically_derived]impl ::core::clone::Clone for ProbeResult {
#[inline]
fn clone(&self) -> Self { *self }
}Clone)]
126enum ProbeResult {
127 NoMatch,
128 BadReturnType,
129 Match,
130}
131
132#[derive(#[automatically_derived]impl ::core::fmt::Debug for AutorefOrPtrAdjustment {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Autoref { mutbl: __self_0, unsize: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Autoref mutbl unsize", __self_0, &__self_1),
Self::ToConstPtr =>
::core::fmt::Formatter::write_str(f, "ToConstPtr"),
Self::ReborrowPin(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"ReborrowPin", &__self_0),
}
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
AutorefOrPtrAdjustment {
}
#[automatically_derived]impl ::core::cmp::PartialEq for AutorefOrPtrAdjustment
{
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Autoref { mutbl: __self_0, unsize: __self_1 },
Self::Autoref { mutbl: __arg1_0, unsize: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::ReborrowPin(__self_0), Self::ReborrowPin(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::marker::Copy for AutorefOrPtrAdjustment {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AutorefOrPtrAdjustment {
}
#[automatically_derived]impl ::core::clone::Clone for AutorefOrPtrAdjustment {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
*self
}
}Clone)]
145pub(crate) enum AutorefOrPtrAdjustment {
146 Autoref {
149 mutbl: hir::Mutability,
150
151 unsize: bool,
154 },
155 ToConstPtr,
157
158 ReborrowPin(hir::Mutability),
160}
161
162impl AutorefOrPtrAdjustment {
163 fn get_unsize(&self) -> bool {
164 match self {
165 AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
166 AutorefOrPtrAdjustment::ToConstPtr => false,
167 AutorefOrPtrAdjustment::ReborrowPin(_) => false,
168 }
169 }
170}
171
172#[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 unsatisfied_predicates",
&self.unstable_candidates, &&self.unsatisfied_predicates)
}
}Debug)]
174struct PickDiagHints<'a, 'tcx> {
175 unstable_candidates: Option<Vec<(Candidate<'tcx>, Symbol)>>,
177
178 unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'tcx>,
181}
182
183pub(crate) type UnsatisfiedPredicates<'tcx> =
184 Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>;
185
186#[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 receiver_steps def_id",
&self.autoderefs, &self.receiver_steps, &&self.def_id)
}
}Debug)]
190struct PickConstraintsForShadowed {
191 autoderefs: usize,
192 receiver_steps: Option<usize>,
193 def_id: DefId,
194}
195
196impl PickConstraintsForShadowed {
197 fn may_shadow_based_on_autoderefs(&self, autoderefs: usize) -> bool {
198 autoderefs == self.autoderefs
199 }
200
201 fn candidate_may_shadow(&self, candidate: &Candidate<'_>) -> bool {
202 candidate.item.def_id != self.def_id
204 && match candidate.kind {
208 CandidateKind::InherentImplCandidate { receiver_steps, .. } => match self.receiver_steps {
209 Some(shadowed_receiver_steps) => receiver_steps > shadowed_receiver_steps,
210 _ => false
211 },
212 _ => false
213 }
214 }
215}
216
217#[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 _ =
"Pick 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, names, values)
}
}Debug, #[automatically_derived]impl<'tcx> ::core::clone::Clone for Pick<'tcx> {
#[inline]
fn clone(&self) -> Self {
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)]
218pub(crate) struct Pick<'tcx> {
219 pub item: ty::AssocItem,
220 pub kind: PickKind<'tcx>,
221 pub import_ids: &'tcx [LocalDefId],
222
223 pub autoderefs: usize,
228
229 pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
232 pub self_ty: Ty<'tcx>,
233
234 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
236
237 pub receiver_steps: Option<usize>,
241
242 pub shadowed_candidates: Vec<ty::AssocItem>,
244}
245
246#[derive(#[automatically_derived]impl<'tcx> ::core::clone::Clone for PickKind<'tcx> {
#[inline]
fn clone(&self) -> Self {
match self {
Self::InherentImplPick => PickKind::InherentImplPick,
Self::ObjectPick => PickKind::ObjectPick,
Self::TraitPick { is_ambiguously_imported: __self_0 } =>
PickKind::TraitPick {
is_ambiguously_imported: ::core::clone::Clone::clone(__self_0),
},
Self::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 {
Self::InherentImplPick =>
::core::fmt::Formatter::write_str(f, "InherentImplPick"),
Self::ObjectPick =>
::core::fmt::Formatter::write_str(f, "ObjectPick"),
Self::TraitPick { is_ambiguously_imported: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TraitPick is_ambiguously_imported", &__self_0),
Self::WhereClausePick(__self_0) =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"WhereClausePick", &__self_0),
}
}
}Debug, #[automatically_derived]impl<'tcx> ::core::marker::StructuralPartialEq for
PickKind<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::cmp::PartialEq for PickKind<'tcx> {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::TraitPick { is_ambiguously_imported: __self_0 },
Self::TraitPick { is_ambiguously_imported: __arg1_0 }) =>
__self_0 == __arg1_0,
(Self::WhereClausePick(__self_0),
Self::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)]
247pub(crate) enum PickKind<'tcx> {
248 InherentImplPick,
249 ObjectPick,
250 TraitPick {
251 is_ambiguously_imported: 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::marker::StructuralPartialEq for Mode { }
#[automatically_derived]impl ::core::cmp::PartialEq for Mode {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Mode { }Eq, #[automatically_derived]impl ::core::marker::Copy for Mode { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Mode {
}
#[automatically_derived]impl ::core::clone::Clone for Mode {
#[inline]
fn clone(&self) -> Self { *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::marker::StructuralPartialEq for
ProbeScope<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::cmp::PartialEq for ProbeScope<'tcx>
{
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Single(__self_0, __self_1),
Self::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 {
Self::Single(__self_0, __self_1) =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Single", __self_0, &__self_1),
Self::TraitsInScope =>
::core::fmt::Formatter::write_str(f, "TraitsInScope"),
Self::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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/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> rustc_errors::Diagnostic<'_sess> for MissingTypeAnnot {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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> rustc_errors::Diagnostic<'_sess> for
MethodCallOnDivergingInferenceVariable {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
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 /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:437",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/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_span::macros::bug_impl(Some(span),
format_args!("reached the recursion limit in 0 steps?"),
Location::caller())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_span::macros::bug_impl(Some(span),
format_args!("instantiating {0:?} failed?", ty), Location::caller())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_span::macros::bug_impl(Some(span),
format_args!("instantiating {0:?} failed?", ty), Location::caller())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 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 self.demand_eqtype(span, ty, self.tcx.types.never);
528 } else {
529 let guar = match *ty.kind() {
530 _ if let Some(guar) = self.tainted_by_errors() => guar,
531 ty::Infer(ty::TyVar(_)) => {
532 let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
535 (
536 Mode::MethodCall,
537 Node::Expr(hir::Expr {
538 kind: ExprKind::MethodCall(_, recv, ..),
539 ..
540 }),
541 ) => recv.span,
542 _ => span,
543 };
544
545 let raw_ptr_call = bad_ty.reached_raw_pointer
546 && !self.tcx.features().arbitrary_self_types();
547
548 let mut err = self.err_ctxt().emit_inference_failure_err(
549 self.body_def_id,
550 err_span,
551 ty.into(),
552 TypeAnnotationNeeded::E0282,
553 !raw_ptr_call,
554 );
555 if raw_ptr_call {
556 err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
557 }
558 err.emit_err()
559 }
560 ty::Error(guar) => guar,
561 _ => ::rustc_span::macros::bug_impl(None,
format_args!("unexpected bad final type in method autoderef"),
Location::caller())bug!("unexpected bad final type in method autoderef"),
562 };
563 self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
564 return Err(MethodError::ErrorReported(guar));
565 }
566 }
567
568 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:568",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(568u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ProbeContext: steps for self_ty={0:?} are {1:?}",
self_ty, steps) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("ProbeContext: steps for self_ty={:?} are {:?}", self_ty, steps);
569
570 self.probe(|_| {
573 let mut probe_cx = ProbeContext::new(
574 self,
575 span,
576 mode,
577 method_name,
578 return_type,
579 &orig_values,
580 steps.steps,
581 scope_expr_id,
582 is_suggestion,
583 );
584
585 match scope {
586 ProbeScope::TraitsInScope => {
587 probe_cx.assemble_inherent_candidates();
588 probe_cx.assemble_extension_candidates_for_traits_in_scope();
589 }
590 ProbeScope::AllTraits => {
591 probe_cx.assemble_inherent_candidates();
592 probe_cx.assemble_extension_candidates_for_all_traits();
593 }
594 ProbeScope::Single(def_id, self_ty_override) => {
595 let item = self.tcx.associated_item(def_id);
596 {
match item.container {
AssocContainer::Trait | AssocContainer::InherentImpl => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"AssocContainer::Trait | AssocContainer::InherentImpl",
::core::option::Option::None);
}
}
};assert_matches!(
597 item.container,
598 AssocContainer::Trait | AssocContainer::InherentImpl
599 );
600
601 let trait_def_id = self.tcx.parent(def_id);
602 let trait_span = self.tcx.def_span(trait_def_id);
603
604 let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
605 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
606
607 probe_cx.self_ty_override = self_ty_override;
608 probe_cx.push_candidate(
609 Candidate {
610 item,
611 kind: match item.container {
612 AssocContainer::Trait => CandidateKind::TraitCandidate {
613 trait_ref: ty::Binder::dummy(trait_ref),
614 is_ambiguously_imported: false,
615 },
616 AssocContainer::InherentImpl => {
617 CandidateKind::InherentImplCandidate {
618 impl_def_id: self.tcx.parent(def_id),
619 receiver_steps: 0,
620 }
621 }
622 _ => ::core::panicking::unreachable_default_msg()unreachable!(),
623 },
624 import_ids: &[],
625 },
626 false,
627 );
628 }
629 };
630 op(probe_cx)
631 })
632 }
633}
634
635pub(crate) fn method_autoderef_steps<'tcx>(
636 tcx: TyCtxt<'tcx>,
637 goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
638) -> MethodAutoderefStepsResult<'tcx> {
639 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:639",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(639u32),
::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);
640
641 let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
642 let ParamEnvAnd {
643 param_env,
644 value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
645 } = goal;
646 for (key, ty) in predefined_opaques_in_body {
647 let prev = infcx
648 .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
649 if let Some(prev) = prev {
661 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:661",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(661u32),
::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`");
662 }
663 }
664 let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
665
666 let self_ty_is_opaque = |ty: Ty<'_>| {
670 if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
671 infcx.has_opaques_with_sub_unified_hidden_type(vid)
672 } else {
673 false
674 }
675 };
676
677 let mut autoderef_via_deref =
687 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
688 .include_raw_pointers()
689 .silence_errors();
690
691 let mut reached_raw_pointer = false;
692 let arbitrary_self_types_enabled =
693 tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
694 let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
695 let reachable_via_deref =
696 autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
697
698 let mut autoderef_via_receiver =
699 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
700 .include_raw_pointers()
701 .use_receiver_trait()
702 .silence_errors();
703 let steps = autoderef_via_receiver
704 .by_ref()
705 .zip(reachable_via_deref)
706 .map(|((ty, d), reachable_via_deref)| {
707 let step = CandidateStep {
708 self_ty: infcx.make_query_response_ignoring_pending_obligations(
709 inference_vars,
710 ty,
711 prev_opaque_entries,
712 ),
713 self_ty_is_opaque: self_ty_is_opaque(ty),
714 autoderefs: d,
715 from_unsafe_deref: reached_raw_pointer,
716 unsize: false,
717 reachable_via_deref,
718 };
719 if ty.is_raw_ptr() {
720 reached_raw_pointer = true;
722 }
723 step
724 })
725 .collect();
726 (steps, autoderef_via_receiver.reached_recursion_limit())
727 } else {
728 let steps = autoderef_via_deref
729 .by_ref()
730 .map(|(ty, d)| {
731 let step = CandidateStep {
732 self_ty: infcx.make_query_response_ignoring_pending_obligations(
733 inference_vars,
734 ty,
735 prev_opaque_entries,
736 ),
737 self_ty_is_opaque: self_ty_is_opaque(ty),
738 autoderefs: d,
739 from_unsafe_deref: reached_raw_pointer,
740 unsize: false,
741 reachable_via_deref: true,
742 };
743 if ty.is_raw_ptr() {
744 reached_raw_pointer = true;
746 }
747 step
748 })
749 .collect();
750 (steps, autoderef_via_deref.reached_recursion_limit())
751 };
752 let final_ty = autoderef_via_deref.final_ty();
753 let opt_bad_ty = match final_ty.kind() {
754 ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
755 reached_raw_pointer,
756 ty: infcx.make_query_response_ignoring_pending_obligations(
757 inference_vars,
758 final_ty,
759 prev_opaque_entries,
760 ),
761 }),
762 ty::Error(_) => Some(MethodAutoderefBadTy {
763 reached_raw_pointer,
764 ty: infcx.make_query_response_ignoring_pending_obligations(
765 inference_vars,
766 final_ty,
767 prev_opaque_entries,
768 ),
769 }),
770 ty::Array(elem_ty, _) => {
771 let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
772 steps.push(CandidateStep {
773 self_ty: infcx.make_query_response_ignoring_pending_obligations(
774 inference_vars,
775 Ty::new_slice(infcx.tcx, *elem_ty),
776 prev_opaque_entries,
777 ),
778 self_ty_is_opaque: false,
779 autoderefs,
780 from_unsafe_deref: reached_raw_pointer,
783 unsize: true,
784 reachable_via_deref: true, });
787
788 None
789 }
790 _ => None,
791 };
792
793 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:793",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(793u32),
::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);
794 let _ = infcx.take_opaque_types();
796 MethodAutoderefStepsResult {
797 steps: tcx.arena.alloc_from_iter(steps),
798 opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
799 reached_recursion_limit,
800 }
801}
802
803impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
804 fn new(
805 fcx: &'a FnCtxt<'a, 'tcx>,
806 span: Span,
807 mode: Mode,
808 method_name: Option<Ident>,
809 return_type: Option<Ty<'tcx>>,
810 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
811 steps: &'tcx [CandidateStep<'tcx>],
812 scope_expr_id: HirId,
813 is_suggestion: IsSuggestion,
814 ) -> ProbeContext<'a, 'tcx> {
815 ProbeContext {
816 fcx,
817 span,
818 mode,
819 method_name,
820 return_type,
821 inherent_candidates: Vec::new(),
822 extension_candidates: Vec::new(),
823 impl_dups: FxHashSet::default(),
824 orig_steps_var_values,
825 steps,
826 allow_similar_names: false,
827 private_candidates: Vec::new(),
828 private_candidate: Cell::new(None),
829 static_candidates: RefCell::new(Vec::new()),
830 scope_expr_id,
831 is_suggestion,
832 self_ty_override: None,
833 }
834 }
835
836 fn reset(&mut self) {
837 self.inherent_candidates.clear();
838 self.extension_candidates.clear();
839 self.impl_dups.clear();
840 self.private_candidates.clear();
841 self.private_candidate.set(None);
842 self.static_candidates.borrow_mut().clear();
843 }
844
845 fn variance(&self) -> ty::Variance {
849 match self.mode {
850 Mode::MethodCall => ty::Covariant,
851 Mode::Path => ty::Invariant,
852 }
853 }
854
855 fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
859 let is_accessible = if let Some(name) = self.method_name {
860 let item = candidate.item;
861 let container_id = item.container_id(self.tcx);
862 let def_scope = self.tcx.adjust_ident_and_get_scope(name, container_id, self.mod_id).1;
863 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
864 } else {
865 true
866 };
867 if is_accessible {
868 if is_inherent {
869 self.inherent_candidates.push(candidate);
870 } else {
871 self.extension_candidates.push(candidate);
872 }
873 } else {
874 self.private_candidates.push(candidate);
875 }
876 }
877
878 fn assemble_inherent_candidates(&mut self) {
879 for step in self.steps.iter() {
880 self.assemble_probe(&step.self_ty, step.autoderefs);
881 }
882 }
883
884 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(884u32),
::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))]
885 fn assemble_probe(
886 &mut self,
887 self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
888 receiver_steps: usize,
889 ) {
890 let raw_self_ty = self_ty.value.value;
891 match *raw_self_ty.kind() {
892 ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
893 let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
911 self.fcx.instantiate_canonical(self.span, self_ty);
912
913 self.assemble_inherent_candidates_from_object(generalized_self_ty);
914 self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
915 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
916 }
917 ty::Adt(def, _) => {
918 let def_id = def.did();
919 self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
920 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
921 }
922 ty::Foreign(did) => {
923 self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
924 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
925 }
926 ty::Param(_) => {
927 self.assemble_inherent_candidates_from_param(raw_self_ty);
928 }
929 ty::Bool
930 | ty::Char
931 | ty::Int(_)
932 | ty::Uint(_)
933 | ty::Float(_)
934 | ty::Str
935 | ty::Array(..)
936 | ty::Slice(_)
937 | ty::RawPtr(_, _)
938 | ty::Ref(..)
939 | ty::Never
940 | ty::Tuple(..) => {
941 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
942 }
943 ty::Alias(..)
944 | ty::Bound(..)
945 | ty::Closure(..)
946 | ty::Coroutine(..)
947 | ty::CoroutineClosure(..)
948 | ty::CoroutineWitness(..)
949 | ty::Dynamic(..)
950 | ty::Error(..)
951 | ty::FnDef(..)
952 | ty::FnPtr(..)
953 | ty::Infer(..)
954 | ty::Pat(..)
955 | ty::Placeholder(..)
956 | ty::UnsafeBinder(..) => {}
957 }
958 }
959
960 fn assemble_inherent_candidates_for_incoherent_ty(
961 &mut self,
962 self_ty: Ty<'tcx>,
963 receiver_steps: usize,
964 ) {
965 let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
966 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected incoherent type: {0:?}", self_ty),
Location::caller())bug!("unexpected incoherent type: {:?}", self_ty)
967 };
968 for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
969 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
970 }
971 }
972
973 fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
974 let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
975 for &impl_def_id in impl_def_ids {
976 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
977 }
978 }
979
980 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(980u32),
::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))]
981 fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
982 if !self.impl_dups.insert(impl_def_id) {
983 return; }
985
986 for item in self.impl_or_trait_item(impl_def_id) {
987 if !self.has_applicable_self(&item) {
988 self.record_static_candidate(CandidateSource::Impl(impl_def_id));
990 continue;
991 }
992 self.push_candidate(
993 Candidate {
994 item,
995 kind: InherentImplCandidate { impl_def_id, receiver_steps },
996 import_ids: &[],
997 },
998 true,
999 );
1000 }
1001 }
1002
1003 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1003u32),
::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_span::macros::bug_impl(Some(self.span),
format_args!("non-object {0:?} in assemble_inherent_candidates_from_object",
self_ty), Location::caller())
});
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))]
1004 fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
1005 let principal = match self_ty.kind() {
1006 ty::Dynamic(data, ..) => Some(data),
1007 _ => None,
1008 }
1009 .and_then(|data| data.principal())
1010 .unwrap_or_else(|| {
1011 span_bug!(
1012 self.span,
1013 "non-object {:?} in assemble_inherent_candidates_from_object",
1014 self_ty
1015 )
1016 });
1017
1018 let trait_ref = principal.with_self_ty(self.tcx, self_ty);
1025 self.assemble_candidates_for_bounds(
1026 traits::supertraits(self.tcx, trait_ref),
1027 |this, new_trait_ref, item| {
1028 this.push_candidate(
1029 Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
1030 true,
1031 );
1032 },
1033 );
1034 }
1035
1036 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1036u32),
::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().trait_clauses(tcx).iter().filter_map(|bound_trait_clause|
{
let trait_clause = bound_trait_clause.skip_binder();
DeepRejectCtxt::relate_rigid_rigid(tcx).types_may_unify(param_ty,
trait_clause.trait_ref.self_ty()).then(||
bound_trait_clause.rebind(trait_clause.trait_ref))
});
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))]
1037 fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
1038 debug_assert_matches!(param_ty.kind(), ty::Param(_));
1039
1040 let tcx = self.tcx;
1041
1042 let bounds = self.param_env.caller_bounds().trait_clauses(tcx).iter().filter_map(
1046 |bound_trait_clause| {
1047 let trait_clause = bound_trait_clause.skip_binder();
1048 DeepRejectCtxt::relate_rigid_rigid(tcx)
1049 .types_may_unify(param_ty, trait_clause.trait_ref.self_ty())
1050 .then(|| bound_trait_clause.rebind(trait_clause.trait_ref))
1051 },
1052 );
1053
1054 self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1055 this.push_candidate(
1056 Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
1057 true,
1058 );
1059 });
1060 }
1061
1062 fn assemble_candidates_for_bounds<F>(
1065 &mut self,
1066 bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1067 mut mk_cand: F,
1068 ) where
1069 F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1070 {
1071 for bound_trait_ref in bounds {
1072 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1072",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1072u32),
::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);
1073 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1074 if !self.has_applicable_self(&item) {
1075 self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1076 } else {
1077 mk_cand(self, bound_trait_ref, item);
1078 }
1079 }
1080 }
1081 }
1082
1083 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1083u32),
::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,
trait_candidate.lint_ambiguous)) {
self.assemble_extension_candidates_for_trait(&trait_candidate.import_ids,
trait_did, trait_candidate.lint_ambiguous);
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1084 fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1085 let mut duplicates = FxHashSet::default();
1086 let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1087 if let Some(applicable_traits) = opt_applicable_traits {
1088 for trait_candidate in applicable_traits.iter() {
1089 let trait_did = trait_candidate.def_id;
1090 if duplicates.insert((trait_did, trait_candidate.lint_ambiguous)) {
1093 self.assemble_extension_candidates_for_trait(
1094 &trait_candidate.import_ids,
1095 trait_did,
1096 trait_candidate.lint_ambiguous,
1097 );
1098 }
1099 }
1100 }
1101 }
1102
1103 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1103u32),
::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))]
1104 fn assemble_extension_candidates_for_all_traits(&mut self) {
1105 let mut duplicates = FxHashSet::default();
1106 for trait_info in suggest::all_traits(self.tcx) {
1107 if duplicates.insert(trait_info.def_id) {
1108 self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
1109 }
1110 }
1111 }
1112
1113 fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1114 match method.kind {
1115 ty::AssocKind::Fn { .. } => self.probe(|_| {
1116 let args = self.fresh_args_for_item(self.span, method.def_id);
1117 let fty =
1118 self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args).skip_norm_wip();
1119 let fty = self.instantiate_binder_with_fresh_vars(
1120 self.span,
1121 BoundRegionConversionTime::FnCall,
1122 fty,
1123 );
1124 self.can_eq(self.param_env, fty.output(), expected)
1125 }),
1126 _ => false,
1127 }
1128 }
1129
1130 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1130u32),
::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("is_ambiguously_imported")
}> =
::tracing::__macro_support::FieldName::new("is_ambiguously_imported");
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(&is_ambiguously_imported
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::ClausePolarity::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 {
trait_ref: bound_trait_ref,
is_ambiguously_imported,
},
}, 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 /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1175",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1175u32),
::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 {
trait_ref: ty::Binder::dummy(trait_ref),
is_ambiguously_imported,
},
}, false);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1131 fn assemble_extension_candidates_for_trait(
1132 &mut self,
1133 import_ids: &'tcx [LocalDefId],
1134 trait_def_id: DefId,
1135 is_ambiguously_imported: bool,
1136 ) {
1137 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1138 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1139
1140 if self.tcx.is_trait_alias(trait_def_id) {
1141 for (bound_trait_pred, _) in
1143 traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1144 {
1145 assert_eq!(bound_trait_pred.polarity(), ty::ClausePolarity::Positive);
1146 let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1147 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1148 if !self.has_applicable_self(&item) {
1149 self.record_static_candidate(CandidateSource::Trait(
1150 bound_trait_ref.def_id(),
1151 ));
1152 } else {
1153 self.push_candidate(
1154 Candidate {
1155 item,
1156 import_ids,
1157 kind: TraitCandidate {
1158 trait_ref: bound_trait_ref,
1159 is_ambiguously_imported,
1160 },
1161 },
1162 false,
1163 );
1164 }
1165 }
1166 }
1167 } else {
1168 debug_assert!(self.tcx.is_trait(trait_def_id));
1169 if self.tcx.trait_is_auto(trait_def_id) {
1170 return;
1171 }
1172 for item in self.impl_or_trait_item(trait_def_id) {
1173 if !self.has_applicable_self(&item) {
1175 debug!("method has inapplicable self");
1176 self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1177 continue;
1178 }
1179 self.push_candidate(
1180 Candidate {
1181 item,
1182 import_ids,
1183 kind: TraitCandidate {
1184 trait_ref: ty::Binder::dummy(trait_ref),
1185 is_ambiguously_imported,
1186 },
1187 },
1188 false,
1189 );
1190 }
1191 }
1192 }
1193
1194 fn candidate_method_names(
1195 &self,
1196 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1197 ) -> Vec<Ident> {
1198 let mut set = FxHashSet::default();
1199 let mut names: Vec<_> = self
1200 .inherent_candidates
1201 .iter()
1202 .chain(&self.extension_candidates)
1203 .filter(|candidate| candidate_filter(&candidate.item))
1204 .filter(|candidate| {
1205 if let Some(return_ty) = self.return_type {
1206 self.matches_return_type(candidate.item, return_ty)
1207 } else {
1208 true
1209 }
1210 })
1211 .filter(|candidate| {
1213 !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
None, DUMMY_SP, None) {
stability::EvalResult::Deny { .. } => true,
_ => false,
}matches!(
1216 self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1217 stability::EvalResult::Deny { .. }
1218 )
1219 })
1220 .map(|candidate| candidate.item.ident(self.tcx))
1221 .filter(|&name| set.insert(name))
1222 .collect();
1223
1224 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1226 names
1227 }
1228
1229 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1232u32),
::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 /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1254",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1254u32),
::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))]
1233 fn pick(mut self) -> PickResult<'tcx> {
1234 assert!(self.method_name.is_some());
1235
1236 let mut unsatisfied_predicates = Vec::new();
1237
1238 if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1239 return r;
1240 }
1241
1242 if self.is_suggestion.0 {
1245 return Err(MethodError::NoMatch(NoMatchData {
1246 static_candidates: vec![],
1247 unsatisfied_predicates: vec![],
1248 out_of_scope_traits: vec![],
1249 similar_candidate: None,
1250 mode: self.mode,
1251 }));
1252 }
1253
1254 debug!("pick: actual search failed, assemble diagnostics");
1255
1256 let static_candidates = std::mem::take(self.static_candidates.get_mut());
1257 let private_candidate = self.private_candidate.take();
1258
1259 self.reset();
1261
1262 self.assemble_extension_candidates_for_all_traits();
1263
1264 let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1265 Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1266 Some(Err(MethodError::Ambiguity(v))) => v
1267 .into_iter()
1268 .map(|source| match source {
1269 CandidateSource::Trait(id) => id,
1270 CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1271 })
1272 .collect(),
1273 Some(Err(MethodError::NoMatch(NoMatchData {
1274 out_of_scope_traits: others, ..
1275 }))) => {
1276 assert!(others.is_empty());
1277 vec![]
1278 }
1279 _ => vec![],
1280 };
1281
1282 if let Some((kind, def_id)) = private_candidate {
1283 return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1284 }
1285 let similar_candidate = self.probe_for_similar_candidate()?;
1286
1287 Err(MethodError::NoMatch(NoMatchData {
1288 static_candidates,
1289 unsatisfied_predicates,
1290 out_of_scope_traits,
1291 similar_candidate,
1292 mode: self.mode,
1293 }))
1294 }
1295
1296 fn pick_core(
1297 &self,
1298 unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1299 ) -> Option<PickResult<'tcx>> {
1300 self.pick_all_method(&mut PickDiagHints {
1302 unstable_candidates: Some(Vec::new()),
1305 unsatisfied_predicates,
1308 })
1309 .or_else(|| {
1310 self.pick_all_method(&mut PickDiagHints {
1311 unstable_candidates: None,
1316 unsatisfied_predicates: &mut Vec::new(),
1319 })
1320 })
1321 }
1322
1323 fn pick_all_method<'b>(
1324 &self,
1325 pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1326 ) -> Option<PickResult<'tcx>> {
1327 let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1328 self.steps
1329 .iter()
1330 .filter(|step| step.reachable_via_deref)
1334 .filter(|step| {
1335 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1335",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1335u32),
::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);
1336 !step.self_ty.value.references_error() && !step.from_unsafe_deref
1339 })
1340 .find_map(|step| {
1341 let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1342 .fcx
1343 .probe_instantiate_query_response(
1344 self.span,
1345 self.orig_steps_var_values,
1346 &step.self_ty,
1347 )
1348 .unwrap_or_else(|_| {
1349 ::rustc_span::macros::bug_impl(Some(self.span),
format_args!("{0:?} was applicable but now isn\'t?", step.self_ty),
Location::caller())span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
1350 });
1351
1352 let by_value_pick = self.pick_by_value_method(
1353 step,
1354 self_ty,
1355 &instantiate_self_ty_obligations,
1356 pick_diag_hints,
1357 );
1358
1359 if let Some(by_value_pick) = by_value_pick {
1361 if let Ok(by_value_pick) = by_value_pick.as_ref() {
1362 if by_value_pick.kind == PickKind::InherentImplPick {
1363 for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1364 if let Err(e) = self.check_for_shadowed_autorefd_method(
1365 by_value_pick,
1366 step,
1367 self_ty,
1368 &instantiate_self_ty_obligations,
1369 mutbl,
1370 track_unstable_candidates,
1371 ) {
1372 return Some(Err(e));
1373 }
1374 }
1375 }
1376 }
1377 return Some(by_value_pick);
1378 }
1379
1380 let autoref_pick = self.pick_autorefd_method(
1381 step,
1382 self_ty,
1383 &instantiate_self_ty_obligations,
1384 hir::Mutability::Not,
1385 pick_diag_hints,
1386 None,
1387 );
1388 if let Some(autoref_pick) = autoref_pick {
1390 if let Ok(autoref_pick) = autoref_pick.as_ref() {
1391 if autoref_pick.kind == PickKind::InherentImplPick {
1393 if let Err(e) = self.check_for_shadowed_autorefd_method(
1394 autoref_pick,
1395 step,
1396 self_ty,
1397 &instantiate_self_ty_obligations,
1398 hir::Mutability::Mut,
1399 track_unstable_candidates,
1400 ) {
1401 return Some(Err(e));
1402 }
1403 }
1404 }
1405 return Some(autoref_pick);
1406 }
1407
1408 self.pick_autorefd_method(
1432 step,
1433 self_ty,
1434 &instantiate_self_ty_obligations,
1435 hir::Mutability::Mut,
1436 pick_diag_hints,
1437 None,
1438 )
1439 .or_else(|| {
1440 self.pick_const_ptr_method(
1441 step,
1442 self_ty,
1443 &instantiate_self_ty_obligations,
1444 pick_diag_hints,
1445 )
1446 })
1447 .or_else(|| {
1448 self.pick_reborrow_pin_method(
1449 step,
1450 self_ty,
1451 &instantiate_self_ty_obligations,
1452 pick_diag_hints,
1453 )
1454 })
1455 })
1456 }
1457
1458 fn check_for_shadowed_autorefd_method(
1474 &self,
1475 possible_shadower: &Pick<'tcx>,
1476 step: &CandidateStep<'tcx>,
1477 self_ty: Ty<'tcx>,
1478 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1479 mutbl: hir::Mutability,
1480 track_unstable_candidates: bool,
1481 ) -> Result<(), MethodError<'tcx>> {
1482 if !self.tcx.features().arbitrary_self_types()
1486 && !self.tcx.features().arbitrary_self_types_pointers()
1487 {
1488 return Ok(());
1489 }
1490
1491 let mut pick_diag_hints = PickDiagHints {
1496 unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1497 unsatisfied_predicates: &mut Vec::new(),
1498 };
1499 let pick_constraints = PickConstraintsForShadowed {
1501 autoderefs: possible_shadower.autoderefs,
1503 receiver_steps: possible_shadower.receiver_steps,
1507 def_id: possible_shadower.item.def_id,
1510 };
1511 let potentially_shadowed_pick = self.pick_autorefd_method(
1541 step,
1542 self_ty,
1543 instantiate_self_ty_obligations,
1544 mutbl,
1545 &mut pick_diag_hints,
1546 Some(&pick_constraints),
1547 );
1548 if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1551 let sources = [possible_shadower, possible_shadowed]
1552 .into_iter()
1553 .map(|p| self.candidate_source_from_pick(p))
1554 .collect();
1555 return Err(MethodError::Ambiguity(sources));
1556 }
1557 Ok(())
1558 }
1559
1560 fn pick_by_value_method(
1567 &self,
1568 step: &CandidateStep<'tcx>,
1569 self_ty: Ty<'tcx>,
1570 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1571 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1572 ) -> Option<PickResult<'tcx>> {
1573 if step.unsize {
1574 return None;
1575 }
1576
1577 self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1578 r.map(|mut pick| {
1579 pick.autoderefs = step.autoderefs;
1580
1581 match *step.self_ty.value.value.kind() {
1582 ty::Ref(_, _, mutbl) => {
1584 pick.autoderefs += 1;
1585 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1586 mutbl,
1587 unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1588 })
1589 }
1590
1591 ty::Adt(def, args)
1592 if self.tcx.features().pin_ergonomics()
1593 && self.tcx.is_lang_item(def.did(), LangItem::Pin) =>
1594 {
1595 if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1597 pick.autoref_or_ptr_adjustment =
1598 Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1599 }
1600 }
1601
1602 _ => (),
1603 }
1604
1605 pick
1606 })
1607 })
1608 }
1609
1610 fn pick_autorefd_method(
1611 &self,
1612 step: &CandidateStep<'tcx>,
1613 self_ty: Ty<'tcx>,
1614 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1615 mutbl: hir::Mutability,
1616 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1617 pick_constraints: Option<&PickConstraintsForShadowed>,
1618 ) -> Option<PickResult<'tcx>> {
1619 let tcx = self.tcx;
1620
1621 if let Some(pick_constraints) = pick_constraints {
1622 if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1623 return None;
1624 }
1625 }
1626
1627 let region = tcx.lifetimes.re_erased;
1629
1630 let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1631 self.pick_method(
1632 autoref_ty,
1633 instantiate_self_ty_obligations,
1634 pick_diag_hints,
1635 pick_constraints,
1636 )
1637 .map(|r| {
1638 r.map(|mut pick| {
1639 pick.autoderefs = step.autoderefs;
1640 pick.autoref_or_ptr_adjustment =
1641 Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1642 pick
1643 })
1644 })
1645 }
1646
1647 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1648u32),
::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))]
1649 fn pick_reborrow_pin_method(
1650 &self,
1651 step: &CandidateStep<'tcx>,
1652 self_ty: Ty<'tcx>,
1653 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1654 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1655 ) -> Option<PickResult<'tcx>> {
1656 if !self.tcx.features().pin_ergonomics() {
1657 return None;
1658 }
1659
1660 let inner_ty = match self_ty.kind() {
1662 ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), LangItem::Pin) => {
1663 match args[0].expect_ty().kind() {
1664 ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1665 _ => {
1666 return None;
1667 }
1668 }
1669 }
1670 _ => return None,
1671 };
1672
1673 let region = self.tcx.lifetimes.re_erased;
1674 let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1675 self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1676 |r| {
1677 r.map(|mut pick| {
1678 pick.autoderefs = step.autoderefs;
1679 pick.autoref_or_ptr_adjustment =
1680 Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1681 pick
1682 })
1683 },
1684 )
1685 }
1686
1687 fn pick_const_ptr_method(
1691 &self,
1692 step: &CandidateStep<'tcx>,
1693 self_ty: Ty<'tcx>,
1694 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1695 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1696 ) -> Option<PickResult<'tcx>> {
1697 if step.unsize {
1699 return None;
1700 }
1701
1702 let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1703 return None;
1704 };
1705
1706 let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1707 self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1708 |r| {
1709 r.map(|mut pick| {
1710 pick.autoderefs = step.autoderefs;
1711 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1712 pick
1713 })
1714 },
1715 )
1716 }
1717
1718 fn pick_method(
1719 &self,
1720 self_ty: Ty<'tcx>,
1721 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1722 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1723 pick_constraints: Option<&PickConstraintsForShadowed>,
1724 ) -> Option<PickResult<'tcx>> {
1725 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1725",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1725u32),
::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));
1726
1727 for (kind, candidates) in
1728 [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1729 {
1730 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1730",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1730u32),
::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);
1731 let res = self.consider_candidates(
1732 self_ty,
1733 instantiate_self_ty_obligations,
1734 candidates,
1735 pick_diag_hints,
1736 pick_constraints,
1737 );
1738 if let Some(pick) = res {
1739 return Some(pick);
1740 }
1741 }
1742
1743 if self.private_candidate.get().is_none() {
1744 if let Some(Ok(pick)) = self.consider_candidates(
1745 self_ty,
1746 instantiate_self_ty_obligations,
1747 &self.private_candidates,
1748 &mut PickDiagHints {
1749 unstable_candidates: None,
1750 unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1751 },
1752 None,
1753 ) {
1754 self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1755 }
1756 }
1757 None
1758 }
1759
1760 fn consider_candidates(
1761 &self,
1762 self_ty: Ty<'tcx>,
1763 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1764 candidates: &[Candidate<'tcx>],
1765 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1766 pick_constraints: Option<&PickConstraintsForShadowed>,
1767 ) -> Option<PickResult<'tcx>> {
1768 let mut applicable_candidates: Vec<_> = candidates
1769 .iter()
1770 .filter(|candidate| {
1771 pick_constraints
1772 .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1773 .unwrap_or(true)
1774 })
1775 .map(|probe| {
1776 (
1777 probe,
1778 self.consider_probe(
1779 self_ty,
1780 instantiate_self_ty_obligations,
1781 probe,
1782 &mut pick_diag_hints.unsatisfied_predicates,
1783 ),
1784 )
1785 })
1786 .filter(|&(_, status)| status != ProbeResult::NoMatch)
1787 .collect();
1788
1789 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:1789",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1789u32),
::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);
1790
1791 if applicable_candidates.len() > 1 {
1792 if let Some(pick) =
1793 self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1794 {
1795 return Some(Ok(pick));
1796 }
1797 }
1798
1799 if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1800 applicable_candidates.retain(|&(candidate, _)| {
1801 if let stability::EvalResult::Deny { feature, .. } =
1802 self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1803 {
1804 uc.push((candidate.clone(), feature));
1805 return false;
1806 }
1807 true
1808 });
1809 }
1810
1811 if applicable_candidates.len() > 1 {
1812 if self.tcx.features().supertrait_item_shadowing() {
1816 if let Some(pick) =
1817 self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1818 {
1819 return Some(Ok(pick));
1820 }
1821 }
1822
1823 let sources =
1824 applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1825 return Some(Err(MethodError::Ambiguity(sources)));
1826 }
1827
1828 applicable_candidates.pop().map(|(probe, status)| match status {
1829 ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1830 self_ty,
1831 pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1832 )),
1833 ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1834 })
1835 }
1836}
1837
1838impl<'tcx> Pick<'tcx> {
1839 pub(crate) fn differs_from(&self, other: &Self) -> bool {
1844 let Self {
1845 item: AssocItem { def_id, kind: _, container: _ },
1846 kind: _,
1847 import_ids: _,
1848 autoderefs: _,
1849 autoref_or_ptr_adjustment: _,
1850 self_ty,
1851 unstable_candidates: _,
1852 receiver_steps: _,
1853 shadowed_candidates: _,
1854 } = *self;
1855 self_ty != other.self_ty || def_id != other.item.def_id
1856 }
1857
1858 pub(crate) fn maybe_emit_unstable_name_collision_hint(
1860 &self,
1861 tcx: TyCtxt<'tcx>,
1862 span: Span,
1863 scope_expr_id: HirId,
1864 ) {
1865 struct ItemMaybeBeAddedToStd<'a, 'tcx> {
1866 this: &'a Pick<'tcx>,
1867 tcx: TyCtxt<'tcx>,
1868 span: Span,
1869 }
1870
1871 impl<'a, 'b, 'tcx> Diagnostic<'a> for ItemMaybeBeAddedToStd<'b, 'tcx> {
1872 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a> {
1873 let Self { this, tcx, span } = self;
1874 let def_kind = this.item.as_def_kind();
1875 let mut lint = Diag::new(
1876 dcx,
1877 level,
1878 ::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!(
1879 "{} {} with this name may be added to the standard library in the future",
1880 tcx.def_kind_descr_article(def_kind, this.item.def_id),
1881 tcx.def_kind_descr(def_kind, this.item.def_id),
1882 ),
1883 );
1884
1885 match (this.item.kind, this.item.container) {
1886 (ty::AssocKind::Fn { .. }, _) => {
1887 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!(
1892 "call with fully qualified syntax `{}(...)` to keep using the current \
1893 method",
1894 tcx.def_path_str(this.item.def_id),
1895 ));
1896 }
1897 (ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
1898 let def_id = this.item.container_id(tcx);
1899 lint.span_suggestion(
1900 span,
1901 "use the fully qualified path to the associated const",
1902 ::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),
1903 Applicability::MachineApplicable,
1904 );
1905 }
1906 _ => {}
1907 }
1908 tcx.disabled_nightly_features(
1909 &mut lint,
1910 this.unstable_candidates.iter().map(|(candidate, feature)| {
1911 (::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)
1912 }),
1913 );
1914 lint
1915 }
1916 }
1917
1918 if self.unstable_candidates.is_empty() {
1919 return;
1920 }
1921 tcx.emit_node_span_lint(
1922 UNSTABLE_NAME_COLLISIONS,
1923 scope_expr_id,
1924 span,
1925 ItemMaybeBeAddedToStd { this: self, tcx, span },
1926 );
1927 }
1928}
1929
1930impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1931 fn select_trait_candidate_for_diagnostics(
1932 &self,
1933 trait_ref: ty::TraitRef<'tcx>,
1934 ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1935 let obligation =
1936 traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1937 let candidate = traits::SelectionContext::new(self).select(&obligation);
1938 if let Ok(Some(traits::ImplSource::UserDefined(impl_source_user_defined_data))) = &candidate
1939 && self.infcx.tcx.do_not_recommend_impl(impl_source_user_defined_data.impl_def_id)
1940 {
1941 return Err(traits::SelectionError::Unimplemented);
1942 }
1943 candidate
1944 }
1945
1946 fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1949 match candidate.kind {
1950 InherentImplCandidate { .. } => {
1951 CandidateSource::Impl(candidate.item.container_id(self.tcx))
1952 }
1953 ObjectCandidate(_) | WhereClauseCandidate(_) => {
1954 CandidateSource::Trait(candidate.item.container_id(self.tcx))
1955 }
1956 TraitCandidate { trait_ref, is_ambiguously_imported: _ } => self.probe(|_| {
1957 let trait_ref = self.instantiate_binder_with_fresh_vars(
1958 self.span,
1959 BoundRegionConversionTime::FnCall,
1960 trait_ref,
1961 );
1962 let (xform_self_ty, _) =
1963 self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1964 let _ = self.sup_raw(
1967 &ObligationCause::dummy(),
1968 self.param_env,
1969 DefineOpaqueTypes::Yes,
1970 xform_self_ty,
1971 self_ty,
1972 );
1973 match self.select_trait_candidate_for_diagnostics(trait_ref) {
1974 Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
1975 CandidateSource::Impl(impl_data.impl_def_id)
1978 }
1979 _ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
1980 }
1981 }),
1982 }
1983 }
1984
1985 fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
1986 match pick.kind {
1987 InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1988 ObjectPick | WhereClausePick(_) | TraitPick { .. } => {
1989 CandidateSource::Trait(pick.item.container_id(self.tcx))
1990 }
1991 }
1992 }
1993
1994 fn consider_probe(
1995 &self,
1996 self_ty: Ty<'tcx>,
1997 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1998 probe: &Candidate<'tcx>,
1999 possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
2000 ) -> ProbeResult {
2001 self.probe(|snapshot| {
2002 let outer_universe = self.universe();
2003
2004 let mut result = ProbeResult::Match;
2005 let cause = &self.misc(self.span);
2006 let ocx = ObligationCtxt::new_with_diagnostics(self);
2007
2008 if self.next_trait_solver() {
2016 ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
2017 let errors = ocx.try_evaluate_obligations();
2018 if !errors.no_errors() {
2019 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected autoderef error {0:?}", errors)));
};unreachable!("unexpected autoderef error {errors:?}");
2020 }
2021 }
2022
2023 let mut trait_predicate = None;
2024 let (mut xform_self_ty, mut xform_ret_ty);
2025
2026 match probe.kind {
2027 InherentImplCandidate { impl_def_id, .. } => {
2028 let impl_args = self.fresh_args_for_item(self.span, impl_def_id);
2029 let impl_ty = self
2030 .tcx
2031 .type_of(impl_def_id)
2032 .instantiate(self.tcx, impl_args)
2033 .skip_norm_wip();
2034 (xform_self_ty, xform_ret_ty) =
2035 self.xform_self_ty(probe.item, impl_ty, impl_args);
2036 xform_self_ty =
2037 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2038 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2039 {
2040 Ok(()) => {}
2041 Err(err) => {
2042 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2042",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2042u32),
::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);
2043 return ProbeResult::NoMatch;
2044 }
2045 }
2046 xform_ret_ty =
2048 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2049 let impl_def_id = probe.item.container_id(self.tcx);
2051 let impl_bounds =
2052 self.tcx.clauses_of(impl_def_id).instantiate(self.tcx, impl_args);
2053 ocx.register_obligations(traits::predicates_for_generics(
2055 |idx, span| {
2056 let code = ObligationCauseCode::WhereClauseInExpr(
2057 impl_def_id,
2058 span,
2059 self.scope_expr_id,
2060 idx,
2061 );
2062 self.cause(self.span, code)
2063 },
2064 |clause| ocx.normalize(cause, self.param_env, clause),
2065 self.param_env,
2066 impl_bounds,
2067 ));
2068 }
2069 TraitCandidate { trait_ref: poly_trait_ref, is_ambiguously_imported: _ } => {
2070 if let Some(method_name) = self.method_name {
2073 if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
2074 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2075 if trait_def.skip_array_during_method_dispatch {
2076 return ProbeResult::NoMatch;
2077 }
2078 }
2079
2080 if self_ty.boxed_ty().is_some_and(Ty::is_slice)
2083 && !method_name.span.at_least_rust_2024()
2084 {
2085 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2086 if trait_def.skip_boxed_slice_during_method_dispatch {
2087 return ProbeResult::NoMatch;
2088 }
2089 }
2090 }
2091
2092 let trait_ref = self.instantiate_binder_with_fresh_vars(
2093 self.span,
2094 BoundRegionConversionTime::FnCall,
2095 poly_trait_ref,
2096 );
2097 let trait_ref =
2098 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(trait_ref));
2099 (xform_self_ty, xform_ret_ty) =
2100 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2101 xform_self_ty =
2102 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2103 match self_ty.kind() {
2104 &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })
2108 if !self.next_trait_solver()
2109 && self.infcx.can_define_opaque_ty(def_id)
2110 && !xform_self_ty.is_ty_var() =>
2111 {
2112 return ProbeResult::NoMatch;
2113 }
2114 _ => match ocx.relate(
2115 cause,
2116 self.param_env,
2117 self.variance(),
2118 self_ty,
2119 xform_self_ty,
2120 ) {
2121 Ok(()) => {}
2122 Err(err) => {
2123 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2123",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2123u32),
::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);
2124 return ProbeResult::NoMatch;
2125 }
2126 },
2127 }
2128 let obligation = traits::Obligation::new(
2129 self.tcx,
2130 cause.clone(),
2131 self.param_env,
2132 ty::Binder::dummy(trait_ref),
2133 );
2134
2135 if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
2137 {
2138 ocx.register_obligation(obligation);
2139 } else {
2140 result = ProbeResult::NoMatch;
2141 if let Ok(Some(candidate)) =
2142 self.select_trait_candidate_for_diagnostics(trait_ref)
2143 {
2144 for nested_obligation in candidate.nested_obligations() {
2145 if !self.infcx.predicate_may_hold(&nested_obligation) {
2146 possibly_unsatisfied_predicates.push((
2147 self.deeply_resolve_ignoring_regions(
2148 nested_obligation.predicate,
2149 ),
2150 Some(
2151 self.deeply_resolve_ignoring_regions(
2152 obligation.predicate,
2153 ),
2154 ),
2155 Some(nested_obligation.cause),
2156 ));
2157 }
2158 }
2159 }
2160 }
2161
2162 trait_predicate = Some(trait_ref.upcast(self.tcx));
2163 }
2164 ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
2165 let trait_ref = self.instantiate_binder_with_fresh_vars(
2166 self.span,
2167 BoundRegionConversionTime::FnCall,
2168 poly_trait_ref,
2169 );
2170 (xform_self_ty, xform_ret_ty) =
2171 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2172
2173 if #[allow(non_exhaustive_omitted_patterns)] match probe.kind {
WhereClauseCandidate(_) => true,
_ => false,
}matches!(probe.kind, WhereClauseCandidate(_)) {
2174 let ty = ocx.normalize(
2178 cause,
2179 self.param_env,
2180 Unnormalized::new_wip(trait_ref.self_ty()),
2181 );
2182 if !#[allow(non_exhaustive_omitted_patterns)] match ty.kind() {
ty::Param(_) => true,
_ => false,
}matches!(ty.kind(), ty::Param(_)) {
2183 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2183",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2183u32),
::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:?}");
2184 return ProbeResult::NoMatch;
2185 }
2186 }
2187
2188 xform_self_ty =
2189 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2190 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2191 {
2192 Ok(()) => {}
2193 Err(err) => {
2194 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2194",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2194u32),
::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);
2195 return ProbeResult::NoMatch;
2196 }
2197 }
2198 }
2199 }
2200
2201 for error in ocx.try_evaluate_obligations() {
2203 result = ProbeResult::NoMatch;
2204 let nested_predicate =
2205 self.deeply_resolve_ignoring_regions(error.obligation.predicate);
2206 if let Some(trait_predicate) = trait_predicate
2207 && nested_predicate == self.deeply_resolve_ignoring_regions(trait_predicate)
2208 {
2209 } else {
2213 possibly_unsatisfied_predicates.push((
2214 nested_predicate,
2215 Some(self.deeply_resolve_ignoring_regions(error.root_obligation.predicate))
2216 .filter(|root_predicate| *root_predicate != nested_predicate),
2217 Some(error.obligation.cause),
2218 ));
2219 }
2220 }
2221
2222 if let ProbeResult::Match = result
2223 && let Some(return_ty) = self.return_type
2224 && let Some(mut xform_ret_ty) = xform_ret_ty
2225 {
2226 if !#[allow(non_exhaustive_omitted_patterns)] match probe.kind {
InherentImplCandidate { .. } => true,
_ => false,
}matches!(probe.kind, InherentImplCandidate { .. }) {
2231 xform_ret_ty =
2232 ocx.normalize(&cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2233 }
2234
2235 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2235",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2235u32),
::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);
2236 match ocx.relate(cause, self.param_env, self.variance(), xform_ret_ty, return_ty) {
2237 Ok(()) => {}
2238 Err(_) => {
2239 result = ProbeResult::BadReturnType;
2240 }
2241 }
2242
2243 for error in ocx.try_evaluate_obligations() {
2245 result = ProbeResult::NoMatch;
2246 possibly_unsatisfied_predicates.push((
2247 error.obligation.predicate,
2248 Some(error.root_obligation.predicate)
2249 .filter(|predicate| *predicate != error.obligation.predicate),
2250 Some(error.root_obligation.cause),
2251 ));
2252 }
2253 }
2254
2255 if self.infcx.next_trait_solver() {
2256 if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
2257 result = ProbeResult::NoMatch;
2258 }
2259 }
2260
2261 if let Err(_) = self.leak_check(outer_universe, Some(snapshot)) {
2267 result = ProbeResult::NoMatch;
2268 }
2269
2270 result
2271 })
2272 }
2273
2274 {}
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("should_reject_candidate_due_to_opaque_treated_as_rigid",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2288u32),
::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("trait_predicate")
}> =
::tracing::__macro_support::FieldName::new("trait_predicate");
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(&trait_predicate)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[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: bool = loop {};
return __tracing_attr_fake_return;
}
{
if let Some(predicate) = trait_predicate {
let goal = Goal { param_env: self.param_env, predicate };
if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
return true;
}
}
for step in self.steps {
if step.self_ty_is_opaque {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2315",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2315u32),
::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("step.autoderefs")
}> =
::tracing::__macro_support::FieldName::new("step.autoderefs");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("step.self_ty")
}> =
::tracing::__macro_support::FieldName::new("step.self_ty");
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!("self_type_is_opaque")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&step.autoderefs)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&step.self_ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let constrained_opaque =
self.probe(|_|
{
let Ok(ok) =
self.fcx.probe_instantiate_query_response(self.span,
self.orig_steps_var_values,
&step.self_ty) else {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2326",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2326u32),
::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!("failed to instantiate self_ty")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return false;
};
let ocx = ObligationCtxt::new(self);
let self_ty = ocx.register_infer_ok_obligations(ok);
if !ocx.try_evaluate_obligations().no_errors() {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2332",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2332u32),
::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!("failed to prove instantiate self_ty obligations")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return false;
}
!self.deeply_resolve_ignoring_regions(self_ty).is_ty_var()
});
if constrained_opaque {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2339",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2339u32),
::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!("opaque type has been constrained")
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
return true;
}
}
}
false
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2288",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2288u32),
::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("return")
}> =
::tracing::__macro_support::FieldName::new("return");
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(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
2289 fn should_reject_candidate_due_to_opaque_treated_as_rigid(
2290 &self,
2291 trait_predicate: Option<ty::Predicate<'tcx>>,
2292 ) -> bool {
2293 if let Some(predicate) = trait_predicate {
2305 let goal = Goal { param_env: self.param_env, predicate };
2306 if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
2307 return true;
2308 }
2309 }
2310
2311 for step in self.steps {
2314 if step.self_ty_is_opaque {
2315 debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
2316 let constrained_opaque = self.probe(|_| {
2317 let Ok(ok) = self.fcx.probe_instantiate_query_response(
2322 self.span,
2323 self.orig_steps_var_values,
2324 &step.self_ty,
2325 ) else {
2326 debug!("failed to instantiate self_ty");
2327 return false;
2328 };
2329 let ocx = ObligationCtxt::new(self);
2330 let self_ty = ocx.register_infer_ok_obligations(ok);
2331 if !ocx.try_evaluate_obligations().no_errors() {
2332 debug!("failed to prove instantiate self_ty obligations");
2333 return false;
2334 }
2335
2336 !self.deeply_resolve_ignoring_regions(self_ty).is_ty_var()
2337 });
2338 if constrained_opaque {
2339 debug!("opaque type has been constrained");
2340 return true;
2341 }
2342 }
2343 }
2344
2345 false
2346 }
2347
2348 fn collapse_candidates_to_trait_pick(
2366 &self,
2367 self_ty: Ty<'tcx>,
2368 probes: &[(&Candidate<'tcx>, ProbeResult)],
2369 ) -> Option<Pick<'tcx>> {
2370 let container = probes[0].0.item.trait_container(self.tcx)?;
2372 for (p, _) in &probes[1..] {
2373 let p_container = p.item.trait_container(self.tcx)?;
2374 if p_container != container {
2375 return None;
2376 }
2377 }
2378
2379 let ambiguous_candidate = probes.iter().find_map(|(p, _)| match p.kind {
2381 TraitCandidate { is_ambiguously_imported: true, .. } => Some(p),
2382 _ => None,
2383 });
2384
2385 let (is_ambiguously_imported, candidate) =
2387 ambiguous_candidate.map(|c| (true, *c)).unwrap_or_else(|| (false, probes[0].0));
2388
2389 Some(Pick {
2392 item: candidate.item,
2393 kind: TraitPick { is_ambiguously_imported },
2394 import_ids: candidate.import_ids,
2395 autoderefs: 0,
2396 autoref_or_ptr_adjustment: None,
2397 self_ty,
2398 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2399 receiver_steps: None,
2400 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2401 })
2402 }
2403
2404 fn collapse_candidates_to_subtrait_pick(
2414 &self,
2415 self_ty: Ty<'tcx>,
2416 probes: &[(&Candidate<'tcx>, ProbeResult)],
2417 ) -> Option<Pick<'tcx>> {
2418 let mut child_candidate = probes[0].0;
2419 let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2420 let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2421
2422 let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2423 while !remaining_candidates.is_empty() {
2424 let mut made_progress = false;
2425 let mut next_round = ::alloc::vec::Vec::new()vec![];
2426
2427 for remaining_candidate in remaining_candidates {
2428 let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2429 if supertraits.contains(&remaining_trait) {
2430 made_progress = true;
2431 continue;
2432 }
2433
2434 let remaining_trait_supertraits: SsoHashSet<_> =
2440 supertrait_def_ids(self.tcx, remaining_trait).collect();
2441 if remaining_trait_supertraits.contains(&child_trait) {
2442 child_candidate = remaining_candidate;
2443 child_trait = remaining_trait;
2444 supertraits = remaining_trait_supertraits;
2445 made_progress = true;
2446 continue;
2447 }
2448
2449 next_round.push(remaining_candidate);
2456 }
2457
2458 if made_progress {
2459 remaining_candidates = next_round;
2461 } else {
2462 return None;
2465 }
2466 }
2467
2468 let is_ambiguously_imported = match child_candidate.kind {
2469 TraitCandidate { is_ambiguously_imported, .. } => is_ambiguously_imported,
2470 _ => false,
2471 };
2472
2473 Some(Pick {
2474 item: child_candidate.item,
2475 kind: TraitPick { is_ambiguously_imported },
2476 import_ids: child_candidate.import_ids,
2477 autoderefs: 0,
2478 autoref_or_ptr_adjustment: None,
2479 self_ty,
2480 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2481 shadowed_candidates: probes
2482 .iter()
2483 .map(|(c, _)| c.item)
2484 .filter(|item| item.def_id != child_candidate.item.def_id)
2485 .collect(),
2486 receiver_steps: None,
2487 })
2488 }
2489
2490 {}
#[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("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2493u32),
::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 /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2497",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2497u32),
::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))]
2494 pub(crate) fn probe_for_similar_candidate(
2495 &mut self,
2496 ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2497 debug!("probing for method names similar to {:?}", self.method_name);
2498
2499 self.probe(|_| {
2500 let mut pcx = ProbeContext::new(
2501 self.fcx,
2502 self.span,
2503 self.mode,
2504 self.method_name,
2505 self.return_type,
2506 self.orig_steps_var_values,
2507 self.steps,
2508 self.scope_expr_id,
2509 IsSuggestion(true),
2510 );
2511 pcx.allow_similar_names = true;
2512 pcx.assemble_inherent_candidates();
2513 pcx.assemble_extension_candidates_for_all_traits();
2514
2515 let method_names = pcx.candidate_method_names(|_| true);
2516 pcx.allow_similar_names = false;
2517 let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2518 .iter()
2519 .filter_map(|&method_name| {
2520 pcx.reset();
2521 pcx.method_name = Some(method_name);
2522 pcx.assemble_inherent_candidates();
2523 pcx.assemble_extension_candidates_for_all_traits();
2524 pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2525 })
2526 .collect();
2527
2528 if applicable_close_candidates.is_empty() {
2529 Ok(None)
2530 } else {
2531 let best_name = applicable_close_candidates
2532 .iter()
2533 .find(|cand| self.matches_by_doc_alias(cand.def_id))
2534 .map(|cand| cand.name())
2535 .or_else(|| {
2536 let names = applicable_close_candidates
2537 .iter()
2538 .map(|cand| cand.name())
2539 .collect::<Vec<Symbol>>();
2540 find_best_match_for_name_with_substrings(
2541 &names,
2542 self.method_name.unwrap().name,
2543 None,
2544 )
2545 });
2546 Ok(best_name.and_then(|best_name| {
2547 applicable_close_candidates
2548 .into_iter()
2549 .find(|method| method.name() == best_name)
2550 }))
2551 }
2552 })
2553 }
2554
2555 fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2558 match self.mode {
2564 Mode::MethodCall => item.is_method(),
2565 Mode::Path => match item.kind {
2566 ty::AssocKind::Type { .. } => false,
2567 ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2568 },
2569 }
2570 }
2577
2578 fn record_static_candidate(&self, source: CandidateSource) {
2579 self.static_candidates.borrow_mut().push(source);
2580 }
2581
2582 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("xform_self_ty",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2582u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item")
}> =
::tracing::__macro_support::FieldName::new("item");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_ty")
}> =
::tracing::__macro_support::FieldName::new("impl_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: (Ty<'tcx>, Option<Ty<'tcx>>) =
loop {};
return __tracing_attr_fake_return;
}
{
if item.is_fn() && self.mode == Mode::MethodCall {
let sig = self.xform_method_sig(item.def_id, args);
(self.self_ty_override.unwrap_or(sig.inputs()[0]),
Some(sig.output()))
} else { (impl_ty, None) }
}
}
}#[instrument(level = "debug", skip(self))]
2583 fn xform_self_ty(
2584 &self,
2585 item: ty::AssocItem,
2586 impl_ty: Ty<'tcx>,
2587 args: GenericArgs<'tcx>,
2588 ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2589 if item.is_fn() && self.mode == Mode::MethodCall {
2590 let sig = self.xform_method_sig(item.def_id, args);
2591 (self.self_ty_override.unwrap_or(sig.inputs()[0]), Some(sig.output()))
2592 } else {
2593 (impl_ty, None)
2594 }
2595 }
2596
2597 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("xform_method_sig",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2597u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("method")
}> =
::tracing::__macro_support::FieldName::new("method");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("args")
}> =
::tracing::__macro_support::FieldName::new("args");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::FnSig<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let fn_sig = self.tcx.fn_sig(method);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs:2600",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/0377038f98d734a74468b6b0f48dd1a9351ed328/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2600u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("fn_sig")
}> =
::tracing::__macro_support::FieldName::new("fn_sig");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&fn_sig)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
if !!args.has_escaping_bound_vars() {
::core::panicking::panic("assertion failed: !args.has_escaping_bound_vars()")
};
let generics = self.tcx.generics_of(method);
{
match (&args.len(), &generics.parent_count) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
}
};
let xform_fn_sig =
if generics.is_own_empty() {
fn_sig.instantiate(self.tcx, args).skip_norm_wip()
} else {
let args =
GenericArgs::for_item(self.tcx, method,
|param, _|
{
let i = param.index as usize;
if i < args.len() {
args[i]
} else {
match param.kind {
GenericParamDefKind::Lifetime => {
self.tcx.lifetimes.re_erased.into()
}
GenericParamDefKind::Type { .. } |
GenericParamDefKind::Const { .. } => {
self.var_for_def(self.span, param)
}
}
}
});
fn_sig.instantiate(self.tcx, args).skip_norm_wip()
};
self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
}
}
}#[instrument(level = "debug", skip(self))]
2598 fn xform_method_sig(&self, method: DefId, args: GenericArgs<'tcx>) -> ty::FnSig<'tcx> {
2599 let fn_sig = self.tcx.fn_sig(method);
2600 debug!(?fn_sig);
2601
2602 assert!(!args.has_escaping_bound_vars());
2603
2604 let generics = self.tcx.generics_of(method);
2610 assert_eq!(args.len(), generics.parent_count);
2611
2612 let xform_fn_sig = if generics.is_own_empty() {
2613 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2614 } else {
2615 let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2616 let i = param.index as usize;
2617 if i < args.len() {
2618 args[i]
2619 } else {
2620 match param.kind {
2621 GenericParamDefKind::Lifetime => {
2622 self.tcx.lifetimes.re_erased.into()
2624 }
2625 GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2626 self.var_for_def(self.span, param)
2627 }
2628 }
2629 }
2630 });
2631 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2632 };
2633
2634 self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2635 }
2636
2637 fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2639 match (self.mode, kind) {
2640 (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2641 (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2642 _ => false,
2643 }
2644 }
2645
2646 fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2649 let Some(method) = self.method_name else {
2650 return false;
2651 };
2652
2653 if let Some(d) = {
{
'done:
{
for i in ::rustc_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::Tool(..) |
::rustc_attr_ir::Attribute::DeriveHelper(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, Doc(d) => d)
2654 && d.aliases.contains_key(&method.name)
2655 {
2656 return true;
2657 }
2658
2659 if let Some(confusables) =
2660 {
{
'done:
{
for i in ::rustc_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::Tool(..) |
::rustc_attr_ir::Attribute::DeriveHelper(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, RustcConfusables{ confusables } => confusables)
2661 && confusables.contains(&method.name)
2662 {
2663 return true;
2664 }
2665
2666 false
2667 }
2668
2669 fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2674 if let Some(name) = self.method_name {
2675 if self.allow_similar_names {
2676 let max_dist = max(name.as_str().len(), 3) / 3;
2677 self.tcx
2678 .associated_items(def_id)
2679 .in_definition_order()
2680 .filter(|x| {
2681 if !self.is_relevant_kind_for_mode(x.kind) {
2682 return false;
2683 }
2684 if let Some(d) = edit_distance_with_substrings(
2685 name.as_str(),
2686 x.name().as_str(),
2687 max_dist,
2688 ) {
2689 return d > 0;
2690 }
2691 self.matches_by_doc_alias(x.def_id)
2692 })
2693 .copied()
2694 .collect()
2695 } else {
2696 self.fcx
2697 .associated_value(def_id, name)
2698 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2699 .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2700 }
2701 } else {
2702 self.tcx
2703 .associated_items(def_id)
2704 .in_definition_order()
2705 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2706 .copied()
2707 .collect()
2708 }
2709 }
2710}
2711
2712impl<'tcx> Candidate<'tcx> {
2713 fn to_unadjusted_pick(
2714 &self,
2715 self_ty: Ty<'tcx>,
2716 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2717 ) -> Pick<'tcx> {
2718 Pick {
2719 item: self.item,
2720 kind: match self.kind {
2721 InherentImplCandidate { .. } => InherentImplPick,
2722 ObjectCandidate(_) => ObjectPick,
2723 TraitCandidate { is_ambiguously_imported, .. } => {
2724 TraitPick { is_ambiguously_imported }
2725 }
2726 WhereClauseCandidate(trait_ref) => {
2727 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!(
2733 !trait_ref.skip_binder().args.has_infer()
2734 && !trait_ref.skip_binder().args.has_placeholders()
2735 );
2736
2737 WhereClausePick(trait_ref)
2738 }
2739 },
2740 import_ids: self.import_ids,
2741 autoderefs: 0,
2742 autoref_or_ptr_adjustment: None,
2743 self_ty,
2744 unstable_candidates,
2745 receiver_steps: match self.kind {
2746 InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2747 _ => None,
2748 },
2749 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2750 }
2751 }
2752}