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
16impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17    /// Returns a list of all obligations whose self type has been unified
18    /// with the unconstrained type `self_ty`.
19    #[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(19u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_hir_typeck::fn_ctxt::inspect_obligations"),
                                    ::tracing_core::field::FieldSet::new(&["self_ty"],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::DEBUG <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&self_ty)
                                                            as &dyn Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: PredicateObligations<'tcx> =
                loop {};
            return __tracing_attr_fake_return;
        }
        {
            if self.next_trait_solver() {
                self.obligations_for_self_ty_next(self_ty)
            } else {
                let ty_var_root = self.root_var(self_ty);
                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:26",
                                        "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(26u32),
                                        ::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,
                            ty_var_root));
                obligations
            }
        }
    }
}#[instrument(skip(self), level = "debug")]
20    pub(crate) fn obligations_for_self_ty(&self, self_ty: ty::TyVid) -> PredicateObligations<'tcx> {
21        if self.next_trait_solver() {
22            self.obligations_for_self_ty_next(self_ty)
23        } else {
24            let ty_var_root = self.root_var(self_ty);
25            let mut obligations = self.fulfillment_cx.borrow().pending_obligations();
26            trace!("pending_obligations = {:#?}", obligations);
27            obligations
28                .retain(|obligation| self.predicate_has_self_ty(obligation.predicate, ty_var_root));
29            obligations
30        }
31    }
32
33    x;#[instrument(level = "debug", skip(self), ret)]
34    fn predicate_has_self_ty(
35        &self,
36        predicate: ty::Predicate<'tcx>,
37        expected_vid: ty::TyVid,
38    ) -> bool {
39        match predicate.kind().skip_binder() {
40            ty::PredicateKind::Clause(ty::ClauseKind::Trait(data)) => {
41                self.type_matches_expected_vid(data.self_ty(), expected_vid)
42            }
43            ty::PredicateKind::Clause(ty::ClauseKind::Projection(data)) => {
44                self.type_matches_expected_vid(data.projection_term.self_ty(), expected_vid)
45            }
46            ty::PredicateKind::Clause(ty::ClauseKind::ConstArgHasType(..))
47            | ty::PredicateKind::Subtype(..)
48            | ty::PredicateKind::Coerce(..)
49            | ty::PredicateKind::Clause(ty::ClauseKind::RegionOutlives(..))
50            | ty::PredicateKind::Clause(ty::ClauseKind::TypeOutlives(..))
51            | ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(..))
52            | ty::PredicateKind::DynCompatible(..)
53            | ty::PredicateKind::NormalizesTo(..)
54            | ty::PredicateKind::AliasRelate(..)
55            | ty::PredicateKind::Clause(ty::ClauseKind::ConstEvaluatable(..))
56            | ty::PredicateKind::ConstEquate(..)
57            | ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(..))
58            | ty::PredicateKind::Clause(ty::ClauseKind::UnstableFeature(_))
59            | ty::PredicateKind::Ambiguous => false,
60        }
61    }
62
63    x;#[instrument(level = "debug", skip(self), ret)]
64    fn type_matches_expected_vid(&self, ty: Ty<'tcx>, expected_vid: ty::TyVid) -> bool {
65        let ty = self.shallow_resolve(ty);
66        debug!(?ty);
67
68        match *ty.kind() {
69            ty::Infer(ty::TyVar(found_vid)) => {
70                self.root_var(expected_vid) == self.root_var(found_vid)
71            }
72            _ => false,
73        }
74    }
75
76    pub(crate) fn obligations_for_self_ty_next(
77        &self,
78        self_ty: ty::TyVid,
79    ) -> PredicateObligations<'tcx> {
80        // We only look at obligations which may reference the self type.
81        // This lookup uses the `sub_root` instead of the inference variable
82        // itself as that's slightly nicer to implement. It shouldn't really
83        // matter.
84        //
85        // This is really impactful when typechecking functions with a lot of
86        // stalled obligations, e.g. in the `wg-grammar` benchmark.
87        let sub_root_var = self.sub_unification_table_root_var(self_ty);
88        let obligations = self
89            .fulfillment_cx
90            .borrow()
91            .pending_obligations_potentially_referencing_sub_root(&self.infcx, sub_root_var);
92        {
    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:92",
                        "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(92u32),
                        ::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);
93        let mut obligations_for_self_ty = PredicateObligations::new();
94        for obligation in obligations {
95            let mut visitor = NestedObligationsForSelfTy {
96                fcx: self,
97                self_ty,
98                obligations_for_self_ty: &mut obligations_for_self_ty,
99                root_cause: &obligation.cause,
100            };
101
102            let goal = obligation.as_goal();
103            self.visit_proof_tree(goal, &mut visitor);
104        }
105
106        obligations_for_self_ty.retain_mut(|obligation| {
107            obligation.predicate = self.resolve_vars_if_possible(obligation.predicate);
108            !obligation.predicate.has_placeholders()
109        });
110        obligations_for_self_ty
111    }
112
113    /// Only needed for the `From<{float}>` for `f32` type fallback.
114    #[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(114u32),
                                    ::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")]
