Skip to content

Commit 48dded9

Browse files
committed
auto merge of #8580 : bytewiseand/rust/tuple-struct-ctor-ptr, r=alexcrichton
Fixes #5315
2 parents 00dd9e9 + 29ab2da commit 48dded9

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/librustc/middle/trans/expr.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -795,14 +795,18 @@ fn trans_def_dps_unadjusted(bcx: @mut Block, ref_expr: &ast::expr,
795795
return bcx;
796796
}
797797
}
798-
ast::def_struct(*) => {
798+
ast::def_struct(def_id) => {
799799
let ty = expr_ty(bcx, ref_expr);
800800
match ty::get(ty).sty {
801801
ty::ty_struct(did, _) if ty::has_dtor(ccx.tcx, did) => {
802802
let repr = adt::represent_type(ccx, ty);
803803
adt::trans_start_init(bcx, repr, lldest, 0);
804804
}
805-
_ => {}
805+
ty::ty_bare_fn(*) => {
806+
let fn_data = callee::trans_fn_ref(bcx, def_id, ref_expr.id);
807+
Store(bcx, fn_data.llfn, lldest);
808+
}
809+
_ => ()
806810
}
807811
return bcx;
808812
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2012 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+
#[deriving(Eq)]
12+
struct Foo(int);
13+
#[deriving(Eq)]
14+
struct Bar(int, int);
15+
16+
fn main() {
17+
let f: extern fn(int) -> Foo = Foo;
18+
let g: extern fn(int, int) -> Bar = Bar;
19+
assert_eq!(f(42), Foo(42));
20+
assert_eq!(g(4, 7), Bar(4, 7));
21+
}

0 commit comments

Comments
 (0)