1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::ops::Deref;
4use std::{assert_matches, debug_assert_matches};
5
6use rustc_attr_ir::find_attr;
7use rustc_attr_ir::lang_items::LangItem;
8use rustc_data_structures::fx::FxHashSet;
9use rustc_data_structures::sso::SsoHashSet;
10use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
11use rustc_hir::def::DefKind;
12use rustc_hir::{self as hir, ExprKind, HirId, Node};
13use rustc_hir_analysis::autoderef::{self, Autoderef};
14use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
15use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
16use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
17use rustc_lint_defs::builtin::{
18 METHOD_CALL_ON_DIVERGING_INFER_VAR, TYVAR_BEHIND_RAW_POINTER, UNSTABLE_NAME_COLLISIONS,
19};
20use rustc_macros::Diagnostic;
21use rustc_middle::middle::stability;
22use rustc_middle::ty::elaborate::supertrait_def_ids;
23use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
24use rustc_middle::ty::{
25 self, AssocContainer, AssocItem, GenericArgs, GenericArgsRef, GenericParamDefKind, ParamEnvAnd,
26 Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
27};
28use rustc_span::def_id::{DefId, LocalDefId};
29use rustc_span::edit_distance::{
30 edit_distance_with_substrings, find_best_match_for_name_with_substrings,
31};
32use rustc_span::{DUMMY_SP, Ident, Span, Symbol, bug, span_bug};
33use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
34use rustc_trait_selection::infer::InferCtxtExt as _;
35use rustc_trait_selection::solve::Goal;
36use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
37use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
38use rustc_trait_selection::traits::query::method_autoderef::{
39 CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
40};
41use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
42use smallvec::SmallVec;
43use tracing::{debug, instrument};
44
45use self::CandidateKind::*;
46pub(crate) use self::PickKind::*;
47use super::{CandidateSource, MethodError, NoMatchData, suggest};
48use crate::FnCtxt;
49
50#[derive(#[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for IsSuggestion {
}
#[automatically_derived]impl ::core::clone::Clone for IsSuggestion {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]impl ::core::marker::Copy for IsSuggestion { }Copy, #[automatically_derived]impl ::core::fmt::Debug for IsSuggestion {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_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) -> Self {
Candidate {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
}
}
}Clone)]
111pub(crate) struct Candidate<'tcx> {
112 pub(crate) item: ty::AssocItem,
113 pub(crate) kind: CandidateKind<'tcx>,
114 pub(crate) import_ids: &'tcx [LocalDefId],
115}
116
117#[derive(#[automatically_derived]impl<'tcx> ::core::fmt::Debug for CandidateKind<'tcx>
{
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InherentImplCandidate", "impl_def_id", __self_0,
"receiver_steps", &__self_1),
Self::ObjectCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ObjectCandidate", &__self_0),
Self::TraitCandidate {
trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"TraitCandidate", "trait_ref", __self_0,
"is_ambiguously_imported", &__self_1),
Self::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) -> Self {
match self {
Self::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
CandidateKind::InherentImplCandidate {
impl_def_id: ::core::clone::Clone::clone(__self_0),
receiver_steps: ::core::clone::Clone::clone(__self_1),
},
Self::ObjectCandidate(__self_0) =>
CandidateKind::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
Self::TraitCandidate {
trait_ref: __self_0, is_ambiguously_imported: __self_1 } =>
CandidateKind::TraitCandidate {
trait_ref: ::core::clone::Clone::clone(__self_0),
is_ambiguously_imported: ::core::clone::Clone::clone(__self_1),
},
Self::WhereClauseCandidate(__self_0) =>
CandidateKind::WhereClauseCandidate(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
118pub(crate) enum CandidateKind<'tcx> {
119 InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
120 ObjectCandidate(ty::PolyTraitRef<'tcx>),
121 TraitCandidate { trait_ref: ty::PolyTraitRef<'tcx>, is_ambiguously_imported: bool },
122 WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
123}
124
125#[derive(#[automatically_derived]impl ::core::fmt::Debug for ProbeResult {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ProbeResult::NoMatch => "NoMatch",
ProbeResult::BadReturnType => "BadReturnType",
ProbeResult::Match => "Match",
})
}
}Debug, #[automatically_derived]impl ::core::marker::StructuralPartialEq for
ProbeResult {
}
#[automatically_derived]impl ::core::cmp::PartialEq for ProbeResult {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for ProbeResult { }Eq, #[automatically_derived]impl ::core::marker::Copy for ProbeResult { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for ProbeResult {
}
#[automatically_derived]impl ::core::clone::Clone for ProbeResult {
#[inline]
fn clone(&self) -> Self { *self }
}Clone)]
126enum ProbeResult {
127 NoMatch,
128 BadReturnType,
129 Match,
130}
131
132#[derive(#[automatically_derived]impl ::core::fmt::Debug for AutorefOrPtrAdjustment {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Autoref { mutbl: __self_0, unsize: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Autoref", "mutbl", __self_0, "unsize", &__self_1),
Self::ToConstPtr =>
::core::fmt::Formatter::write_str(f, "ToConstPtr"),
Self::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: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Autoref { mutbl: __self_0, unsize: __self_1 },
Self::Autoref { mutbl: __arg1_0, unsize: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(Self::ReborrowPin(__self_0), Self::ReborrowPin(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl ::core::marker::Copy for AutorefOrPtrAdjustment {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for AutorefOrPtrAdjustment {
}
#[automatically_derived]impl ::core::clone::Clone for AutorefOrPtrAdjustment {
#[inline]
fn clone(&self) -> Self {
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
*self
}
}Clone)]
145pub(crate) enum AutorefOrPtrAdjustment {
146 Autoref {
149 mutbl: hir::Mutability,
150
151 unsize: bool,
154 },
155 ToConstPtr,
157
158 ReborrowPin(hir::Mutability),
160}
161
162impl AutorefOrPtrAdjustment {
163 fn get_unsize(&self) -> bool {
164 match self {
165 AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
166 AutorefOrPtrAdjustment::ToConstPtr => false,
167 AutorefOrPtrAdjustment::ReborrowPin(_) => false,
168 }
169 }
170}
171
172#[derive(#[automatically_derived]impl<'a, 'tcx> ::core::fmt::Debug for
PickDiagHints<'a, 'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field2_finish(f, "PickDiagHints",
"unstable_candidates", &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) -> Self {
Pick {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
autoderefs: ::core::clone::Clone::clone(&self.autoderefs),
autoref_or_ptr_adjustment: ::core::clone::Clone::clone(&self.autoref_or_ptr_adjustment),
self_ty: ::core::clone::Clone::clone(&self.self_ty),
unstable_candidates: ::core::clone::Clone::clone(&self.unstable_candidates),
receiver_steps: ::core::clone::Clone::clone(&self.receiver_steps),
shadowed_candidates: ::core::clone::Clone::clone(&self.shadowed_candidates),
}
}
}Clone)]
218pub(crate) struct Pick<'tcx> {
219 pub item: ty::AssocItem,
220 pub kind: PickKind<'tcx>,
221 pub import_ids: &'tcx [LocalDefId],
222
223 pub autoderefs: usize,
228
229 pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
232 pub self_ty: Ty<'tcx>,
233
234 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
236
237 pub receiver_steps: Option<usize>,
241
242 pub shadowed_candidates: Vec<ty::AssocItem>,
244}
245
246#[derive(#[automatically_derived]impl<'tcx> ::core::clone::Clone for PickKind<'tcx> {
#[inline]
fn clone(&self) -> Self {
match self {
Self::InherentImplPick => PickKind::InherentImplPick,
Self::ObjectPick => PickKind::ObjectPick,
Self::TraitPick { is_ambiguously_imported: __self_0 } =>
PickKind::TraitPick {
is_ambiguously_imported: ::core::clone::Clone::clone(__self_0),
},
Self::WhereClausePick(__self_0) =>
PickKind::WhereClausePick(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]impl<'tcx> ::core::fmt::Debug for PickKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::InherentImplPick =>
::core::fmt::Formatter::write_str(f, "InherentImplPick"),
Self::ObjectPick =>
::core::fmt::Formatter::write_str(f, "ObjectPick"),
Self::TraitPick { is_ambiguously_imported: __self_0 } =>
::core::fmt::Formatter::debug_struct_field1_finish(f,
"TraitPick", "is_ambiguously_imported", &__self_0),
Self::WhereClausePick(__self_0) =>
::core::fmt::Formatter::debug_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: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::TraitPick { is_ambiguously_imported: __self_0 },
Self::TraitPick { is_ambiguously_imported: __arg1_0 }) =>
__self_0 == __arg1_0,
(Self::WhereClausePick(__self_0),
Self::WhereClausePick(__arg1_0)) => __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl<'tcx> ::core::cmp::Eq for PickKind<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitRef<'tcx>>;
}
}Eq)]
247pub(crate) enum PickKind<'tcx> {
248 InherentImplPick,
249 ObjectPick,
250 TraitPick {
251 is_ambiguously_imported: bool,
252 },
253 WhereClausePick(
254 ty::PolyTraitRef<'tcx>,
256 ),
257}
258
259pub(crate) type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
260
261#[derive(#[automatically_derived]impl ::core::marker::StructuralPartialEq for Mode { }
#[automatically_derived]impl ::core::cmp::PartialEq for Mode {
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other)
}
}PartialEq, #[automatically_derived]impl ::core::cmp::Eq for Mode { }Eq, #[automatically_derived]impl ::core::marker::Copy for Mode { }Copy, #[automatically_derived]#[doc(hidden)]unsafe impl ::core::clone::TrivialClone
for Mode {
}
#[automatically_derived]impl ::core::clone::Clone for Mode {
#[inline]
fn clone(&self) -> Self { *self }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for Mode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Mode::MethodCall => "MethodCall",
Mode::Path => "Path",
})
}
}Debug)]
262pub(crate) enum Mode {
263 MethodCall,
267 Path,
271}
272
273#[derive(#[automatically_derived]impl<'tcx> ::core::marker::StructuralPartialEq for
ProbeScope<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::cmp::PartialEq for ProbeScope<'tcx>
{
#[inline]
fn eq(&self, other: &Self) -> bool {
::core::intrinsics::discriminant_value(self) ==
::core::intrinsics::discriminant_value(other) &&
match (self, other) {
(Self::Single(__self_0, __self_1),
Self::Single(__arg1_0, __arg1_1)) =>
__self_0 == __arg1_0 && __self_1 == __arg1_1,
_ => true,
}
}
}PartialEq, #[automatically_derived]impl<'tcx> ::core::cmp::Eq for ProbeScope<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
let _: ::core::cmp::AssertParamIsEq<Option<Ty<'tcx>>>;
}
}Eq, #[automatically_derived]impl<'tcx> ::core::fmt::Debug for ProbeScope<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
Self::Single(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f, "Single",
__self_0, &__self_1),
Self::TraitsInScope =>
::core::fmt::Formatter::write_str(f, "TraitsInScope"),
Self::AllTraits =>
::core::fmt::Formatter::write_str(f, "AllTraits"),
}
}
}Debug)]
274pub(crate) enum ProbeScope<'tcx> {
275 Single(DefId, Option<Ty<'tcx>> ),
277
278 TraitsInScope,
280
281 AllTraits,
283}
284
285impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
286 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_return_type_for_diagnostic",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(359u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("mode")
}> =
::tracing::__macro_support::FieldName::new("mode");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("item_name")
}> =
::tracing::__macro_support::FieldName::new("item_name");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return_type")
}> =
::tracing::__macro_support::FieldName::new("return_type");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("is_suggestion")
}> =
::tracing::__macro_support::FieldName::new("is_suggestion");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope_expr_id")
}> =
::tracing::__macro_support::FieldName::new("scope_expr_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("scope")
}> =
::tracing::__macro_support::FieldName::new("scope");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
self.probe_op(item_name.span, mode, Some(item_name), return_type,
is_suggestion, self_ty, scope_expr_id, scope,
|probe_cx|
{
Ok(probe_cx.inherent_candidates.into_iter().chain(probe_cx.extension_candidates).collect())
})
}
}
}#[instrument(level = "debug", skip(self))]
360 pub(crate) fn probe_for_name_many(
361 &self,
362 mode: Mode,
363 item_name: Ident,
364 return_type: Option<Ty<'tcx>>,
365 is_suggestion: IsSuggestion,
366 self_ty: Ty<'tcx>,
367 scope_expr_id: HirId,
368 scope: ProbeScope<'tcx>,
369 ) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
370 self.probe_op(
371 item_name.span,
372 mode,
373 Some(item_name),
374 return_type,
375 is_suggestion,
376 self_ty,
377 scope_expr_id,
378 scope,
379 |probe_cx| {
380 Ok(probe_cx
381 .inherent_candidates
382 .into_iter()
383 .chain(probe_cx.extension_candidates)
384 .collect())
385 },
386 )
387 }
388
389 pub(crate) fn probe_op<OP, R>(
390 &'a self,
391 span: Span,
392 mode: Mode,
393 method_name: Option<Ident>,
394 return_type: Option<Ty<'tcx>>,
395 is_suggestion: IsSuggestion,
396 self_ty: Ty<'tcx>,
397 scope_expr_id: HirId,
398 scope: ProbeScope<'tcx>,
399 op: OP,
400 ) -> Result<R, MethodError<'tcx>>
401 where
402 OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
403 {
404 #[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for MissingTypeAnnot {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
MissingTypeAnnot => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type annotations needed")));
;
diag
}
}
}
}
};Diagnostic)]
405 #[diag("type annotations needed")]
406 struct MissingTypeAnnot;
407
408 #[derive(const _: () =
{
impl<'_sess> rustc_errors::Diagnostic<'_sess> for
MethodCallOnDivergingInferenceVariable {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess> {
match self {
MethodCallOnDivergingInferenceVariable => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("method call on a diverging inference variable")));
diag.help(rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("consider providing a type annotation")));
;
diag
}
}
}
}
};Diagnostic)]
409 #[diag("method call on a diverging inference variable")]
410 #[help("consider providing a type annotation")]
411 struct MethodCallOnDivergingInferenceVariable;
412
413 let mut orig_values = OriginalQueryValues::default();
414 let predefined_opaques_in_body = if self.next_trait_solver() {
415 self.tcx.mk_predefined_opaques_in_body_from_iter(
416 self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
417 )
418 } else {
419 ty::List::empty()
420 };
421 let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
422 let query_input = self
423 .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
424
425 let steps = match mode {
426 Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
427 Mode::Path => self.probe(|_| {
428 let infcx = &self.infcx;
434 let (ParamEnvAnd { param_env: _, value }, var_values) =
435 infcx.instantiate_canonical(span, &query_input.canonical);
436 let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
437 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(437u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("query_input")
}> =
::tracing::__macro_support::FieldName::new("query_input");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("probe_op: Mode::Path")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&query_input)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
438 let prev_opaque_entries = self.inner.borrow_mut().opaque_types().num_entries();
439 MethodAutoderefStepsResult {
440 steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
441 self_ty: self.make_query_response_ignoring_pending_obligations(
442 var_values,
443 self_ty,
444 prev_opaque_entries,
445 ),
446 self_ty_is_opaque: false,
447 autoderefs: 0,
448 from_unsafe_deref: false,
449 unsize: false,
450 reachable_via_deref: true,
451 }]),
452 opt_bad_ty: None,
453 reached_recursion_limit: false,
454 }
455 }),
456 };
457
458 if steps.reached_recursion_limit && !is_suggestion.0 {
462 self.probe(|_| {
463 let ty = &steps
464 .steps
465 .last()
466 .unwrap_or_else(|| ::rustc_span::macros::bug_impl(Some(span),
format_args!("reached the recursion limit in 0 steps?"),
Location::caller())span_bug!(span, "reached the recursion limit in 0 steps?"))
467 .self_ty;
468 let ty = self
469 .probe_instantiate_query_response(span, &orig_values, ty)
470 .unwrap_or_else(|_| ::rustc_span::macros::bug_impl(Some(span),
format_args!("instantiating {0:?} failed?", ty), Location::caller())span_bug!(span, "instantiating {:?} failed?", ty));
471 autoderef::report_autoderef_recursion_limit_error(self.tcx, span, ty.value);
472 });
473 }
474
475 if let Some(bad_ty) = &steps.opt_bad_ty {
478 let ty = &bad_ty.ty;
482 let ty = self
483 .probe_instantiate_query_response(span, &orig_values, ty)
484 .unwrap_or_else(|_| ::rustc_span::macros::bug_impl(Some(span),
format_args!("instantiating {0:?} failed?", ty), Location::caller())span_bug!(span, "instantiating {:?} failed?", ty));
485 let ty = ty.value;
486
487 if is_suggestion.0 {
488 return Err(MethodError::NoMatch(NoMatchData {
491 static_candidates: Vec::new(),
492 unsatisfied_predicates: Vec::new(),
493 out_of_scope_traits: Vec::new(),
494 similar_candidate: None,
495 mode,
496 }));
497 } else if bad_ty.reached_raw_pointer
498 && !self.tcx.features().arbitrary_self_types_pointers()
499 && !self.tcx.sess.at_least_rust_2018()
500 {
501 self.tcx.emit_node_span_lint(
505 TYVAR_BEHIND_RAW_POINTER,
506 scope_expr_id,
507 span,
508 MissingTypeAnnot,
509 );
510 } else if let ty::Infer(ty::TyVar(ty_id)) = *ty.kind()
514 && let ty_id = self.sub_unification_table_root_var(ty_id)
515 && self
516 .diverging_type_vars
517 .borrow()
518 .iter()
519 .any(|&candidate_id| self.sub_unification_table_root_var(candidate_id) == ty_id)
520 {
521 self.tcx.emit_node_span_lint(
522 METHOD_CALL_ON_DIVERGING_INFER_VAR,
523 scope_expr_id,
524 span,
525 MethodCallOnDivergingInferenceVariable,
526 );
527 self.demand_eqtype(span, ty, self.tcx.types.never);
528 } else {
529 let guar = match *ty.kind() {
530 _ if let Some(guar) = self.tainted_by_errors() => guar,
531 ty::Infer(ty::TyVar(_)) => {
532 let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
535 (
536 Mode::MethodCall,
537 Node::Expr(hir::Expr {
538 kind: ExprKind::MethodCall(_, recv, ..),
539 ..
540 }),
541 ) => recv.span,
542 _ => span,
543 };
544
545 let raw_ptr_call = bad_ty.reached_raw_pointer
546 && !self.tcx.features().arbitrary_self_types();
547
548 let mut err = self.err_ctxt().emit_inference_failure_err(
549 self.body_def_id,
550 err_span,
551 ty.into(),
552 TypeAnnotationNeeded::E0282,
553 !raw_ptr_call,
554 );
555 if raw_ptr_call {
556 err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
557 }
558 err.emit_err()
559 }
560 ty::Error(guar) => guar,
561 _ => ::rustc_span::macros::bug_impl(None,
format_args!("unexpected bad final type in method autoderef"),
Location::caller())bug!("unexpected bad final type in method autoderef"),
562 };
563 self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
564 return Err(MethodError::ErrorReported(guar));
565 }
566 }
567
568 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:568",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(568u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ProbeContext: steps for self_ty={0:?} are {1:?}",
self_ty, steps) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("ProbeContext: steps for self_ty={:?} are {:?}", self_ty, steps);
569
570 self.probe(|_| {
573 let mut probe_cx = ProbeContext::new(
574 self,
575 span,
576 mode,
577 method_name,
578 return_type,
579 &orig_values,
580 steps.steps,
581 scope_expr_id,
582 is_suggestion,
583 );
584
585 match scope {
586 ProbeScope::TraitsInScope => {
587 probe_cx.assemble_inherent_candidates();
588 probe_cx.assemble_extension_candidates_for_traits_in_scope();
589 }
590 ProbeScope::AllTraits => {
591 probe_cx.assemble_inherent_candidates();
592 probe_cx.assemble_extension_candidates_for_all_traits();
593 }
594 ProbeScope::Single(def_id, self_ty_override) => {
595 let item = self.tcx.associated_item(def_id);
596 {
match item.container {
AssocContainer::Trait | AssocContainer::InherentImpl => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"AssocContainer::Trait | AssocContainer::InherentImpl",
::core::option::Option::None);
}
}
};assert_matches!(
597 item.container,
598 AssocContainer::Trait | AssocContainer::InherentImpl
599 );
600
601 let trait_def_id = self.tcx.parent(def_id);
602 let trait_span = self.tcx.def_span(trait_def_id);
603
604 let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
605 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
606
607 probe_cx.self_ty_override = self_ty_override;
608 probe_cx.push_candidate(
609 Candidate {
610 item,
611 kind: match item.container {
612 AssocContainer::Trait => CandidateKind::TraitCandidate {
613 trait_ref: ty::Binder::dummy(trait_ref),
614 is_ambiguously_imported: false,
615 },
616 AssocContainer::InherentImpl => {
617 CandidateKind::InherentImplCandidate {
618 impl_def_id: self.tcx.parent(def_id),
619 receiver_steps: 0,
620 }
621 }
622 _ => ::core::panicking::unreachable_default_msg()unreachable!(),
623 },
624 import_ids: &[],
625 },
626 false,
627 );
628 }
629 };
630 op(probe_cx)
631 })
632 }
633}
634
635pub(crate) fn method_autoderef_steps<'tcx>(
636 tcx: TyCtxt<'tcx>,
637 goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
638) -> MethodAutoderefStepsResult<'tcx> {
639 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:639",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(639u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps({0:?})",
goal) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("method_autoderef_steps({:?})", goal);
640
641 let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
642 let ParamEnvAnd {
643 param_env,
644 value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
645 } = goal;
646 for (key, ty) in predefined_opaques_in_body {
647 let prev = infcx
648 .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
649 if let Some(prev) = prev {
661 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:661",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(661u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("key")
}> =
::tracing::__macro_support::FieldName::new("key");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("ty")
}> =
::tracing::__macro_support::FieldName::new("ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("prev")
}> =
::tracing::__macro_support::FieldName::new("prev");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&key)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&prev)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
662 }
663 }
664 let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
665
666 let self_ty_is_opaque = |ty: Ty<'_>| {
670 if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
671 infcx.has_opaques_with_sub_unified_hidden_type(vid)
672 } else {
673 false
674 }
675 };
676
677 let mut autoderef_via_deref =
687 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
688 .include_raw_pointers()
689 .silence_errors();
690
691 let mut reached_raw_pointer = false;
692 let arbitrary_self_types_enabled =
693 tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
694 let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
695 let reachable_via_deref =
696 autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
697
698 let mut autoderef_via_receiver =
699 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
700 .include_raw_pointers()
701 .use_receiver_trait()
702 .silence_errors();
703 let steps = autoderef_via_receiver
704 .by_ref()
705 .zip(reachable_via_deref)
706 .map(|((ty, d), reachable_via_deref)| {
707 let step = CandidateStep {
708 self_ty: infcx.make_query_response_ignoring_pending_obligations(
709 inference_vars,
710 ty,
711 prev_opaque_entries,
712 ),
713 self_ty_is_opaque: self_ty_is_opaque(ty),
714 autoderefs: d,
715 from_unsafe_deref: reached_raw_pointer,
716 unsize: false,
717 reachable_via_deref,
718 };
719 if ty.is_raw_ptr() {
720 reached_raw_pointer = true;
722 }
723 step
724 })
725 .collect();
726 (steps, autoderef_via_receiver.reached_recursion_limit())
727 } else {
728 let steps = autoderef_via_deref
729 .by_ref()
730 .map(|(ty, d)| {
731 let step = CandidateStep {
732 self_ty: infcx.make_query_response_ignoring_pending_obligations(
733 inference_vars,
734 ty,
735 prev_opaque_entries,
736 ),
737 self_ty_is_opaque: self_ty_is_opaque(ty),
738 autoderefs: d,
739 from_unsafe_deref: reached_raw_pointer,
740 unsize: false,
741 reachable_via_deref: true,
742 };
743 if ty.is_raw_ptr() {
744 reached_raw_pointer = true;
746 }
747 step
748 })
749 .collect();
750 (steps, autoderef_via_deref.reached_recursion_limit())
751 };
752 let final_ty = autoderef_via_deref.final_ty();
753 let opt_bad_ty = match final_ty.kind() {
754 ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
755 reached_raw_pointer,
756 ty: infcx.make_query_response_ignoring_pending_obligations(
757 inference_vars,
758 final_ty,
759 prev_opaque_entries,
760 ),
761 }),
762 ty::Error(_) => Some(MethodAutoderefBadTy {
763 reached_raw_pointer,
764 ty: infcx.make_query_response_ignoring_pending_obligations(
765 inference_vars,
766 final_ty,
767 prev_opaque_entries,
768 ),
769 }),
770 ty::Array(elem_ty, _) => {
771 let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
772 steps.push(CandidateStep {
773 self_ty: infcx.make_query_response_ignoring_pending_obligations(
774 inference_vars,
775 Ty::new_slice(infcx.tcx, *elem_ty),
776 prev_opaque_entries,
777 ),
778 self_ty_is_opaque: false,
779 autoderefs,
780 from_unsafe_deref: reached_raw_pointer,
783 unsize: true,
784 reachable_via_deref: true, });
787
788 None
789 }
790 _ => None,
791 };
792
793 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:793",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(793u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps: steps={0:?} opt_bad_ty={1:?}",
steps, opt_bad_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("method_autoderef_steps: steps={:?} opt_bad_ty={:?}", steps, opt_bad_ty);
794 let _ = infcx.take_opaque_types();
796 MethodAutoderefStepsResult {
797 steps: tcx.arena.alloc_from_iter(steps),
798 opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
799 reached_recursion_limit,
800 }
801}
802
803impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
804 fn new(
805 fcx: &'a FnCtxt<'a, 'tcx>,
806 span: Span,
807 mode: Mode,
808 method_name: Option<Ident>,
809 return_type: Option<Ty<'tcx>>,
810 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
811 steps: &'tcx [CandidateStep<'tcx>],
812 scope_expr_id: HirId,
813 is_suggestion: IsSuggestion,
814 ) -> ProbeContext<'a, 'tcx> {
815 ProbeContext {
816 fcx,
817 span,
818 mode,
819 method_name,
820 return_type,
821 inherent_candidates: Vec::new(),
822 extension_candidates: Vec::new(),
823 impl_dups: FxHashSet::default(),
824 orig_steps_var_values,
825 steps,
826 allow_similar_names: false,
827 private_candidates: Vec::new(),
828 private_candidate: Cell::new(None),
829 static_candidates: RefCell::new(Vec::new()),
830 scope_expr_id,
831 is_suggestion,
832 self_ty_override: None,
833 }
834 }
835
836 fn reset(&mut self) {
837 self.inherent_candidates.clear();
838 self.extension_candidates.clear();
839 self.impl_dups.clear();
840 self.private_candidates.clear();
841 self.private_candidate.set(None);
842 self.static_candidates.borrow_mut().clear();
843 }
844
845 fn variance(&self) -> ty::Variance {
849 match self.mode {
850 Mode::MethodCall => ty::Covariant,
851 Mode::Path => ty::Invariant,
852 }
853 }
854
855 fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
859 let is_accessible = if let Some(name) = self.method_name {
860 let item = candidate.item;
861 let container_id = item.container_id(self.tcx);
862 let def_scope = self.tcx.adjust_ident_and_get_scope(name, container_id, self.mod_id).1;
863 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
864 } else {
865 true
866 };
867 if is_accessible {
868 if is_inherent {
869 self.inherent_candidates.push(candidate);
870 } else {
871 self.extension_candidates.push(candidate);
872 }
873 } else {
874 self.private_candidates.push(candidate);
875 }
876 }
877
878 fn assemble_inherent_candidates(&mut self) {
879 for step in self.steps.iter() {
880 self.assemble_probe(&step.self_ty, step.autoderefs);
881 }
882 }
883
884 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_probe",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(884u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("receiver_steps")
}> =
::tracing::__macro_support::FieldName::new("receiver_steps");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&receiver_steps as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let raw_self_ty = self_ty.value.value;
match *raw_self_ty.kind() {
ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
let (QueryResponse { value: generalized_self_ty, .. },
_ignored_var_values) =
self.fcx.instantiate_canonical(self.span, self_ty);
self.assemble_inherent_candidates_from_object(generalized_self_ty);
self.assemble_inherent_impl_candidates_for_type(p.def_id(),
receiver_steps);
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps);
}
ty::Adt(def, _) => {
let def_id = def.did();
self.assemble_inherent_impl_candidates_for_type(def_id,
receiver_steps);
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps);
}
ty::Foreign(did) => {
self.assemble_inherent_impl_candidates_for_type(did,
receiver_steps);
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps);
}
ty::Param(_) => {
self.assemble_inherent_candidates_from_param(raw_self_ty);
}
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_)
| ty::Str | ty::Array(..) | ty::Slice(_) | ty::RawPtr(_, _)
| ty::Ref(..) | ty::Never | ty::Tuple(..) => {
self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty,
receiver_steps)
}
ty::Alias(..) | ty::Bound(..) | ty::Closure(..) |
ty::Coroutine(..) | ty::CoroutineClosure(..) |
ty::CoroutineWitness(..) | ty::Dynamic(..) | ty::Error(..) |
ty::FnDef(..) | ty::FnPtr(..) | ty::Infer(..) | ty::Pat(..)
| ty::Placeholder(..) | ty::UnsafeBinder(..) => {}
}
}
}
}#[instrument(level = "debug", skip(self))]
885 fn assemble_probe(
886 &mut self,
887 self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
888 receiver_steps: usize,
889 ) {
890 let raw_self_ty = self_ty.value.value;
891 match *raw_self_ty.kind() {
892 ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
893 let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
911 self.fcx.instantiate_canonical(self.span, self_ty);
912
913 self.assemble_inherent_candidates_from_object(generalized_self_ty);
914 self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
915 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
916 }
917 ty::Adt(def, _) => {
918 let def_id = def.did();
919 self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
920 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
921 }
922 ty::Foreign(did) => {
923 self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
924 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
925 }
926 ty::Param(_) => {
927 self.assemble_inherent_candidates_from_param(raw_self_ty);
928 }
929 ty::Bool
930 | ty::Char
931 | ty::Int(_)
932 | ty::Uint(_)
933 | ty::Float(_)
934 | ty::Str
935 | ty::Array(..)
936 | ty::Slice(_)
937 | ty::RawPtr(_, _)
938 | ty::Ref(..)
939 | ty::Never
940 | ty::Tuple(..) => {
941 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
942 }
943 ty::Alias(..)
944 | ty::Bound(..)
945 | ty::Closure(..)
946 | ty::Coroutine(..)
947 | ty::CoroutineClosure(..)
948 | ty::CoroutineWitness(..)
949 | ty::Dynamic(..)
950 | ty::Error(..)
951 | ty::FnDef(..)
952 | ty::FnPtr(..)
953 | ty::Infer(..)
954 | ty::Pat(..)
955 | ty::Placeholder(..)
956 | ty::UnsafeBinder(..) => {}
957 }
958 }
959
960 fn assemble_inherent_candidates_for_incoherent_ty(
961 &mut self,
962 self_ty: Ty<'tcx>,
963 receiver_steps: usize,
964 ) {
965 let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
966 ::rustc_span::macros::bug_impl(None,
format_args!("unexpected incoherent type: {0:?}", self_ty),
Location::caller())bug!("unexpected incoherent type: {:?}", self_ty)
967 };
968 for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
969 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
970 }
971 }
972
973 fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
974 let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
975 for &impl_def_id in impl_def_ids {
976 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
977 }
978 }
979
980 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_impl_probe",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(980u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("impl_def_id")
}> =
::tracing::__macro_support::FieldName::new("impl_def_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("receiver_steps")
}> =
::tracing::__macro_support::FieldName::new("receiver_steps");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_def_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&receiver_steps as
&dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if !self.impl_dups.insert(impl_def_id) { return; }
for item in self.impl_or_trait_item(impl_def_id) {
if !self.has_applicable_self(&item) {
self.record_static_candidate(CandidateSource::Impl(impl_def_id));
continue;
}
self.push_candidate(Candidate {
item,
kind: InherentImplCandidate { impl_def_id, receiver_steps },
import_ids: &[],
}, true);
}
}
}
}#[instrument(level = "debug", skip(self))]
981 fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
982 if !self.impl_dups.insert(impl_def_id) {
983 return; }
985
986 for item in self.impl_or_trait_item(impl_def_id) {
987 if !self.has_applicable_self(&item) {
988 self.record_static_candidate(CandidateSource::Impl(impl_def_id));
990 continue;
991 }
992 self.push_candidate(
993 Candidate {
994 item,
995 kind: InherentImplCandidate { impl_def_id, receiver_steps },
996 import_ids: &[],
997 },
998 true,
999 );
1000 }
1001 }
1002
1003 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_candidates_from_object",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1003u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("self_ty")
}> =
::tracing::__macro_support::FieldName::new("self_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let principal =
match self_ty.kind() {
ty::Dynamic(data, ..) => Some(data),
_ => None,
}.and_then(|data|
data.principal()).unwrap_or_else(||
{
::rustc_span::macros::bug_impl(Some(self.span),
format_args!("non-object {0:?} in assemble_inherent_candidates_from_object",
self_ty), Location::caller())
});
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.assemble_candidates_for_bounds(traits::supertraits(self.tcx,
trait_ref),
|this, new_trait_ref, item|
{
this.push_candidate(Candidate {
item,
kind: ObjectCandidate(new_trait_ref),
import_ids: &[],
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
1004 fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
1005 let principal = match self_ty.kind() {
1006 ty::Dynamic(data, ..) => Some(data),
1007 _ => None,
1008 }
1009 .and_then(|data| data.principal())
1010 .unwrap_or_else(|| {
1011 span_bug!(
1012 self.span,
1013 "non-object {:?} in assemble_inherent_candidates_from_object",
1014 self_ty
1015 )
1016 });
1017
1018 let trait_ref = principal.with_self_ty(self.tcx, self_ty);
1025 self.assemble_candidates_for_bounds(
1026 traits::supertraits(self.tcx, trait_ref),
1027 |this, new_trait_ref, item| {
1028 this.push_candidate(
1029 Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
1030 true,
1031 );
1032 },
1033 );
1034 }
1035
1036 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_candidates_from_param",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1036u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("param_ty")
}> =
::tracing::__macro_support::FieldName::new("param_ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m_ty)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if true {
{
match param_ty.kind() {
ty::Param(_) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"ty::Param(_)", ::core::option::Option::None);
}
}
};
};
let tcx = self.tcx;
let bounds =
self.param_env.caller_bounds().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))]
1037 fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
1038 debug_assert_matches!(param_ty.kind(), ty::Param(_));
1039
1040 let tcx = self.tcx;
1041
1042 let bounds = self.param_env.caller_bounds().filter_map(|clause| {
1046 let bound_clause = clause.kind();
1047 match bound_clause.skip_binder() {
1048 ty::ClauseKind::Trait(trait_predicate) => DeepRejectCtxt::relate_rigid_rigid(tcx)
1049 .types_may_unify(param_ty, trait_predicate.trait_ref.self_ty())
1050 .then(|| bound_clause.rebind(trait_predicate.trait_ref)),
1051 ty::ClauseKind::RegionOutlives(_)
1052 | ty::ClauseKind::TypeOutlives(_)
1053 | ty::ClauseKind::Projection(_)
1054 | ty::ClauseKind::ConstArgHasType(_, _)
1055 | ty::ClauseKind::WellFormed(_)
1056 | ty::ClauseKind::ConstEvaluatable(_)
1057 | ty::ClauseKind::UnstableFeature(_)
1058 | ty::ClauseKind::HostEffect(..) => None,
1059 }
1060 });
1061
1062 self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1063 this.push_candidate(
1064 Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
1065 true,
1066 );
1067 });
1068 }
1069
1070 fn assemble_candidates_for_bounds<F>(
1073 &mut self,
1074 bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1075 mut mk_cand: F,
1076 ) where
1077 F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1078 {
1079 for bound_trait_ref in bounds {
1080 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1080",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1080u32),
::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);
1081 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1082 if !self.has_applicable_self(&item) {
1083 self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1084 } else {
1085 mk_cand(self, bound_trait_ref, item);
1086 }
1087 }
1088 }
1089 }
1090
1091 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1091u32),
::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))]
1092 fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1093 let mut duplicates = FxHashSet::default();
1094 let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1095 if let Some(applicable_traits) = opt_applicable_traits {
1096 for trait_candidate in applicable_traits.iter() {
1097 let trait_did = trait_candidate.def_id;
1098 if duplicates.insert((trait_did, trait_candidate.lint_ambiguous)) {
1101 self.assemble_extension_candidates_for_trait(
1102 &trait_candidate.import_ids,
1103 trait_did,
1104 trait_candidate.lint_ambiguous,
1105 );
1106 }
1107 }
1108 }
1109 }
1110
1111 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1111u32),
::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))]
1112 fn assemble_extension_candidates_for_all_traits(&mut self) {
1113 let mut duplicates = FxHashSet::default();
1114 for trait_info in suggest::all_traits(self.tcx) {
1115 if duplicates.insert(trait_info.def_id) {
1116 self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
1117 }
1118 }
1119 }
1120
1121 fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1122 match method.kind {
1123 ty::AssocKind::Fn { .. } => self.probe(|_| {
1124 let args = self.fresh_args_for_item(self.span, method.def_id);
1125 let fty =
1126 self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args).skip_norm_wip();
1127 let fty = self.instantiate_binder_with_fresh_vars(
1128 self.span,
1129 BoundRegionConversionTime::FnCall,
1130 fty,
1131 );
1132 self.can_eq(self.param_env, fty.output(), expected)
1133 }),
1134 _ => false,
1135 }
1136 }
1137
1138 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1138u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1183",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1183u32),
::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))]
1139 fn assemble_extension_candidates_for_trait(
1140 &mut self,
1141 import_ids: &'tcx [LocalDefId],
1142 trait_def_id: DefId,
1143 is_ambiguously_imported: bool,
1144 ) {
1145 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1146 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1147
1148 if self.tcx.is_trait_alias(trait_def_id) {
1149 for (bound_trait_pred, _) in
1151 traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1152 {
1153 assert_eq!(bound_trait_pred.polarity(), ty::ClausePolarity::Positive);
1154 let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1155 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1156 if !self.has_applicable_self(&item) {
1157 self.record_static_candidate(CandidateSource::Trait(
1158 bound_trait_ref.def_id(),
1159 ));
1160 } else {
1161 self.push_candidate(
1162 Candidate {
1163 item,
1164 import_ids,
1165 kind: TraitCandidate {
1166 trait_ref: bound_trait_ref,
1167 is_ambiguously_imported,
1168 },
1169 },
1170 false,
1171 );
1172 }
1173 }
1174 }
1175 } else {
1176 debug_assert!(self.tcx.is_trait(trait_def_id));
1177 if self.tcx.trait_is_auto(trait_def_id) {
1178 return;
1179 }
1180 for item in self.impl_or_trait_item(trait_def_id) {
1181 if !self.has_applicable_self(&item) {
1183 debug!("method has inapplicable self");
1184 self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1185 continue;
1186 }
1187 self.push_candidate(
1188 Candidate {
1189 item,
1190 import_ids,
1191 kind: TraitCandidate {
1192 trait_ref: ty::Binder::dummy(trait_ref),
1193 is_ambiguously_imported,
1194 },
1195 },
1196 false,
1197 );
1198 }
1199 }
1200 }
1201
1202 fn candidate_method_names(
1203 &self,
1204 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1205 ) -> Vec<Ident> {
1206 let mut set = FxHashSet::default();
1207 let mut names: Vec<_> = self
1208 .inherent_candidates
1209 .iter()
1210 .chain(&self.extension_candidates)
1211 .filter(|candidate| candidate_filter(&candidate.item))
1212 .filter(|candidate| {
1213 if let Some(return_ty) = self.return_type {
1214 self.matches_return_type(candidate.item, return_ty)
1215 } else {
1216 true
1217 }
1218 })
1219 .filter(|candidate| {
1221 !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
None, DUMMY_SP, None) {
stability::EvalResult::Deny { .. } => true,
_ => false,
}matches!(
1224 self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1225 stability::EvalResult::Deny { .. }
1226 )
1227 })
1228 .map(|candidate| candidate.item.ident(self.tcx))
1229 .filter(|&name| set.insert(name))
1230 .collect();
1231
1232 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1234 names
1235 }
1236
1237 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1240u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1262",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1262u32),
::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))]
1241 fn pick(mut self) -> PickResult<'tcx> {
1242 assert!(self.method_name.is_some());
1243
1244 let mut unsatisfied_predicates = Vec::new();
1245
1246 if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1247 return r;
1248 }
1249
1250 if self.is_suggestion.0 {
1253 return Err(MethodError::NoMatch(NoMatchData {
1254 static_candidates: vec![],
1255 unsatisfied_predicates: vec![],
1256 out_of_scope_traits: vec![],
1257 similar_candidate: None,
1258 mode: self.mode,
1259 }));
1260 }
1261
1262 debug!("pick: actual search failed, assemble diagnostics");
1263
1264 let static_candidates = std::mem::take(self.static_candidates.get_mut());
1265 let private_candidate = self.private_candidate.take();
1266
1267 self.reset();
1269
1270 self.assemble_extension_candidates_for_all_traits();
1271
1272 let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1273 Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1274 Some(Err(MethodError::Ambiguity(v))) => v
1275 .into_iter()
1276 .map(|source| match source {
1277 CandidateSource::Trait(id) => id,
1278 CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1279 })
1280 .collect(),
1281 Some(Err(MethodError::NoMatch(NoMatchData {
1282 out_of_scope_traits: others, ..
1283 }))) => {
1284 assert!(others.is_empty());
1285 vec![]
1286 }
1287 _ => vec![],
1288 };
1289
1290 if let Some((kind, def_id)) = private_candidate {
1291 return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1292 }
1293 let similar_candidate = self.probe_for_similar_candidate()?;
1294
1295 Err(MethodError::NoMatch(NoMatchData {
1296 static_candidates,
1297 unsatisfied_predicates,
1298 out_of_scope_traits,
1299 similar_candidate,
1300 mode: self.mode,
1301 }))
1302 }
1303
1304 fn pick_core(
1305 &self,
1306 unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1307 ) -> Option<PickResult<'tcx>> {
1308 self.pick_all_method(&mut PickDiagHints {
1310 unstable_candidates: Some(Vec::new()),
1313 unsatisfied_predicates,
1316 })
1317 .or_else(|| {
1318 self.pick_all_method(&mut PickDiagHints {
1319 unstable_candidates: None,
1324 unsatisfied_predicates: &mut Vec::new(),
1327 })
1328 })
1329 }
1330
1331 fn pick_all_method<'b>(
1332 &self,
1333 pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1334 ) -> Option<PickResult<'tcx>> {
1335 let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1336 self.steps
1337 .iter()
1338 .filter(|step| step.reachable_via_deref)
1342 .filter(|step| {
1343 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1343",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1343u32),
::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);
1344 !step.self_ty.value.references_error() && !step.from_unsafe_deref
1347 })
1348 .find_map(|step| {
1349 let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1350 .fcx
1351 .probe_instantiate_query_response(
1352 self.span,
1353 self.orig_steps_var_values,
1354 &step.self_ty,
1355 )
1356 .unwrap_or_else(|_| {
1357 ::rustc_span::macros::bug_impl(Some(self.span),
format_args!("{0:?} was applicable but now isn\'t?", step.self_ty),
Location::caller())span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
1358 });
1359
1360 let by_value_pick = self.pick_by_value_method(
1361 step,
1362 self_ty,
1363 &instantiate_self_ty_obligations,
1364 pick_diag_hints,
1365 );
1366
1367 if let Some(by_value_pick) = by_value_pick {
1369 if let Ok(by_value_pick) = by_value_pick.as_ref() {
1370 if by_value_pick.kind == PickKind::InherentImplPick {
1371 for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1372 if let Err(e) = self.check_for_shadowed_autorefd_method(
1373 by_value_pick,
1374 step,
1375 self_ty,
1376 &instantiate_self_ty_obligations,
1377 mutbl,
1378 track_unstable_candidates,
1379 ) {
1380 return Some(Err(e));
1381 }
1382 }
1383 }
1384 }
1385 return Some(by_value_pick);
1386 }
1387
1388 let autoref_pick = self.pick_autorefd_method(
1389 step,
1390 self_ty,
1391 &instantiate_self_ty_obligations,
1392 hir::Mutability::Not,
1393 pick_diag_hints,
1394 None,
1395 );
1396 if let Some(autoref_pick) = autoref_pick {
1398 if let Ok(autoref_pick) = autoref_pick.as_ref() {
1399 if autoref_pick.kind == PickKind::InherentImplPick {
1401 if let Err(e) = self.check_for_shadowed_autorefd_method(
1402 autoref_pick,
1403 step,
1404 self_ty,
1405 &instantiate_self_ty_obligations,
1406 hir::Mutability::Mut,
1407 track_unstable_candidates,
1408 ) {
1409 return Some(Err(e));
1410 }
1411 }
1412 }
1413 return Some(autoref_pick);
1414 }
1415
1416 self.pick_autorefd_method(
1440 step,
1441 self_ty,
1442 &instantiate_self_ty_obligations,
1443 hir::Mutability::Mut,
1444 pick_diag_hints,
1445 None,
1446 )
1447 .or_else(|| {
1448 self.pick_const_ptr_method(
1449 step,
1450 self_ty,
1451 &instantiate_self_ty_obligations,
1452 pick_diag_hints,
1453 )
1454 })
1455 .or_else(|| {
1456 self.pick_reborrow_pin_method(
1457 step,
1458 self_ty,
1459 &instantiate_self_ty_obligations,
1460 pick_diag_hints,
1461 )
1462 })
1463 })
1464 }
1465
1466 fn check_for_shadowed_autorefd_method(
1482 &self,
1483 possible_shadower: &Pick<'tcx>,
1484 step: &CandidateStep<'tcx>,
1485 self_ty: Ty<'tcx>,
1486 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1487 mutbl: hir::Mutability,
1488 track_unstable_candidates: bool,
1489 ) -> Result<(), MethodError<'tcx>> {
1490 if !self.tcx.features().arbitrary_self_types()
1494 && !self.tcx.features().arbitrary_self_types_pointers()
1495 {
1496 return Ok(());
1497 }
1498
1499 let mut pick_diag_hints = PickDiagHints {
1504 unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1505 unsatisfied_predicates: &mut Vec::new(),
1506 };
1507 let pick_constraints = PickConstraintsForShadowed {
1509 autoderefs: possible_shadower.autoderefs,
1511 receiver_steps: possible_shadower.receiver_steps,
1515 def_id: possible_shadower.item.def_id,
1518 };
1519 let potentially_shadowed_pick = self.pick_autorefd_method(
1549 step,
1550 self_ty,
1551 instantiate_self_ty_obligations,
1552 mutbl,
1553 &mut pick_diag_hints,
1554 Some(&pick_constraints),
1555 );
1556 if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1559 let sources = [possible_shadower, possible_shadowed]
1560 .into_iter()
1561 .map(|p| self.candidate_source_from_pick(p))
1562 .collect();
1563 return Err(MethodError::Ambiguity(sources));
1564 }
1565 Ok(())
1566 }
1567
1568 fn pick_by_value_method(
1575 &self,
1576 step: &CandidateStep<'tcx>,
1577 self_ty: Ty<'tcx>,
1578 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1579 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1580 ) -> Option<PickResult<'tcx>> {
1581 if step.unsize {
1582 return None;
1583 }
1584
1585 self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1586 r.map(|mut pick| {
1587 pick.autoderefs = step.autoderefs;
1588
1589 match *step.self_ty.value.value.kind() {
1590 ty::Ref(_, _, mutbl) => {
1592 pick.autoderefs += 1;
1593 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1594 mutbl,
1595 unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1596 })
1597 }
1598
1599 ty::Adt(def, args)
1600 if self.tcx.features().pin_ergonomics()
1601 && self.tcx.is_lang_item(def.did(), LangItem::Pin) =>
1602 {
1603 if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1605 pick.autoref_or_ptr_adjustment =
1606 Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1607 }
1608 }
1609
1610 _ => (),
1611 }
1612
1613 pick
1614 })
1615 })
1616 }
1617
1618 fn pick_autorefd_method(
1619 &self,
1620 step: &CandidateStep<'tcx>,
1621 self_ty: Ty<'tcx>,
1622 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1623 mutbl: hir::Mutability,
1624 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1625 pick_constraints: Option<&PickConstraintsForShadowed>,
1626 ) -> Option<PickResult<'tcx>> {
1627 let tcx = self.tcx;
1628
1629 if let Some(pick_constraints) = pick_constraints {
1630 if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1631 return None;
1632 }
1633 }
1634
1635 let region = tcx.lifetimes.re_erased;
1637
1638 let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1639 self.pick_method(
1640 autoref_ty,
1641 instantiate_self_ty_obligations,
1642 pick_diag_hints,
1643 pick_constraints,
1644 )
1645 .map(|r| {
1646 r.map(|mut pick| {
1647 pick.autoderefs = step.autoderefs;
1648 pick.autoref_or_ptr_adjustment =
1649 Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1650 pick
1651 })
1652 })
1653 }
1654
1655 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1656u32),
::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))]
1657 fn pick_reborrow_pin_method(
1658 &self,
1659 step: &CandidateStep<'tcx>,
1660 self_ty: Ty<'tcx>,
1661 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1662 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1663 ) -> Option<PickResult<'tcx>> {
1664 if !self.tcx.features().pin_ergonomics() {
1665 return None;
1666 }
1667
1668 let inner_ty = match self_ty.kind() {
1670 ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), LangItem::Pin) => {
1671 match args[0].expect_ty().kind() {
1672 ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1673 _ => {
1674 return None;
1675 }
1676 }
1677 }
1678 _ => return None,
1679 };
1680
1681 let region = self.tcx.lifetimes.re_erased;
1682 let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1683 self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1684 |r| {
1685 r.map(|mut pick| {
1686 pick.autoderefs = step.autoderefs;
1687 pick.autoref_or_ptr_adjustment =
1688 Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1689 pick
1690 })
1691 },
1692 )
1693 }
1694
1695 fn pick_const_ptr_method(
1699 &self,
1700 step: &CandidateStep<'tcx>,
1701 self_ty: Ty<'tcx>,
1702 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1703 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1704 ) -> Option<PickResult<'tcx>> {
1705 if step.unsize {
1707 return None;
1708 }
1709
1710 let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1711 return None;
1712 };
1713
1714 let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1715 self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1716 |r| {
1717 r.map(|mut pick| {
1718 pick.autoderefs = step.autoderefs;
1719 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1720 pick
1721 })
1722 },
1723 )
1724 }
1725
1726 fn pick_method(
1727 &self,
1728 self_ty: Ty<'tcx>,
1729 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1730 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1731 pick_constraints: Option<&PickConstraintsForShadowed>,
1732 ) -> Option<PickResult<'tcx>> {
1733 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1733",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1733u32),
::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));
1734
1735 for (kind, candidates) in
1736 [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1737 {
1738 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1738",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1738u32),
::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);
1739 let res = self.consider_candidates(
1740 self_ty,
1741 instantiate_self_ty_obligations,
1742 candidates,
1743 pick_diag_hints,
1744 pick_constraints,
1745 );
1746 if let Some(pick) = res {
1747 return Some(pick);
1748 }
1749 }
1750
1751 if self.private_candidate.get().is_none() {
1752 if let Some(Ok(pick)) = self.consider_candidates(
1753 self_ty,
1754 instantiate_self_ty_obligations,
1755 &self.private_candidates,
1756 &mut PickDiagHints {
1757 unstable_candidates: None,
1758 unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1759 },
1760 None,
1761 ) {
1762 self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1763 }
1764 }
1765 None
1766 }
1767
1768 fn consider_candidates(
1769 &self,
1770 self_ty: Ty<'tcx>,
1771 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1772 candidates: &[Candidate<'tcx>],
1773 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1774 pick_constraints: Option<&PickConstraintsForShadowed>,
1775 ) -> Option<PickResult<'tcx>> {
1776 let mut applicable_candidates: Vec<_> = candidates
1777 .iter()
1778 .filter(|candidate| {
1779 pick_constraints
1780 .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1781 .unwrap_or(true)
1782 })
1783 .map(|probe| {
1784 (
1785 probe,
1786 self.consider_probe(
1787 self_ty,
1788 instantiate_self_ty_obligations,
1789 probe,
1790 &mut pick_diag_hints.unsatisfied_predicates,
1791 ),
1792 )
1793 })
1794 .filter(|&(_, status)| status != ProbeResult::NoMatch)
1795 .collect();
1796
1797 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:1797",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1797u32),
::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);
1798
1799 if applicable_candidates.len() > 1 {
1800 if let Some(pick) =
1801 self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1802 {
1803 return Some(Ok(pick));
1804 }
1805 }
1806
1807 if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1808 applicable_candidates.retain(|&(candidate, _)| {
1809 if let stability::EvalResult::Deny { feature, .. } =
1810 self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1811 {
1812 uc.push((candidate.clone(), feature));
1813 return false;
1814 }
1815 true
1816 });
1817 }
1818
1819 if applicable_candidates.len() > 1 {
1820 if self.tcx.features().supertrait_item_shadowing() {
1824 if let Some(pick) =
1825 self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1826 {
1827 return Some(Ok(pick));
1828 }
1829 }
1830
1831 let sources =
1832 applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1833 return Some(Err(MethodError::Ambiguity(sources)));
1834 }
1835
1836 applicable_candidates.pop().map(|(probe, status)| match status {
1837 ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1838 self_ty,
1839 pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1840 )),
1841 ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1842 })
1843 }
1844}
1845
1846impl<'tcx> Pick<'tcx> {
1847 pub(crate) fn differs_from(&self, other: &Self) -> bool {
1852 let Self {
1853 item: AssocItem { def_id, kind: _, container: _ },
1854 kind: _,
1855 import_ids: _,
1856 autoderefs: _,
1857 autoref_or_ptr_adjustment: _,
1858 self_ty,
1859 unstable_candidates: _,
1860 receiver_steps: _,
1861 shadowed_candidates: _,
1862 } = *self;
1863 self_ty != other.self_ty || def_id != other.item.def_id
1864 }
1865
1866 pub(crate) fn maybe_emit_unstable_name_collision_hint(
1868 &self,
1869 tcx: TyCtxt<'tcx>,
1870 span: Span,
1871 scope_expr_id: HirId,
1872 ) {
1873 struct ItemMaybeBeAddedToStd<'a, 'tcx> {
1874 this: &'a Pick<'tcx>,
1875 tcx: TyCtxt<'tcx>,
1876 span: Span,
1877 }
1878
1879 impl<'a, 'b, 'tcx> Diagnostic<'a> for ItemMaybeBeAddedToStd<'b, 'tcx> {
1880 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a> {
1881 let Self { this, tcx, span } = self;
1882 let def_kind = this.item.as_def_kind();
1883 let mut lint = Diag::new(
1884 dcx,
1885 level,
1886 ::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!(
1887 "{} {} with this name may be added to the standard library in the future",
1888 tcx.def_kind_descr_article(def_kind, this.item.def_id),
1889 tcx.def_kind_descr(def_kind, this.item.def_id),
1890 ),
1891 );
1892
1893 match (this.item.kind, this.item.container) {
1894 (ty::AssocKind::Fn { .. }, _) => {
1895 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!(
1900 "call with fully qualified syntax `{}(...)` to keep using the current \
1901 method",
1902 tcx.def_path_str(this.item.def_id),
1903 ));
1904 }
1905 (ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
1906 let def_id = this.item.container_id(tcx);
1907 lint.span_suggestion(
1908 span,
1909 "use the fully qualified path to the associated const",
1910 ::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),
1911 Applicability::MachineApplicable,
1912 );
1913 }
1914 _ => {}
1915 }
1916 tcx.disabled_nightly_features(
1917 &mut lint,
1918 this.unstable_candidates.iter().map(|(candidate, feature)| {
1919 (::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)
1920 }),
1921 );
1922 lint
1923 }
1924 }
1925
1926 if self.unstable_candidates.is_empty() {
1927 return;
1928 }
1929 tcx.emit_node_span_lint(
1930 UNSTABLE_NAME_COLLISIONS,
1931 scope_expr_id,
1932 span,
1933 ItemMaybeBeAddedToStd { this: self, tcx, span },
1934 );
1935 }
1936}
1937
1938impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1939 fn select_trait_candidate_for_diagnostics(
1940 &self,
1941 trait_ref: ty::TraitRef<'tcx>,
1942 ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1943 let obligation =
1944 traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1945 let candidate = traits::SelectionContext::new(self).select(&obligation);
1946 if let Ok(Some(traits::ImplSource::UserDefined(impl_source_user_defined_data))) = &candidate
1947 && self.infcx.tcx.do_not_recommend_impl(impl_source_user_defined_data.impl_def_id)
1948 {
1949 return Err(traits::SelectionError::Unimplemented);
1950 }
1951 candidate
1952 }
1953
1954 fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1957 match candidate.kind {
1958 InherentImplCandidate { .. } => {
1959 CandidateSource::Impl(candidate.item.container_id(self.tcx))
1960 }
1961 ObjectCandidate(_) | WhereClauseCandidate(_) => {
1962 CandidateSource::Trait(candidate.item.container_id(self.tcx))
1963 }
1964 TraitCandidate { trait_ref, is_ambiguously_imported: _ } => self.probe(|_| {
1965 let trait_ref = self.instantiate_binder_with_fresh_vars(
1966 self.span,
1967 BoundRegionConversionTime::FnCall,
1968 trait_ref,
1969 );
1970 let (xform_self_ty, _) =
1971 self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1972 let _ = self.sup_raw(
1975 &ObligationCause::dummy(),
1976 self.param_env,
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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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 ambiguous_candidate = probes.iter().find_map(|(p, _)| match p.kind {
2389 TraitCandidate { is_ambiguously_imported: true, .. } => Some(p),
2390 _ => None,
2391 });
2392
2393 let (is_ambiguously_imported, candidate) =
2395 ambiguous_candidate.map(|c| (true, *c)).unwrap_or_else(|| (false, probes[0].0));
2396
2397 Some(Pick {
2400 item: candidate.item,
2401 kind: TraitPick { is_ambiguously_imported },
2402 import_ids: candidate.import_ids,
2403 autoderefs: 0,
2404 autoref_or_ptr_adjustment: None,
2405 self_ty,
2406 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2407 receiver_steps: None,
2408 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2409 })
2410 }
2411
2412 fn collapse_candidates_to_subtrait_pick(
2422 &self,
2423 self_ty: Ty<'tcx>,
2424 probes: &[(&Candidate<'tcx>, ProbeResult)],
2425 ) -> Option<Pick<'tcx>> {
2426 let mut child_candidate = probes[0].0;
2427 let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2428 let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2429
2430 let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2431 while !remaining_candidates.is_empty() {
2432 let mut made_progress = false;
2433 let mut next_round = ::alloc::vec::Vec::new()vec![];
2434
2435 for remaining_candidate in remaining_candidates {
2436 let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2437 if supertraits.contains(&remaining_trait) {
2438 made_progress = true;
2439 continue;
2440 }
2441
2442 let remaining_trait_supertraits: SsoHashSet<_> =
2448 supertrait_def_ids(self.tcx, remaining_trait).collect();
2449 if remaining_trait_supertraits.contains(&child_trait) {
2450 child_candidate = remaining_candidate;
2451 child_trait = remaining_trait;
2452 supertraits = remaining_trait_supertraits;
2453 made_progress = true;
2454 continue;
2455 }
2456
2457 next_round.push(remaining_candidate);
2464 }
2465
2466 if made_progress {
2467 remaining_candidates = next_round;
2469 } else {
2470 return None;
2473 }
2474 }
2475
2476 let is_ambiguously_imported = match child_candidate.kind {
2477 TraitCandidate { is_ambiguously_imported, .. } => is_ambiguously_imported,
2478 _ => false,
2479 };
2480
2481 Some(Pick {
2482 item: child_candidate.item,
2483 kind: TraitPick { is_ambiguously_imported },
2484 import_ids: child_candidate.import_ids,
2485 autoderefs: 0,
2486 autoref_or_ptr_adjustment: None,
2487 self_ty,
2488 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2489 shadowed_candidates: probes
2490 .iter()
2491 .map(|(c, _)| c.item)
2492 .filter(|item| item.def_id != child_candidate.item.def_id)
2493 .collect(),
2494 receiver_steps: None,
2495 })
2496 }
2497
2498 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/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(&[],
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:2505",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2505u32),
::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))]
2502 pub(crate) fn probe_for_similar_candidate(
2503 &mut self,
2504 ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2505 debug!("probing for method names similar to {:?}", self.method_name);
2506
2507 self.probe(|_| {
2508 let mut pcx = ProbeContext::new(
2509 self.fcx,
2510 self.span,
2511 self.mode,
2512 self.method_name,
2513 self.return_type,
2514 self.orig_steps_var_values,
2515 self.steps,
2516 self.scope_expr_id,
2517 IsSuggestion(true),
2518 );
2519 pcx.allow_similar_names = true;
2520 pcx.assemble_inherent_candidates();
2521 pcx.assemble_extension_candidates_for_all_traits();
2522
2523 let method_names = pcx.candidate_method_names(|_| true);
2524 pcx.allow_similar_names = false;
2525 let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2526 .iter()
2527 .filter_map(|&method_name| {
2528 pcx.reset();
2529 pcx.method_name = Some(method_name);
2530 pcx.assemble_inherent_candidates();
2531 pcx.assemble_extension_candidates_for_all_traits();
2532 pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2533 })
2534 .collect();
2535
2536 if applicable_close_candidates.is_empty() {
2537 Ok(None)
2538 } else {
2539 let best_name = applicable_close_candidates
2540 .iter()
2541 .find(|cand| self.matches_by_doc_alias(cand.def_id))
2542 .map(|cand| cand.name())
2543 .or_else(|| {
2544 let names = applicable_close_candidates
2545 .iter()
2546 .map(|cand| cand.name())
2547 .collect::<Vec<Symbol>>();
2548 find_best_match_for_name_with_substrings(
2549 &names,
2550 self.method_name.unwrap().name,
2551 None,
2552 )
2553 });
2554 Ok(best_name.and_then(|best_name| {
2555 applicable_close_candidates
2556 .into_iter()
2557 .find(|method| method.name() == best_name)
2558 }))
2559 }
2560 })
2561 }
2562
2563 fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2566 match self.mode {
2572 Mode::MethodCall => item.is_method(),
2573 Mode::Path => match item.kind {
2574 ty::AssocKind::Type { .. } => false,
2575 ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2576 },
2577 }
2578 }
2585
2586 fn record_static_candidate(&self, source: CandidateSource) {
2587 self.static_candidates.borrow_mut().push(source);
2588 }
2589
2590 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2590u32),
::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))]
2591 fn xform_self_ty(
2592 &self,
2593 item: ty::AssocItem,
2594 impl_ty: Ty<'tcx>,
2595 args: GenericArgsRef<'tcx>,
2596 ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2597 if item.is_fn() && self.mode == Mode::MethodCall {
2598 let sig = self.xform_method_sig(item.def_id, args);
2599 (self.self_ty_override.unwrap_or(sig.inputs()[0]), Some(sig.output()))
2600 } else {
2601 (impl_ty, None)
2602 }
2603 }
2604
2605 {}
#[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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2605u32),
::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/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs:2608",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/76456a688bc0ed897fa23a677d4ddb5b3fdb575a/compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2608u32),
::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))]
2606 fn xform_method_sig(&self, method: DefId, args: GenericArgsRef<'tcx>) -> ty::FnSig<'tcx> {
2607 let fn_sig = self.tcx.fn_sig(method);
2608 debug!(?fn_sig);
2609
2610 assert!(!args.has_escaping_bound_vars());
2611
2612 let generics = self.tcx.generics_of(method);
2618 assert_eq!(args.len(), generics.parent_count);
2619
2620 let xform_fn_sig = if generics.is_own_empty() {
2621 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2622 } else {
2623 let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2624 let i = param.index as usize;
2625 if i < args.len() {
2626 args[i]
2627 } else {
2628 match param.kind {
2629 GenericParamDefKind::Lifetime => {
2630 self.tcx.lifetimes.re_erased.into()
2632 }
2633 GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2634 self.var_for_def(self.span, param)
2635 }
2636 }
2637 }
2638 });
2639 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2640 };
2641
2642 self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2643 }
2644
2645 fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2647 match (self.mode, kind) {
2648 (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2649 (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2650 _ => false,
2651 }
2652 }
2653
2654 fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2657 let Some(method) = self.method_name else {
2658 return false;
2659 };
2660
2661 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)
2662 && d.aliases.contains_key(&method.name)
2663 {
2664 return true;
2665 }
2666
2667 if let Some(confusables) =
2668 {
{
'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)
2669 && confusables.contains(&method.name)
2670 {
2671 return true;
2672 }
2673
2674 false
2675 }
2676
2677 fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2682 if let Some(name) = self.method_name {
2683 if self.allow_similar_names {
2684 let max_dist = max(name.as_str().len(), 3) / 3;
2685 self.tcx
2686 .associated_items(def_id)
2687 .in_definition_order()
2688 .filter(|x| {
2689 if !self.is_relevant_kind_for_mode(x.kind) {
2690 return false;
2691 }
2692 if let Some(d) = edit_distance_with_substrings(
2693 name.as_str(),
2694 x.name().as_str(),
2695 max_dist,
2696 ) {
2697 return d > 0;
2698 }
2699 self.matches_by_doc_alias(x.def_id)
2700 })
2701 .copied()
2702 .collect()
2703 } else {
2704 self.fcx
2705 .associated_value(def_id, name)
2706 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2707 .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2708 }
2709 } else {
2710 self.tcx
2711 .associated_items(def_id)
2712 .in_definition_order()
2713 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2714 .copied()
2715 .collect()
2716 }
2717 }
2718}
2719
2720impl<'tcx> Candidate<'tcx> {
2721 fn to_unadjusted_pick(
2722 &self,
2723 self_ty: Ty<'tcx>,
2724 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2725 ) -> Pick<'tcx> {
2726 Pick {
2727 item: self.item,
2728 kind: match self.kind {
2729 InherentImplCandidate { .. } => InherentImplPick,
2730 ObjectCandidate(_) => ObjectPick,
2731 TraitCandidate { is_ambiguously_imported, .. } => {
2732 TraitPick { is_ambiguously_imported }
2733 }
2734 WhereClauseCandidate(trait_ref) => {
2735 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!(
2741 !trait_ref.skip_binder().args.has_infer()
2742 && !trait_ref.skip_binder().args.has_placeholders()
2743 );
2744
2745 WhereClausePick(trait_ref)
2746 }
2747 },
2748 import_ids: self.import_ids,
2749 autoderefs: 0,
2750 autoref_or_ptr_adjustment: None,
2751 self_ty,
2752 unstable_candidates,
2753 receiver_steps: match self.kind {
2754 InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2755 _ => None,
2756 },
2757 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2758 }
2759 }
2760}