Skip to content

Commit 28df20a

Browse files
authored
Unrolled build for rust-lang#131482
Rollup merge of rust-lang#131482 - compiler-errors:struct-res, r=lcnr structurally resolve adts and tuples expectations too r? lcnr
2 parents de19f2b + 2a8f080 commit 28df20a

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

compiler/rustc_hir_typeck/src/expr.rs

+2-2
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);
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+
trait Coerce {
10+
type Assoc;
11+
}
12+
13+
struct TupleGuidance;
14+
impl Coerce for TupleGuidance {
15+
type Assoc = (&'static dyn Any,);
16+
}
17+
18+
struct AdtGuidance;
19+
impl Coerce for AdtGuidance {
20+
type Assoc = Adt<&'static dyn Any>;
21+
}
22+
23+
struct Adt<T> {
24+
f: T,
25+
}
26+
27+
fn foo<'a, T: Coerce>(_: T::Assoc) {}
28+
29+
fn main() {
30+
foo::<TupleGuidance>((&0u32,));
31+
foo::<AdtGuidance>(Adt { f: &0u32 });
32+
}

0 commit comments

Comments
 (0)