Skip to content

Commit 2a8f080

Browse files
Structurallyresolve adts and tuples expectations too
1 parent a1eceec commit 2a8f080

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

‎compiler/rustc_hir_typeck/src/expr.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,7 +1783,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
17831783
expr:&'tcx hir::Expr<'tcx>,
17841784
) -> Ty<'tcx>{
17851785
let flds = expected.only_has_type(self).and_then(|ty| {
1786-
let ty = self.resolve_vars_with_obligations(ty);
1786+
let ty = self.try_structurally_resolve_type(expr.span,ty);
17871787
match ty.kind(){
17881788
ty::Tuple(flds) => Some(&flds[..]),
17891789
_ => None,
@@ -1861,7 +1861,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18611861
){
18621862
let tcx = self.tcx;
18631863

1864-
let adt_ty = self.resolve_vars_with_obligations(adt_ty);
1864+
let adt_ty = self.try_structurally_resolve_type(span,adt_ty);
18651865
let adt_ty_hint = expected.only_has_type(self).and_then(|expected| {
18661866
self.fudge_inference_if_ok(|| {
18671867
let ocx = ObligationCtxt::new(self);
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ check-pass
3+
4+
// Makes sure we structurally normalize before trying to use expectation to guide
5+
// coercion in adt and tuples.
6+
7+
use std::any::Any;
8+
9+
traitCoerce{
10+
typeAssoc;
11+
}
12+
13+
structTupleGuidance;
14+
implCoerceforTupleGuidance{
15+
typeAssoc = (&'staticdynAny,);
16+
}
17+
18+
structAdtGuidance;
19+
implCoerceforAdtGuidance{
20+
typeAssoc = Adt<&'staticdynAny>;
21+
}
22+
23+
structAdt<T>{
24+
f:T,
25+
}
26+
27+
fnfoo<'a,T:Coerce>(_:T::Assoc){}
28+
29+
fnmain(){
30+
foo::<TupleGuidance>((&0u32,));
31+
foo::<AdtGuidance>(Adt{f:&0u32});
32+
}

0 commit comments

Comments
 (0)