1use std::cell::{Cell, RefCell};
2use std::cmp::max;
3use std::ops::Deref;
4
5use rustc_data_structures::debug_assert_matches;
6use rustc_data_structures::fx::FxHashSet;
7use rustc_data_structures::sso::SsoHashSet;
8use rustc_errors::Applicability;
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_middle::middle::stability;
16use rustc_middle::ty::elaborate::supertrait_def_ids;
17use rustc_middle::ty::fast_reject::{DeepRejectCtxt, TreatParams, simplify_type};
18use rustc_middle::ty::{
19 self, AssocContainer, AssocItem, GenericArgs, GenericArgsRef, GenericParamDefKind, ParamEnvAnd,
20 Ty, TyCtxt, TypeVisitableExt, Upcast,
21};
22use rustc_middle::{bug, span_bug};
23use rustc_session::lint;
24use rustc_span::def_id::{DefId, LocalDefId};
25use rustc_span::edit_distance::{
26 edit_distance_with_substrings, find_best_match_for_name_with_substrings,
27};
28use rustc_span::{DUMMY_SP, Ident, Span, Symbol, sym};
29use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
30use rustc_trait_selection::infer::InferCtxtExt as _;
31use rustc_trait_selection::solve::Goal;
32use rustc_trait_selection::traits::query::CanonicalMethodAutoderefStepsGoal;
33use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
34use rustc_trait_selection::traits::query::method_autoderef::{
35 CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
36};
37use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
38use smallvec::{SmallVec, smallvec};
39use tracing::{debug, instrument};
40
41use self::CandidateKind::*;
42pub(crate) use self::PickKind::*;
43use super::{CandidateSource, MethodError, NoMatchData, suggest};
44use crate::FnCtxt;
45
46#[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)]
49pub(crate) struct IsSuggestion(pub bool);
50
51pub(crate) struct ProbeContext<'a, 'tcx> {
52 fcx: &'a FnCtxt<'a, 'tcx>,
53 span: Span,
54 mode: Mode,
55 method_name: Option<Ident>,
56 return_type: Option<Ty<'tcx>>,
57
58 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
61 steps: &'tcx [CandidateStep<'tcx>],
62
63 inherent_candidates: Vec<Candidate<'tcx>>,
64 extension_candidates: Vec<Candidate<'tcx>>,
65 impl_dups: FxHashSet<DefId>,
66
67 allow_similar_names: bool,
70
71 private_candidates: Vec<Candidate<'tcx>>,
74
75 private_candidate: Cell<Option<(DefKind, DefId)>>,
77
78 static_candidates: RefCell<Vec<CandidateSource>>,
81
82 scope_expr_id: HirId,
83
84 is_suggestion: IsSuggestion,
88}
89
90impl<'a, 'tcx> Deref for ProbeContext<'a, 'tcx> {
91 type Target = FnCtxt<'a, 'tcx>;
92 fn deref(&self) -> &Self::Target {
93 self.fcx
94 }
95}
96
97#[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)]
98pub(crate) struct Candidate<'tcx> {
99 pub(crate) item: ty::AssocItem,
100 pub(crate) kind: CandidateKind<'tcx>,
101 pub(crate) import_ids: SmallVec<[LocalDefId; 1]>,
102}
103
104#[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)]
105pub(crate) enum CandidateKind<'tcx> {
106 InherentImplCandidate { impl_def_id: DefId, receiver_steps: usize },
107 ObjectCandidate(ty::PolyTraitRef<'tcx>),
108 TraitCandidate(ty::PolyTraitRef<'tcx>, bool ),
109 WhereClauseCandidate(ty::PolyTraitRef<'tcx>),
110}
111
112#[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 {
#[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)]
113enum ProbeResult {
114 NoMatch,
115 BadReturnType,
116 Match,
117}
118
119#[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)]
132pub(crate) enum AutorefOrPtrAdjustment {
133 Autoref {
136 mutbl: hir::Mutability,
137
138 unsize: bool,
141 },
142 ToConstPtr,
144
145 ReborrowPin(hir::Mutability),
147}
148
149impl AutorefOrPtrAdjustment {
150 fn get_unsize(&self) -> bool {
151 match self {
152 AutorefOrPtrAdjustment::Autoref { mutbl: _, unsize } => *unsize,
153 AutorefOrPtrAdjustment::ToConstPtr => false,
154 AutorefOrPtrAdjustment::ReborrowPin(_) => false,
155 }
156 }
157}
158
159#[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)]
161struct PickDiagHints<'a, 'tcx> {
162 unstable_candidates: Option<Vec<(Candidate<'tcx>, Symbol)>>,
164
165 unsatisfied_predicates: &'a mut UnsatisfiedPredicates<'tcx>,
168}
169
170pub(crate) type UnsatisfiedPredicates<'tcx> =
171 Vec<(ty::Predicate<'tcx>, Option<ty::Predicate<'tcx>>, Option<ObligationCause<'tcx>>)>;
172
173#[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)]
177struct PickConstraintsForShadowed {
178 autoderefs: usize,
179 receiver_steps: Option<usize>,
180 def_id: DefId,
181}
182
183impl PickConstraintsForShadowed {
184 fn may_shadow_based_on_autoderefs(&self, autoderefs: usize) -> bool {
185 autoderefs == self.autoderefs
186 }
187
188 fn candidate_may_shadow(&self, candidate: &Candidate<'_>) -> bool {
189 candidate.item.def_id != self.def_id
191 && match candidate.kind {
195 CandidateKind::InherentImplCandidate { receiver_steps, .. } => match self.receiver_steps {
196 Some(shadowed_receiver_steps) => receiver_steps > shadowed_receiver_steps,
197 _ => false
198 },
199 _ => false
200 }
201 }
202}
203
204#[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)]
205pub(crate) struct Pick<'tcx> {
206 pub item: ty::AssocItem,
207 pub kind: PickKind<'tcx>,
208 pub import_ids: SmallVec<[LocalDefId; 1]>,
209
210 pub autoderefs: usize,
215
216 pub autoref_or_ptr_adjustment: Option<AutorefOrPtrAdjustment>,
219 pub self_ty: Ty<'tcx>,
220
221 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
223
224 pub receiver_steps: Option<usize>,
228
229 pub shadowed_candidates: Vec<ty::AssocItem>,
231}
232
233#[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> {
#[doc(hidden)]
#[coverage(off)]
fn assert_fields_are_eq(&self) {
let _: ::core::cmp::AssertParamIsEq<bool>;
let _: ::core::cmp::AssertParamIsEq<ty::PolyTraitRef<'tcx>>;
}
}Eq)]
234pub(crate) enum PickKind<'tcx> {
235 InherentImplPick,
236 ObjectPick,
237 TraitPick(
238 bool,
240 ),
241 WhereClausePick(
242 ty::PolyTraitRef<'tcx>,
244 ),
245}
246
247pub(crate) type PickResult<'tcx> = Result<Pick<'tcx>, MethodError<'tcx>>;
248
249#[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 {
#[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)]
250pub(crate) enum Mode {
251 MethodCall,
255 Path,
259}
260
261#[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 {
#[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)]
262pub(crate) enum ProbeScope {
263 Single(DefId),
265
266 TraitsInScope,
268
269 AllTraits,
271}
272
273impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
274 #[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(280u32),
::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))]
281 pub(crate) fn probe_for_return_type_for_diagnostic(
282 &self,
283 span: Span,
284 mode: Mode,
285 return_type: Ty<'tcx>,
286 self_ty: Ty<'tcx>,
287 scope_expr_id: HirId,
288 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
289 ) -> Vec<ty::AssocItem> {
290 let method_names = self
291 .probe_op(
292 span,
293 mode,
294 None,
295 Some(return_type),
296 IsSuggestion(true),
297 self_ty,
298 scope_expr_id,
299 ProbeScope::AllTraits,
300 |probe_cx| Ok(probe_cx.candidate_method_names(candidate_filter)),
301 )
302 .unwrap_or_default();
303 method_names
304 .iter()
305 .flat_map(|&method_name| {
306 self.probe_op(
307 span,
308 mode,
309 Some(method_name),
310 Some(return_type),
311 IsSuggestion(true),
312 self_ty,
313 scope_expr_id,
314 ProbeScope::AllTraits,
315 |probe_cx| probe_cx.pick(),
316 )
317 .ok()
318 .map(|pick| pick.item)
319 })
320 .collect()
321 }
322
323 #[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(323u32),
::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))]
324 pub(crate) fn probe_for_name(
325 &self,
326 mode: Mode,
327 item_name: Ident,
328 return_type: Option<Ty<'tcx>>,
329 is_suggestion: IsSuggestion,
330 self_ty: Ty<'tcx>,
331 scope_expr_id: HirId,
332 scope: ProbeScope,
333 ) -> PickResult<'tcx> {
334 self.probe_op(
335 item_name.span,
336 mode,
337 Some(item_name),
338 return_type,
339 is_suggestion,
340 self_ty,
341 scope_expr_id,
342 scope,
343 |probe_cx| probe_cx.pick(),
344 )
345 }
346
347 #[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(347u32),
::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))]
348 pub(crate) fn probe_for_name_many(
349 &self,
350 mode: Mode,
351 item_name: Ident,
352 return_type: Option<Ty<'tcx>>,
353 is_suggestion: IsSuggestion,
354 self_ty: Ty<'tcx>,
355 scope_expr_id: HirId,
356 scope: ProbeScope,
357 ) -> Result<Vec<Candidate<'tcx>>, MethodError<'tcx>> {
358 self.probe_op(
359 item_name.span,
360 mode,
361 Some(item_name),
362 return_type,
363 is_suggestion,
364 self_ty,
365 scope_expr_id,
366 scope,
367 |probe_cx| {
368 Ok(probe_cx
369 .inherent_candidates
370 .into_iter()
371 .chain(probe_cx.extension_candidates)
372 .collect())
373 },
374 )
375 }
376
377 pub(crate) fn probe_op<OP, R>(
378 &'a self,
379 span: Span,
380 mode: Mode,
381 method_name: Option<Ident>,
382 return_type: Option<Ty<'tcx>>,
383 is_suggestion: IsSuggestion,
384 self_ty: Ty<'tcx>,
385 scope_expr_id: HirId,
386 scope: ProbeScope,
387 op: OP,
388 ) -> Result<R, MethodError<'tcx>>
389 where
390 OP: FnOnce(ProbeContext<'_, 'tcx>) -> Result<R, MethodError<'tcx>>,
391 {
392 let mut orig_values = OriginalQueryValues::default();
393 let predefined_opaques_in_body = if self.next_trait_solver() {
394 self.tcx.mk_predefined_opaques_in_body_from_iter(
395 self.inner.borrow_mut().opaque_types().iter_opaque_types().map(|(k, v)| (k, v.ty)),
396 )
397 } else {
398 ty::List::empty()
399 };
400 let value = query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty };
401 let query_input = self
402 .canonicalize_query(ParamEnvAnd { param_env: self.param_env, value }, &mut orig_values);
403
404 let steps = match mode {
405 Mode::MethodCall => self.tcx.method_autoderef_steps(query_input),
406 Mode::Path => self.probe(|_| {
407 let infcx = &self.infcx;
413 let (ParamEnvAnd { param_env: _, value }, var_values) =
414 infcx.instantiate_canonical(span, &query_input.canonical);
415 let query::MethodAutoderefSteps { predefined_opaques_in_body: _, self_ty } = value;
416 {
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:416",
"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(416u32),
::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");
417 let prev_opaque_entries = self.inner.borrow_mut().opaque_types().num_entries();
418 MethodAutoderefStepsResult {
419 steps: infcx.tcx.arena.alloc_from_iter([CandidateStep {
420 self_ty: self.make_query_response_ignoring_pending_obligations(
421 var_values,
422 self_ty,
423 prev_opaque_entries,
424 ),
425 self_ty_is_opaque: false,
426 autoderefs: 0,
427 from_unsafe_deref: false,
428 unsize: false,
429 reachable_via_deref: true,
430 }]),
431 opt_bad_ty: None,
432 reached_recursion_limit: false,
433 }
434 }),
435 };
436
437 if steps.reached_recursion_limit && !is_suggestion.0 {
441 self.probe(|_| {
442 let ty = &steps
443 .steps
444 .last()
445 .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?"))
446 .self_ty;
447 let ty = self
448 .probe_instantiate_query_response(span, &orig_values, ty)
449 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
450 autoderef::report_autoderef_recursion_limit_error(self.tcx, span, ty.value);
451 });
452 }
453
454 if let Some(bad_ty) = &steps.opt_bad_ty {
457 if is_suggestion.0 {
458 return Err(MethodError::NoMatch(NoMatchData {
461 static_candidates: Vec::new(),
462 unsatisfied_predicates: Vec::new(),
463 out_of_scope_traits: Vec::new(),
464 similar_candidate: None,
465 mode,
466 }));
467 } else if bad_ty.reached_raw_pointer
468 && !self.tcx.features().arbitrary_self_types_pointers()
469 && !self.tcx.sess.at_least_rust_2018()
470 {
471 self.tcx.node_span_lint(
475 lint::builtin::TYVAR_BEHIND_RAW_POINTER,
476 scope_expr_id,
477 span,
478 |lint| {
479 lint.primary_message("type annotations needed");
480 },
481 );
482 } else {
483 let ty = &bad_ty.ty;
487 let ty = self
488 .probe_instantiate_query_response(span, &orig_values, ty)
489 .unwrap_or_else(|_| ::rustc_middle::util::bug::span_bug_fmt(span,
format_args!("instantiating {0:?} failed?", ty))span_bug!(span, "instantiating {:?} failed?", ty));
490 let ty = self.resolve_vars_if_possible(ty.value);
491 let guar = match *ty.kind() {
492 _ if let Some(guar) = self.tainted_by_errors() => guar,
493 ty::Infer(ty::TyVar(_)) => {
494 let err_span = match (mode, self.tcx.hir_node(scope_expr_id)) {
497 (
498 Mode::MethodCall,
499 Node::Expr(hir::Expr {
500 kind: ExprKind::MethodCall(_, recv, ..),
501 ..
502 }),
503 ) => recv.span,
504 _ => span,
505 };
506
507 let raw_ptr_call = bad_ty.reached_raw_pointer
508 && !self.tcx.features().arbitrary_self_types();
509
510 let mut err = self.err_ctxt().emit_inference_failure_err(
511 self.body_id,
512 err_span,
513 ty.into(),
514 TypeAnnotationNeeded::E0282,
515 !raw_ptr_call,
516 );
517 if raw_ptr_call {
518 err.span_label(span, "cannot call a method on a raw pointer with an unknown pointee type");
519 }
520 err.emit()
521 }
522 ty::Error(guar) => guar,
523 _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected bad final type in method autoderef"))bug!("unexpected bad final type in method autoderef"),
524 };
525 self.demand_eqtype(span, ty, Ty::new_error(self.tcx, guar));
526 return Err(MethodError::ErrorReported(guar));
527 }
528 }
529
530 {
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:530",
"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(530u32),
::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);
531
532 self.probe(|_| {
535 let mut probe_cx = ProbeContext::new(
536 self,
537 span,
538 mode,
539 method_name,
540 return_type,
541 &orig_values,
542 steps.steps,
543 scope_expr_id,
544 is_suggestion,
545 );
546
547 match scope {
548 ProbeScope::TraitsInScope => {
549 probe_cx.assemble_inherent_candidates();
550 probe_cx.assemble_extension_candidates_for_traits_in_scope();
551 }
552 ProbeScope::AllTraits => {
553 probe_cx.assemble_inherent_candidates();
554 probe_cx.assemble_extension_candidates_for_all_traits();
555 }
556 ProbeScope::Single(def_id) => {
557 let item = self.tcx.associated_item(def_id);
558 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);
560
561 let trait_def_id = self.tcx.parent(def_id);
562 let trait_span = self.tcx.def_span(trait_def_id);
563
564 let trait_args = self.fresh_args_for_item(trait_span, trait_def_id);
565 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
566
567 probe_cx.push_candidate(
568 Candidate {
569 item,
570 kind: CandidateKind::TraitCandidate(
571 ty::Binder::dummy(trait_ref),
572 false,
573 ),
574 import_ids: ::smallvec::SmallVec::new()smallvec![],
575 },
576 false,
577 );
578 }
579 };
580 op(probe_cx)
581 })
582 }
583}
584
585pub(crate) fn method_autoderef_steps<'tcx>(
586 tcx: TyCtxt<'tcx>,
587 goal: CanonicalMethodAutoderefStepsGoal<'tcx>,
588) -> MethodAutoderefStepsResult<'tcx> {
589 {
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:589",
"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(589u32),
::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);
590
591 let (ref infcx, goal, inference_vars) = tcx.infer_ctxt().build_with_canonical(DUMMY_SP, &goal);
592 let ParamEnvAnd {
593 param_env,
594 value: query::MethodAutoderefSteps { predefined_opaques_in_body, self_ty },
595 } = goal;
596 for (key, ty) in predefined_opaques_in_body {
597 let prev = infcx
598 .register_hidden_type_in_storage(key, ty::ProvisionalHiddenType { span: DUMMY_SP, ty });
599 if let Some(prev) = prev {
611 {
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:611",
"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(611u32),
::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`");
612 }
613 }
614 let prev_opaque_entries = infcx.inner.borrow_mut().opaque_types().num_entries();
615
616 let self_ty_is_opaque = |ty: Ty<'_>| {
620 if let &ty::Infer(ty::TyVar(vid)) = ty.kind() {
621 infcx.has_opaques_with_sub_unified_hidden_type(vid)
622 } else {
623 false
624 }
625 };
626
627 let mut autoderef_via_deref =
637 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
638 .include_raw_pointers()
639 .silence_errors();
640
641 let mut reached_raw_pointer = false;
642 let arbitrary_self_types_enabled =
643 tcx.features().arbitrary_self_types() || tcx.features().arbitrary_self_types_pointers();
644 let (mut steps, reached_recursion_limit): (Vec<_>, bool) = if arbitrary_self_types_enabled {
645 let reachable_via_deref =
646 autoderef_via_deref.by_ref().map(|_| true).chain(std::iter::repeat(false));
647
648 let mut autoderef_via_receiver =
649 Autoderef::new(infcx, param_env, hir::def_id::CRATE_DEF_ID, DUMMY_SP, self_ty)
650 .include_raw_pointers()
651 .use_receiver_trait()
652 .silence_errors();
653 let steps = autoderef_via_receiver
654 .by_ref()
655 .zip(reachable_via_deref)
656 .map(|((ty, d), reachable_via_deref)| {
657 let step = CandidateStep {
658 self_ty: infcx.make_query_response_ignoring_pending_obligations(
659 inference_vars,
660 ty,
661 prev_opaque_entries,
662 ),
663 self_ty_is_opaque: self_ty_is_opaque(ty),
664 autoderefs: d,
665 from_unsafe_deref: reached_raw_pointer,
666 unsize: false,
667 reachable_via_deref,
668 };
669 if ty.is_raw_ptr() {
670 reached_raw_pointer = true;
672 }
673 step
674 })
675 .collect();
676 (steps, autoderef_via_receiver.reached_recursion_limit())
677 } else {
678 let steps = autoderef_via_deref
679 .by_ref()
680 .map(|(ty, d)| {
681 let step = CandidateStep {
682 self_ty: infcx.make_query_response_ignoring_pending_obligations(
683 inference_vars,
684 ty,
685 prev_opaque_entries,
686 ),
687 self_ty_is_opaque: self_ty_is_opaque(ty),
688 autoderefs: d,
689 from_unsafe_deref: reached_raw_pointer,
690 unsize: false,
691 reachable_via_deref: true,
692 };
693 if ty.is_raw_ptr() {
694 reached_raw_pointer = true;
696 }
697 step
698 })
699 .collect();
700 (steps, autoderef_via_deref.reached_recursion_limit())
701 };
702 let final_ty = autoderef_via_deref.final_ty();
703 let opt_bad_ty = match final_ty.kind() {
704 ty::Infer(ty::TyVar(_)) if !self_ty_is_opaque(final_ty) => Some(MethodAutoderefBadTy {
705 reached_raw_pointer,
706 ty: infcx.make_query_response_ignoring_pending_obligations(
707 inference_vars,
708 final_ty,
709 prev_opaque_entries,
710 ),
711 }),
712 ty::Error(_) => Some(MethodAutoderefBadTy {
713 reached_raw_pointer,
714 ty: infcx.make_query_response_ignoring_pending_obligations(
715 inference_vars,
716 final_ty,
717 prev_opaque_entries,
718 ),
719 }),
720 ty::Array(elem_ty, _) => {
721 let autoderefs = steps.iter().filter(|s| s.reachable_via_deref).count() - 1;
722 steps.push(CandidateStep {
723 self_ty: infcx.make_query_response_ignoring_pending_obligations(
724 inference_vars,
725 Ty::new_slice(infcx.tcx, *elem_ty),
726 prev_opaque_entries,
727 ),
728 self_ty_is_opaque: false,
729 autoderefs,
730 from_unsafe_deref: reached_raw_pointer,
733 unsize: true,
734 reachable_via_deref: true, });
737
738 None
739 }
740 _ => None,
741 };
742
743 {
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:743",
"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(743u32),
::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);
744 let _ = infcx.take_opaque_types();
746 MethodAutoderefStepsResult {
747 steps: tcx.arena.alloc_from_iter(steps),
748 opt_bad_ty: opt_bad_ty.map(|ty| &*tcx.arena.alloc(ty)),
749 reached_recursion_limit,
750 }
751}
752
753impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
754 fn new(
755 fcx: &'a FnCtxt<'a, 'tcx>,
756 span: Span,
757 mode: Mode,
758 method_name: Option<Ident>,
759 return_type: Option<Ty<'tcx>>,
760 orig_steps_var_values: &'a OriginalQueryValues<'tcx>,
761 steps: &'tcx [CandidateStep<'tcx>],
762 scope_expr_id: HirId,
763 is_suggestion: IsSuggestion,
764 ) -> ProbeContext<'a, 'tcx> {
765 ProbeContext {
766 fcx,
767 span,
768 mode,
769 method_name,
770 return_type,
771 inherent_candidates: Vec::new(),
772 extension_candidates: Vec::new(),
773 impl_dups: FxHashSet::default(),
774 orig_steps_var_values,
775 steps,
776 allow_similar_names: false,
777 private_candidates: Vec::new(),
778 private_candidate: Cell::new(None),
779 static_candidates: RefCell::new(Vec::new()),
780 scope_expr_id,
781 is_suggestion,
782 }
783 }
784
785 fn reset(&mut self) {
786 self.inherent_candidates.clear();
787 self.extension_candidates.clear();
788 self.impl_dups.clear();
789 self.private_candidates.clear();
790 self.private_candidate.set(None);
791 self.static_candidates.borrow_mut().clear();
792 }
793
794 fn variance(&self) -> ty::Variance {
798 match self.mode {
799 Mode::MethodCall => ty::Covariant,
800 Mode::Path => ty::Invariant,
801 }
802 }
803
804 fn push_candidate(&mut self, candidate: Candidate<'tcx>, is_inherent: bool) {
808 let is_accessible = if let Some(name) = self.method_name {
809 let item = candidate.item;
810 let hir_id = self.tcx.local_def_id_to_hir_id(self.body_id);
811 let def_scope =
812 self.tcx.adjust_ident_and_get_scope(name, item.container_id(self.tcx), hir_id).1;
813 item.visibility(self.tcx).is_accessible_from(def_scope, self.tcx)
814 } else {
815 true
816 };
817 if is_accessible {
818 if is_inherent {
819 self.inherent_candidates.push(candidate);
820 } else {
821 self.extension_candidates.push(candidate);
822 }
823 } else {
824 self.private_candidates.push(candidate);
825 }
826 }
827
828 fn assemble_inherent_candidates(&mut self) {
829 for step in self.steps.iter() {
830 self.assemble_probe(&step.self_ty, step.autoderefs);
831 }
832 }
833
834 #[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(834u32),
::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))]
835 fn assemble_probe(
836 &mut self,
837 self_ty: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>,
838 receiver_steps: usize,
839 ) {
840 let raw_self_ty = self_ty.value.value;
841 match *raw_self_ty.kind() {
842 ty::Dynamic(data, ..) if let Some(p) = data.principal() => {
843 let (QueryResponse { value: generalized_self_ty, .. }, _ignored_var_values) =
861 self.fcx.instantiate_canonical(self.span, self_ty);
862
863 self.assemble_inherent_candidates_from_object(generalized_self_ty);
864 self.assemble_inherent_impl_candidates_for_type(p.def_id(), receiver_steps);
865 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
866 }
867 ty::Adt(def, _) => {
868 let def_id = def.did();
869 self.assemble_inherent_impl_candidates_for_type(def_id, receiver_steps);
870 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
871 }
872 ty::Foreign(did) => {
873 self.assemble_inherent_impl_candidates_for_type(did, receiver_steps);
874 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps);
875 }
876 ty::Param(_) => {
877 self.assemble_inherent_candidates_from_param(raw_self_ty);
878 }
879 ty::Bool
880 | ty::Char
881 | ty::Int(_)
882 | ty::Uint(_)
883 | ty::Float(_)
884 | ty::Str
885 | ty::Array(..)
886 | ty::Slice(_)
887 | ty::RawPtr(_, _)
888 | ty::Ref(..)
889 | ty::Never
890 | ty::Tuple(..) => {
891 self.assemble_inherent_candidates_for_incoherent_ty(raw_self_ty, receiver_steps)
892 }
893 ty::Alias(..)
894 | ty::Bound(..)
895 | ty::Closure(..)
896 | ty::Coroutine(..)
897 | ty::CoroutineClosure(..)
898 | ty::CoroutineWitness(..)
899 | ty::Dynamic(..)
900 | ty::Error(..)
901 | ty::FnDef(..)
902 | ty::FnPtr(..)
903 | ty::Infer(..)
904 | ty::Pat(..)
905 | ty::Placeholder(..)
906 | ty::UnsafeBinder(..) => {}
907 }
908 }
909
910 fn assemble_inherent_candidates_for_incoherent_ty(
911 &mut self,
912 self_ty: Ty<'tcx>,
913 receiver_steps: usize,
914 ) {
915 let Some(simp) = simplify_type(self.tcx, self_ty, TreatParams::InstantiateWithInfer) else {
916 ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected incoherent type: {0:?}",
self_ty))bug!("unexpected incoherent type: {:?}", self_ty)
917 };
918 for &impl_def_id in self.tcx.incoherent_impls(simp).into_iter() {
919 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
920 }
921 }
922
923 fn assemble_inherent_impl_candidates_for_type(&mut self, def_id: DefId, receiver_steps: usize) {
924 let impl_def_ids = self.tcx.at(self.span).inherent_impls(def_id).into_iter();
925 for &impl_def_id in impl_def_ids {
926 self.assemble_inherent_impl_probe(impl_def_id, receiver_steps);
927 }
928 }
929
930 #[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(930u32),
::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: ::smallvec::SmallVec::new(),
}, true);
}
}
}
}#[instrument(level = "debug", skip(self))]
931 fn assemble_inherent_impl_probe(&mut self, impl_def_id: DefId, receiver_steps: usize) {
932 if !self.impl_dups.insert(impl_def_id) {
933 return; }
935
936 for item in self.impl_or_trait_item(impl_def_id) {
937 if !self.has_applicable_self(&item) {
938 self.record_static_candidate(CandidateSource::Impl(impl_def_id));
940 continue;
941 }
942 self.push_candidate(
943 Candidate {
944 item,
945 kind: InherentImplCandidate { impl_def_id, receiver_steps },
946 import_ids: smallvec![],
947 },
948 true,
949 );
950 }
951 }
952
953 #[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(953u32),
::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: ::smallvec::SmallVec::new(),
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
954 fn assemble_inherent_candidates_from_object(&mut self, self_ty: Ty<'tcx>) {
955 let principal = match self_ty.kind() {
956 ty::Dynamic(data, ..) => Some(data),
957 _ => None,
958 }
959 .and_then(|data| data.principal())
960 .unwrap_or_else(|| {
961 span_bug!(
962 self.span,
963 "non-object {:?} in assemble_inherent_candidates_from_object",
964 self_ty
965 )
966 });
967
968 let trait_ref = principal.with_self_ty(self.tcx, self_ty);
975 self.assemble_candidates_for_bounds(
976 traits::supertraits(self.tcx, trait_ref),
977 |this, new_trait_ref, item| {
978 this.push_candidate(
979 Candidate {
980 item,
981 kind: ObjectCandidate(new_trait_ref),
982 import_ids: smallvec![],
983 },
984 true,
985 );
986 },
987 );
988 }
989
990 #[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(990u32),
::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: ::smallvec::SmallVec::new(),
}, true);
});
}
}
}#[instrument(level = "debug", skip(self))]
991 fn assemble_inherent_candidates_from_param(&mut self, param_ty: Ty<'tcx>) {
992 debug_assert_matches!(param_ty.kind(), ty::Param(_));
993
994 let tcx = self.tcx;
995
996 let bounds = self.param_env.caller_bounds().iter().filter_map(|predicate| {
1000 let bound_predicate = predicate.kind();
1001 match bound_predicate.skip_binder() {
1002 ty::ClauseKind::Trait(trait_predicate) => DeepRejectCtxt::relate_rigid_rigid(tcx)
1003 .types_may_unify(param_ty, trait_predicate.trait_ref.self_ty())
1004 .then(|| bound_predicate.rebind(trait_predicate.trait_ref)),
1005 ty::ClauseKind::RegionOutlives(_)
1006 | ty::ClauseKind::TypeOutlives(_)
1007 | ty::ClauseKind::Projection(_)
1008 | ty::ClauseKind::ConstArgHasType(_, _)
1009 | ty::ClauseKind::WellFormed(_)
1010 | ty::ClauseKind::ConstEvaluatable(_)
1011 | ty::ClauseKind::UnstableFeature(_)
1012 | ty::ClauseKind::HostEffect(..) => None,
1013 }
1014 });
1015
1016 self.assemble_candidates_for_bounds(bounds, |this, poly_trait_ref, item| {
1017 this.push_candidate(
1018 Candidate {
1019 item,
1020 kind: WhereClauseCandidate(poly_trait_ref),
1021 import_ids: smallvec![],
1022 },
1023 true,
1024 );
1025 });
1026 }
1027
1028 fn assemble_candidates_for_bounds<F>(
1031 &mut self,
1032 bounds: impl Iterator<Item = ty::PolyTraitRef<'tcx>>,
1033 mut mk_cand: F,
1034 ) where
1035 F: for<'b> FnMut(&mut ProbeContext<'b, 'tcx>, ty::PolyTraitRef<'tcx>, ty::AssocItem),
1036 {
1037 for bound_trait_ref in bounds {
1038 {
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:1038",
"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(1038u32),
::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);
1039 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1040 if !self.has_applicable_self(&item) {
1041 self.record_static_candidate(CandidateSource::Trait(bound_trait_ref.def_id()));
1042 } else {
1043 mk_cand(self, bound_trait_ref, item);
1044 }
1045 }
1046 }
1047 }
1048
1049 #[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(1049u32),
::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))]
1050 fn assemble_extension_candidates_for_traits_in_scope(&mut self) {
1051 let mut duplicates = FxHashSet::default();
1052 let opt_applicable_traits = self.tcx.in_scope_traits(self.scope_expr_id);
1053 if let Some(applicable_traits) = opt_applicable_traits {
1054 for trait_candidate in applicable_traits.iter() {
1055 let trait_did = trait_candidate.def_id;
1056 if duplicates.insert(trait_did) {
1057 self.assemble_extension_candidates_for_trait(
1058 &trait_candidate.import_ids,
1059 trait_did,
1060 trait_candidate.lint_ambiguous,
1061 );
1062 }
1063 }
1064 }
1065 }
1066
1067 #[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(1067u32),
::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(&::smallvec::SmallVec::new(),
trait_info.def_id, false);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1068 fn assemble_extension_candidates_for_all_traits(&mut self) {
1069 let mut duplicates = FxHashSet::default();
1070 for trait_info in suggest::all_traits(self.tcx) {
1071 if duplicates.insert(trait_info.def_id) {
1072 self.assemble_extension_candidates_for_trait(
1073 &smallvec![],
1074 trait_info.def_id,
1075 false,
1076 );
1077 }
1078 }
1079 }
1080
1081 fn matches_return_type(&self, method: ty::AssocItem, expected: Ty<'tcx>) -> bool {
1082 match method.kind {
1083 ty::AssocKind::Fn { .. } => self.probe(|_| {
1084 let args = self.fresh_args_for_item(self.span, method.def_id);
1085 let fty = self.tcx.fn_sig(method.def_id).instantiate(self.tcx, args);
1086 let fty = self.instantiate_binder_with_fresh_vars(
1087 self.span,
1088 BoundRegionConversionTime::FnCall,
1089 fty,
1090 );
1091 self.can_eq(self.param_env, fty.output(), expected)
1092 }),
1093 _ => false,
1094 }
1095 }
1096
1097 #[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(1097u32),
::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: import_ids.clone(),
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:1139",
"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(1139u32),
::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: import_ids.clone(),
kind: TraitCandidate(ty::Binder::dummy(trait_ref),
lint_ambiguous),
}, false);
}
}
}
}
}#[instrument(level = "debug", skip(self))]
1098 fn assemble_extension_candidates_for_trait(
1099 &mut self,
1100 import_ids: &SmallVec<[LocalDefId; 1]>,
1101 trait_def_id: DefId,
1102 lint_ambiguous: bool,
1103 ) {
1104 let trait_args = self.fresh_args_for_item(self.span, trait_def_id);
1105 let trait_ref = ty::TraitRef::new_from_args(self.tcx, trait_def_id, trait_args);
1106
1107 if self.tcx.is_trait_alias(trait_def_id) {
1108 for (bound_trait_pred, _) in
1110 traits::expand_trait_aliases(self.tcx, [(trait_ref.upcast(self.tcx), self.span)]).0
1111 {
1112 assert_eq!(bound_trait_pred.polarity(), ty::PredicatePolarity::Positive);
1113 let bound_trait_ref = bound_trait_pred.map_bound(|pred| pred.trait_ref);
1114 for item in self.impl_or_trait_item(bound_trait_ref.def_id()) {
1115 if !self.has_applicable_self(&item) {
1116 self.record_static_candidate(CandidateSource::Trait(
1117 bound_trait_ref.def_id(),
1118 ));
1119 } else {
1120 self.push_candidate(
1121 Candidate {
1122 item,
1123 import_ids: import_ids.clone(),
1124 kind: TraitCandidate(bound_trait_ref, lint_ambiguous),
1125 },
1126 false,
1127 );
1128 }
1129 }
1130 }
1131 } else {
1132 debug_assert!(self.tcx.is_trait(trait_def_id));
1133 if self.tcx.trait_is_auto(trait_def_id) {
1134 return;
1135 }
1136 for item in self.impl_or_trait_item(trait_def_id) {
1137 if !self.has_applicable_self(&item) {
1139 debug!("method has inapplicable self");
1140 self.record_static_candidate(CandidateSource::Trait(trait_def_id));
1141 continue;
1142 }
1143 self.push_candidate(
1144 Candidate {
1145 item,
1146 import_ids: import_ids.clone(),
1147 kind: TraitCandidate(ty::Binder::dummy(trait_ref), lint_ambiguous),
1148 },
1149 false,
1150 );
1151 }
1152 }
1153 }
1154
1155 fn candidate_method_names(
1156 &self,
1157 candidate_filter: impl Fn(&ty::AssocItem) -> bool,
1158 ) -> Vec<Ident> {
1159 let mut set = FxHashSet::default();
1160 let mut names: Vec<_> = self
1161 .inherent_candidates
1162 .iter()
1163 .chain(&self.extension_candidates)
1164 .filter(|candidate| candidate_filter(&candidate.item))
1165 .filter(|candidate| {
1166 if let Some(return_ty) = self.return_type {
1167 self.matches_return_type(candidate.item, return_ty)
1168 } else {
1169 true
1170 }
1171 })
1172 .filter(|candidate| {
1174 !#[allow(non_exhaustive_omitted_patterns)] match self.tcx.eval_stability(candidate.item.def_id,
None, DUMMY_SP, None) {
stability::EvalResult::Deny { .. } => true,
_ => false,
}matches!(
1177 self.tcx.eval_stability(candidate.item.def_id, None, DUMMY_SP, None),
1178 stability::EvalResult::Deny { .. }
1179 )
1180 })
1181 .map(|candidate| candidate.item.ident(self.tcx))
1182 .filter(|&name| set.insert(name))
1183 .collect();
1184
1185 names.sort_by(|a, b| a.as_str().cmp(b.as_str()));
1187 names
1188 }
1189
1190 #[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(1193u32),
::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:1215",
"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(1215u32),
::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))]
1194 fn pick(mut self) -> PickResult<'tcx> {
1195 assert!(self.method_name.is_some());
1196
1197 let mut unsatisfied_predicates = Vec::new();
1198
1199 if let Some(r) = self.pick_core(&mut unsatisfied_predicates) {
1200 return r;
1201 }
1202
1203 if self.is_suggestion.0 {
1206 return Err(MethodError::NoMatch(NoMatchData {
1207 static_candidates: vec![],
1208 unsatisfied_predicates: vec![],
1209 out_of_scope_traits: vec![],
1210 similar_candidate: None,
1211 mode: self.mode,
1212 }));
1213 }
1214
1215 debug!("pick: actual search failed, assemble diagnostics");
1216
1217 let static_candidates = std::mem::take(self.static_candidates.get_mut());
1218 let private_candidate = self.private_candidate.take();
1219
1220 self.reset();
1222
1223 self.assemble_extension_candidates_for_all_traits();
1224
1225 let out_of_scope_traits = match self.pick_core(&mut Vec::new()) {
1226 Some(Ok(p)) => vec![p.item.container_id(self.tcx)],
1227 Some(Err(MethodError::Ambiguity(v))) => v
1228 .into_iter()
1229 .map(|source| match source {
1230 CandidateSource::Trait(id) => id,
1231 CandidateSource::Impl(impl_id) => self.tcx.impl_trait_id(impl_id),
1232 })
1233 .collect(),
1234 Some(Err(MethodError::NoMatch(NoMatchData {
1235 out_of_scope_traits: others, ..
1236 }))) => {
1237 assert!(others.is_empty());
1238 vec![]
1239 }
1240 _ => vec![],
1241 };
1242
1243 if let Some((kind, def_id)) = private_candidate {
1244 return Err(MethodError::PrivateMatch(kind, def_id, out_of_scope_traits));
1245 }
1246 let similar_candidate = self.probe_for_similar_candidate()?;
1247
1248 Err(MethodError::NoMatch(NoMatchData {
1249 static_candidates,
1250 unsatisfied_predicates,
1251 out_of_scope_traits,
1252 similar_candidate,
1253 mode: self.mode,
1254 }))
1255 }
1256
1257 fn pick_core(
1258 &self,
1259 unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1260 ) -> Option<PickResult<'tcx>> {
1261 self.pick_all_method(&mut PickDiagHints {
1263 unstable_candidates: Some(Vec::new()),
1266 unsatisfied_predicates,
1269 })
1270 .or_else(|| {
1271 self.pick_all_method(&mut PickDiagHints {
1272 unstable_candidates: None,
1277 unsatisfied_predicates: &mut Vec::new(),
1280 })
1281 })
1282 }
1283
1284 fn pick_all_method<'b>(
1285 &self,
1286 pick_diag_hints: &mut PickDiagHints<'b, 'tcx>,
1287 ) -> Option<PickResult<'tcx>> {
1288 let track_unstable_candidates = pick_diag_hints.unstable_candidates.is_some();
1289 self.steps
1290 .iter()
1291 .filter(|step| step.reachable_via_deref)
1295 .filter(|step| {
1296 {
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:1296",
"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(1296u32),
::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);
1297 !step.self_ty.value.references_error() && !step.from_unsafe_deref
1300 })
1301 .find_map(|step| {
1302 let InferOk { value: self_ty, obligations: instantiate_self_ty_obligations } = self
1303 .fcx
1304 .probe_instantiate_query_response(
1305 self.span,
1306 self.orig_steps_var_values,
1307 &step.self_ty,
1308 )
1309 .unwrap_or_else(|_| {
1310 ::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)
1311 });
1312
1313 let by_value_pick = self.pick_by_value_method(
1314 step,
1315 self_ty,
1316 &instantiate_self_ty_obligations,
1317 pick_diag_hints,
1318 );
1319
1320 if let Some(by_value_pick) = by_value_pick {
1322 if let Ok(by_value_pick) = by_value_pick.as_ref() {
1323 if by_value_pick.kind == PickKind::InherentImplPick {
1324 for mutbl in [hir::Mutability::Not, hir::Mutability::Mut] {
1325 if let Err(e) = self.check_for_shadowed_autorefd_method(
1326 by_value_pick,
1327 step,
1328 self_ty,
1329 &instantiate_self_ty_obligations,
1330 mutbl,
1331 track_unstable_candidates,
1332 ) {
1333 return Some(Err(e));
1334 }
1335 }
1336 }
1337 }
1338 return Some(by_value_pick);
1339 }
1340
1341 let autoref_pick = self.pick_autorefd_method(
1342 step,
1343 self_ty,
1344 &instantiate_self_ty_obligations,
1345 hir::Mutability::Not,
1346 pick_diag_hints,
1347 None,
1348 );
1349 if let Some(autoref_pick) = autoref_pick {
1351 if let Ok(autoref_pick) = autoref_pick.as_ref() {
1352 if autoref_pick.kind == PickKind::InherentImplPick {
1354 if let Err(e) = self.check_for_shadowed_autorefd_method(
1355 autoref_pick,
1356 step,
1357 self_ty,
1358 &instantiate_self_ty_obligations,
1359 hir::Mutability::Mut,
1360 track_unstable_candidates,
1361 ) {
1362 return Some(Err(e));
1363 }
1364 }
1365 }
1366 return Some(autoref_pick);
1367 }
1368
1369 self.pick_autorefd_method(
1393 step,
1394 self_ty,
1395 &instantiate_self_ty_obligations,
1396 hir::Mutability::Mut,
1397 pick_diag_hints,
1398 None,
1399 )
1400 .or_else(|| {
1401 self.pick_const_ptr_method(
1402 step,
1403 self_ty,
1404 &instantiate_self_ty_obligations,
1405 pick_diag_hints,
1406 )
1407 })
1408 .or_else(|| {
1409 self.pick_reborrow_pin_method(
1410 step,
1411 self_ty,
1412 &instantiate_self_ty_obligations,
1413 pick_diag_hints,
1414 )
1415 })
1416 })
1417 }
1418
1419 fn check_for_shadowed_autorefd_method(
1435 &self,
1436 possible_shadower: &Pick<'tcx>,
1437 step: &CandidateStep<'tcx>,
1438 self_ty: Ty<'tcx>,
1439 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1440 mutbl: hir::Mutability,
1441 track_unstable_candidates: bool,
1442 ) -> Result<(), MethodError<'tcx>> {
1443 if !self.tcx.features().arbitrary_self_types()
1447 && !self.tcx.features().arbitrary_self_types_pointers()
1448 {
1449 return Ok(());
1450 }
1451
1452 let mut pick_diag_hints = PickDiagHints {
1457 unstable_candidates: if track_unstable_candidates { Some(Vec::new()) } else { None },
1458 unsatisfied_predicates: &mut Vec::new(),
1459 };
1460 let pick_constraints = PickConstraintsForShadowed {
1462 autoderefs: possible_shadower.autoderefs,
1464 receiver_steps: possible_shadower.receiver_steps,
1468 def_id: possible_shadower.item.def_id,
1471 };
1472 let potentially_shadowed_pick = self.pick_autorefd_method(
1502 step,
1503 self_ty,
1504 instantiate_self_ty_obligations,
1505 mutbl,
1506 &mut pick_diag_hints,
1507 Some(&pick_constraints),
1508 );
1509 if let Some(Ok(possible_shadowed)) = potentially_shadowed_pick.as_ref() {
1512 let sources = [possible_shadower, possible_shadowed]
1513 .into_iter()
1514 .map(|p| self.candidate_source_from_pick(p))
1515 .collect();
1516 return Err(MethodError::Ambiguity(sources));
1517 }
1518 Ok(())
1519 }
1520
1521 fn pick_by_value_method(
1528 &self,
1529 step: &CandidateStep<'tcx>,
1530 self_ty: Ty<'tcx>,
1531 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1532 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1533 ) -> Option<PickResult<'tcx>> {
1534 if step.unsize {
1535 return None;
1536 }
1537
1538 self.pick_method(self_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(|r| {
1539 r.map(|mut pick| {
1540 pick.autoderefs = step.autoderefs;
1541
1542 match *step.self_ty.value.value.kind() {
1543 ty::Ref(_, _, mutbl) => {
1545 pick.autoderefs += 1;
1546 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::Autoref {
1547 mutbl,
1548 unsize: pick.autoref_or_ptr_adjustment.is_some_and(|a| a.get_unsize()),
1549 })
1550 }
1551
1552 ty::Adt(def, args)
1553 if self.tcx.features().pin_ergonomics()
1554 && self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) =>
1555 {
1556 if let ty::Ref(_, _, mutbl) = args[0].expect_ty().kind() {
1558 pick.autoref_or_ptr_adjustment =
1559 Some(AutorefOrPtrAdjustment::ReborrowPin(*mutbl));
1560 }
1561 }
1562
1563 _ => (),
1564 }
1565
1566 pick
1567 })
1568 })
1569 }
1570
1571 fn pick_autorefd_method(
1572 &self,
1573 step: &CandidateStep<'tcx>,
1574 self_ty: Ty<'tcx>,
1575 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1576 mutbl: hir::Mutability,
1577 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1578 pick_constraints: Option<&PickConstraintsForShadowed>,
1579 ) -> Option<PickResult<'tcx>> {
1580 let tcx = self.tcx;
1581
1582 if let Some(pick_constraints) = pick_constraints {
1583 if !pick_constraints.may_shadow_based_on_autoderefs(step.autoderefs) {
1584 return None;
1585 }
1586 }
1587
1588 let region = tcx.lifetimes.re_erased;
1590
1591 let autoref_ty = Ty::new_ref(tcx, region, self_ty, mutbl);
1592 self.pick_method(
1593 autoref_ty,
1594 instantiate_self_ty_obligations,
1595 pick_diag_hints,
1596 pick_constraints,
1597 )
1598 .map(|r| {
1599 r.map(|mut pick| {
1600 pick.autoderefs = step.autoderefs;
1601 pick.autoref_or_ptr_adjustment =
1602 Some(AutorefOrPtrAdjustment::Autoref { mutbl, unsize: step.unsize });
1603 pick
1604 })
1605 })
1606 }
1607
1608 #[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(1609u32),
::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))]
1610 fn pick_reborrow_pin_method(
1611 &self,
1612 step: &CandidateStep<'tcx>,
1613 self_ty: Ty<'tcx>,
1614 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1615 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1616 ) -> Option<PickResult<'tcx>> {
1617 if !self.tcx.features().pin_ergonomics() {
1618 return None;
1619 }
1620
1621 let inner_ty = match self_ty.kind() {
1623 ty::Adt(def, args) if self.tcx.is_lang_item(def.did(), hir::LangItem::Pin) => {
1624 match args[0].expect_ty().kind() {
1625 ty::Ref(_, ty, hir::Mutability::Mut) => *ty,
1626 _ => {
1627 return None;
1628 }
1629 }
1630 }
1631 _ => return None,
1632 };
1633
1634 let region = self.tcx.lifetimes.re_erased;
1635 let autopin_ty = Ty::new_pinned_ref(self.tcx, region, inner_ty, hir::Mutability::Not);
1636 self.pick_method(autopin_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1637 |r| {
1638 r.map(|mut pick| {
1639 pick.autoderefs = step.autoderefs;
1640 pick.autoref_or_ptr_adjustment =
1641 Some(AutorefOrPtrAdjustment::ReborrowPin(hir::Mutability::Not));
1642 pick
1643 })
1644 },
1645 )
1646 }
1647
1648 fn pick_const_ptr_method(
1652 &self,
1653 step: &CandidateStep<'tcx>,
1654 self_ty: Ty<'tcx>,
1655 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1656 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1657 ) -> Option<PickResult<'tcx>> {
1658 if step.unsize {
1660 return None;
1661 }
1662
1663 let &ty::RawPtr(ty, hir::Mutability::Mut) = self_ty.kind() else {
1664 return None;
1665 };
1666
1667 let const_ptr_ty = Ty::new_imm_ptr(self.tcx, ty);
1668 self.pick_method(const_ptr_ty, instantiate_self_ty_obligations, pick_diag_hints, None).map(
1669 |r| {
1670 r.map(|mut pick| {
1671 pick.autoderefs = step.autoderefs;
1672 pick.autoref_or_ptr_adjustment = Some(AutorefOrPtrAdjustment::ToConstPtr);
1673 pick
1674 })
1675 },
1676 )
1677 }
1678
1679 fn pick_method(
1680 &self,
1681 self_ty: Ty<'tcx>,
1682 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1683 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1684 pick_constraints: Option<&PickConstraintsForShadowed>,
1685 ) -> Option<PickResult<'tcx>> {
1686 {
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:1686",
"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(1686u32),
::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));
1687
1688 for (kind, candidates) in
1689 [("inherent", &self.inherent_candidates), ("extension", &self.extension_candidates)]
1690 {
1691 {
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:1691",
"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(1691u32),
::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);
1692 let res = self.consider_candidates(
1693 self_ty,
1694 instantiate_self_ty_obligations,
1695 candidates,
1696 pick_diag_hints,
1697 pick_constraints,
1698 );
1699 if let Some(pick) = res {
1700 return Some(pick);
1701 }
1702 }
1703
1704 if self.private_candidate.get().is_none() {
1705 if let Some(Ok(pick)) = self.consider_candidates(
1706 self_ty,
1707 instantiate_self_ty_obligations,
1708 &self.private_candidates,
1709 &mut PickDiagHints {
1710 unstable_candidates: None,
1711 unsatisfied_predicates: &mut ::alloc::vec::Vec::new()vec![],
1712 },
1713 None,
1714 ) {
1715 self.private_candidate.set(Some((pick.item.as_def_kind(), pick.item.def_id)));
1716 }
1717 }
1718 None
1719 }
1720
1721 fn consider_candidates(
1722 &self,
1723 self_ty: Ty<'tcx>,
1724 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1725 candidates: &[Candidate<'tcx>],
1726 pick_diag_hints: &mut PickDiagHints<'_, 'tcx>,
1727 pick_constraints: Option<&PickConstraintsForShadowed>,
1728 ) -> Option<PickResult<'tcx>> {
1729 let mut applicable_candidates: Vec<_> = candidates
1730 .iter()
1731 .filter(|candidate| {
1732 pick_constraints
1733 .map(|pick_constraints| pick_constraints.candidate_may_shadow(&candidate))
1734 .unwrap_or(true)
1735 })
1736 .map(|probe| {
1737 (
1738 probe,
1739 self.consider_probe(
1740 self_ty,
1741 instantiate_self_ty_obligations,
1742 probe,
1743 &mut pick_diag_hints.unsatisfied_predicates,
1744 ),
1745 )
1746 })
1747 .filter(|&(_, status)| status != ProbeResult::NoMatch)
1748 .collect();
1749
1750 {
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:1750",
"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(1750u32),
::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);
1751
1752 if applicable_candidates.len() > 1 {
1753 if let Some(pick) =
1754 self.collapse_candidates_to_trait_pick(self_ty, &applicable_candidates)
1755 {
1756 return Some(Ok(pick));
1757 }
1758 }
1759
1760 if let Some(uc) = &mut pick_diag_hints.unstable_candidates {
1761 applicable_candidates.retain(|&(candidate, _)| {
1762 if let stability::EvalResult::Deny { feature, .. } =
1763 self.tcx.eval_stability(candidate.item.def_id, None, self.span, None)
1764 {
1765 uc.push((candidate.clone(), feature));
1766 return false;
1767 }
1768 true
1769 });
1770 }
1771
1772 if applicable_candidates.len() > 1 {
1773 if self.tcx.features().supertrait_item_shadowing() {
1777 if let Some(pick) =
1778 self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
1779 {
1780 return Some(Ok(pick));
1781 }
1782 }
1783
1784 let sources =
1785 applicable_candidates.iter().map(|p| self.candidate_source(p.0, self_ty)).collect();
1786 return Some(Err(MethodError::Ambiguity(sources)));
1787 }
1788
1789 applicable_candidates.pop().map(|(probe, status)| match status {
1790 ProbeResult::Match => Ok(probe.to_unadjusted_pick(
1791 self_ty,
1792 pick_diag_hints.unstable_candidates.clone().unwrap_or_default(),
1793 )),
1794 ProbeResult::NoMatch | ProbeResult::BadReturnType => Err(MethodError::BadReturnType),
1795 })
1796 }
1797}
1798
1799impl<'tcx> Pick<'tcx> {
1800 pub(crate) fn differs_from(&self, other: &Self) -> bool {
1805 let Self {
1806 item: AssocItem { def_id, kind: _, container: _ },
1807 kind: _,
1808 import_ids: _,
1809 autoderefs: _,
1810 autoref_or_ptr_adjustment: _,
1811 self_ty,
1812 unstable_candidates: _,
1813 receiver_steps: _,
1814 shadowed_candidates: _,
1815 } = *self;
1816 self_ty != other.self_ty || def_id != other.item.def_id
1817 }
1818
1819 pub(crate) fn maybe_emit_unstable_name_collision_hint(
1821 &self,
1822 tcx: TyCtxt<'tcx>,
1823 span: Span,
1824 scope_expr_id: HirId,
1825 ) {
1826 if self.unstable_candidates.is_empty() {
1827 return;
1828 }
1829 let def_kind = self.item.as_def_kind();
1830 tcx.node_span_lint(lint::builtin::UNSTABLE_NAME_COLLISIONS, scope_expr_id, span, |lint| {
1831 lint.primary_message(::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, self.item.def_id),
tcx.def_kind_descr(def_kind, self.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, self.item.def_id),
1834 tcx.def_kind_descr(def_kind, self.item.def_id),
1835 ));
1836
1837 match (self.item.kind, self.item.container) {
1838 (ty::AssocKind::Fn { .. }, _) => {
1839 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(self.item.def_id)))
})format!(
1844 "call with fully qualified syntax `{}(...)` to keep using the current \
1845 method",
1846 tcx.def_path_str(self.item.def_id),
1847 ));
1848 }
1849 (ty::AssocKind::Const { name }, ty::AssocContainer::Trait) => {
1850 let def_id = self.item.container_id(tcx);
1851 lint.span_suggestion(
1852 span,
1853 "use the fully qualified path to the associated const",
1854 ::alloc::__export::must_use({
::alloc::fmt::format(format_args!("<{0} as {1}>::{2}", self.self_ty,
tcx.def_path_str(def_id), name))
})format!("<{} as {}>::{}", self.self_ty, tcx.def_path_str(def_id), name),
1855 Applicability::MachineApplicable,
1856 );
1857 }
1858 _ => {}
1859 }
1860 tcx.disabled_nightly_features(
1861 lint,
1862 self.unstable_candidates.iter().map(|(candidate, feature)| {
1863 (::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)
1864 }),
1865 );
1866 });
1867 }
1868}
1869
1870impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1871 fn select_trait_candidate(
1872 &self,
1873 trait_ref: ty::TraitRef<'tcx>,
1874 ) -> traits::SelectionResult<'tcx, traits::Selection<'tcx>> {
1875 let obligation =
1876 traits::Obligation::new(self.tcx, self.misc(self.span), self.param_env, trait_ref);
1877 traits::SelectionContext::new(self).select(&obligation)
1878 }
1879
1880 fn candidate_source(&self, candidate: &Candidate<'tcx>, self_ty: Ty<'tcx>) -> CandidateSource {
1883 match candidate.kind {
1884 InherentImplCandidate { .. } => {
1885 CandidateSource::Impl(candidate.item.container_id(self.tcx))
1886 }
1887 ObjectCandidate(_) | WhereClauseCandidate(_) => {
1888 CandidateSource::Trait(candidate.item.container_id(self.tcx))
1889 }
1890 TraitCandidate(trait_ref, _) => self.probe(|_| {
1891 let trait_ref = self.instantiate_binder_with_fresh_vars(
1892 self.span,
1893 BoundRegionConversionTime::FnCall,
1894 trait_ref,
1895 );
1896 let (xform_self_ty, _) =
1897 self.xform_self_ty(candidate.item, trait_ref.self_ty(), trait_ref.args);
1898 let _ = self.at(&ObligationCause::dummy(), self.param_env).sup(
1901 DefineOpaqueTypes::Yes,
1902 xform_self_ty,
1903 self_ty,
1904 );
1905 match self.select_trait_candidate(trait_ref) {
1906 Ok(Some(traits::ImplSource::UserDefined(ref impl_data))) => {
1907 CandidateSource::Impl(impl_data.impl_def_id)
1910 }
1911 _ => CandidateSource::Trait(candidate.item.container_id(self.tcx)),
1912 }
1913 }),
1914 }
1915 }
1916
1917 fn candidate_source_from_pick(&self, pick: &Pick<'tcx>) -> CandidateSource {
1918 match pick.kind {
1919 InherentImplPick => CandidateSource::Impl(pick.item.container_id(self.tcx)),
1920 ObjectPick | WhereClausePick(_) | TraitPick(_) => {
1921 CandidateSource::Trait(pick.item.container_id(self.tcx))
1922 }
1923 }
1924 }
1925
1926 x;#[instrument(level = "debug", skip(self, possibly_unsatisfied_predicates), ret)]
1927 fn consider_probe(
1928 &self,
1929 self_ty: Ty<'tcx>,
1930 instantiate_self_ty_obligations: &[PredicateObligation<'tcx>],
1931 probe: &Candidate<'tcx>,
1932 possibly_unsatisfied_predicates: &mut UnsatisfiedPredicates<'tcx>,
1933 ) -> ProbeResult {
1934 self.probe(|snapshot| {
1935 let outer_universe = self.universe();
1936
1937 let mut result = ProbeResult::Match;
1938 let cause = &self.misc(self.span);
1939 let ocx = ObligationCtxt::new_with_diagnostics(self);
1940
1941 if self.next_trait_solver() {
1949 ocx.register_obligations(instantiate_self_ty_obligations.iter().cloned());
1950 let errors = ocx.try_evaluate_obligations();
1951 if !errors.is_empty() {
1952 unreachable!("unexpected autoderef error {errors:?}");
1953 }
1954 }
1955
1956 let mut trait_predicate = None;
1957 let (mut xform_self_ty, mut xform_ret_ty);
1958
1959 match probe.kind {
1960 InherentImplCandidate { impl_def_id, .. } => {
1961 let impl_args = self.fresh_args_for_item(self.span, impl_def_id);
1962 let impl_ty = self.tcx.type_of(impl_def_id).instantiate(self.tcx, impl_args);
1963 (xform_self_ty, xform_ret_ty) =
1964 self.xform_self_ty(probe.item, impl_ty, impl_args);
1965 xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
1966 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
1967 {
1968 Ok(()) => {}
1969 Err(err) => {
1970 debug!("--> cannot relate self-types {:?}", err);
1971 return ProbeResult::NoMatch;
1972 }
1973 }
1974 xform_ret_ty = ocx.normalize(cause, self.param_env, xform_ret_ty);
1976 let impl_def_id = probe.item.container_id(self.tcx);
1978 let impl_bounds =
1979 self.tcx.predicates_of(impl_def_id).instantiate(self.tcx, impl_args);
1980 let impl_bounds = ocx.normalize(cause, self.param_env, impl_bounds);
1981 ocx.register_obligations(traits::predicates_for_generics(
1983 |idx, span| {
1984 let code = ObligationCauseCode::WhereClauseInExpr(
1985 impl_def_id,
1986 span,
1987 self.scope_expr_id,
1988 idx,
1989 );
1990 self.cause(self.span, code)
1991 },
1992 self.param_env,
1993 impl_bounds,
1994 ));
1995 }
1996 TraitCandidate(poly_trait_ref, _) => {
1997 if let Some(method_name) = self.method_name {
2000 if self_ty.is_array() && !method_name.span.at_least_rust_2021() {
2001 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2002 if trait_def.skip_array_during_method_dispatch {
2003 return ProbeResult::NoMatch;
2004 }
2005 }
2006
2007 if self_ty.boxed_ty().is_some_and(Ty::is_slice)
2010 && !method_name.span.at_least_rust_2024()
2011 {
2012 let trait_def = self.tcx.trait_def(poly_trait_ref.def_id());
2013 if trait_def.skip_boxed_slice_during_method_dispatch {
2014 return ProbeResult::NoMatch;
2015 }
2016 }
2017 }
2018
2019 let trait_ref = self.instantiate_binder_with_fresh_vars(
2020 self.span,
2021 BoundRegionConversionTime::FnCall,
2022 poly_trait_ref,
2023 );
2024 let trait_ref = ocx.normalize(cause, self.param_env, trait_ref);
2025 (xform_self_ty, xform_ret_ty) =
2026 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2027 xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
2028 match self_ty.kind() {
2029 ty::Alias(ty::Opaque, alias_ty)
2033 if !self.next_trait_solver()
2034 && self.infcx.can_define_opaque_ty(alias_ty.def_id)
2035 && !xform_self_ty.is_ty_var() =>
2036 {
2037 return ProbeResult::NoMatch;
2038 }
2039 _ => match ocx.relate(
2040 cause,
2041 self.param_env,
2042 self.variance(),
2043 self_ty,
2044 xform_self_ty,
2045 ) {
2046 Ok(()) => {}
2047 Err(err) => {
2048 debug!("--> cannot relate self-types {:?}", err);
2049 return ProbeResult::NoMatch;
2050 }
2051 },
2052 }
2053 let obligation = traits::Obligation::new(
2054 self.tcx,
2055 cause.clone(),
2056 self.param_env,
2057 ty::Binder::dummy(trait_ref),
2058 );
2059
2060 if self.infcx.next_trait_solver() || self.infcx.predicate_may_hold(&obligation)
2062 {
2063 ocx.register_obligation(obligation);
2064 } else {
2065 result = ProbeResult::NoMatch;
2066 if let Ok(Some(candidate)) = self.select_trait_candidate(trait_ref) {
2067 for nested_obligation in candidate.nested_obligations() {
2068 if !self.infcx.predicate_may_hold(&nested_obligation) {
2069 possibly_unsatisfied_predicates.push((
2070 self.resolve_vars_if_possible(nested_obligation.predicate),
2071 Some(self.resolve_vars_if_possible(obligation.predicate)),
2072 Some(nested_obligation.cause),
2073 ));
2074 }
2075 }
2076 }
2077 }
2078
2079 trait_predicate = Some(trait_ref.upcast(self.tcx));
2080 }
2081 ObjectCandidate(poly_trait_ref) | WhereClauseCandidate(poly_trait_ref) => {
2082 let trait_ref = self.instantiate_binder_with_fresh_vars(
2083 self.span,
2084 BoundRegionConversionTime::FnCall,
2085 poly_trait_ref,
2086 );
2087 (xform_self_ty, xform_ret_ty) =
2088 self.xform_self_ty(probe.item, trait_ref.self_ty(), trait_ref.args);
2089
2090 if matches!(probe.kind, WhereClauseCandidate(_)) {
2091 match ocx.structurally_normalize_ty(
2095 cause,
2096 self.param_env,
2097 trait_ref.self_ty(),
2098 ) {
2099 Ok(ty) => {
2100 if !matches!(ty.kind(), ty::Param(_)) {
2101 debug!("--> not a param ty: {xform_self_ty:?}");
2102 return ProbeResult::NoMatch;
2103 }
2104 }
2105 Err(errors) => {
2106 debug!("--> cannot relate self-types {:?}", errors);
2107 return ProbeResult::NoMatch;
2108 }
2109 }
2110 }
2111
2112 xform_self_ty = ocx.normalize(cause, self.param_env, xform_self_ty);
2113 match ocx.relate(cause, self.param_env, self.variance(), self_ty, xform_self_ty)
2114 {
2115 Ok(()) => {}
2116 Err(err) => {
2117 debug!("--> cannot relate self-types {:?}", err);
2118 return ProbeResult::NoMatch;
2119 }
2120 }
2121 }
2122 }
2123
2124 if let Some(xform_ret_ty) = xform_ret_ty
2136 && self.infcx.next_trait_solver()
2137 {
2138 ocx.register_obligation(traits::Obligation::new(
2139 self.tcx,
2140 cause.clone(),
2141 self.param_env,
2142 ty::ClauseKind::WellFormed(xform_ret_ty.into()),
2143 ));
2144 }
2145
2146 for error in ocx.try_evaluate_obligations() {
2148 result = ProbeResult::NoMatch;
2149 let nested_predicate = self.resolve_vars_if_possible(error.obligation.predicate);
2150 if let Some(trait_predicate) = trait_predicate
2151 && nested_predicate == self.resolve_vars_if_possible(trait_predicate)
2152 {
2153 } else {
2157 possibly_unsatisfied_predicates.push((
2158 nested_predicate,
2159 Some(self.resolve_vars_if_possible(error.root_obligation.predicate))
2160 .filter(|root_predicate| *root_predicate != nested_predicate),
2161 Some(error.obligation.cause),
2162 ));
2163 }
2164 }
2165
2166 if let ProbeResult::Match = result
2167 && let Some(return_ty) = self.return_type
2168 && let Some(mut xform_ret_ty) = xform_ret_ty
2169 {
2170 if !matches!(probe.kind, InherentImplCandidate { .. }) {
2175 xform_ret_ty = ocx.normalize(&cause, self.param_env, xform_ret_ty);
2176 }
2177
2178 debug!("comparing return_ty {:?} with xform ret ty {:?}", return_ty, xform_ret_ty);
2179 match ocx.relate(cause, self.param_env, self.variance(), xform_ret_ty, return_ty) {
2180 Ok(()) => {}
2181 Err(_) => {
2182 result = ProbeResult::BadReturnType;
2183 }
2184 }
2185
2186 for error in ocx.try_evaluate_obligations() {
2188 result = ProbeResult::NoMatch;
2189 possibly_unsatisfied_predicates.push((
2190 error.obligation.predicate,
2191 Some(error.root_obligation.predicate)
2192 .filter(|predicate| *predicate != error.obligation.predicate),
2193 Some(error.root_obligation.cause),
2194 ));
2195 }
2196 }
2197
2198 if self.infcx.next_trait_solver() {
2199 if self.should_reject_candidate_due_to_opaque_treated_as_rigid(trait_predicate) {
2200 result = ProbeResult::NoMatch;
2201 }
2202 }
2203
2204 if let Err(_) = self.leak_check(outer_universe, Some(snapshot)) {
2210 result = ProbeResult::NoMatch;
2211 }
2212
2213 result
2214 })
2215 }
2216
2217 x;#[instrument(level = "debug", skip(self), ret)]
2232 fn should_reject_candidate_due_to_opaque_treated_as_rigid(
2233 &self,
2234 trait_predicate: Option<ty::Predicate<'tcx>>,
2235 ) -> bool {
2236 if let Some(predicate) = trait_predicate {
2248 let goal = Goal { param_env: self.param_env, predicate };
2249 if !self.infcx.goal_may_hold_opaque_types_jank(goal) {
2250 return true;
2251 }
2252 }
2253
2254 for step in self.steps {
2257 if step.self_ty_is_opaque {
2258 debug!(?step.autoderefs, ?step.self_ty, "self_type_is_opaque");
2259 let constrained_opaque = self.probe(|_| {
2260 let Ok(ok) = self.fcx.probe_instantiate_query_response(
2265 self.span,
2266 self.orig_steps_var_values,
2267 &step.self_ty,
2268 ) else {
2269 debug!("failed to instantiate self_ty");
2270 return false;
2271 };
2272 let ocx = ObligationCtxt::new(self);
2273 let self_ty = ocx.register_infer_ok_obligations(ok);
2274 if !ocx.try_evaluate_obligations().is_empty() {
2275 debug!("failed to prove instantiate self_ty obligations");
2276 return false;
2277 }
2278
2279 !self.resolve_vars_if_possible(self_ty).is_ty_var()
2280 });
2281 if constrained_opaque {
2282 debug!("opaque type has been constrained");
2283 return true;
2284 }
2285 }
2286 }
2287
2288 false
2289 }
2290
2291 fn collapse_candidates_to_trait_pick(
2309 &self,
2310 self_ty: Ty<'tcx>,
2311 probes: &[(&Candidate<'tcx>, ProbeResult)],
2312 ) -> Option<Pick<'tcx>> {
2313 let container = probes[0].0.item.trait_container(self.tcx)?;
2315 for (p, _) in &probes[1..] {
2316 let p_container = p.item.trait_container(self.tcx)?;
2317 if p_container != container {
2318 return None;
2319 }
2320 }
2321
2322 let lint_ambiguous = match probes[0].0.kind {
2323 TraitCandidate(_, lint) => lint,
2324 _ => false,
2325 };
2326
2327 Some(Pick {
2330 item: probes[0].0.item,
2331 kind: TraitPick(lint_ambiguous),
2332 import_ids: probes[0].0.import_ids.clone(),
2333 autoderefs: 0,
2334 autoref_or_ptr_adjustment: None,
2335 self_ty,
2336 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2337 receiver_steps: None,
2338 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2339 })
2340 }
2341
2342 fn collapse_candidates_to_subtrait_pick(
2348 &self,
2349 self_ty: Ty<'tcx>,
2350 probes: &[(&Candidate<'tcx>, ProbeResult)],
2351 ) -> Option<Pick<'tcx>> {
2352 let mut child_candidate = probes[0].0;
2353 let mut child_trait = child_candidate.item.trait_container(self.tcx)?;
2354 let mut supertraits: SsoHashSet<_> = supertrait_def_ids(self.tcx, child_trait).collect();
2355
2356 let mut remaining_candidates: Vec<_> = probes[1..].iter().map(|&(p, _)| p).collect();
2357 while !remaining_candidates.is_empty() {
2358 let mut made_progress = false;
2359 let mut next_round = ::alloc::vec::Vec::new()vec![];
2360
2361 for remaining_candidate in remaining_candidates {
2362 let remaining_trait = remaining_candidate.item.trait_container(self.tcx)?;
2363 if supertraits.contains(&remaining_trait) {
2364 made_progress = true;
2365 continue;
2366 }
2367
2368 let remaining_trait_supertraits: SsoHashSet<_> =
2374 supertrait_def_ids(self.tcx, remaining_trait).collect();
2375 if remaining_trait_supertraits.contains(&child_trait) {
2376 child_candidate = remaining_candidate;
2377 child_trait = remaining_trait;
2378 supertraits = remaining_trait_supertraits;
2379 made_progress = true;
2380 continue;
2381 }
2382
2383 next_round.push(remaining_candidate);
2389 }
2390
2391 if made_progress {
2392 remaining_candidates = next_round;
2394 } else {
2395 return None;
2398 }
2399 }
2400
2401 let lint_ambiguous = match probes[0].0.kind {
2402 TraitCandidate(_, lint) => lint,
2403 _ => false,
2404 };
2405
2406 Some(Pick {
2407 item: child_candidate.item,
2408 kind: TraitPick(lint_ambiguous),
2409 import_ids: child_candidate.import_ids.clone(),
2410 autoderefs: 0,
2411 autoref_or_ptr_adjustment: None,
2412 self_ty,
2413 unstable_candidates: ::alloc::vec::Vec::new()vec![],
2414 shadowed_candidates: probes
2415 .iter()
2416 .map(|(c, _)| c.item)
2417 .filter(|item| item.def_id != child_candidate.item.def_id)
2418 .collect(),
2419 receiver_steps: None,
2420 })
2421 }
2422
2423 #[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(2426u32),
::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:2430",
"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(2430u32),
::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))]
2427 pub(crate) fn probe_for_similar_candidate(
2428 &mut self,
2429 ) -> Result<Option<ty::AssocItem>, MethodError<'tcx>> {
2430 debug!("probing for method names similar to {:?}", self.method_name);
2431
2432 self.probe(|_| {
2433 let mut pcx = ProbeContext::new(
2434 self.fcx,
2435 self.span,
2436 self.mode,
2437 self.method_name,
2438 self.return_type,
2439 self.orig_steps_var_values,
2440 self.steps,
2441 self.scope_expr_id,
2442 IsSuggestion(true),
2443 );
2444 pcx.allow_similar_names = true;
2445 pcx.assemble_inherent_candidates();
2446 pcx.assemble_extension_candidates_for_all_traits();
2447
2448 let method_names = pcx.candidate_method_names(|_| true);
2449 pcx.allow_similar_names = false;
2450 let applicable_close_candidates: Vec<ty::AssocItem> = method_names
2451 .iter()
2452 .filter_map(|&method_name| {
2453 pcx.reset();
2454 pcx.method_name = Some(method_name);
2455 pcx.assemble_inherent_candidates();
2456 pcx.assemble_extension_candidates_for_all_traits();
2457 pcx.pick_core(&mut Vec::new()).and_then(|pick| pick.ok()).map(|pick| pick.item)
2458 })
2459 .collect();
2460
2461 if applicable_close_candidates.is_empty() {
2462 Ok(None)
2463 } else {
2464 let best_name = {
2465 let names = applicable_close_candidates
2466 .iter()
2467 .map(|cand| cand.name())
2468 .collect::<Vec<Symbol>>();
2469 find_best_match_for_name_with_substrings(
2470 &names,
2471 self.method_name.unwrap().name,
2472 None,
2473 )
2474 }
2475 .or_else(|| {
2476 applicable_close_candidates
2477 .iter()
2478 .find(|cand| self.matches_by_doc_alias(cand.def_id))
2479 .map(|cand| cand.name())
2480 });
2481 Ok(best_name.and_then(|best_name| {
2482 applicable_close_candidates
2483 .into_iter()
2484 .find(|method| method.name() == best_name)
2485 }))
2486 }
2487 })
2488 }
2489
2490 fn has_applicable_self(&self, item: &ty::AssocItem) -> bool {
2493 match self.mode {
2499 Mode::MethodCall => item.is_method(),
2500 Mode::Path => match item.kind {
2501 ty::AssocKind::Type { .. } => false,
2502 ty::AssocKind::Fn { .. } | ty::AssocKind::Const { .. } => true,
2503 },
2504 }
2505 }
2512
2513 fn record_static_candidate(&self, source: CandidateSource) {
2514 self.static_candidates.borrow_mut().push(source);
2515 }
2516
2517 #[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(2517u32),
::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))]
2518 fn xform_self_ty(
2519 &self,
2520 item: ty::AssocItem,
2521 impl_ty: Ty<'tcx>,
2522 args: GenericArgsRef<'tcx>,
2523 ) -> (Ty<'tcx>, Option<Ty<'tcx>>) {
2524 if item.is_fn() && self.mode == Mode::MethodCall {
2525 let sig = self.xform_method_sig(item.def_id, args);
2526 (sig.inputs()[0], Some(sig.output()))
2527 } else {
2528 (impl_ty, None)
2529 }
2530 }
2531
2532 #[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(2532u32),
::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:2535",
"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(2535u32),
::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)
} 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)
};
self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
}
}
}#[instrument(level = "debug", skip(self))]
2533 fn xform_method_sig(&self, method: DefId, args: GenericArgsRef<'tcx>) -> ty::FnSig<'tcx> {
2534 let fn_sig = self.tcx.fn_sig(method);
2535 debug!(?fn_sig);
2536
2537 assert!(!args.has_escaping_bound_vars());
2538
2539 let generics = self.tcx.generics_of(method);
2545 assert_eq!(args.len(), generics.parent_count);
2546
2547 let xform_fn_sig = if generics.is_own_empty() {
2548 fn_sig.instantiate(self.tcx, args)
2549 } else {
2550 let args = GenericArgs::for_item(self.tcx, method, |param, _| {
2551 let i = param.index as usize;
2552 if i < args.len() {
2553 args[i]
2554 } else {
2555 match param.kind {
2556 GenericParamDefKind::Lifetime => {
2557 self.tcx.lifetimes.re_erased.into()
2559 }
2560 GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => {
2561 self.var_for_def(self.span, param)
2562 }
2563 }
2564 }
2565 });
2566 fn_sig.instantiate(self.tcx, args)
2567 };
2568
2569 self.tcx.instantiate_bound_regions_with_erased(xform_fn_sig)
2570 }
2571
2572 fn is_relevant_kind_for_mode(&self, kind: ty::AssocKind) -> bool {
2574 match (self.mode, kind) {
2575 (Mode::MethodCall, ty::AssocKind::Fn { .. }) => true,
2576 (Mode::Path, ty::AssocKind::Const { .. } | ty::AssocKind::Fn { .. }) => true,
2577 _ => false,
2578 }
2579 }
2580
2581 fn matches_by_doc_alias(&self, def_id: DefId) -> bool {
2584 let Some(method) = self.method_name else {
2585 return false;
2586 };
2587 let Some(local_def_id) = def_id.as_local() else {
2588 return false;
2589 };
2590 let hir_id = self.fcx.tcx.local_def_id_to_hir_id(local_def_id);
2591 let attrs = self.fcx.tcx.hir_attrs(hir_id);
2592
2593 if let Some(d) = {
'done:
{
for i in attrs {
#[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!(attrs, Doc(d) => d)
2594 && d.aliases.contains_key(&method.name)
2595 {
2596 return true;
2597 }
2598
2599 for attr in attrs {
2600 if attr.has_name(sym::rustc_confusables) {
2601 let Some(confusables) = attr.meta_item_list() else {
2602 continue;
2603 };
2604 for n in confusables {
2606 if let Some(lit) = n.lit()
2607 && method.name == lit.symbol
2608 {
2609 return true;
2610 }
2611 }
2612 }
2613 }
2614 false
2615 }
2616
2617 fn impl_or_trait_item(&self, def_id: DefId) -> SmallVec<[ty::AssocItem; 1]> {
2622 if let Some(name) = self.method_name {
2623 if self.allow_similar_names {
2624 let max_dist = max(name.as_str().len(), 3) / 3;
2625 self.tcx
2626 .associated_items(def_id)
2627 .in_definition_order()
2628 .filter(|x| {
2629 if !self.is_relevant_kind_for_mode(x.kind) {
2630 return false;
2631 }
2632 if let Some(d) = edit_distance_with_substrings(
2633 name.as_str(),
2634 x.name().as_str(),
2635 max_dist,
2636 ) {
2637 return d > 0;
2638 }
2639 self.matches_by_doc_alias(x.def_id)
2640 })
2641 .copied()
2642 .collect()
2643 } else {
2644 self.fcx
2645 .associated_value(def_id, name)
2646 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2647 .map_or_else(SmallVec::new, |x| SmallVec::from_buf([x]))
2648 }
2649 } else {
2650 self.tcx
2651 .associated_items(def_id)
2652 .in_definition_order()
2653 .filter(|x| self.is_relevant_kind_for_mode(x.kind))
2654 .copied()
2655 .collect()
2656 }
2657 }
2658}
2659
2660impl<'tcx> Candidate<'tcx> {
2661 fn to_unadjusted_pick(
2662 &self,
2663 self_ty: Ty<'tcx>,
2664 unstable_candidates: Vec<(Candidate<'tcx>, Symbol)>,
2665 ) -> Pick<'tcx> {
2666 Pick {
2667 item: self.item,
2668 kind: match self.kind {
2669 InherentImplCandidate { .. } => InherentImplPick,
2670 ObjectCandidate(_) => ObjectPick,
2671 TraitCandidate(_, lint_ambiguous) => TraitPick(lint_ambiguous),
2672 WhereClauseCandidate(trait_ref) => {
2673 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!(
2679 !trait_ref.skip_binder().args.has_infer()
2680 && !trait_ref.skip_binder().args.has_placeholders()
2681 );
2682
2683 WhereClausePick(trait_ref)
2684 }
2685 },
2686 import_ids: self.import_ids.clone(),
2687 autoderefs: 0,
2688 autoref_or_ptr_adjustment: None,
2689 self_ty,
2690 unstable_candidates,
2691 receiver_steps: match self.kind {
2692 InherentImplCandidate { receiver_steps, .. } => Some(receiver_steps),
2693 _ => None,
2694 },
2695 shadowed_candidates: ::alloc::vec::Vec::new()vec![],
2696 }
2697 }
2698}