Structurallyresolve adts and tuples expectations too
This commit is contained in:
parent
a1eceec00b
commit
2a8f08083f
@ -1783,7 +1783,7 @@ fn check_expr_tuple(
|
|||||||
expr: &'tcx hir::Expr<'tcx>,
|
expr: &'tcx hir::Expr<'tcx>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
let flds = expected.only_has_type(self).and_then(|ty| {
|
let flds = expected.only_has_type(self).and_then(|ty| {
|
||||||
let ty = self.resolve_vars_with_obligations(ty);
|
let ty = self.try_structurally_resolve_type(expr.span, ty);
|
||||||
match ty.kind() {
|
match ty.kind() {
|
||||||
ty::Tuple(flds) => Some(&flds[..]),
|
ty::Tuple(flds) => Some(&flds[..]),
|
||||||
_ => None,
|
_ => None,
|
||||||
@ -1861,7 +1861,7 @@ fn check_expr_struct_fields(
|
|||||||
) {
|
) {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
|
|
||||||
let adt_ty = self.resolve_vars_with_obligations(adt_ty);
|
let adt_ty = self.try_structurally_resolve_type(span, adt_ty);
|
||||||
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
|
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
|
||||||
self.fudge_inference_if_ok(|| {
|
self.fudge_inference_if_ok(|| {
|
||||||
let ocx = ObligationCtxt::new(self);
|
let ocx = ObligationCtxt::new(self);
|
||||||
|
32
tests/ui/traits/next-solver/typeck/guide-ctors.rs
Normal file
32
tests/ui/traits/next-solver/typeck/guide-ctors.rs
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
//@ compile-flags: -Znext-solver
|
||||||
|
//@ check-pass
|
||||||
|
|
||||||
|
// Makes sure we structurally normalize before trying to use expectation to guide
|
||||||
|
// coercion in adt and tuples.
|
||||||
|
|
||||||
|
use std::any::Any;
|
||||||
|
|
||||||
|
trait Coerce {
|
||||||
|
type Assoc;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct TupleGuidance;
|
||||||
|
impl Coerce for TupleGuidance {
|
||||||
|
type Assoc = (&'static dyn Any,);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct AdtGuidance;
|
||||||
|
impl Coerce for AdtGuidance {
|
||||||
|
type Assoc = Adt<&'static dyn Any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Adt<T> {
|
||||||
|
f: T,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo<'a, T: Coerce>(_: T::Assoc) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
foo::<TupleGuidance>((&0u32,));
|
||||||
|
foo::<AdtGuidance>(Adt { f: &0u32 });
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user