Skip to content

Commit 2541da9

Browse files
authored
Merge pull request #22092 from ShoyuVanilla/fudge
Sync function call args check fudging with rustc
2 parents fa3dbe6 + 4e67fc0 commit 2541da9

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

crates/hir-ty/src/infer/expr.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ use crate::{
3535
lower::{GenericPredicates, lower_mutability},
3636
method_resolution::{self, CandidateId, MethodCallee, MethodError},
3737
next_solver::{
38-
ErrorGuaranteed, FnSig, GenericArg, GenericArgs, TraitRef, Ty, TyKind, TypeError,
38+
ClauseKind, ErrorGuaranteed, FnSig, GenericArg, GenericArgs, TraitRef, Ty, TyKind,
39+
TypeError,
3940
infer::{
4041
BoundRegionConversionTime, InferOk,
4142
traits::{Obligation, ObligationCause},
@@ -1898,6 +1899,15 @@ impl<'db> InferenceContext<'_, 'db> {
18981899
// Whether the function is variadic, for example when imported from C
18991900
c_variadic: bool,
19001901
) {
1902+
let formal_input_tys: Vec<_> = formal_input_tys
1903+
.iter()
1904+
.map(|&ty| {
1905+
let generalized_ty = self.table.next_ty_var();
1906+
let _ = self.demand_eqtype(call_expr.into(), ty, generalized_ty);
1907+
generalized_ty
1908+
})
1909+
.collect();
1910+
19011911
// First, let's unify the formal method signature with the expectation eagerly.
19021912
// We use this to guide coercion inference; it's output is "fudged" which means
19031913
// any remaining type variables are assigned to new, unrelated variables. This
@@ -1917,18 +1927,23 @@ impl<'db> InferenceContext<'_, 'db> {
19171927
// No argument expectations are produced if unification fails.
19181928
let origin = ObligationCause::new();
19191929
ocx.sup(&origin, self.table.param_env, expected_output, formal_output)?;
1930+
1931+
for &ty in &formal_input_tys {
1932+
ocx.register_obligation(Obligation::new(
1933+
self.interner(),
1934+
ObligationCause::new(),
1935+
self.table.param_env,
1936+
ClauseKind::WellFormed(ty.into()),
1937+
));
1938+
}
1939+
19201940
if !ocx.try_evaluate_obligations().is_empty() {
19211941
return Err(TypeError::Mismatch);
19221942
}
19231943

19241944
// Record all the argument types, with the args
19251945
// produced from the above subtyping unification.
1926-
Ok(Some(
1927-
formal_input_tys
1928-
.iter()
1929-
.map(|&ty| self.table.infer_ctxt.resolve_vars_if_possible(ty))
1930-
.collect(),
1931-
))
1946+
Ok(Some(formal_input_tys.clone()))
19321947
})
19331948
.ok()
19341949
})
@@ -1939,7 +1954,7 @@ impl<'db> InferenceContext<'_, 'db> {
19391954
assert_eq!(expected_input_tys.len(), formal_input_tys.len());
19401955
expected_input_tys
19411956
} else {
1942-
formal_input_tys
1957+
&formal_input_tys
19431958
};
19441959

19451960
let minimum_input_count = expected_input_tys.len();

0 commit comments

Comments
 (0)