Skip to content

Commit 96ba514

Browse files
committed
trans: use types from argument patterns instead of the function signature.
This fixes ICEs caused by late-bound lifetimes ending up in argument datum types and being used in cleanup - user Drop impl's would then fail to monomorphize if the type was used to look up the impl of a method call - which happens in trans now, I presume for multidispatch.
1 parent 82045ca commit 96ba514

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ use middle::trans::cleanup;
5050
use middle::trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral, C_nil};
5151
use middle::trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef};
5252
use middle::trans::common::{CrateContext, ExternMap, FunctionContext};
53-
use middle::trans::common::{NodeInfo, Result, SubstP, monomorphize_type};
53+
use middle::trans::common::{NodeInfo, Result, SubstP};
5454
use middle::trans::common::{node_id_type, param_substs, return_type_is_void};
5555
use middle::trans::common::{tydesc_info, type_is_immediate};
5656
use middle::trans::common::{type_is_zero_size, val_ty};
@@ -1794,7 +1794,6 @@ pub fn trans_closure(ccx: &CrateContext,
17941794
param_substs: &param_substs,
17951795
fn_ast_id: ast::NodeId,
17961796
_attributes: &[ast::Attribute],
1797-
arg_types: Vec<ty::t>,
17981797
output_type: ty::FnOutput,
17991798
abi: Abi,
18001799
has_env: bool,
@@ -1829,9 +1828,19 @@ pub fn trans_closure(ccx: &CrateContext,
18291828

18301829
// Set up arguments to the function.
18311830
let monomorphized_arg_types =
1832-
arg_types.iter()
1833-
.map(|at| monomorphize_type(bcx, *at))
1834-
.collect::<Vec<_>>();
1831+
decl.inputs.iter()
1832+
.map(|arg| node_id_type(bcx, arg.id))
1833+
.collect::<Vec<_>>();
1834+
let monomorphized_arg_types = match is_unboxed_closure {
1835+
NotUnboxedClosure => monomorphized_arg_types,
1836+
1837+
// Tuple up closure argument types for the "rust-call" ABI.
1838+
IsUnboxedClosure => vec![if monomorphized_arg_types.is_empty() {
1839+
ty::mk_nil()
1840+
} else {
1841+
ty::mk_tup(ccx.tcx(), monomorphized_arg_types)
1842+
}]
1843+
};
18351844
for monomorphized_arg_type in monomorphized_arg_types.iter() {
18361845
debug!("trans_closure: monomorphized_arg_type: {}",
18371846
ty_to_string(ccx.tcx(), *monomorphized_arg_type));
@@ -1933,7 +1942,6 @@ pub fn trans_fn(ccx: &CrateContext,
19331942
debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx()));
19341943
let _icx = push_ctxt("trans_fn");
19351944
let fn_ty = ty::node_id_to_type(ccx.tcx(), id);
1936-
let arg_types = ty::ty_fn_args(fn_ty);
19371945
let output_type = ty::ty_fn_ret(fn_ty);
19381946
let abi = ty::ty_fn_abi(fn_ty);
19391947
trans_closure(ccx,
@@ -1943,7 +1951,6 @@ pub fn trans_fn(ccx: &CrateContext,
19431951
param_substs,
19441952
id,
19451953
attrs,
1946-
arg_types,
19471954
output_type,
19481955
abi,
19491956
false,

src/librustc/middle/trans/closure.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,6 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
408408
bcx.fcx.param_substs,
409409
id,
410410
[],
411-
ty::ty_fn_args(fty),
412411
ty::ty_fn_ret(fty),
413412
ty::ty_fn_abi(fty),
414413
true,
@@ -501,7 +500,6 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
501500
bcx.fcx.param_substs,
502501
id,
503502
[],
504-
ty::ty_fn_args(function_type),
505503
ty::ty_fn_ret(function_type),
506504
ty::ty_fn_abi(function_type),
507505
true,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub fn resolve_type_vars_in_fn(fcx: &FnCtxt,
5353
let mut wbcx = WritebackCx::new(fcx);
5454
wbcx.visit_block(blk);
5555
for arg in decl.inputs.iter() {
56+
wbcx.visit_node_id(ResolvingPattern(arg.pat.span), arg.id);
5657
wbcx.visit_pat(&*arg.pat);
5758

5859
// Privacy needs the type for the whole pattern, not just each binding
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+
#![feature(unsafe_destructor)]
12+
13+
pub struct Foo<T>;
14+
15+
impl<T> Iterator<T> for Foo<T> {
16+
fn next(&mut self) -> Option<T> {
17+
None
18+
}
19+
}
20+
21+
#[unsafe_destructor]
22+
impl<T> Drop for Foo<T> {
23+
fn drop(&mut self) {
24+
self.next();
25+
}
26+
}
27+
28+
pub fn foo<'a>(_: Foo<&'a ()>) {}
29+
30+
pub fn main() {}

0 commit comments

Comments
 (0)