1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::ops::Deref;
4use std::{assert_matches, debug_assert_matches};
5
6use rustc_data_structures::fx::FxHashSet;
7use rustc_data_structures::sso::SsoHashSet;
8use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
9use rustc_hir::attrs::lang_items::LangItem;
10use rustc_hir::def::DefKind;
11use rustc_hir::{self as hir, ExprKind, HirId, Node, find_attr};
12use rustc_hir_analysis::autoderef::{self, Autoderef};
13use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
14use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
15use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
16use rustc_lint_defs::builtin::{
17 METHOD_CALL_ON_DIVERGING_INFER_VAR, TYVAR_BEHIND_RAW_POINTER, UNSTABLE_NAME_COLLISIONS,
18};
19use rustc_macros::Diagnostic;
20use rustc_middle::middle::stability;
21use rustc_middle::ty::elaborate::supertrait_def_ids;
22use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
23use rustc_middle::ty::{
24 self, AssocContainer, AssocItem, GenericArgs, GenericArgsRef, GenericParamDefKind, ParamEnvAnd,
25 Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
26};
27use rustc_middle::{bug, span_bug};
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};
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) -> IsSuggestion {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IsSuggestion { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for IsSuggestion {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "IsSuggestion",
&&self.0)
}
}Debug)]
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", &self.item, "kind", &self.kind, "import_ids",
&&self.import_ids)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Candidate<'tcx> {
#[inline]
fn clone(&self) -> Candidate<'tcx> {
Candidate {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
}
}
}Clone)]
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 {
CandidateKind::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InherentImplCandidate", "impl_def_id", __self_0,
"receiver_steps", &__self_1),
CandidateKind::ObjectCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ObjectCandidate", &__self_0),
CandidateKind::TraitCandidate {
trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"TraitCandidate", "trait_ref", __self_0,
"is_ambiguously_imported", &__self_1),
CandidateKind::WhereClauseCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WhereClauseCandidate", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for CandidateKind<'tcx> {
#[inline]
fn clone(&self) -> CandidateKind<'tcx> {
match self {
CandidateKind::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
CandidateKind::InherentImplCandidate {
impl_def_id: ::core::clone::Clone::clone(__self_0),
receiver_steps: ::core::clone::Clone::clone(__self_1),
},
CandidateKind::ObjectCandidate(__self_0) =>
CandidateKind::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
CandidateKind::TraitCandidate {
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),
},
CandidateKind::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: &ProbeResult) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ProbeResult {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for ProbeResult { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for ProbeResult { }
#[automatically_derived]
impl ::core::clone::Clone for ProbeResult {
#[inline]
fn clone(&self) -> ProbeResult { *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 {
AutorefOrPtrAdjustment::Autoref {
mutbl: __self_0, unsize: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Autoref", "mutbl", __self_0, "unsize", &__self_1),
AutorefOrPtrAdjustment::ToConstPtr =>
::core::fmt::Formatter::write_str(f, "ToConstPtr"),
AutorefOrPtrAdjustment::ReborrowPin(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ReborrowPin", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::marker::StructuralPartialEq for AutorefOrPtrAdjustment { }
#[automatically_derived]
impl ::core::cmp::PartialEq for AutorefOrPtrAdjustment {
#[inline]
fn eq(&self, other: &AutorefOrPtrAdjustment) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AutorefOrPtrAdjustment::Autoref {
mutbl: __self_0, unsize: __self_1 },
AutorefOrPtrAdjustment::Autoref {
mutbl: __arg1_0, unsize: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(AutorefOrPtrAdjustment::ReborrowPin(__self_0),
AutorefOrPtrAdjustment::ReborrowPin(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::marker::Copy for AutorefOrPtrAdjustment { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for AutorefOrPtrAdjustment { }
#[automatically_derived]
impl ::core::clone::Clone for AutorefOrPtrAdjustment {
#[inline]
fn clone(&self) -> AutorefOrPtrAdjustment {
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
*self
}
}Clone)]
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", &self.unstable_candidates,
"unsatisfied_predicates", &&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", &self.autoderefs,
"receiver_steps", &self.receiver_steps, "def_id", &&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 _ =
&["item", "kind", "import_ids", "autoderefs",
"autoref_or_ptr_adjustment", "self_ty",
"unstable_candidates", "receiver_steps",
"shadowed_candidates"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.item, &self.kind, &self.import_ids, &self.autoderefs,
&self.autoref_or_ptr_adjustment, &self.self_ty,
&self.unstable_candidates, &self.receiver_steps,
&&self.shadowed_candidates];
::core::fmt::Formatter::debug_struct_fields_finish(f, "Pick", names,
values)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Pick<'tcx> {
#[inline]
fn clone(&self) -> Pick<'tcx> {
Pick {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
autoderefs: ::core::clone::Clone::clone(&self.autoderefs),
autoref_or_ptr_adjustment: ::core::clone::Clone::clone(&self.autoref_or_ptr_adjustment),
self_ty: ::core::clone::Clone::clone(&self.self_ty),
unstable_candidates: ::core::clone::Clone::clone(&self.unstable_candidates),
receiver_steps: ::core::clone::Clone::clone(&self.receiver_steps),
shadowed_candidates: ::core::clone::Clone::clone(&self.shadowed_candidates),
}
}
}Clone)]
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) -> PickKind<'tcx> {
match self {
PickKind::InherentImplPick => PickKind::InherentImplPick,
PickKind::ObjectPick => PickKind::ObjectPick,
PickKind::TraitPick { is_ambiguously_imported: __self_0 } =>
PickKind::TraitPick {
is_ambiguously_imported: ::core::clone::Clone::clone(__self_0),
},
PickKind::WhereClausePick(__self_0) =>
PickKind::WhereClausePick(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PickKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
PickKind::InherentImplPick =>
::core::fmt::Formatter::write_str(f, "InherentImplPick"),
PickKind::ObjectPick =>
::core::fmt::Formatter::write_str(f, "ObjectPick"),
PickKind::TraitPick { is_ambiguously_imported: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TraitPick", "is_ambiguously_imported", &__self_0),
PickKind::WhereClausePick(__self_0) =>
::core::fmt::Formatter::debug_tuple_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: &PickKind<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(PickKind::TraitPick { is_ambiguously_imported: __self_0 },
PickKind::TraitPick { is_ambiguously_imported: __arg1_0 })
=> __self_0 == __arg1_0,
(PickKind::WhereClausePick(__self_0),
PickKind::WhereClausePick(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for PickKind<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitRef<'tcx>>;
}
}Eq)]
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: &Mode) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Mode {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for Mode { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl ::core::clone::TrivialClone for Mode { }
#[automatically_derived]
impl ::core::clone::Clone for Mode {
#[inline]
fn clone(&self) -> Mode { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Mode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Mode::MethodCall => "MethodCall",
Mode::Path => "Path",
})
}
}Debug)]
262pub(crate) enum Mode {
263 MethodCall,
267 Path,
271}
272
273#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::StructuralPartialEq for ProbeScope<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for ProbeScope<'tcx> {
#[inline]
fn eq(&self, other: &ProbeScope<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ProbeScope::Single(__self_0, __self_1),
ProbeScope::Single(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for ProbeScope<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
}
}Eq, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for ProbeScope<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ProbeScope::Single(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Single",
__self_0, &__self_1),
ProbeScope::TraitsInScope =>
::core::fmt::Formatter::write_str(f, "TraitsInScope"),
ProbeScope::AllTraits =>
::core::fmt::Formatter::write_str(f, "AllTraits"),
}
}
}Debug)]
274pub(crate) enum ProbeScope<'tcx> {
275 Single(DefId, Option<Ty<'tcx>> ),
277
278 TraitsInScope,
280
281 AllTraits,
283}
284
285impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_return_type_for_diagnostic",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/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/809936eac66c547a5127ce1da805f0d3a6789b98/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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(359u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mode")
}> =
::tracing::__macro_support::FieldName::new("mode");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_name")
}> =
::tracing::__macro_support::FieldName::new("item_name");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return_type")
}> =
::tracing::__macro_support::FieldName::new("return_type");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_suggestion")
}> =
::tracing::__macro_support::FieldName::new("is_suggestion");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope_expr_id")
}> =
::tracing::__macro_support::FieldName::new("scope_expr_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope")
}> =
::tracing::__macro_support::FieldName::new("scope");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
self.probe_op(item_name.span, mode, Some(item_name), return_type,
is_suggestion, self_ty, scope_expr_id, scope,
|probe_cx|
{
Ok(probe_cx.inherent_candidates.into_iter().chain(probe_cx.extension_candidates).collect())
})
}
}
}#[instrument(level = "debug", skip(self))]
360 pub(crate) fn probe_for_name_many(
361 &self,
362 mode: Mode,
363 item_name: Ident,
364 return_type: Option<Ty<'tcx>>,
365 is_suggestion: IsSuggestion,
366 self_ty: Ty<'tcx>,
367 scope_expr_id: HirId,
368 scope: ProbeScope<'tcx>,
369 ) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
370 self.probe_op(
371 item_name.span,
372 mode,
373 Some(item_name),
374 return_type,
375 is_suggestion,
376 self_ty,
377 scope_expr_id,
378 scope,
379 |probe_cx| {
380 Ok(probe_cx
381 .inherent_candidates
382 .into_iter()
383 .chain(probe_cx.extension_candidates)
384 .collect())
385 },
386 )
387 }
388
389 pub(crate) fn probe_op<OP, R>(
390 &'a self,
391 span: Span,
392 mode: Mode,
393 method_name: Option<Ident>,
394 return_type: Option<Ty<'tcx>>,
395 is_suggestion: IsSuggestion,
396 self_ty: Ty<'tcx>,
397 scope_expr_id: HirId,
398 scope: ProbeScope<'tcx>,
399 op: OP,
400 ) -> Result<R, MethodError<'tcx>>
401 where
402 OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
403 {
404 #[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MissingTypeAnnot where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MissingTypeAnnot => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type annotations needed")));
;
diag
}
}
}
}
};Diagnostic)]
405 #[diag("type annotations needed")]
406 struct MissingTypeAnnot;
407
408 #[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MethodCallOnDivergingInferenceVariable where
G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MethodCallOnDivergingInferenceVariable => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method call on a diverging inference variable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider providing a type annotation")));
;
diag
}
}
}
}
};Diagnostic)]
409 #[diag("method call on a diverging inference variable")]
410 #[help("consider providing a type annotation")]
411 struct MethodCallOnDivergingInferenceVariable;
412
413 let mut orig_values = OriginalQueryValues::default();
414 let predefined_opaques_in_body = if self.next_trait_solver() {
415 self.tcx.mk_predefined_opaques_in_body_from_iter(
416 self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
417 )
418 } else {
419 ty::List::empty()
420 };
421 let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
422 let query_input = self
423 .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
424
425 let steps = match mode {
426 Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
427 Mode::Path => self.probe(|_| {
428 let infcx = &self.infcx;
434 let (ParamEnvAnd { param_env: _, value }, var_values) =
435 infcx.instantiate_canonical(span, &query_input.canonical);
436 let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
437 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(437u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("query_input")
}> =
::tracing::__macro_support::FieldName::new("query_input");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("probe_op: Mode::Path")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_input)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
438 let prev_opaque_entries = self.inner.borrow_mut().opaque_types().num_entries();
439 MethodAutoderefStepsResult {
440 steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
441 self_ty: self.make_query_response_ignoring_pending_obligations(
442 var_values,
443 self_ty,
444 prev_opaque_entries,
445 ),
446 self_ty_is_opaque: false,
447 autoderefs: 0,
448 from_unsafe_deref: false,
449 unsize: false,
450 reachable_via_deref: true,
451 }]),
452 opt_bad_ty: None,
453 reached_recursion_limit: false,
454 }
455 }),
456 };
457
458 if steps.reached_recursion_limit && !is_suggestion.0 {
462 self.probe(|_| {
463 let ty = &steps
464 .steps
465 .last()
466 .unwrap_or_else(|| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("reached the recursion limit in 0 steps?"))span_bug!(span, "reached the recursion limit in 0 steps?"))
467 .self_ty;
468 let ty = self
469 .probe_instantiate_query_response(span, &orig_values, ty)
470 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
471 autoderef::report_autoderef_recursion_limit_error(self.tcx, span, ty.value);
472 });
473 }
474
475 if let Some(bad_ty) = &steps.opt_bad_ty {
478 let ty = &bad_ty.ty;
482 let ty = self
483 .probe_instantiate_query_response(span, &orig_values, ty)
484 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
485 let ty = ty.value;
486
487 if is_suggestion.0 {
488 return Err(MethodError::NoMatch(NoMatchData {
491 static_candidates: Vec::new(),
492 unsatisfied_predicates: Vec::new(),
493 out_of_scope_traits: Vec::new(),
494 similar_candidate: None,
495 mode,
496 }));
497 } else if bad_ty.reached_raw_pointer
498 && !self.tcx.features().arbitrary_self_types_pointers()
499 && !self.tcx.sess.at_least_rust_2018()
500 {
501 self.tcx.emit_node_span_lint(
505 TYVAR_BEHIND_RAW_POINTER,
506 scope_expr_id,
507 span,
508 MissingTypeAnnot,
509 );
510 } else if let ty::Infer(ty::TyVar(ty_id)) = *ty.kind()
514 && let ty_id = self.sub_unification_table_root_var(ty_id)
515 && self
516 .diverging_type_vars
517 .borrow()
518 .iter()
519 .any(|&candidate_id| self.sub_unification_table_root_var(candidate_id) == ty_id)
520 {
521 self.tcx.emit_node_span_lint(
522 METHOD_CALL_ON_DIVERGING_INFER_VAR,
523 scope_expr_id,
524 span,
525 MethodCallOnDivergingInferenceVariable,
526 );
527 let root_ty = Ty::new_var(self.tcx, ty_id);
528 self.demand_eqtype(span, root_ty, self.tcx.types.never);
529 } else {
530 let guar = match *ty.kind() {
531 _ if let Some(guar) = self.tainted_by_errors() => guar,
532 ty::Infer(ty::TyVar(_)) => {
533 let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
536 (
537 Mode::MethodCall,
538 Node::Expr(hir::Expr {
539 kind: ExprKind::MethodCall(_, recv, ..),
540 ..
541 }),
542 ) => recv.span,
543 _ => span,
544 };
545
546 let raw_ptr_call = bad_ty.reached_raw_pointer
547 && !self.tcx.features().arbitrary_self_types();
548
549 let mut err = self.err_ctxt().emit_inference_failure_err(
550 self.body_def_id,
551 err_span,
552 ty.into(),
553 TypeAnnotationNeeded::E0282,
554 !raw_ptr_call,
555 );
556 if raw_ptr_call {
557 err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
558 }
559 err.emit()
560 }
561 ty::Error(guar) => guar,
562 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected bad final type in method autoderef"))bug!("unexpected bad final type in method autoderef"),
563 };
564 self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
565 return Err(MethodError::ErrorReported(guar));
566 }
567 }
568
569 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:569",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(569u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ProbeContext: steps for self_ty={0:?} are {1:?}",
self_ty, steps) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("ProbeContext: steps for self_ty={:?} are {:?}", self_ty, steps);
570
571 self.probe(|_| {
574 let mut probe_cx = ProbeContext::new(
575 self,
576 span,
577 mode,
578 method_name,
579 return_type,
580 &orig_values,
581 steps.steps,
582 scope_expr_id,
583 is_suggestion,
584 );
585
586 match scope {
587 ProbeScope::TraitsInScope => {
588 probe_cx.assemble_inherent_candidates();
589 probe_cx.assemble_extension_candidates_for_traits_in_scope();
590 }
591 ProbeScope::AllTraits => {
592 probe_cx.assemble_inherent_candidates();
593 probe_cx.assemble_extension_candidates_for_all_traits();
594 }
595 ProbeScope::Single(def_id, self_ty_override) => {
596 let item = self.tcx.associated_item(def_id);
597 {
match item.container {
AssocContainer::Trait | AssocContainer::InherentImpl => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"AssocContainer::Trait | AssocContainer::InherentImpl",
::core::option::Option::None);
}
}
};assert_matches!(
598 item.container,
599 AssocContainer::Trait | AssocContainer::InherentImpl
600 );
601
602 let trait_def_id = self.tcx.parent(def_id);
603 let trait_span = self.tcx.def_span(trait_def_id);
604
605 let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
606 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
607
608 probe_cx.self_ty_override = self_ty_override;
609 probe_cx.push_candidate(
610 Candidate {
611 item,
612 kind: match item.container {
613 AssocContainer::Trait => CandidateKind::TraitCandidate {
614 trait_ref: ty::Binder::dummy(trait_ref),
615 is_ambiguously_imported: false,
616 },
617 AssocContainer::InherentImpl => {
618 CandidateKind::InherentImplCandidate {
619 impl_def_id: self.tcx.parent(def_id),
620 receiver_steps: 0,
621 }
622 }
623 _ => ::core::panicking::panic("internal error: entered unreachable code")unreachable!(),
624 },
625 import_ids: &[],
626 },
627 false,
628 );
629 }
630 };
631 op(probe_cx)
632 })
633 }
634}
635
636pub(crate) fn method_autoderef_steps<'tcx>(
637 tcx: TyCtxt<'tcx>,
638 goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
639) -> MethodAutoderefStepsResult<'tcx> {
640 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:640",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(640u32),
::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);
641
642 let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
643 let ParamEnvAnd {
644 param_env,
645 value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
646 } = goal;
647 for (key, ty) in predefined_opaques_in_body {
648 let prev = infcx
649 .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
650 if let Some(prev) = prev {
662 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:662",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(662u32),
::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`");
663 }
664 }
665 let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
666
667 let self_ty_is_opaque = |ty: Ty<'_>| {
671 if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
672 infcx.has_opaques_with_sub_unified_hidden_type(vid)
673 } else {
674 false
675 }
676 };
677
678 let mut autoderef_via_deref =
688 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
689 .include_raw_pointers()
690 .silence_errors();
691
692 let mut reached_raw_pointer = false;
693 let arbitrary_self_types_enabled =
694 tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
695 let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
696 let reachable_via_deref =
697 autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
698
699 let mut autoderef_via_receiver =
700 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
701 .include_raw_pointers()
702 .use_receiver_trait()
703 .silence_errors();
704 let steps = autoderef_via_receiver
705 .by_ref()
706 .zip(reachable_via_deref)
707 .map(|((ty, d), reachable_via_deref)| {
708 let step = CandidateStep {
709 self_ty: infcx.make_query_response_ignoring_pending_obligations(
710 inference_vars,
711 ty,
712 prev_opaque_entries,
713 ),
714 self_ty_is_opaque: self_ty_is_opaque(ty),
715 autoderefs: d,
716 from_unsafe_deref: reached_raw_pointer,
717 unsize: false,
718 reachable_via_deref,
719 };
720 if ty.is_raw_ptr() {
721 reached_raw_pointer = true;
723 }
724 step
725 })
726 .collect();
727 (steps, autoderef_via_receiver.reached_recursion_limit())
728 } else {
729 let steps = autoderef_via_deref
730 .by_ref()
731 .map(|(ty, d)| {
732 let step = CandidateStep {
733 self_ty: infcx.make_query_response_ignoring_pending_obligations(
734 inference_vars,
735 ty,
736 prev_opaque_entries,
737 ),
738 self_ty_is_opaque: self_ty_is_opaque(ty),
739 autoderefs: d,
740 from_unsafe_deref: reached_raw_pointer,
741 unsize: false,
742 reachable_via_deref: true,
743 };
744 if ty.is_raw_ptr() {
745 reached_raw_pointer = true;
747 }
748 step
749 })
750 .collect();
751 (steps, autoderef_via_deref.reached_recursion_limit())
752 };
753 let final_ty = autoderef_via_deref.final_ty();
754 let opt_bad_ty = match final_ty.kind() {
755 ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
756 reached_raw_pointer,
757 ty: infcx.make_query_response_ignoring_pending_obligations(
758 inference_vars,
759 final_ty,
760 prev_opaque_entries,
761 ),
762 }),
763 ty::Error(_) => Some(MethodAutoderefBadTy {
764 reached_raw_pointer,
765 ty: infcx.make_query_response_ignoring_pending_obligations(
766 inference_vars,
767 final_ty,
768 prev_opaque_entries,
769 ),
770 }),
771 ty::Array(elem_ty, _) => {
772 let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
773 steps.push(CandidateStep {
774 self_ty: infcx.make_query_response_ignoring_pending_obligations(
775 inference_vars,
776 Ty::new_slice(infcx.tcx, *elem_ty),
777 prev_opaque_entries,
778 ),
779 self_ty_is_opaque: false,
780 autoderefs,
781 from_unsafe_deref: reached_raw_pointer,
784 unsize: true,
785 reachable_via_deref: true, });
788
789 None
790 }
791 _ => None,
792 };
793
794 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:794",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(794u32),
::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);
795 let _ = infcx.take_opaque_types();
797 MethodAutoderefStepsResult {
798 steps: tcx.arena.alloc_from_iter(steps),
799 opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
800 reached_recursion_limit,
801 }
802}
803
804impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
805 fn new(
806 fcx: &'a FnCtxt<'a, 'tcx>,
807 span: Span,
808 mode: Mode,
809 method_name: Option<Ident>,
810 return_type: Option<Ty<'tcx>>,
811 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
812 steps: &'tcx [CandidateStep<'tcx>],
813 scope_expr_id: HirId,
814 is_suggestion: IsSuggestion,
815 ) -> ProbeContext<'a, 'tcx> {
816 ProbeContext {
817 fcx,
818 span,
819 mode,
820 method_name,
821 return_type,
822 inherent_candidates: Vec::new(),
823 extension_candidates: Vec::new(),
824 impl_dups: FxHashSet::default(),
825 orig_steps_var_values,
826 steps,
827 allow_similar_names: false,
828 private_candidates: Vec::new(),
829 private_candidate: Cell::new(None),
830 static_candidates: RefCell::new(Vec::new()),
831 scope_expr_id,
832 is_suggestion,
833 self_ty_override: None,
834 }
835 }
836
837 fn reset(&mut self) {
838 self.inherent_candidates.clear();
839 self.extension_candidates.clear();
840 self.impl_dups.clear();
841 self.private_candidates.clear();
842 self.private_candidate.set(None);
843 self.static_candidates.borrow_mut().clear();
844 }
845
846 fn variance(&self) -> ty::Variance {
850 match self.mode {
851 Mode::MethodCall => ty::Covariant,
852 Mode::Path => ty::Invariant,
853 }
854 }
855
856 fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
860 let is_accessible = if let Some(name) = self.method_name {
861 let item = candidate.item;
862 let container_id = item.container_id(self.tcx);
863 let def_scope =
864 self.tcx.adjust_ident_and_get_scope(name, container_id, self.body_def_id).1;
865 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
866 } else {
867 true
868 };
869 if is_accessible {
870 if is_inherent {
871 self.inherent_candidates.push(candidate);
872 } else {
873 self.extension_candidates.push(candidate);
874 }
875 } else {
876 self.private_candidates.push(candidate);
877 }
878 }
879
880 fn assemble_inherent_candidates(&mut self) {
881 for step in self.steps.iter() {
882 self.assemble_probe(&step.self_ty, step.autoderefs);
883 }
884 }
885
886 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(886u32),
::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))]
887 fn assemble_probe(
888 &mut self,
889 self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
890 receiver_steps: usize,
891 ) {
892 let raw_self_ty = self_ty.value.value;
893 match *raw_self_ty.kind() {
894 ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
895 let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
913 self.fcx.instantiate_canonical(self.span, self_ty);
914
915 self.assemble_inherent_candidates_from_object(generalized_self_ty);
916 self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
917 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
918 }
919 ty::Adt(def, _) => {
920 let def_id = def.did();
921 self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
922 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
923 }
924 ty::Foreign(did) => {
925 self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
926 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
927 }
928 ty::Param(_) => {
929 self.assemble_inherent_candidates_from_param(raw_self_ty);
930 }
931 ty::Bool
932 | ty::Char
933 | ty::Int(_)
934 | ty::Uint(_)
935 | ty::Float(_)
936 | ty::Str
937 | ty::Array(..)
938 | ty::Slice(_)
939 | ty::RawPtr(_, _)
940 | ty::Ref(..)
941 | ty::Never
942 | ty::Tuple(..) => {
943 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
944 }
945 ty::Alias(..)
946 | ty::Bound(..)
947 | ty::Closure(..)
948 | ty::Coroutine(..)
949 | ty::CoroutineClosure(..)
950 | ty::CoroutineWitness(..)
951 | ty::Dynamic(..)
952 | ty::Error(..)
953 | ty::FnDef(..)
954 | ty::FnPtr(..)
955 | ty::Infer(..)
956 | ty::Pat(..)
957 | ty::Placeholder(..)
958 | ty::UnsafeBinder(..) => {}
959 }
960 }
961
962 fn assemble_inherent_candidates_for_incoherent_ty(
963 &mut self,
964 self_ty: Ty<'tcx>,
965 receiver_steps: usize,
966 ) {
967 let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
968 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected incoherent type: {0:?}",
self_ty))bug!("unexpected incoherent type: {:?}", self_ty)
969 };
970 for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
971 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
972 }
973 }
974
975 fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
976 let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
977 for &impl_def_id in impl_def_ids {
978 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
979 }
980 }
981
982 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(982u32),
::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))]
983 fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
984 if !self.impl_dups.insert(impl_def_id) {
985 return; }
987
988 for item in self.impl_or_trait_item(impl_def_id) {
989 if !self.has_applicable_self(&item) {
990 self.record_static_candidate(CandidateSource::Impl(impl_def_id));
992 continue;
993 }
994 self.push_candidate(
995 Candidate {
996 item,
997 kind: InherentImplCandidate { impl_def_id, receiver_steps },
998 import_ids: &[],
999 },
1000 true,
1001 );
1002 }
1003 }
1004
1005 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1005u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let principal =
match self_ty.kind() {
ty::Dynamic(data, ..) => Some(data),
_ => None,
}.and_then(|data|
data.principal()).unwrap_or_else(||
{
::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("non-object {0:?} in assemble_inherent_candidates_from_object",
self_ty))
});
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.assemble_candidates_for_bounds(traits::supertraits(self.tcx,
trait_ref),
|this, new_trait_ref, item|
{
this.push_candidate(Candidate {
item,
kind: ObjectCandidate(new_trait_ref),
import_ids: &[],
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
1006 fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
1007 let principal = match self_ty.kind() {
1008 ty::Dynamic(data, ..) => Some(data),
1009 _ => None,
1010 }
1011 .and_then(|data| data.principal())
1012 .unwrap_or_else(|| {
1013 span_bug!(
1014 self.span,
1015 "non-object {:?} in assemble_inherent_candidates_from_object",
1016 self_ty
1017 )
1018 });
1019
1020 let trait_ref = principal.with_self_ty(self.tcx, self_ty);
1027 self.assemble_candidates_for_bounds(
1028 traits::supertraits(self.tcx, trait_ref),
1029 |this, new_trait_ref, item| {
1030 this.push_candidate(
1031 Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
1032 true,
1033 );
1034 },
1035 );
1036 }
1037
1038 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1038u32),
::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().filter_map(|clause|
{
let bound_clause = clause.kind();
match bound_clause.skip_binder() {
ty::ClauseKind::Trait(trait_predicate) =>
DeepRejectCtxt::relate_rigid_rigid(tcx).types_may_unify(param_ty,
trait_predicate.trait_ref.self_ty()).then(||
bound_clause.rebind(trait_predicate.trait_ref)),
ty::ClauseKind::RegionOutlives(_) |
ty::ClauseKind::TypeOutlives(_) |
ty::ClauseKind::Projection(_) |
ty::ClauseKind::ConstArgHasType(_, _) |
ty::ClauseKind::WellFormed(_) |
ty::ClauseKind::ConstEvaluatable(_) |
ty::ClauseKind::UnstableFeature(_) |
ty::ClauseKind::HostEffect(..) => None,
}
});
self.assemble_candidates_for_bounds(bounds,
|this, poly_trait_ref, item|
{
this.push_candidate(Candidate {
item,
kind: WhereClauseCandidate(poly_trait_ref),
import_ids: &[],
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
1039 fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
1040 debug_assert_matches!(param_ty.kind(), ty::Param(_));
1041
1042 let tcx = self.tcx;
1043
1044 let bounds = self.param_env.caller_bounds().filter_map(|clause| {
1048 let bound_clause = clause.kind();
1049 match bound_clause.skip_binder() {
1050 ty::ClauseKind::Trait(trait_predicate) => DeepRejectCtxt::relate_rigid_rigid(tcx)
1051 .types_may_unify(param_ty, trait_predicate.trait_ref.self_ty())
1052 .then(|| bound_clause.rebind(trait_predicate.trait_ref)),
1053 ty::ClauseKind::RegionOutlives(_)
1054 | ty::ClauseKind::TypeOutlives(_)
1055 | ty::ClauseKind::Projection(_)
1056 | ty::ClauseKind::ConstArgHasType(_, _)
1057 | ty::ClauseKind::WellFormed(_)
1058 | ty::ClauseKind::ConstEvaluatable(_)
1059 | ty::ClauseKind::UnstableFeature(_)
1060 | ty::ClauseKind::HostEffect(..) => None,
1061 }
1062 });
1063
1064 self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1065 this.push_candidate(
1066 Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
1067 true,
1068 );
1069 });
1070 }
1071
1072 fn assemble_candidates_for_bounds<F>(
1075 &mut self,
1076 bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1077 mut mk_cand: F,
1078 ) where
1079 F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1080 {
1081 for bound_trait_ref in bounds {
1082 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1082",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1082u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["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);
1083 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1084 if !self.has_applicable_self(&item) {
1085 self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1086 } else {
1087 mk_cand(self, bound_trait_ref, item);
1088 }
1089 }
1090 }
1091 }
1092
1093 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1093u32),
::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))]
1094 fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1095 let mut duplicates = FxHashSet::default();
1096 let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1097 if let Some(applicable_traits) = opt_applicable_traits {
1098 for trait_candidate in applicable_traits.iter() {
1099 let trait_did = trait_candidate.def_id;
1100 if duplicates.insert((trait_did, trait_candidate.lint_ambiguous)) {
1103 self.assemble_extension_candidates_for_trait(
1104 &trait_candidate.import_ids,
1105 trait_did,
1106 trait_candidate.lint_ambiguous,
1107 );
1108 }
1109 }
1110 }
1111 }
1112
1113 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1113u32),
::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))]
1114 fn assemble_extension_candidates_for_all_traits(&mut self) {
1115 let mut duplicates = FxHashSet::default();
1116 for trait_info in suggest::all_traits(self.tcx) {
1117 if duplicates.insert(trait_info.def_id) {
1118 self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
1119 }
1120 }
1121 }
1122
1123 fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1124 match method.kind {
1125 ty::AssocKind::Fn { .. } => self.probe(|_| {
1126 let args = self.fresh_args_for_item(self.span, method.def_id);
1127 let fty =
1128 self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args).skip_norm_wip();
1129 let fty = self.instantiate_binder_with_fresh_vars(
1130 self.span,
1131 BoundRegionConversionTime::FnCall,
1132 fty,
1133 );
1134 self.can_eq(self.param_env, fty.output(), expected)
1135 }),
1136 _ => false,
1137 }
1138 }
1139
1140 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1140u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1185",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1185u32),
::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))]
1141 fn assemble_extension_candidates_for_trait(
1142 &mut self,
1143 import_ids: &'tcx [LocalDefId],
1144 trait_def_id: DefId,
1145 is_ambiguously_imported: bool,
1146 ) {
1147 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1148 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1149
1150 if self.tcx.is_trait_alias(trait_def_id) {
1151 for (bound_trait_pred, _) in
1153 traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1154 {
1155 assert_eq!(bound_trait_pred.polarity(), ty::ClausePolarity::Positive);
1156 let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1157 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1158 if !self.has_applicable_self(&item) {
1159 self.record_static_candidate(CandidateSource::Trait(
1160 bound_trait_ref.def_id(),
1161 ));
1162 } else {
1163 self.push_candidate(
1164 Candidate {
1165 item,
1166 import_ids,
1167 kind: TraitCandidate {
1168 trait_ref: bound_trait_ref,
1169 is_ambiguously_imported,
1170 },
1171 },
1172 false,
1173 );
1174 }
1175 }
1176 }
1177 } else {
1178 debug_assert!(self.tcx.is_trait(trait_def_id));
1179 if self.tcx.trait_is_auto(trait_def_id) {
1180 return;
1181 }
1182 for item in self.impl_or_trait_item(trait_def_id) {
1183 if !self.has_applicable_self(&item) {
1185 debug!("method has inapplicable self");
1186 self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1187 continue;
1188 }
1189 self.push_candidate(
1190 Candidate {
1191 item,
1192 import_ids,
1193 kind: TraitCandidate {
1194 trait_ref: ty::Binder::dummy(trait_ref),
1195 is_ambiguously_imported,
1196 },
1197 },
1198 false,
1199 );
1200 }
1201 }
1202 }
1203
1204 fn candidate_method_names(
1205 &self,
1206 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1207 ) -> Vec<Ident> {
1208 let mut set = FxHashSet::default();
1209 let mut names: Vec<_> = self
1210 .inherent_candidates
1211 .iter()
1212 .chain(&self.extension_candidates)
1213 .filter(|candidate| candidate_filter(&candidate.item))
1214 .filter(|candidate| {
1215 if let Some(return_ty) = self.return_type {
1216 self.matches_return_type(candidate.item, return_ty)
1217 } else {
1218 true
1219 }
1220 })
1221 .filter(|candidate| {
1223 !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
None, DUMMY_SP, None) {
stability::EvalResult::Deny { .. } => true,
_ => false,
}matches!(
1226 self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1227 stability::EvalResult::Deny { .. }
1228 )
1229 })
1230 .map(|candidate| candidate.item.ident(self.tcx))
1231 .filter(|&name| set.insert(name))
1232 .collect();
1233
1234 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1236 names
1237 }
1238
1239 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1242u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1264",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1264u32),
::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))]
1243 fn pick(mut self) -> PickResult<'tcx> {
1244 assert!(self.method_name.is_some());
1245
1246 let mut unsatisfied_predicates = Vec::new();
1247
1248 if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1249 return r;
1250 }
1251
1252 if self.is_suggestion.0 {
1255 return Err(MethodError::NoMatch(NoMatchData {
1256 static_candidates: vec![],
1257 unsatisfied_predicates: vec![],
1258 out_of_scope_traits: vec![],
1259 similar_candidate: None,
1260 mode: self.mode,
1261 }));
1262 }
1263
1264 debug!("pick: actual search failed, assemble diagnostics");
1265
1266 let static_candidates = std::mem::take(self.static_candidates.get_mut());
1267 let private_candidate = self.private_candidate.take();
1268
1269 self.reset();
1271
1272 self.assemble_extension_candidates_for_all_traits();
1273
1274 let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1275 Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1276 Some(Err(MethodError::Ambiguity(v))) => v
1277 .into_iter()
1278 .map(|source| match source {
1279 CandidateSource::Trait(id) => id,
1280 CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1281 })
1282 .collect(),
1283 Some(Err(MethodError::NoMatch(NoMatchData {
1284 out_of_scope_traits: others, ..
1285 }))) => {
1286 assert!(others.is_empty());
1287 vec![]
1288 }
1289 _ => vec![],
1290 };
1291
1292 if let Some((kind, def_id)) = private_candidate {
1293 return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1294 }
1295 let similar_candidate = self.probe_for_similar_candidate()?;
1296
1297 Err(MethodError::NoMatch(NoMatchData {
1298 static_candidates,
1299 unsatisfied_predicates,
1300 out_of_scope_traits,
1301 similar_candidate,
1302 mode: self.mode,
1303 }))
1304 }
1305
1306 fn pick_core(
1307 &self,
1308 unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1309 ) -> Option<PickResult<'tcx>> {
1310 self.pick_all_method(&mut PickDiagHints {
1312 unstable_candidates: Some(Vec::new()),
1315 unsatisfied_predicates,
1318 })
1319 .or_else(|| {
1320 self.pick_all_method(&mut PickDiagHints {
1321 unstable_candidates: None,
1326 unsatisfied_predicates: &mut Vec::new(),
1329 })
1330 })
1331 }
1332
1333 fn pick_all_method<'b>(
1334 &self,
1335 pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1336 ) -> Option<PickResult<'tcx>> {
1337 let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1338 self.steps
1339 .iter()
1340 .filter(|step| step.reachable_via_deref)
1344 .filter(|step| {
1345 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1345",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1345u32),
::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);
1346 !step.self_ty.value.references_error() && !step.from_unsafe_deref
1349 })
1350 .find_map(|step| {
1351 let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1352 .fcx
1353 .probe_instantiate_query_response(
1354 self.span,
1355 self.orig_steps_var_values,
1356 &step.self_ty,
1357 )
1358 .unwrap_or_else(|_| {
1359 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("{0:?} was applicable but now isn\'t?", step.self_ty))span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
1360 });
1361
1362 let by_value_pick = self.pick_by_value_method(
1363 step,
1364 self_ty,
1365 &instantiate_self_ty_obligations,
1366 pick_diag_hints,
1367 );
1368
1369 if let Some(by_value_pick) = by_value_pick {
1371 if let Ok(by_value_pick) = by_value_pick.as_ref() {
1372 if by_value_pick.kind == PickKind::InherentImplPick {
1373 for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1374 if let Err(e) = self.check_for_shadowed_autorefd_method(
1375 by_value_pick,
1376 step,
1377 self_ty,
1378 &instantiate_self_ty_obligations,
1379 mutbl,
1380 track_unstable_candidates,
1381 ) {
1382 return Some(Err(e));
1383 }
1384 }
1385 }
1386 }
1387 return Some(by_value_pick);
1388 }
1389
1390 let autoref_pick = self.pick_autorefd_method(
1391 step,
1392 self_ty,
1393 &instantiate_self_ty_obligations,
1394 hir::Mutability::Not,
1395 pick_diag_hints,
1396 None,
1397 );
1398 if let Some(autoref_pick) = autoref_pick {
1400 if let Ok(autoref_pick) = autoref_pick.as_ref() {
1401 if autoref_pick.kind == PickKind::InherentImplPick {
1403 if let Err(e) = self.check_for_shadowed_autorefd_method(
1404 autoref_pick,
1405 step,
1406 self_ty,
1407 &instantiate_self_ty_obligations,
1408 hir::Mutability::Mut,
1409 track_unstable_candidates,
1410 ) {
1411 return Some(Err(e));
1412 }
1413 }
1414 }
1415 return Some(autoref_pick);
1416 }
1417
1418 self.pick_autorefd_method(
1442 step,
1443 self_ty,
1444 &instantiate_self_ty_obligations,
1445 hir::Mutability::Mut,
1446 pick_diag_hints,
1447 None,
1448 )
1449 .or_else(|| {
1450 self.pick_const_ptr_method(
1451 step,
1452 self_ty,
1453 &instantiate_self_ty_obligations,
1454 pick_diag_hints,
1455 )
1456 })
1457 .or_else(|| {
1458 self.pick_reborrow_pin_method(
1459 step,
1460 self_ty,
1461 &instantiate_self_ty_obligations,
1462 pick_diag_hints,
1463 )
1464 })
1465 })
1466 }
1467
1468 fn check_for_shadowed_autorefd_method(
1484 &self,
1485 possible_shadower: &Pick<'tcx>,
1486 step: &CandidateStep<'tcx>,
1487 self_ty: Ty<'tcx>,
1488 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1489 mutbl: hir::Mutability,
1490 track_unstable_candidates: bool,
1491 ) -> Result<(), MethodError<'tcx>> {
1492 if !self.tcx.features().arbitrary_self_types()
1496 && !self.tcx.features().arbitrary_self_types_pointers()
1497 {
1498 return Ok(());
1499 }
1500
1501 let mut pick_diag_hints = PickDiagHints {
1506 unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1507 unsatisfied_predicates: &mut Vec::new(),
1508 };
1509 let pick_constraints = PickConstraintsForShadowed {
1511 autoderefs: possible_shadower.autoderefs,
1513 receiver_steps: possible_shadower.receiver_steps,
1517 def_id: possible_shadower.item.def_id,
1520 };
1521 let potentially_shadowed_pick = self.pick_autorefd_method(
1551 step,
1552 self_ty,
1553 instantiate_self_ty_obligations,
1554 mutbl,
1555 &mut pick_diag_hints,
1556 Some(&pick_constraints),
1557 );
1558 if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1561 let sources = [possible_shadower, possible_shadowed]
1562 .into_iter()
1563 .map(|p| self.candidate_source_from_pick(p))
1564 .collect();
1565 return Err(MethodError::Ambiguity(sources));
1566 }
1567 Ok(())
1568 }
1569
1570 fn pick_by_value_method(
1577 &self,
1578 step: &CandidateStep<'tcx>,
1579 self_ty: Ty<'tcx>,
1580 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1581 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1582 ) -> Option<PickResult<'tcx>> {
1583 if step.unsize {
1584 return None;
1585 }
1586
1587 self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1588 r.map(|mut pick| {
1589 pick.autoderefs = step.autoderefs;
1590
1591 match *step.self_ty.value.value.kind() {
1592 ty::Ref(_, _, mutbl) => {
1594 pick.autoderefs += 1;
1595 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1596 mutbl,
1597 unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1598 })
1599 }
1600
1601 ty::Adt(def, args)
1602 if self.tcx.features().pin_ergonomics()
1603 && self.tcx.is_lang_item(def.did(), LangItem::Pin) =>
1604 {
1605 if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1607 pick.autoref_or_ptr_adjustment =
1608 Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1609 }
1610 }
1611
1612 _ => (),
1613 }
1614
1615 pick
1616 })
1617 })
1618 }
1619
1620 fn pick_autorefd_method(
1621 &self,
1622 step: &CandidateStep<'tcx>,
1623 self_ty: Ty<'tcx>,
1624 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1625 mutbl: hir::Mutability,
1626 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1627 pick_constraints: Option<&PickConstraintsForShadowed>,
1628 ) -> Option<PickResult<'tcx>> {
1629 let tcx = self.tcx;
1630
1631 if let Some(pick_constraints) = pick_constraints {
1632 if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1633 return None;
1634 }
1635 }
1636
1637 let region = tcx.lifetimes.re_erased;
1639
1640 let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1641 self.pick_method(
1642 autoref_ty,
1643 instantiate_self_ty_obligations,
1644 pick_diag_hints,
1645 pick_constraints,
1646 )
1647 .map(|r| {
1648 r.map(|mut pick| {
1649 pick.autoderefs = step.autoderefs;
1650 pick.autoref_or_ptr_adjustment =
1651 Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1652 pick
1653 })
1654 })
1655 }
1656
1657 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1658u32),
::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))]
1659 fn pick_reborrow_pin_method(
1660 &self,
1661 step: &CandidateStep<'tcx>,
1662 self_ty: Ty<'tcx>,
1663 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1664 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1665 ) -> Option<PickResult<'tcx>> {
1666 if !self.tcx.features().pin_ergonomics() {
1667 return None;
1668 }
1669
1670 let inner_ty = match self_ty.kind() {
1672 ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), LangItem::Pin) => {
1673 match args[0].expect_ty().kind() {
1674 ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1675 _ => {
1676 return None;
1677 }
1678 }
1679 }
1680 _ => return None,
1681 };
1682
1683 let region = self.tcx.lifetimes.re_erased;
1684 let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1685 self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1686 |r| {
1687 r.map(|mut pick| {
1688 pick.autoderefs = step.autoderefs;
1689 pick.autoref_or_ptr_adjustment =
1690 Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1691 pick
1692 })
1693 },
1694 )
1695 }
1696
1697 fn pick_const_ptr_method(
1701 &self,
1702 step: &CandidateStep<'tcx>,
1703 self_ty: Ty<'tcx>,
1704 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1705 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1706 ) -> Option<PickResult<'tcx>> {
1707 if step.unsize {
1709 return None;
1710 }
1711
1712 let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1713 return None;
1714 };
1715
1716 let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1717 self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1718 |r| {
1719 r.map(|mut pick| {
1720 pick.autoderefs = step.autoderefs;
1721 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1722 pick
1723 })
1724 },
1725 )
1726 }
1727
1728 fn pick_method(
1729 &self,
1730 self_ty: Ty<'tcx>,
1731 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1732 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1733 pick_constraints: Option<&PickConstraintsForShadowed>,
1734 ) -> Option<PickResult<'tcx>> {
1735 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1735",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1735u32),
::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));
1736
1737 for (kind, candidates) in
1738 [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1739 {
1740 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1740",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1740u32),
::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);
1741 let res = self.consider_candidates(
1742 self_ty,
1743 instantiate_self_ty_obligations,
1744 candidates,
1745 pick_diag_hints,
1746 pick_constraints,
1747 );
1748 if let Some(pick) = res {
1749 return Some(pick);
1750 }
1751 }
1752
1753 if self.private_candidate.get().is_none() {
1754 if let Some(Ok(pick)) = self.consider_candidates(
1755 self_ty,
1756 instantiate_self_ty_obligations,
1757 &self.private_candidates,
1758 &mut PickDiagHints {
1759 unstable_candidates: None,
1760 unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1761 },
1762 None,
1763 ) {
1764 self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1765 }
1766 }
1767 None
1768 }
1769
1770 fn consider_candidates(
1771 &self,
1772 self_ty: Ty<'tcx>,
1773 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1774 candidates: &[Candidate<'tcx>],
1775 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1776 pick_constraints: Option<&PickConstraintsForShadowed>,
1777 ) -> Option<PickResult<'tcx>> {
1778 let mut applicable_candidates: Vec<_> = candidates
1779 .iter()
1780 .filter(|candidate| {
1781 pick_constraints
1782 .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1783 .unwrap_or(true)
1784 })
1785 .map(|probe| {
1786 (
1787 probe,
1788 self.consider_probe(
1789 self_ty,
1790 instantiate_self_ty_obligations,
1791 probe,
1792 &mut pick_diag_hints.unsatisfied_predicates,
1793 ),
1794 )
1795 })
1796 .filter(|&(_, status)| status != ProbeResult::NoMatch)
1797 .collect();
1798
1799 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:1799",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1799u32),
::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);
1800
1801 if applicable_candidates.len() > 1 {
1802 if let Some(pick) =
1803 self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1804 {
1805 return Some(Ok(pick));
1806 }
1807 }
1808
1809 if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1810 applicable_candidates.retain(|&(candidate, _)| {
1811 if let stability::EvalResult::Deny { feature, .. } =
1812 self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1813 {
1814 uc.push((candidate.clone(), feature));
1815 return false;
1816 }
1817 true
1818 });
1819 }
1820
1821 if applicable_candidates.len() > 1 {
1822 if self.tcx.features().supertrait_item_shadowing() {
1826 if let Some(pick) =
1827 self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1828 {
1829 return Some(Ok(pick));
1830 }
1831 }
1832
1833 let sources =
1834 applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1835 return Some(Err(MethodError::Ambiguity(sources)));
1836 }
1837
1838 applicable_candidates.pop().map(|(probe, status)| match status {
1839 ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1840 self_ty,
1841 pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1842 )),
1843 ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1844 })
1845 }
1846}
1847
1848impl<'tcx> Pick<'tcx> {
1849 pub(crate) fn differs_from(&self, other: &Self) -> bool {
1854 let Self {
1855 item: AssocItem { def_id, kind: _, container: _ },
1856 kind: _,
1857 import_ids: _,
1858 autoderefs: _,
1859 autoref_or_ptr_adjustment: _,
1860 self_ty,
1861 unstable_candidates: _,
1862 receiver_steps: _,
1863 shadowed_candidates: _,
1864 } = *self;
1865 self_ty != other.self_ty || def_id != other.item.def_id
1866 }
1867
1868 pub(crate) fn maybe_emit_unstable_name_collision_hint(
1870 &self,
1871 tcx: TyCtxt<'tcx>,
1872 span: Span,
1873 scope_expr_id: HirId,
1874 ) {
1875 struct ItemMaybeBeAddedToStd<'a, 'tcx> {
1876 this: &'a Pick<'tcx>,
1877 tcx: TyCtxt<'tcx>,
1878 span: Span,
1879 }
1880
1881 impl<'a, 'b, 'tcx> Diagnostic<'a, ()> for ItemMaybeBeAddedToStd<'b, 'tcx> {
1882 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
1883 let Self { this, tcx, span } = self;
1884 let def_kind = this.item.as_def_kind();
1885 let mut lint = Diag::new(
1886 dcx,
1887 level,
1888 ::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!(
1889 "{} {} with this name may be added to the standard library in the future",
1890 tcx.def_kind_descr_article(def_kind, this.item.def_id),
1891 tcx.def_kind_descr(def_kind, this.item.def_id),
1892 ),
1893 );
1894
1895 match (this.item.kind, this.item.container) {
1896 (ty::AssocKind::Fn { .. }, _) => {
1897 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!(
1902 "call with fully qualified syntax `{}(...)` to keep using the current \
1903 method",
1904 tcx.def_path_str(this.item.def_id),
1905 ));
1906 }
1907 (ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
1908 let def_id = this.item.container_id(tcx);
1909 lint.span_suggestion(
1910 span,
1911 "use the fully qualified path to the associated const",
1912 ::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),
1913 Applicability::MachineApplicable,
1914 );
1915 }
1916 _ => {}
1917 }
1918 tcx.disabled_nightly_features(
1919 &mut lint,
1920 this.unstable_candidates.iter().map(|(candidate, feature)| {
1921 (::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)
1922 }),
1923 );
1924 lint
1925 }
1926 }
1927
1928 if self.unstable_candidates.is_empty() {
1929 return;
1930 }
1931 tcx.emit_node_span_lint(
1932 UNSTABLE_NAME_COLLISIONS,
1933 scope_expr_id,
1934 span,
1935 ItemMaybeBeAddedToStd { this: self, tcx, span },
1936 );
1937 }
1938}
1939
1940impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1941 fn select_trait_candidate_for_diagnostics(
1942 &self,
1943 trait_ref: ty::TraitRef<'tcx>,
1944 ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1945 let obligation =
1946 traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1947 let candidate = traits::SelectionContext::new(self).select(&obligation);
1948 if let Ok(Some(traits::ImplSource::UserDefined(impl_source_user_defined_data))) = &candidate
1949 && self.infcx.tcx.do_not_recommend_impl(impl_source_user_defined_data.impl_def_id)
1950 {
1951 return Err(traits::SelectionError::Unimplemented);
1952 }
1953 candidate
1954 }
1955
1956 fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1959 match candidate.kind {
1960 InherentImplCandidate { .. } => {
1961 CandidateSource::Impl(candidate.item.container_id(self.tcx))
1962 }
1963 ObjectCandidate(_) | WhereClauseCandidate(_) => {
1964 CandidateSource::Trait(candidate.item.container_id(self.tcx))
1965 }
1966 TraitCandidate { trait_ref, is_ambiguously_imported: _ } => self.probe(|_| {
1967 let trait_ref = self.instantiate_binder_with_fresh_vars(
1968 self.span,
1969 BoundRegionConversionTime::FnCall,
1970 trait_ref,
1971 );
1972 let (xform_self_ty, _) =
1973 self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1974 let _ = self.at(&ObligationCause::dummy(), self.param_env).sup(
1977 DefineOpaqueTypes::Yes,
1978 xform_self_ty,
1979 self_ty,
1980 );
1981 match self.select_trait_candidate_for_diagnostics(trait_ref) {
1982 Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
1983 CandidateSource::Impl(impl_data.impl_def_id)
1986 }
1987 _ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
1988 }
1989 }),
1990 }
1991 }
1992
1993 fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
1994 match pick.kind {
1995 InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1996 ObjectPick | WhereClausePick(_) | TraitPick { .. } => {
1997 CandidateSource::Trait(pick.item.container_id(self.tcx))
1998 }
1999 }
2000 }
2001
2002 fn consider_probe(
2003 &self,
2004 self_ty: Ty<'tcx>,
2005 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
2006 probe: &Candidate<'tcx>,
2007 possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
2008 ) -> ProbeResult {
2009 self.probe(|snapshot| {
2010 let outer_universe = self.universe();
2011
2012 let mut result = ProbeResult::Match;
2013 let cause = &self.misc(self.span);
2014 let ocx = ObligationCtxt::new_with_diagnostics(self);
2015
2016 if self.next_trait_solver() {
2024 ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
2025 let errors = ocx.try_evaluate_obligations();
2026 if !errors.no_errors() {
2027 {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("unexpected autoderef error {0:?}", errors)));
};unreachable!("unexpected autoderef error {errors:?}");
2028 }
2029 }
2030
2031 let mut trait_predicate = None;
2032 let (mut xform_self_ty, mut xform_ret_ty);
2033
2034 match probe.kind {
2035 InherentImplCandidate { impl_def_id, .. } => {
2036 let impl_args = self.fresh_args_for_item(self.span, impl_def_id);
2037 let impl_ty = self
2038 .tcx
2039 .type_of(impl_def_id)
2040 .instantiate(self.tcx, impl_args)
2041 .skip_norm_wip();
2042 (xform_self_ty, xform_ret_ty) =
2043 self.xform_self_ty(probe.item, impl_ty, impl_args);
2044 xform_self_ty =
2045 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2046 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2047 {
2048 Ok(()) => {}
2049 Err(err) => {
2050 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2050",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2050u32),
::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);
2051 return ProbeResult::NoMatch;
2052 }
2053 }
2054 xform_ret_ty =
2056 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2057 let impl_def_id = probe.item.container_id(self.tcx);
2059 let impl_bounds =
2060 self.tcx.clauses_of(impl_def_id).instantiate(self.tcx, impl_args);
2061 ocx.register_obligations(traits::predicates_for_generics(
2063 |idx, span| {
2064 let code = ObligationCauseCode::WhereClauseInExpr(
2065 impl_def_id,
2066 span,
2067 self.scope_expr_id,
2068 idx,
2069 );
2070 self.cause(self.span, code)
2071 },
2072 |clause| ocx.normalize(cause, self.param_env, clause),
2073 self.param_env,
2074 impl_bounds,
2075 ));
2076 }
2077 TraitCandidate { trait_ref: poly_trait_ref, is_ambiguously_imported: _ } => {
2078 if let Some(method_name) = self.method_name {
2081 if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
2082 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2083 if trait_def.skip_array_during_method_dispatch {
2084 return ProbeResult::NoMatch;
2085 }
2086 }
2087
2088 if self_ty.boxed_ty().is_some_and(Ty::is_slice)
2091 && !method_name.span.at_least_rust_2024()
2092 {
2093 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2094 if trait_def.skip_boxed_slice_during_method_dispatch {
2095 return ProbeResult::NoMatch;
2096 }
2097 }
2098 }
2099
2100 let trait_ref = self.instantiate_binder_with_fresh_vars(
2101 self.span,
2102 BoundRegionConversionTime::FnCall,
2103 poly_trait_ref,
2104 );
2105 let trait_ref =
2106 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(trait_ref));
2107 (xform_self_ty, xform_ret_ty) =
2108 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2109 xform_self_ty =
2110 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2111 match self_ty.kind() {
2112 &ty::Alias(_, ty::AliasTy { kind: ty::Opaque { def_id }, .. })
2116 if !self.next_trait_solver()
2117 && self.infcx.can_define_opaque_ty(def_id)
2118 && !xform_self_ty.is_ty_var() =>
2119 {
2120 return ProbeResult::NoMatch;
2121 }
2122 _ => match ocx.relate(
2123 cause,
2124 self.param_env,
2125 self.variance(),
2126 self_ty,
2127 xform_self_ty,
2128 ) {
2129 Ok(()) => {}
2130 Err(err) => {
2131 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2131",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2131u32),
::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);
2132 return ProbeResult::NoMatch;
2133 }
2134 },
2135 }
2136 let obligation = traits::Obligation::new(
2137 self.tcx,
2138 cause.clone(),
2139 self.param_env,
2140 ty::Binder::dummy(trait_ref),
2141 );
2142
2143 if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
2145 {
2146 ocx.register_obligation(obligation);
2147 } else {
2148 result = ProbeResult::NoMatch;
2149 if let Ok(Some(candidate)) =
2150 self.select_trait_candidate_for_diagnostics(trait_ref)
2151 {
2152 for nested_obligation in candidate.nested_obligations() {
2153 if !self.infcx.predicate_may_hold(&nested_obligation) {
2154 possibly_unsatisfied_predicates.push((
2155 self.deeply_resolve_ignoring_regions(
2156 nested_obligation.predicate,
2157 ),
2158 Some(
2159 self.deeply_resolve_ignoring_regions(
2160 obligation.predicate,
2161 ),
2162 ),
2163 Some(nested_obligation.cause),
2164 ));
2165 }
2166 }
2167 }
2168 }
2169
2170 trait_predicate = Some(trait_ref.upcast(self.tcx));
2171 }
2172 ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
2173 let trait_ref = self.instantiate_binder_with_fresh_vars(
2174 self.span,
2175 BoundRegionConversionTime::FnCall,
2176 poly_trait_ref,
2177 );
2178 (xform_self_ty, xform_ret_ty) =
2179 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2180
2181 if #[allow(non_exhaustive_omitted_patterns)] match probe.kind {
WhereClauseCandidate(_) => true,
_ => false,
}matches!(probe.kind, WhereClauseCandidate(_)) {
2182 let ty = ocx.normalize(
2186 cause,
2187 self.param_env,
2188 Unnormalized::new_wip(trait_ref.self_ty()),
2189 );
2190 if !#[allow(non_exhaustive_omitted_patterns)] match ty.kind() {
ty::Param(_) => true,
_ => false,
}matches!(ty.kind(), ty::Param(_)) {
2191 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2191",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2191u32),
::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:?}");
2192 return ProbeResult::NoMatch;
2193 }
2194 }
2195
2196 xform_self_ty =
2197 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2198 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2199 {
2200 Ok(()) => {}
2201 Err(err) => {
2202 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2202",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2202u32),
::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);
2203 return ProbeResult::NoMatch;
2204 }
2205 }
2206 }
2207 }
2208
2209 for error in ocx.try_evaluate_obligations() {
2211 result = ProbeResult::NoMatch;
2212 let nested_predicate =
2213 self.deeply_resolve_ignoring_regions(error.obligation.predicate);
2214 if let Some(trait_predicate) = trait_predicate
2215 && nested_predicate == self.deeply_resolve_ignoring_regions(trait_predicate)
2216 {
2217 } else {
2221 possibly_unsatisfied_predicates.push((
2222 nested_predicate,
2223 Some(self.deeply_resolve_ignoring_regions(error.root_obligation.predicate))
2224 .filter(|root_predicate| *root_predicate != nested_predicate),
2225 Some(error.obligation.cause),
2226 ));
2227 }
2228 }
2229
2230 if let ProbeResult::Match = result
2231 && let Some(return_ty) = self.return_type
2232 && let Some(mut xform_ret_ty) = xform_ret_ty
2233 {
2234 if !#[allow(non_exhaustive_omitted_patterns)] match probe.kind {
InherentImplCandidate { .. } => true,
_ => false,
}matches!(probe.kind, InherentImplCandidate { .. }) {
2239 xform_ret_ty =
2240 ocx.normalize(&cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2241 }
2242
2243 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2243",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2243u32),
::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);
2244 match ocx.relate(cause, self.param_env, self.variance(), xform_ret_ty, return_ty) {
2245 Ok(()) => {}
2246 Err(_) => {
2247 result = ProbeResult::BadReturnType;
2248 }
2249 }
2250
2251 for error in ocx.try_evaluate_obligations() {
2253 result = ProbeResult::NoMatch;
2254 possibly_unsatisfied_predicates.push((
2255 error.obligation.predicate,
2256 Some(error.root_obligation.predicate)
2257 .filter(|predicate| *predicate != error.obligation.predicate),
2258 Some(error.root_obligation.cause),
2259 ));
2260 }
2261 }
2262
2263 if self.infcx.next_trait_solver() {
2264 if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
2265 result = ProbeResult::NoMatch;
2266 }
2267 }
2268
2269 if let Err(_) = self.leak_check(outer_universe, Some(snapshot)) {
2275 result = ProbeResult::NoMatch;
2276 }
2277
2278 result
2279 })
2280 }
2281
2282 {}
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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2296u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2323",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2323u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2334",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2334u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2340",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2340u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2347",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2347u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2296",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2296u32),
::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)]
2297 fn should_reject_candidate_due_to_opaque_treated_as_rigid(
2298 &self,
2299 trait_predicate: Option<ty::Predicate<'tcx>>,
2300 ) -> bool {
2301 if let Some(predicate) = trait_predicate {
2313 let goal = Goal { param_env: self.param_env, predicate };
2314 if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
2315 return true;
2316 }
2317 }
2318
2319 for step in self.steps {
2322 if step.self_ty_is_opaque {
2323 debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
2324 let constrained_opaque = self.probe(|_| {
2325 let Ok(ok) = self.fcx.probe_instantiate_query_response(
2330 self.span,
2331 self.orig_steps_var_values,
2332 &step.self_ty,
2333 ) else {
2334 debug!("failed to instantiate self_ty");
2335 return false;
2336 };
2337 let ocx = ObligationCtxt::new(self);
2338 let self_ty = ocx.register_infer_ok_obligations(ok);
2339 if !ocx.try_evaluate_obligations().no_errors() {
2340 debug!("failed to prove instantiate self_ty obligations");
2341 return false;
2342 }
2343
2344 !self.deeply_resolve_ignoring_regions(self_ty).is_ty_var()
2345 });
2346 if constrained_opaque {
2347 debug!("opaque type has been constrained");
2348 return true;
2349 }
2350 }
2351 }
2352
2353 false
2354 }
2355
2356 fn collapse_candidates_to_trait_pick(
2374 &self,
2375 self_ty: Ty<'tcx>,
2376 probes: &[(&Candidate<'tcx>, ProbeResult)],
2377 ) -> Option<Pick<'tcx>> {
2378 let container = probes[0].0.item.trait_container(self.tcx)?;
2380 for (p, _) in &probes[1..] {
2381 let p_container = p.item.trait_container(self.tcx)?;
2382 if p_container != container {
2383 return None;
2384 }
2385 }
2386
2387 let is_ambiguously_imported = probes.iter().any(|(p, _)| match p.kind {
2389 TraitCandidate { is_ambiguously_imported, .. } => is_ambiguously_imported,
2390 _ => false,
2391 });
2392
2393 Some(Pick {
2396 item: probes[0].0.item,
2397 kind: TraitPick { is_ambiguously_imported },
2398 import_ids: probes[0].0.import_ids,
2399 autoderefs: 0,
2400 autoref_or_ptr_adjustment: None,
2401 self_ty,
2402 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2403 receiver_steps: None,
2404 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2405 })
2406 }
2407
2408 fn collapse_candidates_to_subtrait_pick(
2418 &self,
2419 self_ty: Ty<'tcx>,
2420 probes: &[(&Candidate<'tcx>, ProbeResult)],
2421 ) -> Option<Pick<'tcx>> {
2422 let mut child_candidate = probes[0].0;
2423 let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2424 let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2425
2426 let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2427 while !remaining_candidates.is_empty() {
2428 let mut made_progress = false;
2429 let mut next_round = ::alloc::vec::Vec::new()vec![];
2430
2431 for remaining_candidate in remaining_candidates {
2432 let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2433 if supertraits.contains(&remaining_trait) {
2434 made_progress = true;
2435 continue;
2436 }
2437
2438 let remaining_trait_supertraits: SsoHashSet<_> =
2444 supertrait_def_ids(self.tcx, remaining_trait).collect();
2445 if remaining_trait_supertraits.contains(&child_trait) {
2446 child_candidate = remaining_candidate;
2447 child_trait = remaining_trait;
2448 supertraits = remaining_trait_supertraits;
2449 made_progress = true;
2450 continue;
2451 }
2452
2453 next_round.push(remaining_candidate);
2460 }
2461
2462 if made_progress {
2463 remaining_candidates = next_round;
2465 } else {
2466 return None;
2469 }
2470 }
2471
2472 let is_ambiguously_imported = match child_candidate.kind {
2473 TraitCandidate { is_ambiguously_imported, .. } => is_ambiguously_imported,
2474 _ => false,
2475 };
2476
2477 Some(Pick {
2478 item: child_candidate.item,
2479 kind: TraitPick { is_ambiguously_imported },
2480 import_ids: child_candidate.import_ids,
2481 autoderefs: 0,
2482 autoref_or_ptr_adjustment: None,
2483 self_ty,
2484 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2485 shadowed_candidates: probes
2486 .iter()
2487 .map(|(c, _)| c.item)
2488 .filter(|item| item.def_id != child_candidate.item.def_id)
2489 .collect(),
2490 receiver_steps: None,
2491 })
2492 }
2493
2494 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/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(&[],
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2501",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2501u32),
::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))]
2498 pub(crate) fn probe_for_similar_candidate(
2499 &mut self,
2500 ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2501 debug!("probing for method names similar to {:?}", self.method_name);
2502
2503 self.probe(|_| {
2504 let mut pcx = ProbeContext::new(
2505 self.fcx,
2506 self.span,
2507 self.mode,
2508 self.method_name,
2509 self.return_type,
2510 self.orig_steps_var_values,
2511 self.steps,
2512 self.scope_expr_id,
2513 IsSuggestion(true),
2514 );
2515 pcx.allow_similar_names = true;
2516 pcx.assemble_inherent_candidates();
2517 pcx.assemble_extension_candidates_for_all_traits();
2518
2519 let method_names = pcx.candidate_method_names(|_| true);
2520 pcx.allow_similar_names = false;
2521 let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2522 .iter()
2523 .filter_map(|&method_name| {
2524 pcx.reset();
2525 pcx.method_name = Some(method_name);
2526 pcx.assemble_inherent_candidates();
2527 pcx.assemble_extension_candidates_for_all_traits();
2528 pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2529 })
2530 .collect();
2531
2532 if applicable_close_candidates.is_empty() {
2533 Ok(None)
2534 } else {
2535 let best_name = applicable_close_candidates
2536 .iter()
2537 .find(|cand| self.matches_by_doc_alias(cand.def_id))
2538 .map(|cand| cand.name())
2539 .or_else(|| {
2540 let names = applicable_close_candidates
2541 .iter()
2542 .map(|cand| cand.name())
2543 .collect::<Vec<Symbol>>();
2544 find_best_match_for_name_with_substrings(
2545 &names,
2546 self.method_name.unwrap().name,
2547 None,
2548 )
2549 });
2550 Ok(best_name.and_then(|best_name| {
2551 applicable_close_candidates
2552 .into_iter()
2553 .find(|method| method.name() == best_name)
2554 }))
2555 }
2556 })
2557 }
2558
2559 fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2562 match self.mode {
2568 Mode::MethodCall => item.is_method(),
2569 Mode::Path => match item.kind {
2570 ty::AssocKind::Type { .. } => false,
2571 ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2572 },
2573 }
2574 }
2581
2582 fn record_static_candidate(&self, source: CandidateSource) {
2583 self.static_candidates.borrow_mut().push(source);
2584 }
2585
2586 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2586u32),
::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))]
2587 fn xform_self_ty(
2588 &self,
2589 item: ty::AssocItem,
2590 impl_ty: Ty<'tcx>,
2591 args: GenericArgsRef<'tcx>,
2592 ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2593 if item.is_fn() && self.mode == Mode::MethodCall {
2594 let sig = self.xform_method_sig(item.def_id, args);
2595 (self.self_ty_override.unwrap_or(sig.inputs()[0]), Some(sig.output()))
2596 } else {
2597 (impl_ty, None)
2598 }
2599 }
2600
2601 {}
#[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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2601u32),
::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/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs:2604",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/809936eac66c547a5127ce1da805f0d3a6789b98/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2604u32),
::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))]
2602 fn xform_method_sig(&self, method: DefId, args: GenericArgsRef<'tcx>) -> ty::FnSig<'tcx> {
2603 let fn_sig = self.tcx.fn_sig(method);
2604 debug!(?fn_sig);
2605
2606 assert!(!args.has_escaping_bound_vars());
2607
2608 let generics = self.tcx.generics_of(method);
2614 assert_eq!(args.len(), generics.parent_count);
2615
2616 let xform_fn_sig = if generics.is_own_empty() {
2617 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2618 } else {
2619 let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2620 let i = param.index as usize;
2621 if i < args.len() {
2622 args[i]
2623 } else {
2624 match param.kind {
2625 GenericParamDefKind::Lifetime => {
2626 self.tcx.lifetimes.re_erased.into()
2628 }
2629 GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2630 self.var_for_def(self.span, param)
2631 }
2632 }
2633 }
2634 });
2635 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2636 };
2637
2638 self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2639 }
2640
2641 fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2643 match (self.mode, kind) {
2644 (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2645 (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2646 _ => false,
2647 }
2648 }
2649
2650 fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2653 let Some(method) = self.method_name else {
2654 return false;
2655 };
2656
2657 if let Some(d) = {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(Doc(d)) => {
break 'done Some(d);
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, Doc(d) => d)
2658 && d.aliases.contains_key(&method.name)
2659 {
2660 return true;
2661 }
2662
2663 if let Some(confusables) =
2664 {
{
'done:
{
for i in ::rustc_attr_ir::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(RustcConfusables {
confusables }) => {
break 'done Some(confusables);
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, RustcConfusables{ confusables } => confusables)
2665 && confusables.contains(&method.name)
2666 {
2667 return true;
2668 }
2669
2670 false
2671 }
2672
2673 fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2678 if let Some(name) = self.method_name {
2679 if self.allow_similar_names {
2680 let max_dist = max(name.as_str().len(), 3) / 3;
2681 self.tcx
2682 .associated_items(def_id)
2683 .in_definition_order()
2684 .filter(|x| {
2685 if !self.is_relevant_kind_for_mode(x.kind) {
2686 return false;
2687 }
2688 if let Some(d) = edit_distance_with_substrings(
2689 name.as_str(),
2690 x.name().as_str(),
2691 max_dist,
2692 ) {
2693 return d > 0;
2694 }
2695 self.matches_by_doc_alias(x.def_id)
2696 })
2697 .copied()
2698 .collect()
2699 } else {
2700 self.fcx
2701 .associated_value(def_id, name)
2702 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2703 .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2704 }
2705 } else {
2706 self.tcx
2707 .associated_items(def_id)
2708 .in_definition_order()
2709 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2710 .copied()
2711 .collect()
2712 }
2713 }
2714}
2715
2716impl<'tcx> Candidate<'tcx> {
2717 fn to_unadjusted_pick(
2718 &self,
2719 self_ty: Ty<'tcx>,
2720 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2721 ) -> Pick<'tcx> {
2722 Pick {
2723 item: self.item,
2724 kind: match self.kind {
2725 InherentImplCandidate { .. } => InherentImplPick,
2726 ObjectCandidate(_) => ObjectPick,
2727 TraitCandidate { is_ambiguously_imported, .. } => {
2728 TraitPick { is_ambiguously_imported }
2729 }
2730 WhereClauseCandidate(trait_ref) => {
2731 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!(
2737 !trait_ref.skip_binder().args.has_infer()
2738 && !trait_ref.skip_binder().args.has_placeholders()
2739 );
2740
2741 WhereClausePick(trait_ref)
2742 }
2743 },
2744 import_ids: self.import_ids,
2745 autoderefs: 0,
2746 autoref_or_ptr_adjustment: None,
2747 self_ty,
2748 unstable_candidates,
2749 receiver_steps: match self.kind {
2750 InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2751 _ => None,
2752 },
2753 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2754 }
2755 }
2756}