pub(super) fn expected_inputs_for_expected_output(
        &self,
        call_span: Span,
        expected_ret: Expectation<'tcx>,
        formal_ret: Ty<'tcx>,
        formal_args: &[Ty<'tcx>],
    ) -> Vec<Ty<'tcx>> {
        let formal_ret = self.resolve_vars_with_obligations(formal_ret);
        let ret_ty = match expected_ret.only_has_type(self) {
            Some(ret) => ret,
            None => return Vec::new(),
        };
        let expect_args = self
            .fudge_inference_if_ok(|| {
                // Attempt to apply a subtyping relationship between the formal
                // return type (likely containing type variables if the function
                // is polymorphic) and the expected return type.
                // No argument expectations are produced if unification fails.
                let origin = self.misc(call_span);
                let ures = self.at(&origin, self.param_env).sup(ret_ty, &formal_ret);

                // FIXME(#27336) can't use ? here, Try::from_error doesn't default
                // to identity so the resulting type is not constrained.
                match ures {
                    Ok(ok) => {
                        // Process any obligations locally as much as
                        // we can.  We don't care if some things turn
                        // out unconstrained or ambiguous, as we're
                        // just trying to get hints here.
                        self.save_and_restore_in_snapshot_flag(|_| {
                            let mut fulfill = TraitEngine::new(self.tcx);
                            for obligation in ok.obligations {
                                fulfill.register_predicate_obligation(self, obligation);
                            }
                            fulfill.select_where_possible(self)
                        })
                        .map_err(|_| ())?;
                    }
                    Err(_) => return Err(()),
                }

                // Record all the argument types, with the substitutions
                // produced from the above subtyping unification.
                Ok(formal_args.iter().map(|ty| self.resolve_vars_if_possible(ty)).collect())
            })
            .unwrap_or_default();
        debug!(
            "expected_inputs_for_expected_output(formal={:?} -> {:?}, expected={:?} -> {:?})",
            formal_args, formal_ret, expect_args, expected_ret
        );
        expect_args
    }
/// Unifies the output type with the expected type early, for more coercions
/// and forward type information on the input expressions.
Unifies the output type with the expected type early, for more coercions
and forward type information on the input expressions.
Unifies the output type with the expected type early for more coercions and forward type information on the input expressions .
pub(super) fn expected_inputs_for_expected_output(
        &self,
        call_span: Span,
        expected_ret: Expectation<'tcx>,
        formal_ret: Ty<'tcx>,
        formal_args: &[Ty<'tcx>],
    ) -> Vec<Ty<'tcx>> {
        let formal_ret = self.resolve_vars_with_obligations(formal_ret);
        let ret_ty = match expected_ret.only_has_type(self) {
            Some(ret) => ret,
            None => return Vec::new(),
        };
        let expect_args = self
            .fudge_inference_if_ok(|| {
                // Attempt to apply a subtyping relationship between the formal
                // return type (likely containing type variables if the function
                // is polymorphic) and the expected return type.
                // No argument expectations are produced if unification fails.
                let origin = self.misc(call_span);
                let ures = self.at(&origin, self.param_env).sup(ret_ty, &formal_ret);
                // FIXME(#27336) can't use ? here, Try::from_error doesn't default
                // to identity so the resulting type is not constrained.
                match ures {
                    Ok(ok) => {
                        // Process any obligations locally as much as
                        // we can.  We don't care if some things turn
                        // out unconstrained or ambiguous, as we're
                        // just trying to get hints here.
                        self.save_and_restore_in_snapshot_flag(|_| {
                            let mut fulfill = TraitEngine::new(self.tcx);
                            for obligation in ok.obligations {
                                fulfill.register_predicate_obligation(self, obligation);
                            }
                            fulfill.select_where_possible(self)
                        })
                        .map_err(|_| ())?;
                    }
                    Err(_) => return Err(()),
                }
                // Record all the argument types, with the substitutions
                // produced from the above subtyping unification.
                Ok(formal_args.iter().map(|ty| self.resolve_vars_if_possible(ty)).collect())
            })
            .unwrap_or_default();
        debug!(
            "expected_inputs_for_expected_output(formal={:?} -> {:?}, expected={:?} -> {:?})",
            formal_args, formal_ret, expect_args, expected_ret
        );
        expect_args
    }
pub ( super ) fn expected_inputs_for_expected_output ( & self , call_span : Span , expected_ret : Expectation < ' tcx > , formal_ret : Ty < ' tcx > , formal_args : & [ Ty < ' tcx > ] , ) -> Vec < Ty < ' tcx > > { let formal_ret = self . resolve_vars_with_obligations ( formal_ret ) ; let ret_ty = match expected_ret . only_has_type ( self ) { Some ( ret ) => ret , None => return Vec :: new ( ) , } ; let expect_args = self . fudge_inference_if_ok ( | | { // Attempt to apply a subtyping relationship between the formal // return type (likely containing type variables if the function // is polymorphic) and the expected return type. // No argument expectations are produced if unification fails. let origin = self . misc ( call_span ) ; let ures = self . at ( & origin , self . param_env ) . sup ( ret_ty , & formal_ret ) ; // FIXME(#27336) can't use ? here, Try::from_error doesn't default // to identity so the resulting type is not constrained. match ures { Ok ( ok ) => { // Process any obligations locally as much as // we can.  We don't care if some things turn // out unconstrained or ambiguous, as we're // just trying to get hints here. self . save_and_restore_in_snapshot_flag ( | _ | { let mut fulfill = TraitEngine :: new ( self . tcx ) ; for obligation in ok . obligations { fulfill . register_predicate_obligation ( self , obligation ) ; } fulfill . select_where_possible ( self ) } ) . map_err ( | _ | ( ) ) ? ; } Err ( _ ) => return Err ( ( ) ) , } // Record all the argument types, with the substitutions // produced from the above subtyping unification. Ok ( formal_args . iter ( ) . map ( | ty | self . resolve_vars_if_possible ( ty ) ) . collect ( ) ) } ) . unwrap_or_default ( ) ; debug ! ( " " formal_args formal_ret expect_args expected_ret ) ; expect_args }
Unifies the output type with the expected type early, for more coercions
and forward type information on the input expressions.
Unifies the output type with the expected type early for more coercions and forward type information on the input expressions .
&self
call_span
Span
expected_ret
Expectation<'tcx>
formal_ret
Ty<'tcx>
formal_args
&[Ty<'tcx>]
&self
call_span
Span
expected_ret
Expectation<'tcx>
formal_ret
Ty<'tcx>
formal_args
&[Ty<'tcx>]