Skip to content

Commit

Permalink
trans: use types from argument patterns instead of the function signa…
Browse files Browse the repository at this point in the history
…ture.

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.
  • Loading branch information
eddyb committed Oct 31, 2014
1 parent 82045ca commit 96ba514
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
21 changes: 14 additions & 7 deletions src/librustc/middle/trans/base.rs
Expand Up @@ -50,7 +50,7 @@ use middle::trans::cleanup;
use middle::trans::common::{Block, C_bool, C_bytes_in_context, C_i32, C_integral, C_nil};
use middle::trans::common::{C_null, C_struct_in_context, C_u64, C_u8, C_uint, C_undef};
use middle::trans::common::{CrateContext, ExternMap, FunctionContext};
use middle::trans::common::{NodeInfo, Result, SubstP, monomorphize_type};
use middle::trans::common::{NodeInfo, Result, SubstP};
use middle::trans::common::{node_id_type, param_substs, return_type_is_void};
use middle::trans::common::{tydesc_info, type_is_immediate};
use middle::trans::common::{type_is_zero_size, val_ty};
Expand Down Expand Up @@ -1794,7 +1794,6 @@ pub fn trans_closure(ccx: &CrateContext,
param_substs: &param_substs,
fn_ast_id: ast::NodeId,
_attributes: &[ast::Attribute],
arg_types: Vec<ty::t>,
output_type: ty::FnOutput,
abi: Abi,
has_env: bool,
Expand Down Expand Up @@ -1829,9 +1828,19 @@ pub fn trans_closure(ccx: &CrateContext,

// Set up arguments to the function.
let monomorphized_arg_types =
arg_types.iter()
.map(|at| monomorphize_type(bcx, *at))
.collect::<Vec<_>>();
decl.inputs.iter()
.map(|arg| node_id_type(bcx, arg.id))
.collect::<Vec<_>>();
let monomorphized_arg_types = match is_unboxed_closure {
NotUnboxedClosure => monomorphized_arg_types,

// Tuple up closure argument types for the "rust-call" ABI.
IsUnboxedClosure => vec![if monomorphized_arg_types.is_empty() {
ty::mk_nil()
} else {
ty::mk_tup(ccx.tcx(), monomorphized_arg_types)
}]
};
for monomorphized_arg_type in monomorphized_arg_types.iter() {
debug!("trans_closure: monomorphized_arg_type: {}",
ty_to_string(ccx.tcx(), *monomorphized_arg_type));
Expand Down Expand Up @@ -1933,7 +1942,6 @@ pub fn trans_fn(ccx: &CrateContext,
debug!("trans_fn(param_substs={})", param_substs.repr(ccx.tcx()));
let _icx = push_ctxt("trans_fn");
let fn_ty = ty::node_id_to_type(ccx.tcx(), id);
let arg_types = ty::ty_fn_args(fn_ty);
let output_type = ty::ty_fn_ret(fn_ty);
let abi = ty::ty_fn_abi(fn_ty);
trans_closure(ccx,
Expand All @@ -1943,7 +1951,6 @@ pub fn trans_fn(ccx: &CrateContext,
param_substs,
id,
attrs,
arg_types,
output_type,
abi,
false,
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/trans/closure.rs
Expand Up @@ -408,7 +408,6 @@ pub fn trans_expr_fn<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
bcx.fcx.param_substs,
id,
[],
ty::ty_fn_args(fty),
ty::ty_fn_ret(fty),
ty::ty_fn_abi(fty),
true,
Expand Down Expand Up @@ -501,7 +500,6 @@ pub fn trans_unboxed_closure<'blk, 'tcx>(
bcx.fcx.param_substs,
id,
[],
ty::ty_fn_args(function_type),
ty::ty_fn_ret(function_type),
ty::ty_fn_abi(function_type),
true,
Expand Down
1 change: 1 addition & 0 deletions src/librustc/middle/typeck/check/writeback.rs
Expand Up @@ -53,6 +53,7 @@ pub fn resolve_type_vars_in_fn(fcx: &FnCtxt,
let mut wbcx = WritebackCx::new(fcx);
wbcx.visit_block(blk);
for arg in decl.inputs.iter() {
wbcx.visit_node_id(ResolvingPattern(arg.pat.span), arg.id);
wbcx.visit_pat(&*arg.pat);

// Privacy needs the type for the whole pattern, not just each binding
Expand Down
30 changes: 30 additions & 0 deletions src/test/run-pass/regions-no-bound-in-argument-cleanup.rs
@@ -0,0 +1,30 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(unsafe_destructor)]

pub struct Foo<T>;

impl<T> Iterator<T> for Foo<T> {
fn next(&mut self) -> Option<T> {
None
}
}

#[unsafe_destructor]
impl<T> Drop for Foo<T> {
fn drop(&mut self) {
self.next();
}
}

pub fn foo<'a>(_: Foo<&'a ()>) {}

pub fn main() {}

5 comments on commit 96ba514

@bors
Copy link
Contributor

@bors bors commented on 96ba514 Oct 31, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from nikomatsakis
at eddyb@96ba514

@bors
Copy link
Contributor

@bors bors commented on 96ba514 Oct 31, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging eddyb/rust/free-region-args = 96ba514 into auto

@bors
Copy link
Contributor

@bors bors commented on 96ba514 Oct 31, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

eddyb/rust/free-region-args = 96ba514 merged ok, testing candidate = 7e66231

@bors
Copy link
Contributor

@bors bors commented on 96ba514 Oct 31, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 96ba514 Oct 31, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 7e66231

Please sign in to comment.