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