Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions src/librustc_trans/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ pub fn decl_rust_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
self_type.repr(ccx.tcx()));
(&function_type.sig, RustCall, Some(llenvironment_type))
}
_ => panic!("expected closure or fn")
_ => ccx.sess().bug("expected closure or fn")
};

let sig = ty::erase_late_bound_regions(ccx.tcx(), sig);
Expand Down Expand Up @@ -2410,12 +2410,15 @@ fn register_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
node_id: ast::NodeId,
node_type: Ty<'tcx>)
-> ValueRef {
match node_type.sty {
ty::ty_bare_fn(_, ref f) => {
assert!(f.abi == Rust || f.abi == RustCall);
if let ty::ty_bare_fn(_, ref f) = node_type.sty {
if f.abi != Rust && f.abi != RustCall {
ccx.sess().span_bug(sp, &format!("only the `{}` or `{}` calling conventions are valid \
for this function; `{}` was specified",
Rust.name(), RustCall.name(), f.abi.name()));
}
_ => panic!("expected bare rust fn")
};
} else {
ccx.sess().span_bug(sp, "expected bare rust function")
}

let llfn = decl_rust_fn(ccx, node_type, &sym[..]);
finish_register_fn(ccx, sp, sym, node_id, llfn);
Expand Down Expand Up @@ -2802,7 +2805,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
llfn
}

_ => panic!("get_item_val: weird result in table")
_ => ccx.sess().bug("get_item_val: weird result in table")
};

match attr::first_attr_value_str_by_name(&i.attrs,
Expand Down Expand Up @@ -2866,7 +2869,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
let args = match v.node.kind {
ast::TupleVariantKind(ref args) => args,
ast::StructVariantKind(_) => {
panic!("struct variant kind unexpected in get_item_val")
ccx.sess().bug("struct variant kind unexpected in get_item_val")
}
};
assert!(args.len() != 0);
Expand All @@ -2882,7 +2885,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
ast::ItemEnum(_, _) => {
register_fn(ccx, (*v).span, sym, id, ty)
}
_ => panic!("NodeVariant, shouldn't happen")
_ => ccx.sess().bug("NodeVariant, shouldn't happen")
};
set_inline_hint(llfn);
llfn
Expand Down Expand Up @@ -2935,9 +2938,17 @@ fn register_method(ccx: &CrateContext, id: ast::NodeId,

let sym = exported_name(ccx, id, mty, &m.attrs);

let llfn = register_fn(ccx, m.span, sym, id, mty);
set_llvm_fn_attrs(ccx, &m.attrs, llfn);
llfn
if let ty::ty_bare_fn(_, ref f) = mty.sty {
let llfn = if f.abi == Rust || f.abi == RustCall {
register_fn(ccx, m.span, sym, id, mty)
} else {
foreign::register_rust_fn_with_foreign_abi(ccx, m.span, sym, id)
};
set_llvm_fn_attrs(ccx, &m.attrs, llfn);
return llfn;
} else {
ccx.sess().span_bug(m.span, "expected bare rust function");
}
}

pub fn crate_ctxt_to_encode_parms<'a, 'tcx>(cx: &'a SharedCrateContext<'tcx>,
Expand Down
35 changes: 35 additions & 0 deletions src/test/run-pass/extern-methods.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2015 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.
trait A {
extern "fastcall" fn test1(i: i32);
extern fn test2(i: i32);
}

struct S;
impl S {
extern "stdcall" fn test3(i: i32) {
assert_eq!(i, 3);
}
}

impl A for S {
extern "fastcall" fn test1(i: i32) {
assert_eq!(i, 1);
}
extern fn test2(i: i32) {
assert_eq!(i, 2);
}
}

fn main() {
<S as A>::test1(1);
<S as A>::test2(2);
S::test3(3);
}