-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Sync function call args check fudging with rustc #22092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -35,7 +35,8 @@ use crate::{ | |||
| lower::{GenericPredicates, lower_mutability}, | ||||
| method_resolution::{self, CandidateId, MethodCallee, MethodError}, | ||||
| next_solver::{ | ||||
| ErrorGuaranteed, FnSig, GenericArg, GenericArgs, TraitRef, Ty, TyKind, TypeError, | ||||
| ClauseKind, ErrorGuaranteed, FnSig, GenericArg, GenericArgs, TraitRef, Ty, TyKind, | ||||
| TypeError, | ||||
| infer::{ | ||||
| BoundRegionConversionTime, InferOk, | ||||
| traits::{Obligation, ObligationCause}, | ||||
|
|
@@ -1898,6 +1899,15 @@ impl<'db> InferenceContext<'_, 'db> { | |||
| // Whether the function is variadic, for example when imported from C | ||||
| c_variadic: bool, | ||||
| ) { | ||||
| let formal_input_tys: Vec<_> = formal_input_tys | ||||
| .iter() | ||||
| .map(|&ty| { | ||||
| let generalized_ty = self.table.next_ty_var(); | ||||
| let _ = self.demand_eqtype(call_expr.into(), ty, generalized_ty); | ||||
| generalized_ty | ||||
| }) | ||||
| .collect(); | ||||
|
|
||||
| // First, let's unify the formal method signature with the expectation eagerly. | ||||
| // We use this to guide coercion inference; it's output is "fudged" which means | ||||
| // any remaining type variables are assigned to new, unrelated variables. This | ||||
|
|
@@ -1917,18 +1927,23 @@ impl<'db> InferenceContext<'_, 'db> { | |||
| // No argument expectations are produced if unification fails. | ||||
| let origin = ObligationCause::new(); | ||||
| ocx.sup(&origin, self.table.param_env, expected_output, formal_output)?; | ||||
|
|
||||
| for &ty in &formal_input_tys { | ||||
| ocx.register_obligation(Obligation::new( | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, I forgot about it 😅 Thanks!
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh wait, I think we shouldn't use it, since we are probing in this context so we shouldn't leave anything to the |
||||
| self.interner(), | ||||
| ObligationCause::new(), | ||||
| self.table.param_env, | ||||
| ClauseKind::WellFormed(ty.into()), | ||||
| )); | ||||
| } | ||||
|
|
||||
| if !ocx.try_evaluate_obligations().is_empty() { | ||||
| return Err(TypeError::Mismatch); | ||||
| } | ||||
|
|
||||
| // Record all the argument types, with the args | ||||
| // produced from the above subtyping unification. | ||||
| Ok(Some( | ||||
| formal_input_tys | ||||
| .iter() | ||||
| .map(|&ty| self.table.infer_ctxt.resolve_vars_if_possible(ty)) | ||||
| .collect(), | ||||
| )) | ||||
| Ok(Some(formal_input_tys.clone())) | ||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't (yet) applied to rustc, but as we call
|
||||
| }) | ||||
| .ok() | ||||
| }) | ||||
|
|
@@ -1939,7 +1954,7 @@ impl<'db> InferenceContext<'_, 'db> { | |||
| assert_eq!(expected_input_tys.len(), formal_input_tys.len()); | ||||
| expected_input_tys | ||||
| } else { | ||||
| formal_input_tys | ||||
| &formal_input_tys | ||||
| }; | ||||
|
|
||||
| let minimum_input_count = expected_input_tys.len(); | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is interesting, if you'd demand supertype/subtype I would understand, but isn't demand_eqtype equivalent to setting the type var?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's a bit subtle thing. Relating a type with a ty var generalizes it, which entails normalization:
rust-analyzer/crates/hir-ty/src/next_solver/infer/relate/generalize.rs
Line 42 in 848e6aa