Skip to main content

rustc_hir_typeck/fn_ctxt/
inspect_obligations.rs

1//! A utility module to inspect currently ambiguous obligations in the current context.
2
3use rustc_data_structures::unord::UnordSet;
4use rustc_hir::def_id::DefId;
5use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
6use rustc_middle::ty::{self, Ty, TypeVisitableExt};
7use rustc_span::Span;
8use rustc_trait_selection::solve::Certainty;
9use rustc_trait_selection::solve::inspect::{
10    InferCtxtProofTreeExt, InspectConfig, InspectGoal, ProofTreeVisitor,
11};
12use tracing::{debug, instrument, trace};
13
14use crate::FnCtxt;
15
16/// Whatever to use subtyping or not when inspecting obligations
17#[derive(#[automatically_derived]
impl ::core::fmt::Debug for UseSubtyping {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::write_str(f,
            match self {
                UseSubtyping::No => "No",
                UseSubtyping::Yes => "Yes",
            })
    }
}Debug, #[automatically_derived]
impl ::core::marker::Copy for UseSubtyping { }Copy, #[automatically_derived]
impl ::core::clone::Clone for UseSubtyping {
    #[inline]
    fn clone(&self) -> UseSubtyping { *self }
}Clone)]
18pub(crate) enum UseSubtyping {
19    /// Do **not** use subtyping. [`FnCtxt::obligations_for_self_ty`] will only return obligations
20    /// where the self type is known to be equal to the provided vid.
21    No,
22
23    /// Use subtyping. [`FnCtxt::obligations_for_self_ty`] will return obligations
24    /// where the self type is related to the provided vid via subtyping.
25    ///
26    /// Using this requires extra care, as traits holding for a subtype or a supertype, does not
27    /// necessarily imply that they hold for the respective supertype or subtype.
28    Yes,
29}
30
31impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
32    /// Returns a list of all obligations whose self type has been unified
33    /// with the unconstrained type `self_ty`.
34    #[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("obligations_for_self_ty",
                                    "rustc_hir_typeck::fn_ctxt::inspect_obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(34u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                                    ::tracing_core::field::FieldSet::new(&["self_ty",
                                                    "subtyping"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&subtyping)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: PredicateObligations<'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            if self.next_trait_solver() {
                self.obligations_for_self_ty_next(self_ty, subtyping)
            } else {
                let mut obligations =
                    self.fulfillment_cx.borrow().pending_obligations();
                {
                    use ::tracing::__macro_support::Callsite as _;
                    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                        {
                            static META: ::tracing::Metadata<'static> =
                                {
                                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs:44",
                                        "rustc_hir_typeck::fn_ctxt::inspect_obligations",
                                        ::tracing::Level::TRACE,
                                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs"),
                                        ::tracing_core::__macro_support::Option::Some(44u32),
                                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                                        ::tracing_core::field::FieldSet::new(&["message"],
                                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                        ::tracing::metadata::Kind::EVENT)
                                };
                            ::tracing::callsite::DefaultCallsite::new(&META)
                        };
                    let enabled =
                        ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            {
                                let interest = __CALLSITE.interest();
                                !interest.is_never() &&
                                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                        interest)
                            };
                    if enabled {
                        (|value_set: ::tracing::field::ValueSet|
                                    {
                                        let meta = __CALLSITE.metadata();
                                        ::tracing::Event::dispatch(meta, &value_set);
                                        ;
                                    })({
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = __CALLSITE.metadata().fields().iter();
                                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&format_args!("pending_obligations = {0:#?}",
                                                                    obligations) as &dyn Value))])
                            });
                    } else { ; }
                };
                obligations.retain(|obligation|
                        {
                            self.predicate_has_self_ty(obligation.predicate, self_ty,
                                subtyping)
                        });
                obligations
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
35    pub(crate) fn obligations_for_self_ty(
36        &self,
37        self_ty: ty::TyVid,
38        subtyping: UseSubtyping,
39    ) -> PredicateObligations<'tcx> {
40        if self.next_trait_solver() {
41            self.obligations_for_self_ty_next(self_ty, subtyping)
42        } else {
43            let mut obligations = self.fulfillment_cx.borrow().pending_obligations();
44            trace!("pending_obligations = {:#?}", obligations);
45            obligations.retain(|obligation| {
46                self.predicate_has_self_ty(obligation.predicate, self_ty, subtyping)
47            });
48            obligations
49        }
50    }
51
52    x;#[instrument(level = "debug", skip(self), ret)]
53    fn predicate_has_self_ty(
54        &self,
55        predicate: ty::Predicate<'tcx>,
56        expected_vid: ty::TyVid,
57        subtyping: UseSubtyping,
58    ) -> bool {
59        match predicate.kind().skip_binder() {
60            ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
61                self.type_matches_expected_vid(data.self_ty(), expected_vid, subtyping)
62            }
63            ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
64                if data.projection_term.kind.is_trait_projection() {
65                    self.type_matches_expected_vid(data.self_ty(), expected_vid, subtyping)
66                } else {
67                    false
68                }
69            }
70            ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
71            | ty::PredicateKind::Subtype(..)
72            | ty::PredicateKind::Coerce(..)
73            | ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
74            | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..))
75            | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
76            | ty::PredicateKind::DynCompatible(..)
77            | ty::PredicateKind::NormalizesTo(..)
78            | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
79            | ty::PredicateKind::ConstEquate(..)
80            | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
81            | ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
82            | ty::PredicateKind::Ambiguous => false,
83        }
84    }
85
86    x;#[instrument(level = "debug", skip(self), ret)]
87    fn type_matches_expected_vid(
88        &self,
89        ty: Ty<'tcx>,
90        expected_vid: ty::TyVid,
91        subtyping: UseSubtyping,
92    ) -> bool {
93        let ty = self.shallow_resolve(ty);
94        debug!(?ty);
95
96        match *ty.kind() {
97            ty::Infer(ty::TyVar(found_vid)) => match subtyping {
98                UseSubtyping::No => self.root_var(expected_vid) == self.root_var(found_vid),
99                UseSubtyping::Yes => {
100                    self.sub_unification_table_root_var(expected_vid)
101                        == self.sub_unification_table_root_var(found_vid)
102                }
103            },
104            _ => false,
105        }
106    }
107
108    pub(crate) fn obligations_for_self_ty_next(
109        &self,
110        self_ty: ty::TyVid,
111        subtyping: UseSubtyping,
112    ) -> PredicateObligations<'tcx> {
113        // We only look at obligations which may reference the self type.
114        // This lookup uses the `sub_root` instead of the inference variable
115        // itself as that's slightly nicer to implement. It shouldn't really
116        // matter.
117        //
118        // This is really impactful when typechecking functions with a lot of
119        // stalled obligations, e.g. in the `wg-grammar` benchmark.
120        let sub_root_var = self.sub_unification_table_root_var(self_ty);
121        let obligations = self
122            .fulfillment_cx
123            .borrow()
124            .pending_obligations_potentially_referencing_sub_root(&self.infcx, sub_root_var);
125        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs:125",
                        "rustc_hir_typeck::fn_ctxt::inspect_obligations",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs"),
                        ::tracing_core::__macro_support::Option::Some(125u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                        ::tracing_core::field::FieldSet::new(&["obligations"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligations)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?obligations);
126
127        let mut obligations_for_self_ty = PredicateObligations::new();
128        for obligation in obligations {
129            let mut visitor = NestedObligationsForSelfTy {
130                fcx: self,
131                self_ty,
132                obligations_for_self_ty: &mut obligations_for_self_ty,
133                root_cause: &obligation.cause,
134                subtyping,
135            };
136
137            let goal = obligation.as_goal();
138            self.visit_proof_tree(goal, &mut visitor);
139        }
140
141        obligations_for_self_ty.retain_mut(|obligation| {
142            obligation.predicate = self.resolve_vars_if_possible(obligation.predicate);
143            !obligation.predicate.has_placeholders()
144        });
145        obligations_for_self_ty
146    }
147
148    /// Only needed for the `From<{float}>` for `f32` type fallback.
149    #[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("from_float_for_f32_root_vids",
                                    "rustc_hir_typeck::fn_ctxt::inspect_obligations",
                                    ::tracing::Level::DEBUG,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs"),
                                    ::tracing_core::__macro_support::Option::Some(149u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: UnordSet<ty::FloatVid> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            if self.next_trait_solver() {
                self.from_float_for_f32_root_vids_next()
            } else {
                let Some(from_trait) =
                    self.tcx.lang_items().from_trait() else {
                        return UnordSet::new();
                    };
                self.fulfillment_cx.borrow_mut().pending_obligations().into_iter().filter_map(|obligation|
                            {
                                self.predicate_from_float_for_f32_root_vid(from_trait,
                                    obligation.predicate)
                            }).collect()
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
150    pub(crate) fn from_float_for_f32_root_vids(&self) -> UnordSet<ty::FloatVid> {
151        if self.next_trait_solver() {
152            self.from_float_for_f32_root_vids_next()
153        } else {
154            let Some(from_trait) = self.tcx.lang_items().from_trait() else {
155                return UnordSet::new();
156            };
157            self.fulfillment_cx
158                .borrow_mut()
159                .pending_obligations()
160                .into_iter()
161                .filter_map(|obligation| {
162                    self.predicate_from_float_for_f32_root_vid(from_trait, obligation.predicate)
163                })
164                .collect()
165        }
166    }
167
168    fn predicate_from_float_for_f32_root_vid(
169        &self,
170        from_trait: DefId,
171        predicate: ty::Predicate<'tcx>,
172    ) -> Option<ty::FloatVid> {
173        // The predicates we are looking for look like
174        // `TraitPredicate(<f32 as std::convert::From<{float}>>, polarity:Positive)`.
175        // They will have no bound variables.
176        match predicate.kind().no_bound_vars() {
177            Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
178                polarity: ty::PredicatePolarity::Positive,
179                trait_ref,
180            }))) if trait_ref.def_id == from_trait
181                && self.shallow_resolve(trait_ref.self_ty()).kind()
182                    == &ty::Float(ty::FloatTy::F32) =>
183            {
184                self.root_float_vid(trait_ref.args.type_at(1))
185            }
186            _ => None,
187        }
188    }
189
190    fn from_float_for_f32_root_vids_next(&self) -> UnordSet<ty::FloatVid> {
191        let Some(from_trait) = self.tcx.lang_items().from_trait() else {
192            return UnordSet::new();
193        };
194        let obligations = self.fulfillment_cx.borrow().pending_obligations();
195        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs:195",
                        "rustc_hir_typeck::fn_ctxt::inspect_obligations",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs"),
                        ::tracing_core::__macro_support::Option::Some(195u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                        ::tracing_core::field::FieldSet::new(&["obligations"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&obligations)
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(?obligations);
196        let mut vids = UnordSet::new();
197        for obligation in obligations {
198            let mut visitor = FindFromFloatForF32RootVids {
199                fcx: self,
200                from_trait,
201                vids: &mut vids,
202                span: obligation.cause.span,
203            };
204
205            let goal = obligation.as_goal();
206            self.visit_proof_tree(goal, &mut visitor);
207        }
208        vids
209    }
210}
211
212struct NestedObligationsForSelfTy<'a, 'tcx> {
213    fcx: &'a FnCtxt<'a, 'tcx>,
214    self_ty: ty::TyVid,
215    root_cause: &'a ObligationCause<'tcx>,
216    obligations_for_self_ty: &'a mut PredicateObligations<'tcx>,
217    subtyping: UseSubtyping,
218}
219
220impl<'tcx> ProofTreeVisitor<'tcx> for NestedObligationsForSelfTy<'_, 'tcx> {
221    fn span(&self) -> Span {
222        self.root_cause.span
223    }
224
225    fn config(&self) -> InspectConfig {
226        // Using an intentionally low depth to minimize the chance of future
227        // breaking changes in case we adapt the approach later on. This also
228        // avoids any hangs for exponentially growing proof trees.
229        InspectConfig { max_depth: 5 }
230    }
231
232    fn visit_goal(&mut self, inspect_goal: &InspectGoal<'_, 'tcx>) {
233        // No need to walk into goal subtrees that certainly hold, since they
234        // wouldn't then be stalled on an infer var.
235        if inspect_goal.result() == Ok(Certainty::Yes) {
236            return;
237        }
238
239        // We don't care about any pending goals which don't actually
240        // use the self type.
241        if !inspect_goal
242            .orig_values()
243            .iter()
244            .filter_map(|arg| arg.as_type())
245            .any(|ty| self.fcx.type_matches_expected_vid(ty, self.self_ty, self.subtyping))
246        {
247            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs:247",
                        "rustc_hir_typeck::fn_ctxt::inspect_obligations",
                        ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs"),
                        ::tracing_core::__macro_support::Option::Some(247u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                        ::tracing_core::field::FieldSet::new(&["message", "goal"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("goal does not mention self type")
                                            as &dyn Value)),
                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&debug(&inspect_goal.goal())
                                            as &dyn Value))])
            });
    } else { ; }
};debug!(goal = ?inspect_goal.goal(), "goal does not mention self type");
248            return;
249        }
250
251        let tcx = self.fcx.tcx;
252        let goal = inspect_goal.goal();
253        if self.fcx.predicate_has_self_ty(goal.predicate, self.self_ty, self.subtyping) {
254            self.obligations_for_self_ty.push(traits::Obligation::new(
255                tcx,
256                self.root_cause.clone(),
257                goal.param_env,
258                goal.predicate,
259            ));
260        }
261
262        // If there's a unique way to prove a given goal, recurse into
263        // that candidate. This means that for `impl<F: FnOnce(u32)> Trait<F> for () {}`
264        // and a `(): Trait<?0>` goal we recurse into the impl and look at
265        // the nested `?0: FnOnce(u32)` goal.
266        if let Some(candidate) = inspect_goal.unique_applicable_candidate() {
267            candidate.visit_nested_no_probe(self)
268        }
269    }
270}
271
272struct FindFromFloatForF32RootVids<'a, 'tcx> {
273    fcx: &'a FnCtxt<'a, 'tcx>,
274    from_trait: DefId,
275    vids: &'a mut UnordSet<ty::FloatVid>,
276    span: Span,
277}
278
279impl<'tcx> ProofTreeVisitor<'tcx> for FindFromFloatForF32RootVids<'_, 'tcx> {
280    fn span(&self) -> Span {
281        self.span
282    }
283
284    fn config(&self) -> InspectConfig {
285        // Avoid hang from exponentially growing proof trees (see `cycle-modulo-ambig-aliases.rs`).
286        // 3 is more than enough for all occurrences in practice (a.k.a. `Into`).
287        InspectConfig { max_depth: 3 }
288    }
289
290    fn visit_goal(&mut self, inspect_goal: &InspectGoal<'_, 'tcx>) {
291        if let Some(vid) = self
292            .fcx
293            .predicate_from_float_for_f32_root_vid(self.from_trait, inspect_goal.goal().predicate)
294        {
295            self.vids.insert(vid);
296        } else if let Some(candidate) = inspect_goal.unique_applicable_candidate() {
297            let start_len = self.vids.len();
298            let _ = candidate.goal().infcx().commit_if_ok(|_| {
299                candidate.visit_nested_no_probe(self);
300                if self.vids.len() > start_len { Ok(()) } else { Err(()) }
301            });
302        }
303    }
304}