-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Use equality when relating formal and expected type in arg checking #129317
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 |
---|---|---|
|
@@ -1673,15 +1673,22 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
) { | ||
let tcx = self.tcx; | ||
|
||
let expected_inputs = | ||
self.expected_inputs_for_expected_output(span, expected, adt_ty, &[adt_ty]); | ||
let adt_ty_hint = if let Some(expected_inputs) = expected_inputs { | ||
expected_inputs.get(0).cloned().unwrap_or(adt_ty) | ||
} else { | ||
adt_ty | ||
}; | ||
// re-link the regions that EIfEO can erase. | ||
self.demand_eqtype(span, adt_ty_hint, adt_ty); | ||
let adt_ty = self.resolve_vars_with_obligations(adt_ty); | ||
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| { | ||
self.fudge_inference_if_ok(|| { | ||
let ocx = ObligationCtxt::new(self); | ||
ocx.sup(&self.misc(span), self.param_env, expected, adt_ty)?; | ||
if !ocx.select_where_possible().is_empty() { | ||
return Err(TypeError::Mismatch); | ||
} | ||
Ok(self.resolve_vars_if_possible(adt_ty)) | ||
}) | ||
.ok() | ||
}); | ||
if let Some(adt_ty_hint) = adt_ty_hint { | ||
// re-link the variables that the fudging above can create. | ||
self.demand_eqtype(span, adt_ty_hint, adt_ty); | ||
} | ||
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. that's weird, why do we first check whether subtyping succeeds to then require equality 🤔 I feel like this can just be a 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 never want to relate the real variables of the expectation to the ADT type, since the expectation is just a hint. We would still need to fudge first then commit-if-ok. I don't believe this can be simplified. |
||
|
||
let ty::Adt(adt, args) = adt_ty.kind() else { | ||
span_bug!(span, "non-ADT passed to check_expr_struct_fields"); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
//@ check-pass | ||
|
||
compiler-errors marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// Regression test for for #129286. | ||
// Makes sure that we don't have unconstrained type variables that come from | ||
// bivariant type parameters due to the way that we construct expectation types | ||
// when checking call expressions in HIR typeck. | ||
|
||
trait Trait { | ||
type Item; | ||
} | ||
|
||
struct Struct<A: Trait<Item = B>, B> { | ||
pub field: A, | ||
} | ||
|
||
fn identity<T>(x: T) -> T { | ||
x | ||
} | ||
|
||
fn test<A: Trait<Item = B>, B>(x: &Struct<A, B>) { | ||
let x: &Struct<_, _> = identity(x); | ||
} | ||
|
||
fn main() {} |
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.
why not just pass in the whole
fn_sig
🤔 we currently always pass in inputs, outputs, and c_variadic manuallyThere 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.
ah,
check_argument_types
is also used during diagnostics 🤔 that code should also be able to use a full error dummyFnSig
though 🤔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.
We still also need to rip off the receiver from the method signature when checking method args. I don't really think it simplifies much to have to make a new sig in that codepath.