1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::debug_assert_matches;
4use std::ops::Deref;
5
6use rustc_data_structures::fx::FxHashSet;
7use rustc_data_structures::sso::SsoHashSet;
8use rustc_errors::{Applicability, Diag, DiagCtxtHandle, Diagnostic, Level};
9use rustc_hir::def::DefKind;
10use rustc_hir::{self as hir, ExprKind, HirId, Node, find_attr};
11use rustc_hir_analysis::autoderef::{self, Autoderef};
12use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryResponse};
13use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
14use rustc_infer::traits::{ObligationCauseCode, PredicateObligation, query};
15use rustc_macros::Diagnostic;
16use rustc_middle::middle::stability;
17use rustc_middle::ty::elaborate::supertrait_def_ids;
18use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
19use rustc_middle::ty::{
20 self, AssocContainer, AssocItem, GenericArgs, GenericArgsRef, GenericParamDefKind, ParamEnvAnd,
21 Ty, TyCtxt, TypeVisitableExt, Unnormalized, Upcast,
22};
23use rustc_middle::{bug, span_bug};
24use rustc_session::lint;
25use rustc_span::def_id::{DefId, LocalDefId};
26use rustc_span::edit_distance::{
27 edit_distance_with_substrings, find_best_match_for_name_with_substrings,
28};
29use rustc_span::{DUMMY_SP, Ident, Span, Symbol};
30use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
31use rustc_trait_selection::infer::InferCtxtExt as _;
32use rustc_trait_selection::solve::Goal;
33use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
34use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
35use rustc_trait_selection::traits::query::method_autoderef::{
36 CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
37};
38use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
39use smallvec::SmallVec;
40use tracing::{debug, instrument};
41
42use self::CandidateKind::*;
43pub(crate) use self::PickKind::*;
44use super::{CandidateSource, MethodError, NoMatchData, suggest};
45use crate::FnCtxt;
46
47#[derive(#[automatically_derived]
impl ::core::clone::Clone for IsSuggestion {
#[inline]
fn clone(&self) -> IsSuggestion {
let _: ::core::clone::AssertParamIsClone<bool>;
*self
}
}Clone, #[automatically_derived]
impl ::core::marker::Copy for IsSuggestion { }Copy, #[automatically_derived]
impl ::core::fmt::Debug for IsSuggestion {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_tuple_field1_finish(f, "IsSuggestion",
&&self.0)
}
}Debug)]
50pub(crate) struct IsSuggestion(pub bool);
51
52pub(crate) struct ProbeContext<'a, 'tcx> {
53 fcx: &'a FnCtxt<'a, 'tcx>,
54 span: Span,
55 mode: Mode,
56 method_name: Option<Ident>,
57 return_type: Option<Ty<'tcx>>,
58
59 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
62 steps: &'tcx [CandidateStep<'tcx>],
63
64 inherent_candidates: Vec<Candidate<'tcx>>,
65 extension_candidates: Vec<Candidate<'tcx>>,
66 impl_dups: FxHashSet<DefId>,
67
68 allow_similar_names: bool,
71
72 private_candidates: Vec<Candidate<'tcx>>,
75
76 private_candidate: Cell<Option<(DefKind, DefId)>>,
78
79 static_candidates: RefCell<Vec<CandidateSource>>,
82
83 scope_expr_id: HirId,
84
85 is_suggestion: IsSuggestion,
89}
90
91impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
92 type Target = FnCtxt<'a, 'tcx>;
93 fn deref(&self) -> &Self::Target {
94 self.fcx
95 }
96}
97
98#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Candidate<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::debug_struct_field3_finish(f, "Candidate",
"item", &self.item, "kind", &self.kind, "import_ids",
&&self.import_ids)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Candidate<'tcx> {
#[inline]
fn clone(&self) -> Candidate<'tcx> {
Candidate {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
}
}
}Clone)]
99pub(crate) struct Candidate<'tcx> {
100 pub(crate) item: ty::AssocItem,
101 pub(crate) kind: CandidateKind<'tcx>,
102 pub(crate) import_ids: &'tcx [LocalDefId],
103}
104
105#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for CandidateKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
CandidateKind::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"InherentImplCandidate", "impl_def_id", __self_0,
"receiver_steps", &__self_1),
CandidateKind::ObjectCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ObjectCandidate", &__self_0),
CandidateKind::TraitCandidate(__self_0, __self_1) =>
::core::fmt::Formatter::debug_tuple_field2_finish(f,
"TraitCandidate", __self_0, &__self_1),
CandidateKind::WhereClauseCandidate(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WhereClauseCandidate", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for CandidateKind<'tcx> {
#[inline]
fn clone(&self) -> CandidateKind<'tcx> {
match self {
CandidateKind::InherentImplCandidate {
impl_def_id: __self_0, receiver_steps: __self_1 } =>
CandidateKind::InherentImplCandidate {
impl_def_id: ::core::clone::Clone::clone(__self_0),
receiver_steps: ::core::clone::Clone::clone(__self_1),
},
CandidateKind::ObjectCandidate(__self_0) =>
CandidateKind::ObjectCandidate(::core::clone::Clone::clone(__self_0)),
CandidateKind::TraitCandidate(__self_0, __self_1) =>
CandidateKind::TraitCandidate(::core::clone::Clone::clone(__self_0),
::core::clone::Clone::clone(__self_1)),
CandidateKind::WhereClauseCandidate(__self_0) =>
CandidateKind::WhereClauseCandidate(::core::clone::Clone::clone(__self_0)),
}
}
}Clone)]
106pub(crate) enum CandidateKind<'tcx> {
107 InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
108 ObjectCandidate(ty::PolyTraitRef<'tcx>),
109 TraitCandidate(ty::PolyTraitRef<'tcx>, bool ),
110 WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
111}
112
113#[derive(#[automatically_derived]
impl ::core::fmt::Debug for ProbeResult {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
ProbeResult::NoMatch => "NoMatch",
ProbeResult::BadReturnType => "BadReturnType",
ProbeResult::Match => "Match",
})
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for ProbeResult {
#[inline]
fn eq(&self, other: &ProbeResult) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ProbeResult {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for ProbeResult { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ProbeResult {
#[inline]
fn clone(&self) -> ProbeResult { *self }
}Clone)]
114enum ProbeResult {
115 NoMatch,
116 BadReturnType,
117 Match,
118}
119
120#[derive(#[automatically_derived]
impl ::core::fmt::Debug for AutorefOrPtrAdjustment {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
AutorefOrPtrAdjustment::Autoref {
mutbl: __self_0, unsize: __self_1 } =>
::core::fmt::Formatter::debug_struct_field2_finish(f,
"Autoref", "mutbl", __self_0, "unsize", &__self_1),
AutorefOrPtrAdjustment::ToConstPtr =>
::core::fmt::Formatter::write_str(f, "ToConstPtr"),
AutorefOrPtrAdjustment::ReborrowPin(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"ReborrowPin", &__self_0),
}
}
}Debug, #[automatically_derived]
impl ::core::cmp::PartialEq for AutorefOrPtrAdjustment {
#[inline]
fn eq(&self, other: &AutorefOrPtrAdjustment) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(AutorefOrPtrAdjustment::Autoref {
mutbl: __self_0, unsize: __self_1 },
AutorefOrPtrAdjustment::Autoref {
mutbl: __arg1_0, unsize: __arg1_1 }) =>
__self_1 == __arg1_1 && __self_0 == __arg1_0,
(AutorefOrPtrAdjustment::ReborrowPin(__self_0),
AutorefOrPtrAdjustment::ReborrowPin(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::marker::Copy for AutorefOrPtrAdjustment { }Copy, #[automatically_derived]
impl ::core::clone::Clone for AutorefOrPtrAdjustment {
#[inline]
fn clone(&self) -> AutorefOrPtrAdjustment {
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
let _: ::core::clone::AssertParamIsClone<bool>;
let _: ::core::clone::AssertParamIsClone<hir::Mutability>;
*self
}
}Clone)]
133pub(crate) enum AutorefOrPtrAdjustment {
134 Autoref {
137 mutbl: hir::Mutability,
138
139 unsize: bool,
142 },
143 ToConstPtr,
145
146 ReborrowPin(hir::Mutability),
148}
149
150impl AutorefOrPtrAdjustment {
151 fn get_unsize(&self) -> bool {
152 match self {
153 AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
154 AutorefOrPtrAdjustment::ToConstPtr => false,
155 AutorefOrPtrAdjustment::ReborrowPin(_) => false,
156 }
157 }
158}
159
160#[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)]
162struct PickDiagHints<'a, 'tcx> {
163 unstable_candidates: Option<Vec<(Candidate<'tcx>, Symbol)>>,
165
166 unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'tcx>,
169}
170
171pub(crate) type UnsatisfiedPredicates<'tcx> =
172 Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>;
173
174#[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)]
178struct PickConstraintsForShadowed {
179 autoderefs: usize,
180 receiver_steps: Option<usize>,
181 def_id: DefId,
182}
183
184impl PickConstraintsForShadowed {
185 fn may_shadow_based_on_autoderefs(&self, autoderefs: usize) -> bool {
186 autoderefs == self.autoderefs
187 }
188
189 fn candidate_may_shadow(&self, candidate: &Candidate<'_>) -> bool {
190 candidate.item.def_id != self.def_id
192 && match candidate.kind {
196 CandidateKind::InherentImplCandidate { receiver_steps, .. } => match self.receiver_steps {
197 Some(shadowed_receiver_steps) => receiver_steps > shadowed_receiver_steps,
198 _ => false
199 },
200 _ => false
201 }
202 }
203}
204
205#[derive(#[automatically_derived]
impl<'tcx> ::core::fmt::Debug for Pick<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
let names: &'static _ =
&["item", "kind", "import_ids", "autoderefs",
"autoref_or_ptr_adjustment", "self_ty",
"unstable_candidates", "receiver_steps",
"shadowed_candidates"];
let values: &[&dyn ::core::fmt::Debug] =
&[&self.item, &self.kind, &self.import_ids, &self.autoderefs,
&self.autoref_or_ptr_adjustment, &self.self_ty,
&self.unstable_candidates, &self.receiver_steps,
&&self.shadowed_candidates];
::core::fmt::Formatter::debug_struct_fields_finish(f, "Pick", names,
values)
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::clone::Clone for Pick<'tcx> {
#[inline]
fn clone(&self) -> Pick<'tcx> {
Pick {
item: ::core::clone::Clone::clone(&self.item),
kind: ::core::clone::Clone::clone(&self.kind),
import_ids: ::core::clone::Clone::clone(&self.import_ids),
autoderefs: ::core::clone::Clone::clone(&self.autoderefs),
autoref_or_ptr_adjustment: ::core::clone::Clone::clone(&self.autoref_or_ptr_adjustment),
self_ty: ::core::clone::Clone::clone(&self.self_ty),
unstable_candidates: ::core::clone::Clone::clone(&self.unstable_candidates),
receiver_steps: ::core::clone::Clone::clone(&self.receiver_steps),
shadowed_candidates: ::core::clone::Clone::clone(&self.shadowed_candidates),
}
}
}Clone)]
206pub(crate) struct Pick<'tcx> {
207 pub item: ty::AssocItem,
208 pub kind: PickKind<'tcx>,
209 pub import_ids: &'tcx [LocalDefId],
210
211 pub autoderefs: usize,
216
217 pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
220 pub self_ty: Ty<'tcx>,
221
222 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
224
225 pub receiver_steps: Option<usize>,
229
230 pub shadowed_candidates: Vec<ty::AssocItem>,
232}
233
234#[derive(#[automatically_derived]
impl<'tcx> ::core::clone::Clone for PickKind<'tcx> {
#[inline]
fn clone(&self) -> PickKind<'tcx> {
match self {
PickKind::InherentImplPick => PickKind::InherentImplPick,
PickKind::ObjectPick => PickKind::ObjectPick,
PickKind::TraitPick(__self_0) =>
PickKind::TraitPick(::core::clone::Clone::clone(__self_0)),
PickKind::WhereClausePick(__self_0) =>
PickKind::WhereClausePick(::core::clone::Clone::clone(__self_0)),
}
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for PickKind<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
PickKind::InherentImplPick =>
::core::fmt::Formatter::write_str(f, "InherentImplPick"),
PickKind::ObjectPick =>
::core::fmt::Formatter::write_str(f, "ObjectPick"),
PickKind::TraitPick(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"TraitPick", &__self_0),
PickKind::WhereClausePick(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"WhereClausePick", &__self_0),
}
}
}Debug, #[automatically_derived]
impl<'tcx> ::core::cmp::PartialEq for PickKind<'tcx> {
#[inline]
fn eq(&self, other: &PickKind<'tcx>) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(PickKind::TraitPick(__self_0), PickKind::TraitPick(__arg1_0))
=> __self_0 == __arg1_0,
(PickKind::WhereClausePick(__self_0),
PickKind::WhereClausePick(__arg1_0)) =>
__self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl<'tcx> ::core::cmp::Eq for PickKind<'tcx> {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitRef<'tcx>>;
}
}Eq)]
235pub(crate) enum PickKind<'tcx> {
236 InherentImplPick,
237 ObjectPick,
238 TraitPick(
239 bool,
241 ),
242 WhereClausePick(
243 ty::PolyTraitRef<'tcx>,
245 ),
246}
247
248pub(crate) type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
249
250#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for Mode {
#[inline]
fn eq(&self, other: &Mode) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for Mode {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for Mode { }Copy, #[automatically_derived]
impl ::core::clone::Clone for Mode {
#[inline]
fn clone(&self) -> Mode { *self }
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for Mode {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
::core::fmt::Formatter::write_str(f,
match self {
Mode::MethodCall => "MethodCall",
Mode::Path => "Path",
})
}
}Debug)]
251pub(crate) enum Mode {
252 MethodCall,
256 Path,
260}
261
262#[derive(#[automatically_derived]
impl ::core::cmp::PartialEq for ProbeScope {
#[inline]
fn eq(&self, other: &ProbeScope) -> bool {
let __self_discr = ::core::intrinsics::discriminant_value(self);
let __arg1_discr = ::core::intrinsics::discriminant_value(other);
__self_discr == __arg1_discr &&
match (self, other) {
(ProbeScope::Single(__self_0), ProbeScope::Single(__arg1_0))
=> __self_0 == __arg1_0,
_ => true,
}
}
}PartialEq, #[automatically_derived]
impl ::core::cmp::Eq for ProbeScope {
#[inline]
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<DefId>;
}
}Eq, #[automatically_derived]
impl ::core::marker::Copy for ProbeScope { }Copy, #[automatically_derived]
impl ::core::clone::Clone for ProbeScope {
#[inline]
fn clone(&self) -> ProbeScope {
let _: ::core::clone::AssertParamIsClone<DefId>;
*self
}
}Clone, #[automatically_derived]
impl ::core::fmt::Debug for ProbeScope {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
ProbeScope::Single(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f, "Single",
&__self_0),
ProbeScope::TraitsInScope =>
::core::fmt::Formatter::write_str(f, "TraitsInScope"),
ProbeScope::AllTraits =>
::core::fmt::Formatter::write_str(f, "AllTraits"),
}
}
}Debug)]
263pub(crate) enum ProbeScope {
264 Single(DefId),
266
267 TraitsInScope,
269
270 AllTraits,
272}
273
274impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
275 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_return_type_for_diagnostic",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(281u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["span", "mode",
"return_type", "self_ty", "scope_expr_id"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&span)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn 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))]
282 pub(crate) fn probe_for_return_type_for_diagnostic(
283 &self,
284 span: Span,
285 mode: Mode,
286 return_type: Ty<'tcx>,
287 self_ty: Ty<'tcx>,
288 scope_expr_id: HirId,
289 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
290 ) -> Vec<ty::AssocItem> {
291 let method_names = self
292 .probe_op(
293 span,
294 mode,
295 None,
296 Some(return_type),
297 IsSuggestion(true),
298 self_ty,
299 scope_expr_id,
300 ProbeScope::AllTraits,
301 |probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
302 )
303 .unwrap_or_default();
304 method_names
305 .iter()
306 .flat_map(|&method_name| {
307 self.probe_op(
308 span,
309 mode,
310 Some(method_name),
311 Some(return_type),
312 IsSuggestion(true),
313 self_ty,
314 scope_expr_id,
315 ProbeScope::AllTraits,
316 |probe_cx| probe_cx.pick(),
317 )
318 .ok()
319 .map(|pick| pick.item)
320 })
321 .collect()
322 }
323
324 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_name",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(324u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["mode", "item_name",
"return_type", "is_suggestion", "self_ty", "scope_expr_id",
"scope"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
as &dyn 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))]
325 pub(crate) fn probe_for_name(
326 &self,
327 mode: Mode,
328 item_name: Ident,
329 return_type: Option<Ty<'tcx>>,
330 is_suggestion: IsSuggestion,
331 self_ty: Ty<'tcx>,
332 scope_expr_id: HirId,
333 scope: ProbeScope,
334 ) -> PickResult<'tcx> {
335 self.probe_op(
336 item_name.span,
337 mode,
338 Some(item_name),
339 return_type,
340 is_suggestion,
341 self_ty,
342 scope_expr_id,
343 scope,
344 |probe_cx| probe_cx.pick(),
345 )
346 }
347
348 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_name_many",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(348u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["mode", "item_name",
"return_type", "is_suggestion", "self_ty", "scope_expr_id",
"scope"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&mode)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item_name)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&return_type)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&is_suggestion)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope_expr_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&scope)
as &dyn 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))]
349 pub(crate) fn probe_for_name_many(
350 &self,
351 mode: Mode,
352 item_name: Ident,
353 return_type: Option<Ty<'tcx>>,
354 is_suggestion: IsSuggestion,
355 self_ty: Ty<'tcx>,
356 scope_expr_id: HirId,
357 scope: ProbeScope,
358 ) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
359 self.probe_op(
360 item_name.span,
361 mode,
362 Some(item_name),
363 return_type,
364 is_suggestion,
365 self_ty,
366 scope_expr_id,
367 scope,
368 |probe_cx| {
369 Ok(probe_cx
370 .inherent_candidates
371 .into_iter()
372 .chain(probe_cx.extension_candidates)
373 .collect())
374 },
375 )
376 }
377
378 pub(crate) fn probe_op<OP, R>(
379 &'a self,
380 span: Span,
381 mode: Mode,
382 method_name: Option<Ident>,
383 return_type: Option<Ty<'tcx>>,
384 is_suggestion: IsSuggestion,
385 self_ty: Ty<'tcx>,
386 scope_expr_id: HirId,
387 scope: ProbeScope,
388 op: OP,
389 ) -> Result<R, MethodError<'tcx>>
390 where
391 OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
392 {
393 #[derive(const _: () =
{
impl<'_sess, G> rustc_errors::Diagnostic<'_sess, G> for
MissingTypeAnnot where G: rustc_errors::EmissionGuarantee {
#[track_caller]
fn into_diag(self, dcx: rustc_errors::DiagCtxtHandle<'_sess>,
level: rustc_errors::Level) -> rustc_errors::Diag<'_sess, G> {
match self {
MissingTypeAnnot => {
let mut diag =
rustc_errors::Diag::new(dcx, level,
rustc_errors::DiagMessage::Inline(std::borrow::Cow::Borrowed("type annotations needed")));
;
diag
}
}
}
}
};Diagnostic)]
394 #[diag("type annotations needed")]
395 struct MissingTypeAnnot;
396
397 let mut orig_values = OriginalQueryValues::default();
398 let predefined_opaques_in_body = if self.next_trait_solver() {
399 self.tcx.mk_predefined_opaques_in_body_from_iter(
400 self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
401 )
402 } else {
403 ty::List::empty()
404 };
405 let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
406 let query_input = self
407 .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
408
409 let steps = match mode {
410 Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
411 Mode::Path => self.probe(|_| {
412 let infcx = &self.infcx;
418 let (ParamEnvAnd { param_env: _, value }, var_values) =
419 infcx.instantiate_canonical(span, &query_input.canonical);
420 let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
421 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:421",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(421u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message", "self_ty",
"query_input"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("probe_op: Mode::Path")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&self_ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&query_input)
as &dyn Value))])
});
} else { ; }
};debug!(?self_ty, ?query_input, "probe_op: Mode::Path");
422 let prev_opaque_entries = self.inner.borrow_mut().opaque_types().num_entries();
423 MethodAutoderefStepsResult {
424 steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
425 self_ty: self.make_query_response_ignoring_pending_obligations(
426 var_values,
427 self_ty,
428 prev_opaque_entries,
429 ),
430 self_ty_is_opaque: false,
431 autoderefs: 0,
432 from_unsafe_deref: false,
433 unsize: false,
434 reachable_via_deref: true,
435 }]),
436 opt_bad_ty: None,
437 reached_recursion_limit: false,
438 }
439 }),
440 };
441
442 if steps.reached_recursion_limit && !is_suggestion.0 {
446 self.probe(|_| {
447 let ty = &steps
448 .steps
449 .last()
450 .unwrap_or_else(|| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("reached the recursion limit in 0 steps?"))span_bug!(span, "reached the recursion limit in 0 steps?"))
451 .self_ty;
452 let ty = self
453 .probe_instantiate_query_response(span, &orig_values, ty)
454 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
455 autoderef::report_autoderef_recursion_limit_error(self.tcx, span, ty.value);
456 });
457 }
458
459 if let Some(bad_ty) = &steps.opt_bad_ty {
462 if is_suggestion.0 {
463 return Err(MethodError::NoMatch(NoMatchData {
466 static_candidates: Vec::new(),
467 unsatisfied_predicates: Vec::new(),
468 out_of_scope_traits: Vec::new(),
469 similar_candidate: None,
470 mode,
471 }));
472 } else if bad_ty.reached_raw_pointer
473 && !self.tcx.features().arbitrary_self_types_pointers()
474 && !self.tcx.sess.at_least_rust_2018()
475 {
476 self.tcx.emit_node_span_lint(
480 lint::builtin::TYVAR_BEHIND_RAW_POINTER,
481 scope_expr_id,
482 span,
483 MissingTypeAnnot,
484 );
485 } else {
486 let ty = &bad_ty.ty;
490 let ty = self
491 .probe_instantiate_query_response(span, &orig_values, ty)
492 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
493 let ty = self.resolve_vars_if_possible(ty.value);
494 let guar = match *ty.kind() {
495 _ if let Some(guar) = self.tainted_by_errors() => guar,
496 ty::Infer(ty::TyVar(_)) => {
497 let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
500 (
501 Mode::MethodCall,
502 Node::Expr(hir::Expr {
503 kind: ExprKind::MethodCall(_, recv, ..),
504 ..
505 }),
506 ) => recv.span,
507 _ => span,
508 };
509
510 let raw_ptr_call = bad_ty.reached_raw_pointer
511 && !self.tcx.features().arbitrary_self_types();
512
513 let mut err = self.err_ctxt().emit_inference_failure_err(
514 self.body_id,
515 err_span,
516 ty.into(),
517 TypeAnnotationNeeded::E0282,
518 !raw_ptr_call,
519 );
520 if raw_ptr_call {
521 err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
522 }
523 err.emit()
524 }
525 ty::Error(guar) => guar,
526 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected bad final type in method autoderef"))bug!("unexpected bad final type in method autoderef"),
527 };
528 self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
529 return Err(MethodError::ErrorReported(guar));
530 }
531 }
532
533 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:533",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(533u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("ProbeContext: steps for self_ty={0:?} are {1:?}",
self_ty, steps) as &dyn Value))])
});
} else { ; }
};debug!("ProbeContext: steps for self_ty={:?} are {:?}", self_ty, steps);
534
535 self.probe(|_| {
538 let mut probe_cx = ProbeContext::new(
539 self,
540 span,
541 mode,
542 method_name,
543 return_type,
544 &orig_values,
545 steps.steps,
546 scope_expr_id,
547 is_suggestion,
548 );
549
550 match scope {
551 ProbeScope::TraitsInScope => {
552 probe_cx.assemble_inherent_candidates();
553 probe_cx.assemble_extension_candidates_for_traits_in_scope();
554 }
555 ProbeScope::AllTraits => {
556 probe_cx.assemble_inherent_candidates();
557 probe_cx.assemble_extension_candidates_for_all_traits();
558 }
559 ProbeScope::Single(def_id) => {
560 let item = self.tcx.associated_item(def_id);
561 match (&item.container, &AssocContainer::Trait) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val, &*right_val,
::core::option::Option::None);
}
}
};assert_eq!(item.container, AssocContainer::Trait);
563
564 let trait_def_id = self.tcx.parent(def_id);
565 let trait_span = self.tcx.def_span(trait_def_id);
566
567 let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
568 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
569
570 probe_cx.push_candidate(
571 Candidate {
572 item,
573 kind: CandidateKind::TraitCandidate(
574 ty::Binder::dummy(trait_ref),
575 false,
576 ),
577 import_ids: &[],
578 },
579 false,
580 );
581 }
582 };
583 op(probe_cx)
584 })
585 }
586}
587
588pub(crate) fn method_autoderef_steps<'tcx>(
589 tcx: TyCtxt<'tcx>,
590 goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
591) -> MethodAutoderefStepsResult<'tcx> {
592 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:592",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(592u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps({0:?})",
goal) as &dyn Value))])
});
} else { ; }
};debug!("method_autoderef_steps({:?})", goal);
593
594 let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
595 let ParamEnvAnd {
596 param_env,
597 value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
598 } = goal;
599 for (key, ty) in predefined_opaques_in_body {
600 let prev = infcx
601 .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
602 if let Some(prev) = prev {
614 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:614",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(614u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["message", "key",
"ty", "prev"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("ignore duplicate in `opaque_types_storage`")
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&key) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&ty) as
&dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&prev) as
&dyn Value))])
});
} else { ; }
};debug!(?key, ?ty, ?prev, "ignore duplicate in `opaque_types_storage`");
615 }
616 }
617 let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
618
619 let self_ty_is_opaque = |ty: Ty<'_>| {
623 if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
624 infcx.has_opaques_with_sub_unified_hidden_type(vid)
625 } else {
626 false
627 }
628 };
629
630 let mut autoderef_via_deref =
640 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
641 .include_raw_pointers()
642 .silence_errors();
643
644 let mut reached_raw_pointer = false;
645 let arbitrary_self_types_enabled =
646 tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
647 let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
648 let reachable_via_deref =
649 autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
650
651 let mut autoderef_via_receiver =
652 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
653 .include_raw_pointers()
654 .use_receiver_trait()
655 .silence_errors();
656 let steps = autoderef_via_receiver
657 .by_ref()
658 .zip(reachable_via_deref)
659 .map(|((ty, d), reachable_via_deref)| {
660 let step = CandidateStep {
661 self_ty: infcx.make_query_response_ignoring_pending_obligations(
662 inference_vars,
663 ty,
664 prev_opaque_entries,
665 ),
666 self_ty_is_opaque: self_ty_is_opaque(ty),
667 autoderefs: d,
668 from_unsafe_deref: reached_raw_pointer,
669 unsize: false,
670 reachable_via_deref,
671 };
672 if ty.is_raw_ptr() {
673 reached_raw_pointer = true;
675 }
676 step
677 })
678 .collect();
679 (steps, autoderef_via_receiver.reached_recursion_limit())
680 } else {
681 let steps = autoderef_via_deref
682 .by_ref()
683 .map(|(ty, d)| {
684 let step = CandidateStep {
685 self_ty: infcx.make_query_response_ignoring_pending_obligations(
686 inference_vars,
687 ty,
688 prev_opaque_entries,
689 ),
690 self_ty_is_opaque: self_ty_is_opaque(ty),
691 autoderefs: d,
692 from_unsafe_deref: reached_raw_pointer,
693 unsize: false,
694 reachable_via_deref: true,
695 };
696 if ty.is_raw_ptr() {
697 reached_raw_pointer = true;
699 }
700 step
701 })
702 .collect();
703 (steps, autoderef_via_deref.reached_recursion_limit())
704 };
705 let final_ty = autoderef_via_deref.final_ty();
706 let opt_bad_ty = match final_ty.kind() {
707 ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
708 reached_raw_pointer,
709 ty: infcx.make_query_response_ignoring_pending_obligations(
710 inference_vars,
711 final_ty,
712 prev_opaque_entries,
713 ),
714 }),
715 ty::Error(_) => Some(MethodAutoderefBadTy {
716 reached_raw_pointer,
717 ty: infcx.make_query_response_ignoring_pending_obligations(
718 inference_vars,
719 final_ty,
720 prev_opaque_entries,
721 ),
722 }),
723 ty::Array(elem_ty, _) => {
724 let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
725 steps.push(CandidateStep {
726 self_ty: infcx.make_query_response_ignoring_pending_obligations(
727 inference_vars,
728 Ty::new_slice(infcx.tcx, *elem_ty),
729 prev_opaque_entries,
730 ),
731 self_ty_is_opaque: false,
732 autoderefs,
733 from_unsafe_deref: reached_raw_pointer,
736 unsize: true,
737 reachable_via_deref: true, });
740
741 None
742 }
743 _ => None,
744 };
745
746 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:746",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(746u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("method_autoderef_steps: steps={0:?} opt_bad_ty={1:?}",
steps, opt_bad_ty) as &dyn Value))])
});
} else { ; }
};debug!("method_autoderef_steps: steps={:?} opt_bad_ty={:?}", steps, opt_bad_ty);
747 let _ = infcx.take_opaque_types();
749 MethodAutoderefStepsResult {
750 steps: tcx.arena.alloc_from_iter(steps),
751 opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
752 reached_recursion_limit,
753 }
754}
755
756impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
757 fn new(
758 fcx: &'a FnCtxt<'a, 'tcx>,
759 span: Span,
760 mode: Mode,
761 method_name: Option<Ident>,
762 return_type: Option<Ty<'tcx>>,
763 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
764 steps: &'tcx [CandidateStep<'tcx>],
765 scope_expr_id: HirId,
766 is_suggestion: IsSuggestion,
767 ) -> ProbeContext<'a, 'tcx> {
768 ProbeContext {
769 fcx,
770 span,
771 mode,
772 method_name,
773 return_type,
774 inherent_candidates: Vec::new(),
775 extension_candidates: Vec::new(),
776 impl_dups: FxHashSet::default(),
777 orig_steps_var_values,
778 steps,
779 allow_similar_names: false,
780 private_candidates: Vec::new(),
781 private_candidate: Cell::new(None),
782 static_candidates: RefCell::new(Vec::new()),
783 scope_expr_id,
784 is_suggestion,
785 }
786 }
787
788 fn reset(&mut self) {
789 self.inherent_candidates.clear();
790 self.extension_candidates.clear();
791 self.impl_dups.clear();
792 self.private_candidates.clear();
793 self.private_candidate.set(None);
794 self.static_candidates.borrow_mut().clear();
795 }
796
797 fn variance(&self) -> ty::Variance {
801 match self.mode {
802 Mode::MethodCall => ty::Covariant,
803 Mode::Path => ty::Invariant,
804 }
805 }
806
807 fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
811 let is_accessible = if let Some(name) = self.method_name {
812 let item = candidate.item;
813 let hir_id = self.tcx.local_def_id_to_hir_id(self.body_id);
814 let def_scope =
815 self.tcx.adjust_ident_and_get_scope(name, item.container_id(self.tcx), hir_id).1;
816 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
817 } else {
818 true
819 };
820 if is_accessible {
821 if is_inherent {
822 self.inherent_candidates.push(candidate);
823 } else {
824 self.extension_candidates.push(candidate);
825 }
826 } else {
827 self.private_candidates.push(candidate);
828 }
829 }
830
831 fn assemble_inherent_candidates(&mut self) {
832 for step in self.steps.iter() {
833 self.assemble_probe(&step.self_ty, step.autoderefs);
834 }
835 }
836
837 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_probe",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(837u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["self_ty",
"receiver_steps"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&receiver_steps as
&dyn 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))]
838 fn assemble_probe(
839 &mut self,
840 self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
841 receiver_steps: usize,
842 ) {
843 let raw_self_ty = self_ty.value.value;
844 match *raw_self_ty.kind() {
845 ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
846 let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
864 self.fcx.instantiate_canonical(self.span, self_ty);
865
866 self.assemble_inherent_candidates_from_object(generalized_self_ty);
867 self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
868 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
869 }
870 ty::Adt(def, _) => {
871 let def_id = def.did();
872 self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
873 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
874 }
875 ty::Foreign(did) => {
876 self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
877 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
878 }
879 ty::Param(_) => {
880 self.assemble_inherent_candidates_from_param(raw_self_ty);
881 }
882 ty::Bool
883 | ty::Char
884 | ty::Int(_)
885 | ty::Uint(_)
886 | ty::Float(_)
887 | ty::Str
888 | ty::Array(..)
889 | ty::Slice(_)
890 | ty::RawPtr(_, _)
891 | ty::Ref(..)
892 | ty::Never
893 | ty::Tuple(..) => {
894 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
895 }
896 ty::Alias(..)
897 | ty::Bound(..)
898 | ty::Closure(..)
899 | ty::Coroutine(..)
900 | ty::CoroutineClosure(..)
901 | ty::CoroutineWitness(..)
902 | ty::Dynamic(..)
903 | ty::Error(..)
904 | ty::FnDef(..)
905 | ty::FnPtr(..)
906 | ty::Infer(..)
907 | ty::Pat(..)
908 | ty::Placeholder(..)
909 | ty::UnsafeBinder(..) => {}
910 }
911 }
912
913 fn assemble_inherent_candidates_for_incoherent_ty(
914 &mut self,
915 self_ty: Ty<'tcx>,
916 receiver_steps: usize,
917 ) {
918 let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
919 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected incoherent type: {0:?}",
self_ty))bug!("unexpected incoherent type: {:?}", self_ty)
920 };
921 for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
922 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
923 }
924 }
925
926 fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
927 let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
928 for &impl_def_id in impl_def_ids {
929 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
930 }
931 }
932
933 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_impl_probe",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(933u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["impl_def_id",
"receiver_steps"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&receiver_steps as
&dyn 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))]
934 fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
935 if !self.impl_dups.insert(impl_def_id) {
936 return; }
938
939 for item in self.impl_or_trait_item(impl_def_id) {
940 if !self.has_applicable_self(&item) {
941 self.record_static_candidate(CandidateSource::Impl(impl_def_id));
943 continue;
944 }
945 self.push_candidate(
946 Candidate {
947 item,
948 kind: InherentImplCandidate { impl_def_id, receiver_steps },
949 import_ids: &[],
950 },
951 true,
952 );
953 }
954 }
955
956 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_candidates_from_object",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(956u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["self_ty"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let principal =
match self_ty.kind() {
ty::Dynamic(data, ..) => Some(data),
_ => None,
}.and_then(|data|
data.principal()).unwrap_or_else(||
{
::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("non-object {0:?} in assemble_inherent_candidates_from_object",
self_ty))
});
let trait_ref = principal.with_self_ty(self.tcx, self_ty);
self.assemble_candidates_for_bounds(traits::supertraits(self.tcx,
trait_ref),
|this, new_trait_ref, item|
{
this.push_candidate(Candidate {
item,
kind: ObjectCandidate(new_trait_ref),
import_ids: &[],
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
957 fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
958 let principal = match self_ty.kind() {
959 ty::Dynamic(data, ..) => Some(data),
960 _ => None,
961 }
962 .and_then(|data| data.principal())
963 .unwrap_or_else(|| {
964 span_bug!(
965 self.span,
966 "non-object {:?} in assemble_inherent_candidates_from_object",
967 self_ty
968 )
969 });
970
971 let trait_ref = principal.with_self_ty(self.tcx, self_ty);
978 self.assemble_candidates_for_bounds(
979 traits::supertraits(self.tcx, trait_ref),
980 |this, new_trait_ref, item| {
981 this.push_candidate(
982 Candidate { item, kind: ObjectCandidate(new_trait_ref), import_ids: &[] },
983 true,
984 );
985 },
986 );
987 }
988
989 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_inherent_candidates_from_param",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(989u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["param_ty"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(¶m_ty)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
if true {
{
match param_ty.kind() {
ty::Param(_) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"ty::Param(_)", ::core::option::Option::None);
}
}
};
};
let tcx = self.tcx;
let bounds =
self.param_env.caller_bounds().iter().filter_map(|predicate|
{
let bound_predicate = predicate.kind();
match bound_predicate.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_predicate.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))]
990 fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
991 debug_assert_matches!(param_ty.kind(), ty::Param(_));
992
993 let tcx = self.tcx;
994
995 let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
999 let bound_predicate = predicate.kind();
1000 match bound_predicate.skip_binder() {
1001 ty::ClauseKind::Trait(trait_predicate) => DeepRejectCtxt::relate_rigid_rigid(tcx)
1002 .types_may_unify(param_ty, trait_predicate.trait_ref.self_ty())
1003 .then(|| bound_predicate.rebind(trait_predicate.trait_ref)),
1004 ty::ClauseKind::RegionOutlives(_)
1005 | ty::ClauseKind::TypeOutlives(_)
1006 | ty::ClauseKind::Projection(_)
1007 | ty::ClauseKind::ConstArgHasType(_, _)
1008 | ty::ClauseKind::WellFormed(_)
1009 | ty::ClauseKind::ConstEvaluatable(_)
1010 | ty::ClauseKind::UnstableFeature(_)
1011 | ty::ClauseKind::HostEffect(..) => None,
1012 }
1013 });
1014
1015 self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1016 this.push_candidate(
1017 Candidate { item, kind: WhereClauseCandidate(poly_trait_ref), import_ids: &[] },
1018 true,
1019 );
1020 });
1021 }
1022
1023 fn assemble_candidates_for_bounds<F>(
1026 &mut self,
1027 bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1028 mut mk_cand: F,
1029 ) where
1030 F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1031 {
1032 for bound_trait_ref in bounds {
1033 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1033",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1033u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("elaborate_bounds(bound_trait_ref={0:?})",
bound_trait_ref) as &dyn Value))])
});
} else { ; }
};debug!("elaborate_bounds(bound_trait_ref={:?})", bound_trait_ref);
1034 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1035 if !self.has_applicable_self(&item) {
1036 self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1037 } else {
1038 mk_cand(self, bound_trait_ref, item);
1039 }
1040 }
1041 }
1042 }
1043
1044 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_traits_in_scope",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1044u32),
::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(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let mut duplicates = FxHashSet::default();
let opt_applicable_traits =
self.tcx.in_scope_traits(self.scope_expr_id);
if let Some(applicable_traits) = opt_applicable_traits {
for trait_candidate in applicable_traits.iter() {
let trait_did = trait_candidate.def_id;
if duplicates.insert(trait_did) {
self.assemble_extension_candidates_for_trait(&trait_candidate.import_ids,
trait_did, trait_candidate.lint_ambiguous);
}
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1045 fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1046 let mut duplicates = FxHashSet::default();
1047 let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1048 if let Some(applicable_traits) = opt_applicable_traits {
1049 for trait_candidate in applicable_traits.iter() {
1050 let trait_did = trait_candidate.def_id;
1051 if duplicates.insert(trait_did) {
1052 self.assemble_extension_candidates_for_trait(
1053 &trait_candidate.import_ids,
1054 trait_did,
1055 trait_candidate.lint_ambiguous,
1056 );
1057 }
1058 }
1059 }
1060 }
1061
1062 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_all_traits",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1062u32),
::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(&[]) })
} 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))]
1063 fn assemble_extension_candidates_for_all_traits(&mut self) {
1064 let mut duplicates = FxHashSet::default();
1065 for trait_info in suggest::all_traits(self.tcx) {
1066 if duplicates.insert(trait_info.def_id) {
1067 self.assemble_extension_candidates_for_trait(&[], trait_info.def_id, false);
1068 }
1069 }
1070 }
1071
1072 fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1073 match method.kind {
1074 ty::AssocKind::Fn { .. } => self.probe(|_| {
1075 let args = self.fresh_args_for_item(self.span, method.def_id);
1076 let fty =
1077 self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args).skip_norm_wip();
1078 let fty = self.instantiate_binder_with_fresh_vars(
1079 self.span,
1080 BoundRegionConversionTime::FnCall,
1081 fty,
1082 );
1083 self.can_eq(self.param_env, fty.output(), expected)
1084 }),
1085 _ => false,
1086 }
1087 }
1088
1089 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("assemble_extension_candidates_for_trait",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1089u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["import_ids",
"trait_def_id", "lint_ambiguous"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&import_ids)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&trait_def_id)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&lint_ambiguous as
&dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: () = loop {};
return __tracing_attr_fake_return;
}
{
let trait_args =
self.fresh_args_for_item(self.span, trait_def_id);
let trait_ref =
ty::TraitRef::new_from_args(self.tcx, trait_def_id,
trait_args);
if self.tcx.is_trait_alias(trait_def_id) {
for (bound_trait_pred, _) in
traits::expand_trait_aliases(self.tcx,
[(trait_ref.upcast(self.tcx), self.span)]).0 {
match (&bound_trait_pred.polarity(),
&ty::PredicatePolarity::Positive) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
let bound_trait_ref =
bound_trait_pred.map_bound(|pred| pred.trait_ref);
for item in
self.impl_or_trait_item(bound_trait_ref.def_id()) {
if !self.has_applicable_self(&item) {
self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
} else {
self.push_candidate(Candidate {
item,
import_ids,
kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
}, false);
}
}
}
} else {
if true {
if !self.tcx.is_trait(trait_def_id) {
::core::panicking::panic("assertion failed: self.tcx.is_trait(trait_def_id)")
};
};
if self.tcx.trait_is_auto(trait_def_id) { return; }
for item in self.impl_or_trait_item(trait_def_id) {
if !self.has_applicable_self(&item) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1131",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1131u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("method has inapplicable self")
as &dyn Value))])
});
} else { ; }
};
self.record_static_candidate(CandidateSource::Trait(trait_def_id));
continue;
}
self.push_candidate(Candidate {
item,
import_ids,
kind: TraitCandidate(ty::Binder::dummy(trait_ref),
lint_ambiguous),
}, false);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1090 fn assemble_extension_candidates_for_trait(
1091 &mut self,
1092 import_ids: &'tcx [LocalDefId],
1093 trait_def_id: DefId,
1094 lint_ambiguous: bool,
1095 ) {
1096 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1097 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1098
1099 if self.tcx.is_trait_alias(trait_def_id) {
1100 for (bound_trait_pred, _) in
1102 traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1103 {
1104 assert_eq!(bound_trait_pred.polarity(), ty::PredicatePolarity::Positive);
1105 let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1106 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1107 if !self.has_applicable_self(&item) {
1108 self.record_static_candidate(CandidateSource::Trait(
1109 bound_trait_ref.def_id(),
1110 ));
1111 } else {
1112 self.push_candidate(
1113 Candidate {
1114 item,
1115 import_ids,
1116 kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
1117 },
1118 false,
1119 );
1120 }
1121 }
1122 }
1123 } else {
1124 debug_assert!(self.tcx.is_trait(trait_def_id));
1125 if self.tcx.trait_is_auto(trait_def_id) {
1126 return;
1127 }
1128 for item in self.impl_or_trait_item(trait_def_id) {
1129 if !self.has_applicable_self(&item) {
1131 debug!("method has inapplicable self");
1132 self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1133 continue;
1134 }
1135 self.push_candidate(
1136 Candidate {
1137 item,
1138 import_ids,
1139 kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
1140 },
1141 false,
1142 );
1143 }
1144 }
1145 }
1146
1147 fn candidate_method_names(
1148 &self,
1149 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1150 ) -> Vec<Ident> {
1151 let mut set = FxHashSet::default();
1152 let mut names: Vec<_> = self
1153 .inherent_candidates
1154 .iter()
1155 .chain(&self.extension_candidates)
1156 .filter(|candidate| candidate_filter(&candidate.item))
1157 .filter(|candidate| {
1158 if let Some(return_ty) = self.return_type {
1159 self.matches_return_type(candidate.item, return_ty)
1160 } else {
1161 true
1162 }
1163 })
1164 .filter(|candidate| {
1166 !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
None, DUMMY_SP, None) {
stability::EvalResult::Deny { .. } => true,
_ => false,
}matches!(
1169 self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1170 stability::EvalResult::Deny { .. }
1171 )
1172 })
1173 .map(|candidate| candidate.item.ident(self.tcx))
1174 .filter(|&name| set.insert(name))
1175 .collect();
1176
1177 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1179 names
1180 }
1181
1182 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("pick",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1185u32),
::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(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: PickResult<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
if !self.method_name.is_some() {
::core::panicking::panic("assertion failed: self.method_name.is_some()")
};
let mut unsatisfied_predicates = Vec::new();
if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
return r;
}
if self.is_suggestion.0 {
return Err(MethodError::NoMatch(NoMatchData {
static_candidates: ::alloc::vec::Vec::new(),
unsatisfied_predicates: ::alloc::vec::Vec::new(),
out_of_scope_traits: ::alloc::vec::Vec::new(),
similar_candidate: None,
mode: self.mode,
}));
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1207",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1207u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("pick: actual search failed, assemble diagnostics")
as &dyn 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))]
1186 fn pick(mut self) -> PickResult<'tcx> {
1187 assert!(self.method_name.is_some());
1188
1189 let mut unsatisfied_predicates = Vec::new();
1190
1191 if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1192 return r;
1193 }
1194
1195 if self.is_suggestion.0 {
1198 return Err(MethodError::NoMatch(NoMatchData {
1199 static_candidates: vec![],
1200 unsatisfied_predicates: vec![],
1201 out_of_scope_traits: vec![],
1202 similar_candidate: None,
1203 mode: self.mode,
1204 }));
1205 }
1206
1207 debug!("pick: actual search failed, assemble diagnostics");
1208
1209 let static_candidates = std::mem::take(self.static_candidates.get_mut());
1210 let private_candidate = self.private_candidate.take();
1211
1212 self.reset();
1214
1215 self.assemble_extension_candidates_for_all_traits();
1216
1217 let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1218 Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1219 Some(Err(MethodError::Ambiguity(v))) => v
1220 .into_iter()
1221 .map(|source| match source {
1222 CandidateSource::Trait(id) => id,
1223 CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1224 })
1225 .collect(),
1226 Some(Err(MethodError::NoMatch(NoMatchData {
1227 out_of_scope_traits: others, ..
1228 }))) => {
1229 assert!(others.is_empty());
1230 vec![]
1231 }
1232 _ => vec![],
1233 };
1234
1235 if let Some((kind, def_id)) = private_candidate {
1236 return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1237 }
1238 let similar_candidate = self.probe_for_similar_candidate()?;
1239
1240 Err(MethodError::NoMatch(NoMatchData {
1241 static_candidates,
1242 unsatisfied_predicates,
1243 out_of_scope_traits,
1244 similar_candidate,
1245 mode: self.mode,
1246 }))
1247 }
1248
1249 fn pick_core(
1250 &self,
1251 unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1252 ) -> Option<PickResult<'tcx>> {
1253 self.pick_all_method(&mut PickDiagHints {
1255 unstable_candidates: Some(Vec::new()),
1258 unsatisfied_predicates,
1261 })
1262 .or_else(|| {
1263 self.pick_all_method(&mut PickDiagHints {
1264 unstable_candidates: None,
1269 unsatisfied_predicates: &mut Vec::new(),
1272 })
1273 })
1274 }
1275
1276 fn pick_all_method<'b>(
1277 &self,
1278 pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1279 ) -> Option<PickResult<'tcx>> {
1280 let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1281 self.steps
1282 .iter()
1283 .filter(|step| step.reachable_via_deref)
1287 .filter(|step| {
1288 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1288",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1288u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("pick_all_method: step={0:?}",
step) as &dyn Value))])
});
} else { ; }
};debug!("pick_all_method: step={:?}", step);
1289 !step.self_ty.value.references_error() && !step.from_unsafe_deref
1292 })
1293 .find_map(|step| {
1294 let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1295 .fcx
1296 .probe_instantiate_query_response(
1297 self.span,
1298 self.orig_steps_var_values,
1299 &step.self_ty,
1300 )
1301 .unwrap_or_else(|_| {
1302 ::rustc_middle::util::bug::span_bug_fmt(self.span,
format_args!("{0:?} was applicable but now isn\'t?", step.self_ty))span_bug!(self.span, "{:?} was applicable but now isn't?", step.self_ty)
1303 });
1304
1305 let by_value_pick = self.pick_by_value_method(
1306 step,
1307 self_ty,
1308 &instantiate_self_ty_obligations,
1309 pick_diag_hints,
1310 );
1311
1312 if let Some(by_value_pick) = by_value_pick {
1314 if let Ok(by_value_pick) = by_value_pick.as_ref() {
1315 if by_value_pick.kind == PickKind::InherentImplPick {
1316 for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1317 if let Err(e) = self.check_for_shadowed_autorefd_method(
1318 by_value_pick,
1319 step,
1320 self_ty,
1321 &instantiate_self_ty_obligations,
1322 mutbl,
1323 track_unstable_candidates,
1324 ) {
1325 return Some(Err(e));
1326 }
1327 }
1328 }
1329 }
1330 return Some(by_value_pick);
1331 }
1332
1333 let autoref_pick = self.pick_autorefd_method(
1334 step,
1335 self_ty,
1336 &instantiate_self_ty_obligations,
1337 hir::Mutability::Not,
1338 pick_diag_hints,
1339 None,
1340 );
1341 if let Some(autoref_pick) = autoref_pick {
1343 if let Ok(autoref_pick) = autoref_pick.as_ref() {
1344 if autoref_pick.kind == PickKind::InherentImplPick {
1346 if let Err(e) = self.check_for_shadowed_autorefd_method(
1347 autoref_pick,
1348 step,
1349 self_ty,
1350 &instantiate_self_ty_obligations,
1351 hir::Mutability::Mut,
1352 track_unstable_candidates,
1353 ) {
1354 return Some(Err(e));
1355 }
1356 }
1357 }
1358 return Some(autoref_pick);
1359 }
1360
1361 self.pick_autorefd_method(
1385 step,
1386 self_ty,
1387 &instantiate_self_ty_obligations,
1388 hir::Mutability::Mut,
1389 pick_diag_hints,
1390 None,
1391 )
1392 .or_else(|| {
1393 self.pick_const_ptr_method(
1394 step,
1395 self_ty,
1396 &instantiate_self_ty_obligations,
1397 pick_diag_hints,
1398 )
1399 })
1400 .or_else(|| {
1401 self.pick_reborrow_pin_method(
1402 step,
1403 self_ty,
1404 &instantiate_self_ty_obligations,
1405 pick_diag_hints,
1406 )
1407 })
1408 })
1409 }
1410
1411 fn check_for_shadowed_autorefd_method(
1427 &self,
1428 possible_shadower: &Pick<'tcx>,
1429 step: &CandidateStep<'tcx>,
1430 self_ty: Ty<'tcx>,
1431 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1432 mutbl: hir::Mutability,
1433 track_unstable_candidates: bool,
1434 ) -> Result<(), MethodError<'tcx>> {
1435 if !self.tcx.features().arbitrary_self_types()
1439 && !self.tcx.features().arbitrary_self_types_pointers()
1440 {
1441 return Ok(());
1442 }
1443
1444 let mut pick_diag_hints = PickDiagHints {
1449 unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1450 unsatisfied_predicates: &mut Vec::new(),
1451 };
1452 let pick_constraints = PickConstraintsForShadowed {
1454 autoderefs: possible_shadower.autoderefs,
1456 receiver_steps: possible_shadower.receiver_steps,
1460 def_id: possible_shadower.item.def_id,
1463 };
1464 let potentially_shadowed_pick = self.pick_autorefd_method(
1494 step,
1495 self_ty,
1496 instantiate_self_ty_obligations,
1497 mutbl,
1498 &mut pick_diag_hints,
1499 Some(&pick_constraints),
1500 );
1501 if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1504 let sources = [possible_shadower, possible_shadowed]
1505 .into_iter()
1506 .map(|p| self.candidate_source_from_pick(p))
1507 .collect();
1508 return Err(MethodError::Ambiguity(sources));
1509 }
1510 Ok(())
1511 }
1512
1513 fn pick_by_value_method(
1520 &self,
1521 step: &CandidateStep<'tcx>,
1522 self_ty: Ty<'tcx>,
1523 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1524 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1525 ) -> Option<PickResult<'tcx>> {
1526 if step.unsize {
1527 return None;
1528 }
1529
1530 self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1531 r.map(|mut pick| {
1532 pick.autoderefs = step.autoderefs;
1533
1534 match *step.self_ty.value.value.kind() {
1535 ty::Ref(_, _, mutbl) => {
1537 pick.autoderefs += 1;
1538 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1539 mutbl,
1540 unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1541 })
1542 }
1543
1544 ty::Adt(def, args)
1545 if self.tcx.features().pin_ergonomics()
1546 && self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) =>
1547 {
1548 if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1550 pick.autoref_or_ptr_adjustment =
1551 Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1552 }
1553 }
1554
1555 _ => (),
1556 }
1557
1558 pick
1559 })
1560 })
1561 }
1562
1563 fn pick_autorefd_method(
1564 &self,
1565 step: &CandidateStep<'tcx>,
1566 self_ty: Ty<'tcx>,
1567 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1568 mutbl: hir::Mutability,
1569 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1570 pick_constraints: Option<&PickConstraintsForShadowed>,
1571 ) -> Option<PickResult<'tcx>> {
1572 let tcx = self.tcx;
1573
1574 if let Some(pick_constraints) = pick_constraints {
1575 if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1576 return None;
1577 }
1578 }
1579
1580 let region = tcx.lifetimes.re_erased;
1582
1583 let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1584 self.pick_method(
1585 autoref_ty,
1586 instantiate_self_ty_obligations,
1587 pick_diag_hints,
1588 pick_constraints,
1589 )
1590 .map(|r| {
1591 r.map(|mut pick| {
1592 pick.autoderefs = step.autoderefs;
1593 pick.autoref_or_ptr_adjustment =
1594 Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1595 pick
1596 })
1597 })
1598 }
1599
1600 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("pick_reborrow_pin_method",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1601u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["self_ty",
"instantiate_self_ty_obligations"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&instantiate_self_ty_obligations)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Option<PickResult<'tcx>> =
loop {};
return __tracing_attr_fake_return;
}
{
if !self.tcx.features().pin_ergonomics() { return None; }
let inner_ty =
match self_ty.kind() {
ty::Adt(def, args) if
self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => {
match args[0].expect_ty().kind() {
ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
_ => { return None; }
}
}
_ => return None,
};
let region = self.tcx.lifetimes.re_erased;
let autopin_ty =
Ty::new_pinned_ref(self.tcx, region, inner_ty,
hir::Mutability::Not);
self.pick_method(autopin_ty, instantiate_self_ty_obligations,
pick_diag_hints,
None).map(|r|
{
r.map(|mut pick|
{
pick.autoderefs = step.autoderefs;
pick.autoref_or_ptr_adjustment =
Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
pick
})
})
}
}
}#[instrument(level = "debug", skip(self, step, pick_diag_hints))]
1602 fn pick_reborrow_pin_method(
1603 &self,
1604 step: &CandidateStep<'tcx>,
1605 self_ty: Ty<'tcx>,
1606 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1607 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1608 ) -> Option<PickResult<'tcx>> {
1609 if !self.tcx.features().pin_ergonomics() {
1610 return None;
1611 }
1612
1613 let inner_ty = match self_ty.kind() {
1615 ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => {
1616 match args[0].expect_ty().kind() {
1617 ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1618 _ => {
1619 return None;
1620 }
1621 }
1622 }
1623 _ => return None,
1624 };
1625
1626 let region = self.tcx.lifetimes.re_erased;
1627 let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1628 self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1629 |r| {
1630 r.map(|mut pick| {
1631 pick.autoderefs = step.autoderefs;
1632 pick.autoref_or_ptr_adjustment =
1633 Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1634 pick
1635 })
1636 },
1637 )
1638 }
1639
1640 fn pick_const_ptr_method(
1644 &self,
1645 step: &CandidateStep<'tcx>,
1646 self_ty: Ty<'tcx>,
1647 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1648 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1649 ) -> Option<PickResult<'tcx>> {
1650 if step.unsize {
1652 return None;
1653 }
1654
1655 let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1656 return None;
1657 };
1658
1659 let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1660 self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1661 |r| {
1662 r.map(|mut pick| {
1663 pick.autoderefs = step.autoderefs;
1664 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1665 pick
1666 })
1667 },
1668 )
1669 }
1670
1671 fn pick_method(
1672 &self,
1673 self_ty: Ty<'tcx>,
1674 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1675 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1676 pick_constraints: Option<&PickConstraintsForShadowed>,
1677 ) -> Option<PickResult<'tcx>> {
1678 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1678",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1678u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("pick_method(self_ty={0})",
self.ty_to_string(self_ty)) as &dyn Value))])
});
} else { ; }
};debug!("pick_method(self_ty={})", self.ty_to_string(self_ty));
1679
1680 for (kind, candidates) in
1681 [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1682 {
1683 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1683",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1683u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("searching {0} candidates",
kind) as &dyn Value))])
});
} else { ; }
};debug!("searching {} candidates", kind);
1684 let res = self.consider_candidates(
1685 self_ty,
1686 instantiate_self_ty_obligations,
1687 candidates,
1688 pick_diag_hints,
1689 pick_constraints,
1690 );
1691 if let Some(pick) = res {
1692 return Some(pick);
1693 }
1694 }
1695
1696 if self.private_candidate.get().is_none() {
1697 if let Some(Ok(pick)) = self.consider_candidates(
1698 self_ty,
1699 instantiate_self_ty_obligations,
1700 &self.private_candidates,
1701 &mut PickDiagHints {
1702 unstable_candidates: None,
1703 unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1704 },
1705 None,
1706 ) {
1707 self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1708 }
1709 }
1710 None
1711 }
1712
1713 fn consider_candidates(
1714 &self,
1715 self_ty: Ty<'tcx>,
1716 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1717 candidates: &[Candidate<'tcx>],
1718 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1719 pick_constraints: Option<&PickConstraintsForShadowed>,
1720 ) -> Option<PickResult<'tcx>> {
1721 let mut applicable_candidates: Vec<_> = candidates
1722 .iter()
1723 .filter(|candidate| {
1724 pick_constraints
1725 .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1726 .unwrap_or(true)
1727 })
1728 .map(|probe| {
1729 (
1730 probe,
1731 self.consider_probe(
1732 self_ty,
1733 instantiate_self_ty_obligations,
1734 probe,
1735 &mut pick_diag_hints.unsatisfied_predicates,
1736 ),
1737 )
1738 })
1739 .filter(|&(_, status)| status != ProbeResult::NoMatch)
1740 .collect();
1741
1742 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:1742",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(1742u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("applicable_candidates: {0:?}",
applicable_candidates) as &dyn Value))])
});
} else { ; }
};debug!("applicable_candidates: {:?}", applicable_candidates);
1743
1744 if applicable_candidates.len() > 1 {
1745 if let Some(pick) =
1746 self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1747 {
1748 return Some(Ok(pick));
1749 }
1750 }
1751
1752 if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1753 applicable_candidates.retain(|&(candidate, _)| {
1754 if let stability::EvalResult::Deny { feature, .. } =
1755 self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1756 {
1757 uc.push((candidate.clone(), feature));
1758 return false;
1759 }
1760 true
1761 });
1762 }
1763
1764 if applicable_candidates.len() > 1 {
1765 if self.tcx.features().supertrait_item_shadowing() {
1769 if let Some(pick) =
1770 self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1771 {
1772 return Some(Ok(pick));
1773 }
1774 }
1775
1776 let sources =
1777 applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1778 return Some(Err(MethodError::Ambiguity(sources)));
1779 }
1780
1781 applicable_candidates.pop().map(|(probe, status)| match status {
1782 ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1783 self_ty,
1784 pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1785 )),
1786 ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1787 })
1788 }
1789}
1790
1791impl<'tcx> Pick<'tcx> {
1792 pub(crate) fn differs_from(&self, other: &Self) -> bool {
1797 let Self {
1798 item: AssocItem { def_id, kind: _, container: _ },
1799 kind: _,
1800 import_ids: _,
1801 autoderefs: _,
1802 autoref_or_ptr_adjustment: _,
1803 self_ty,
1804 unstable_candidates: _,
1805 receiver_steps: _,
1806 shadowed_candidates: _,
1807 } = *self;
1808 self_ty != other.self_ty || def_id != other.item.def_id
1809 }
1810
1811 pub(crate) fn maybe_emit_unstable_name_collision_hint(
1813 &self,
1814 tcx: TyCtxt<'tcx>,
1815 span: Span,
1816 scope_expr_id: HirId,
1817 ) {
1818 struct ItemMaybeBeAddedToStd<'a, 'tcx> {
1819 this: &'a Pick<'tcx>,
1820 tcx: TyCtxt<'tcx>,
1821 span: Span,
1822 }
1823
1824 impl<'a, 'b, 'tcx> Diagnostic<'a, ()> for ItemMaybeBeAddedToStd<'b, 'tcx> {
1825 fn into_diag(self, dcx: DiagCtxtHandle<'a>, level: Level) -> Diag<'a, ()> {
1826 let Self { this, tcx, span } = self;
1827 let def_kind = this.item.as_def_kind();
1828 let mut lint = Diag::new(
1829 dcx,
1830 level,
1831 ::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!(
1832 "{} {} with this name may be added to the standard library in the future",
1833 tcx.def_kind_descr_article(def_kind, this.item.def_id),
1834 tcx.def_kind_descr(def_kind, this.item.def_id),
1835 ),
1836 );
1837
1838 match (this.item.kind, this.item.container) {
1839 (ty::AssocKind::Fn { .. }, _) => {
1840 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!(
1845 "call with fully qualified syntax `{}(...)` to keep using the current \
1846 method",
1847 tcx.def_path_str(this.item.def_id),
1848 ));
1849 }
1850 (ty::AssocKind::Const { name, .. }, ty::AssocContainer::Trait) => {
1851 let def_id = this.item.container_id(tcx);
1852 lint.span_suggestion(
1853 span,
1854 "use the fully qualified path to the associated const",
1855 ::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),
1856 Applicability::MachineApplicable,
1857 );
1858 }
1859 _ => {}
1860 }
1861 tcx.disabled_nightly_features(
1862 &mut lint,
1863 this.unstable_candidates.iter().map(|(candidate, feature)| {
1864 (::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)
1865 }),
1866 );
1867 lint
1868 }
1869 }
1870
1871 if self.unstable_candidates.is_empty() {
1872 return;
1873 }
1874 tcx.emit_node_span_lint(
1875 lint::builtin::UNSTABLE_NAME_COLLISIONS,
1876 scope_expr_id,
1877 span,
1878 ItemMaybeBeAddedToStd { this: self, tcx, span },
1879 );
1880 }
1881}
1882
1883impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1884 fn select_trait_candidate(
1885 &self,
1886 trait_ref: ty::TraitRef<'tcx>,
1887 ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1888 let obligation =
1889 traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1890 traits::SelectionContext::new(self).select(&obligation)
1891 }
1892
1893 fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1896 match candidate.kind {
1897 InherentImplCandidate { .. } => {
1898 CandidateSource::Impl(candidate.item.container_id(self.tcx))
1899 }
1900 ObjectCandidate(_) | WhereClauseCandidate(_) => {
1901 CandidateSource::Trait(candidate.item.container_id(self.tcx))
1902 }
1903 TraitCandidate(trait_ref, _) => self.probe(|_| {
1904 let trait_ref = self.instantiate_binder_with_fresh_vars(
1905 self.span,
1906 BoundRegionConversionTime::FnCall,
1907 trait_ref,
1908 );
1909 let (xform_self_ty, _) =
1910 self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1911 let _ = self.at(&ObligationCause::dummy(), self.param_env).sup(
1914 DefineOpaqueTypes::Yes,
1915 xform_self_ty,
1916 self_ty,
1917 );
1918 match self.select_trait_candidate(trait_ref) {
1919 Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
1920 CandidateSource::Impl(impl_data.impl_def_id)
1923 }
1924 _ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
1925 }
1926 }),
1927 }
1928 }
1929
1930 fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
1931 match pick.kind {
1932 InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1933 ObjectPick | WhereClausePick(_) | TraitPick(_) => {
1934 CandidateSource::Trait(pick.item.container_id(self.tcx))
1935 }
1936 }
1937 }
1938
1939 x;#[instrument(level = "debug", skip(self, possibly_unsatisfied_predicates), ret)]
1940 fn consider_probe(
1941 &self,
1942 self_ty: Ty<'tcx>,
1943 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1944 probe: &Candidate<'tcx>,
1945 possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1946 ) -> ProbeResult {
1947 self.probe(|snapshot| {
1948 let outer_universe = self.universe();
1949
1950 let mut result = ProbeResult::Match;
1951 let cause = &self.misc(self.span);
1952 let ocx = ObligationCtxt::new_with_diagnostics(self);
1953
1954 if self.next_trait_solver() {
1962 ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
1963 let errors = ocx.try_evaluate_obligations();
1964 if !errors.is_empty() {
1965 unreachable!("unexpected autoderef error {errors:?}");
1966 }
1967 }
1968
1969 let mut trait_predicate = None;
1970 let (mut xform_self_ty, mut xform_ret_ty);
1971
1972 match probe.kind {
1973 InherentImplCandidate { impl_def_id, .. } => {
1974 let impl_args = self.fresh_args_for_item(self.span, impl_def_id);
1975 let impl_ty = self
1976 .tcx
1977 .type_of(impl_def_id)
1978 .instantiate(self.tcx, impl_args)
1979 .skip_norm_wip();
1980 (xform_self_ty, xform_ret_ty) =
1981 self.xform_self_ty(probe.item, impl_ty, impl_args);
1982 xform_self_ty =
1983 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
1984 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
1985 {
1986 Ok(()) => {}
1987 Err(err) => {
1988 debug!("--> cannot relate self-types {:?}", err);
1989 return ProbeResult::NoMatch;
1990 }
1991 }
1992 xform_ret_ty =
1994 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
1995 let impl_def_id = probe.item.container_id(self.tcx);
1997 let impl_bounds =
1998 self.tcx.predicates_of(impl_def_id).instantiate(self.tcx, impl_args);
1999 ocx.register_obligations(traits::predicates_for_generics(
2001 |idx, span| {
2002 let code = ObligationCauseCode::WhereClauseInExpr(
2003 impl_def_id,
2004 span,
2005 self.scope_expr_id,
2006 idx,
2007 );
2008 self.cause(self.span, code)
2009 },
2010 |pred| ocx.normalize(cause, self.param_env, pred),
2011 self.param_env,
2012 impl_bounds,
2013 ));
2014 }
2015 TraitCandidate(poly_trait_ref, _) => {
2016 if let Some(method_name) = self.method_name {
2019 if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
2020 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2021 if trait_def.skip_array_during_method_dispatch {
2022 return ProbeResult::NoMatch;
2023 }
2024 }
2025
2026 if self_ty.boxed_ty().is_some_and(Ty::is_slice)
2029 && !method_name.span.at_least_rust_2024()
2030 {
2031 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2032 if trait_def.skip_boxed_slice_during_method_dispatch {
2033 return ProbeResult::NoMatch;
2034 }
2035 }
2036 }
2037
2038 let trait_ref = self.instantiate_binder_with_fresh_vars(
2039 self.span,
2040 BoundRegionConversionTime::FnCall,
2041 poly_trait_ref,
2042 );
2043 let trait_ref =
2044 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(trait_ref));
2045 (xform_self_ty, xform_ret_ty) =
2046 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2047 xform_self_ty =
2048 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2049 match self_ty.kind() {
2050 &ty::Alias(ty::AliasTy { kind: ty::Opaque { def_id }, .. })
2054 if !self.next_trait_solver()
2055 && self.infcx.can_define_opaque_ty(def_id)
2056 && !xform_self_ty.is_ty_var() =>
2057 {
2058 return ProbeResult::NoMatch;
2059 }
2060 _ => match ocx.relate(
2061 cause,
2062 self.param_env,
2063 self.variance(),
2064 self_ty,
2065 xform_self_ty,
2066 ) {
2067 Ok(()) => {}
2068 Err(err) => {
2069 debug!("--> cannot relate self-types {:?}", err);
2070 return ProbeResult::NoMatch;
2071 }
2072 },
2073 }
2074 let obligation = traits::Obligation::new(
2075 self.tcx,
2076 cause.clone(),
2077 self.param_env,
2078 ty::Binder::dummy(trait_ref),
2079 );
2080
2081 if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
2083 {
2084 ocx.register_obligation(obligation);
2085 } else {
2086 result = ProbeResult::NoMatch;
2087 if let Ok(Some(candidate)) = self.select_trait_candidate(trait_ref) {
2088 for nested_obligation in candidate.nested_obligations() {
2089 if !self.infcx.predicate_may_hold(&nested_obligation) {
2090 possibly_unsatisfied_predicates.push((
2091 self.resolve_vars_if_possible(nested_obligation.predicate),
2092 Some(self.resolve_vars_if_possible(obligation.predicate)),
2093 Some(nested_obligation.cause),
2094 ));
2095 }
2096 }
2097 }
2098 }
2099
2100 trait_predicate = Some(trait_ref.upcast(self.tcx));
2101 }
2102 ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
2103 let trait_ref = self.instantiate_binder_with_fresh_vars(
2104 self.span,
2105 BoundRegionConversionTime::FnCall,
2106 poly_trait_ref,
2107 );
2108 (xform_self_ty, xform_ret_ty) =
2109 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2110
2111 if matches!(probe.kind, WhereClauseCandidate(_)) {
2112 match ocx.structurally_normalize_ty(
2116 cause,
2117 self.param_env,
2118 Unnormalized::new_wip(trait_ref.self_ty()),
2119 ) {
2120 Ok(ty) => {
2121 if !matches!(ty.kind(), ty::Param(_)) {
2122 debug!("--> not a param ty: {xform_self_ty:?}");
2123 return ProbeResult::NoMatch;
2124 }
2125 }
2126 Err(errors) => {
2127 debug!("--> cannot relate self-types {:?}", errors);
2128 return ProbeResult::NoMatch;
2129 }
2130 }
2131 }
2132
2133 xform_self_ty =
2134 ocx.normalize(cause, self.param_env, Unnormalized::new_wip(xform_self_ty));
2135 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2136 {
2137 Ok(()) => {}
2138 Err(err) => {
2139 debug!("--> cannot relate self-types {:?}", err);
2140 return ProbeResult::NoMatch;
2141 }
2142 }
2143 }
2144 }
2145
2146 if let Some(xform_ret_ty) = xform_ret_ty
2158 && self.infcx.next_trait_solver()
2159 {
2160 ocx.register_obligation(traits::Obligation::new(
2161 self.tcx,
2162 cause.clone(),
2163 self.param_env,
2164 ty::ClauseKind::WellFormed(xform_ret_ty.into()),
2165 ));
2166 }
2167
2168 for error in ocx.try_evaluate_obligations() {
2170 result = ProbeResult::NoMatch;
2171 let nested_predicate = self.resolve_vars_if_possible(error.obligation.predicate);
2172 if let Some(trait_predicate) = trait_predicate
2173 && nested_predicate == self.resolve_vars_if_possible(trait_predicate)
2174 {
2175 } else {
2179 possibly_unsatisfied_predicates.push((
2180 nested_predicate,
2181 Some(self.resolve_vars_if_possible(error.root_obligation.predicate))
2182 .filter(|root_predicate| *root_predicate != nested_predicate),
2183 Some(error.obligation.cause),
2184 ));
2185 }
2186 }
2187
2188 if let ProbeResult::Match = result
2189 && let Some(return_ty) = self.return_type
2190 && let Some(mut xform_ret_ty) = xform_ret_ty
2191 {
2192 if !matches!(probe.kind, InherentImplCandidate { .. }) {
2197 xform_ret_ty =
2198 ocx.normalize(&cause, self.param_env, Unnormalized::new_wip(xform_ret_ty));
2199 }
2200
2201 debug!("comparing return_ty {:?} with xform ret ty {:?}", return_ty, xform_ret_ty);
2202 match ocx.relate(cause, self.param_env, self.variance(), xform_ret_ty, return_ty) {
2203 Ok(()) => {}
2204 Err(_) => {
2205 result = ProbeResult::BadReturnType;
2206 }
2207 }
2208
2209 for error in ocx.try_evaluate_obligations() {
2211 result = ProbeResult::NoMatch;
2212 possibly_unsatisfied_predicates.push((
2213 error.obligation.predicate,
2214 Some(error.root_obligation.predicate)
2215 .filter(|predicate| *predicate != error.obligation.predicate),
2216 Some(error.root_obligation.cause),
2217 ));
2218 }
2219 }
2220
2221 if self.infcx.next_trait_solver() {
2222 if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
2223 result = ProbeResult::NoMatch;
2224 }
2225 }
2226
2227 if let Err(_) = self.leak_check(outer_universe, Some(snapshot)) {
2233 result = ProbeResult::NoMatch;
2234 }
2235
2236 result
2237 })
2238 }
2239
2240 x;#[instrument(level = "debug", skip(self), ret)]
2255 fn should_reject_candidate_due_to_opaque_treated_as_rigid(
2256 &self,
2257 trait_predicate: Option<ty::Predicate<'tcx>>,
2258 ) -> bool {
2259 if let Some(predicate) = trait_predicate {
2271 let goal = Goal { param_env: self.param_env, predicate };
2272 if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
2273 return true;
2274 }
2275 }
2276
2277 for step in self.steps {
2280 if step.self_ty_is_opaque {
2281 debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
2282 let constrained_opaque = self.probe(|_| {
2283 let Ok(ok) = self.fcx.probe_instantiate_query_response(
2288 self.span,
2289 self.orig_steps_var_values,
2290 &step.self_ty,
2291 ) else {
2292 debug!("failed to instantiate self_ty");
2293 return false;
2294 };
2295 let ocx = ObligationCtxt::new(self);
2296 let self_ty = ocx.register_infer_ok_obligations(ok);
2297 if !ocx.try_evaluate_obligations().is_empty() {
2298 debug!("failed to prove instantiate self_ty obligations");
2299 return false;
2300 }
2301
2302 !self.resolve_vars_if_possible(self_ty).is_ty_var()
2303 });
2304 if constrained_opaque {
2305 debug!("opaque type has been constrained");
2306 return true;
2307 }
2308 }
2309 }
2310
2311 false
2312 }
2313
2314 fn collapse_candidates_to_trait_pick(
2332 &self,
2333 self_ty: Ty<'tcx>,
2334 probes: &[(&Candidate<'tcx>, ProbeResult)],
2335 ) -> Option<Pick<'tcx>> {
2336 let container = probes[0].0.item.trait_container(self.tcx)?;
2338 for (p, _) in &probes[1..] {
2339 let p_container = p.item.trait_container(self.tcx)?;
2340 if p_container != container {
2341 return None;
2342 }
2343 }
2344
2345 let lint_ambiguous = match probes[0].0.kind {
2346 TraitCandidate(_, lint) => lint,
2347 _ => false,
2348 };
2349
2350 Some(Pick {
2353 item: probes[0].0.item,
2354 kind: TraitPick(lint_ambiguous),
2355 import_ids: probes[0].0.import_ids,
2356 autoderefs: 0,
2357 autoref_or_ptr_adjustment: None,
2358 self_ty,
2359 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2360 receiver_steps: None,
2361 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2362 })
2363 }
2364
2365 fn collapse_candidates_to_subtrait_pick(
2371 &self,
2372 self_ty: Ty<'tcx>,
2373 probes: &[(&Candidate<'tcx>, ProbeResult)],
2374 ) -> Option<Pick<'tcx>> {
2375 let mut child_candidate = probes[0].0;
2376 let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2377 let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2378
2379 let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2380 while !remaining_candidates.is_empty() {
2381 let mut made_progress = false;
2382 let mut next_round = ::alloc::vec::Vec::new()vec![];
2383
2384 for remaining_candidate in remaining_candidates {
2385 let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2386 if supertraits.contains(&remaining_trait) {
2387 made_progress = true;
2388 continue;
2389 }
2390
2391 let remaining_trait_supertraits: SsoHashSet<_> =
2397 supertrait_def_ids(self.tcx, remaining_trait).collect();
2398 if remaining_trait_supertraits.contains(&child_trait) {
2399 child_candidate = remaining_candidate;
2400 child_trait = remaining_trait;
2401 supertraits = remaining_trait_supertraits;
2402 made_progress = true;
2403 continue;
2404 }
2405
2406 next_round.push(remaining_candidate);
2413 }
2414
2415 if made_progress {
2416 remaining_candidates = next_round;
2418 } else {
2419 return None;
2422 }
2423 }
2424
2425 let lint_ambiguous = match probes[0].0.kind {
2426 TraitCandidate(_, lint) => lint,
2427 _ => false,
2428 };
2429
2430 Some(Pick {
2431 item: child_candidate.item,
2432 kind: TraitPick(lint_ambiguous),
2433 import_ids: child_candidate.import_ids,
2434 autoderefs: 0,
2435 autoref_or_ptr_adjustment: None,
2436 self_ty,
2437 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2438 shadowed_candidates: probes
2439 .iter()
2440 .map(|(c, _)| c.item)
2441 .filter(|item| item.def_id != child_candidate.item.def_id)
2442 .collect(),
2443 receiver_steps: None,
2444 })
2445 }
2446
2447 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("probe_for_similar_candidate",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2450u32),
::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(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return:
Result<Option<ty::AssocItem>, MethodError<'tcx>> = loop {};
return __tracing_attr_fake_return;
}
{
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2454",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2454u32),
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("probing for method names similar to {0:?}",
self.method_name) as &dyn Value))])
});
} else { ; }
};
self.probe(|_|
{
let mut pcx =
ProbeContext::new(self.fcx, self.span, self.mode,
self.method_name, self.return_type,
self.orig_steps_var_values, self.steps, self.scope_expr_id,
IsSuggestion(true));
pcx.allow_similar_names = true;
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_all_traits();
let method_names = pcx.candidate_method_names(|_| true);
pcx.allow_similar_names = false;
let applicable_close_candidates: Vec<ty::AssocItem> =
method_names.iter().filter_map(|&method_name|
{
pcx.reset();
pcx.method_name = Some(method_name);
pcx.assemble_inherent_candidates();
pcx.assemble_extension_candidates_for_all_traits();
pcx.pick_core(&mut Vec::new()).and_then(|pick|
pick.ok()).map(|pick| pick.item)
}).collect();
if applicable_close_candidates.is_empty() {
Ok(None)
} else {
let best_name =
{
let names =
applicable_close_candidates.iter().map(|cand|
cand.name()).collect::<Vec<Symbol>>();
find_best_match_for_name_with_substrings(&names,
self.method_name.unwrap().name, None)
}.or_else(||
{
applicable_close_candidates.iter().find(|cand|
self.matches_by_doc_alias(cand.def_id)).map(|cand|
cand.name())
});
Ok(best_name.and_then(|best_name|
{
applicable_close_candidates.into_iter().find(|method|
method.name() == best_name)
}))
}
})
}
}
}#[instrument(level = "debug", skip(self))]
2451 pub(crate) fn probe_for_similar_candidate(
2452 &mut self,
2453 ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2454 debug!("probing for method names similar to {:?}", self.method_name);
2455
2456 self.probe(|_| {
2457 let mut pcx = ProbeContext::new(
2458 self.fcx,
2459 self.span,
2460 self.mode,
2461 self.method_name,
2462 self.return_type,
2463 self.orig_steps_var_values,
2464 self.steps,
2465 self.scope_expr_id,
2466 IsSuggestion(true),
2467 );
2468 pcx.allow_similar_names = true;
2469 pcx.assemble_inherent_candidates();
2470 pcx.assemble_extension_candidates_for_all_traits();
2471
2472 let method_names = pcx.candidate_method_names(|_| true);
2473 pcx.allow_similar_names = false;
2474 let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2475 .iter()
2476 .filter_map(|&method_name| {
2477 pcx.reset();
2478 pcx.method_name = Some(method_name);
2479 pcx.assemble_inherent_candidates();
2480 pcx.assemble_extension_candidates_for_all_traits();
2481 pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2482 })
2483 .collect();
2484
2485 if applicable_close_candidates.is_empty() {
2486 Ok(None)
2487 } else {
2488 let best_name = {
2489 let names = applicable_close_candidates
2490 .iter()
2491 .map(|cand| cand.name())
2492 .collect::<Vec<Symbol>>();
2493 find_best_match_for_name_with_substrings(
2494 &names,
2495 self.method_name.unwrap().name,
2496 None,
2497 )
2498 }
2499 .or_else(|| {
2500 applicable_close_candidates
2501 .iter()
2502 .find(|cand| self.matches_by_doc_alias(cand.def_id))
2503 .map(|cand| cand.name())
2504 });
2505 Ok(best_name.and_then(|best_name| {
2506 applicable_close_candidates
2507 .into_iter()
2508 .find(|method| method.name() == best_name)
2509 }))
2510 }
2511 })
2512 }
2513
2514 fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2517 match self.mode {
2523 Mode::MethodCall => item.is_method(),
2524 Mode::Path => match item.kind {
2525 ty::AssocKind::Type { .. } => false,
2526 ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2527 },
2528 }
2529 }
2536
2537 fn record_static_candidate(&self, source: CandidateSource) {
2538 self.static_candidates.borrow_mut().push(source);
2539 }
2540
2541 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("xform_self_ty",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2541u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["item", "impl_ty",
"args"], ::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&item)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&impl_ty)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn 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);
(sig.inputs()[0], Some(sig.output()))
} else { (impl_ty, None) }
}
}
}#[instrument(level = "debug", skip(self))]
2542 fn xform_self_ty(
2543 &self,
2544 item: ty::AssocItem,
2545 impl_ty: Ty<'tcx>,
2546 args: GenericArgsRef<'tcx>,
2547 ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2548 if item.is_fn() && self.mode == Mode::MethodCall {
2549 let sig = self.xform_method_sig(item.def_id, args);
2550 (sig.inputs()[0], Some(sig.output()))
2551 } else {
2552 (impl_ty, None)
2553 }
2554 }
2555
2556 #[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("xform_method_sig",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2556u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["method", "args"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&method)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&args)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ty::FnSig<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let fn_sig = self.tcx.fn_sig(method);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/method/probe.rs:2559",
"rustc_hir_typeck::method::probe", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/method/probe.rs"),
::tracing_core::__macro_support::Option::Some(2559u32),
::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::method::probe"),
::tracing_core::field::FieldSet::new(&["fn_sig"],
::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};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&debug(&fn_sig) as
&dyn 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))]
2557 fn xform_method_sig(&self, method: DefId, args: GenericArgsRef<'tcx>) -> ty::FnSig<'tcx> {
2558 let fn_sig = self.tcx.fn_sig(method);
2559 debug!(?fn_sig);
2560
2561 assert!(!args.has_escaping_bound_vars());
2562
2563 let generics = self.tcx.generics_of(method);
2569 assert_eq!(args.len(), generics.parent_count);
2570
2571 let xform_fn_sig = if generics.is_own_empty() {
2572 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2573 } else {
2574 let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2575 let i = param.index as usize;
2576 if i < args.len() {
2577 args[i]
2578 } else {
2579 match param.kind {
2580 GenericParamDefKind::Lifetime => {
2581 self.tcx.lifetimes.re_erased.into()
2583 }
2584 GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2585 self.var_for_def(self.span, param)
2586 }
2587 }
2588 }
2589 });
2590 fn_sig.instantiate(self.tcx, args).skip_norm_wip()
2591 };
2592
2593 self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2594 }
2595
2596 fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2598 match (self.mode, kind) {
2599 (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2600 (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2601 _ => false,
2602 }
2603 }
2604
2605 fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2608 let Some(method) = self.method_name else {
2609 return false;
2610 };
2611
2612 if let Some(d) = {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(Doc(d)) => {
break 'done Some(d);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, Doc(d) => d)
2613 && d.aliases.contains_key(&method.name)
2614 {
2615 return true;
2616 }
2617
2618 if let Some(confusables) =
2619 {
{
'done:
{
for i in
::rustc_hir::attrs::HasAttrs::get_attrs(def_id, &self.tcx) {
#[allow(unused_imports)]
use rustc_hir::attrs::AttributeKind::*;
let i: &rustc_hir::Attribute = i;
match i {
rustc_hir::Attribute::Parsed(RustcConfusables { confusables
}) => {
break 'done Some(confusables);
}
rustc_hir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}find_attr!(self.tcx, def_id, RustcConfusables{ confusables } => confusables)
2620 && confusables.contains(&method.name)
2621 {
2622 return true;
2623 }
2624
2625 false
2626 }
2627
2628 fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2633 if let Some(name) = self.method_name {
2634 if self.allow_similar_names {
2635 let max_dist = max(name.as_str().len(), 3) / 3;
2636 self.tcx
2637 .associated_items(def_id)
2638 .in_definition_order()
2639 .filter(|x| {
2640 if !self.is_relevant_kind_for_mode(x.kind) {
2641 return false;
2642 }
2643 if let Some(d) = edit_distance_with_substrings(
2644 name.as_str(),
2645 x.name().as_str(),
2646 max_dist,
2647 ) {
2648 return d > 0;
2649 }
2650 self.matches_by_doc_alias(x.def_id)
2651 })
2652 .copied()
2653 .collect()
2654 } else {
2655 self.fcx
2656 .associated_value(def_id, name)
2657 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2658 .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2659 }
2660 } else {
2661 self.tcx
2662 .associated_items(def_id)
2663 .in_definition_order()
2664 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2665 .copied()
2666 .collect()
2667 }
2668 }
2669}
2670
2671impl<'tcx> Candidate<'tcx> {
2672 fn to_unadjusted_pick(
2673 &self,
2674 self_ty: Ty<'tcx>,
2675 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2676 ) -> Pick<'tcx> {
2677 Pick {
2678 item: self.item,
2679 kind: match self.kind {
2680 InherentImplCandidate { .. } => InherentImplPick,
2681 ObjectCandidate(_) => ObjectPick,
2682 TraitCandidate(_, lint_ambiguous) => TraitPick(lint_ambiguous),
2683 WhereClauseCandidate(trait_ref) => {
2684 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!(
2690 !trait_ref.skip_binder().args.has_infer()
2691 && !trait_ref.skip_binder().args.has_placeholders()
2692 );
2693
2694 WhereClausePick(trait_ref)
2695 }
2696 },
2697 import_ids: self.import_ids,
2698 autoderefs: 0,
2699 autoref_or_ptr_adjustment: None,
2700 self_ty,
2701 unstable_candidates,
2702 receiver_steps: match self.kind {
2703 InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2704 _ => None,
2705 },
2706 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2707 }
2708 }
2709}