Skip to content

Commit 1d64acd

Browse files
authored
Auto merge of #36822 - Aatch:resolve-callee-expr, r=luqmana
Resolve the callee type in check_call before autoderef If the callee type is an associated type, then it needs to be normalized before trying to deref it. This matches the behaviour of `check_method_call` for autoderef behaviour in calls. Fixes #36786
2 parents c88ed2a + ec2e051 commit 1d64acd

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/librustc_typeck/check/callee.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
4747
expected: Expectation<'tcx>) -> Ty<'tcx>
4848
{
4949
let original_callee_ty = self.check_expr(callee_expr);
50+
let expr_ty = self.structurally_resolved_type(call_expr.span, original_callee_ty);
5051

51-
let mut autoderef = self.autoderef(callee_expr.span, original_callee_ty);
52+
let mut autoderef = self.autoderef(callee_expr.span, expr_ty);
5253
let result = autoderef.by_ref().flat_map(|(adj_ty, idx)| {
5354
self.try_overloaded_call_step(call_expr, callee_expr, adj_ty, idx)
5455
}).next();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2016 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+
// Ensure that types that rely on obligations are autoderefed
12+
// correctly
13+
14+
fn main() {
15+
let x : Vec<Box<Fn()>> = vec![Box::new(|| ())];
16+
x[0]()
17+
}

0 commit comments

Comments
 (0)