Skip to content

Commit 735e518

Browse files
luqmanaalexcrichton
authored andcommitted
librustc: Update AutoObject adjustment in writeback.
1 parent f35328c commit 735e518

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

src/librustc/middle/typeck/check/regionck.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ fn visit_expr(rcx: &mut Rcx, expr: &ast::Expr) {
432432
// function check_cast_for_escaping_regions() in kind.rs
433433
// explaining how it goes about doing that.
434434

435-
let source_ty = rcx.fcx.expr_ty(expr);
435+
let source_ty = rcx.resolve_node_type(expr.id);
436436
constrain_regions_in_type(rcx, trait_region,
437437
infer::RelateObjectBound(expr.span), source_ty);
438438
}

src/librustc/middle/typeck/check/writeback.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,14 @@ impl<'cx> WritebackCx<'cx> {
260260
})
261261
}
262262

263-
adjustment => adjustment
263+
ty::AutoObject(trait_store, bb, def_id, substs) => {
264+
ty::AutoObject(
265+
self.resolve(&trait_store, reason),
266+
self.resolve(&bb, reason),
267+
def_id,
268+
self.resolve(&substs, reason)
269+
)
270+
}
264271
};
265272
debug!("Adjustments for node {}: {:?}", id, resolved_adjustment);
266273
self.tcx().adjustments.borrow_mut().insert(

src/test/run-pass/issue-11612.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// #11612
12+
// We weren't updating the auto adjustments with all the resolved
13+
// type information after type check.
14+
15+
trait A {}
16+
17+
struct B<'a, T> {
18+
f: &'a T
19+
}
20+
21+
impl<'a, T> A for B<'a, T> {}
22+
23+
fn foo(_: &A) {}
24+
25+
fn bar<G>(b: &B<G>) {
26+
foo(b); // Coercion should work
27+
foo(b as &A); // Explicit cast should work as well
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)