115    pub(crate) fn from_float_for_f32_root_vids(&self) -> UnordSet<ty::FloatVid> {
116        if self.next_trait_solver() {
117            self.from_float_for_f32_root_vids_next()
118        } else {
119            let Some(from_trait) = self.tcx.lang_items().from_trait() else {
120                return UnordSet::new();
121            };
122            self.fulfillment_cx
123                .borrow_mut()
124                .pending_obligations()
125                .into_iter()
126                .filter_map(|obligation| {
127                    self.predicate_from_float_for_f32_root_vid(from_trait, obligation.predicate)
128                })
129                .collect()
130        }
131    }
132
133    fn predicate_from_float_for_f32_root_vid(
134        &self,
135        from_trait: DefId,
136        predicate: ty::Predicate<'tcx>,
137    ) -> Option<ty::FloatVid> {
138        // The predicates we are looking for look like
139        // `TraitPredicate(<f32 as std::convert::From<{float}>>, polarity:Positive)`.
140        // They will have no bound variables.
141        match predicate.kind().no_bound_vars() {
142            Some(ty::PredicateKind::Clause(ty::ClauseKind::Trait(ty::TraitPredicate {
143                polarity: ty::PredicatePolarity::Positive,
144                trait_ref,
145            }))) if trait_ref.def_id == from_trait
146                && self.shallow_resolve(trait_ref.self_ty()).kind()
147                    == &ty::Float(ty::FloatTy::F32) =>
148            {
149                self.root_float_vid(trait_ref.args.type_at(1))
150            }
151            _ => None,
152        }
153    }
154
155    fn from_float_for_f32_root_vids_next(&self) -> UnordSet<ty::FloatVid> {
156        let Some(from_trait) = self.tcx.lang_items().from_trait() else {
157            return UnordSet::new();
158        };
159        let obligations = self.fulfillment_cx.borrow().pending_obligations();
160        {
    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:160",
                        "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(160u32),
                        ::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);
161        let mut vids = UnordSet::new();
162        for obligation in obligations {
163            let mut visitor = FindFromFloatForF32RootVids {
164                fcx: self,
165                from_trait,
166                vids: &mut vids,
167                span: obligation.cause.span,
168            };
169
170            let goal = obligation.as_goal();
171            self.visit_proof_tree(goal, &mut visitor);
172        }
173        vids
174    }
175}
176
177struct NestedObligationsForSelfTy<'a, 'tcx> {
178    fcx: &'a FnCtxt<'a, 'tcx>,
179    self_ty: ty::TyVid,
180    root_cause: &'a ObligationCause<'tcx>,
181    obligations_for_self_ty: &'a mut PredicateObligations<'tcx>,
182}
183
184impl<'tcx> ProofTreeVisitor<'tcx> for NestedObligationsForSelfTy<'_, 'tcx> {
185    fn span(&self) -> Span {
186        self.root_cause.span
187    }
188
189    fn config(&self) -> InspectConfig {
190        // Using an intentionally low depth to minimize the chance of future
191        // breaking changes in case we adapt the approach later on. This also
192        // avoids any hangs for exponentially growing proof trees.
193        InspectConfig { max_depth: 5 }
194    }
195
196    fn visit_goal(&mut self, inspect_goal: &InspectGoal<'_, 'tcx>) {
197        // No need to walk into goal subtrees that certainly hold, since they
198        // wouldn't then be stalled on an infer var.
199        if inspect_goal.result() == Ok(Certainty::Yes) {
200            return;
201        }
202
203        // We don't care about any pending goals which don't actually
204        // use the self type.
205        if !inspect_goal
206            .orig_values()
207            .iter()
208            .filter_map(|arg| arg.as_type())
209            .any(|ty| self.fcx.type_matches_expected_vid(ty, self.self_ty))
210        {
211            {
    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:211",
                        "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(211u32),
                        ::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");
212            return;
213        }
214
215        let tcx = self.fcx.tcx;
216        let goal = inspect_goal.goal();
217        if self.fcx.predicate_has_self_ty(goal.predicate, self.self_ty) {
218            self.obligations_for_self_ty.push(traits::Obligation::new(
219                tcx,
220                self.root_cause.clone(),
221                goal.param_env,
222                goal.predicate,
223            ));
224        }
225
226        // If there's a unique way to prove a given goal, recurse into
227        // that candidate. This means that for `impl<F: FnOnce(u32)> Trait<F> for () {}`
228        // and a `(): Trait<?0>` goal we recurse into the impl and look at
229        // the nested `?0: FnOnce(u32)` goal.
230        if let Some(candidate) = inspect_goal.unique_applicable_candidate() {
231            candidate.visit_nested_no_probe(self)
232        }
233    }
234}
235
236struct FindFromFloatForF32RootVids<'a, 'tcx> {
237    fcx: &'a FnCtxt<'a, 'tcx>,
238    from_trait: DefId,
239    vids: &'a mut UnordSet<ty::FloatVid>,
240    span: Span,
241}
242
243impl<'tcx> ProofTreeVisitor<'tcx> for FindFromFloatForF32RootVids<'_, 'tcx> {
244    fn span(&self) -> Span {
245        self.span
246    }
247
248    fn config(&self) -> InspectConfig {
249        // Avoid hang from exponentially growing proof trees (see `cycle-modulo-ambig-aliases.rs`).
250        // 3 is more than enough for all occurrences in practice (a.k.a. `Into`).
251        InspectConfig { max_depth: 3 }
252    }
253
254    fn visit_goal(&mut self, inspect_goal: &InspectGoal<'_, 'tcx>) {
255        if let Some(vid) = self
256            .fcx
257            .predicate_from_float_for_f32_root_vid(self.from_trait, inspect_goal.goal().predicate)
258        {
259            self.vids.insert(vid);
260        } else if let Some(candidate) = inspect_goal.unique_applicable_candidate() {
261            let start_len = self.vids.len();
262            let _ = candidate.goal().infcx().commit_if_ok(|_| {
263                candidate.visit_nested_no_probe(self);
264                if self.vids.len() > start_len { Ok(()) } else { Err(()) }
265            });
266        }
267    }
268}