Skip to content

Commit 539dd78

Browse files
committed
Detect invalid ABIs on methods and throw an error.
Trying to call methods with a non-Rust ABI on a trait object results in an ICE. While we could try to translate them, it makes more sense to just reject non-Rust ABIs in type-check. This is technically a [breaking-change] due to that fact that we didn't ICE when statically dispatching these method calls. Fixes rust-lang#26049
1 parent c21fd9a commit 539dd78

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/librustc_typeck/collect.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,10 @@ fn convert_method<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
622622
astconv::ty_of_method(&ccx.icx(&(rcvr_ty_predicates, &sig.generics)),
623623
sig, untransformed_rcvr_ty);
624624

625+
if !(fty.abi == abi::Rust || fty.abi == abi::RustCall) {
626+
627+
}
628+
625629
let def_id = local_def(id);
626630
let ty_method = ty::Method::new(ident.name,
627631
ty_generics,
@@ -759,6 +763,11 @@ fn convert_methods<'a,'tcx,'i,I>(ccx: &CrateCtxt<'a, 'tcx>,
759763
span_err!(tcx.sess, span, E0201, "duplicate {}", fn_desc);
760764
}
761765

766+
if !(sig.abi == abi::Rust || sig.abi == abi::RustCall) {
767+
span_err!(tcx.sess, span, E0394,
768+
"invalid ABI {}, methods must have a Rust ABI", sig.abi);
769+
}
770+
762771
convert_method(ccx,
763772
container,
764773
sig,

src/librustc_typeck/diagnostics.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,6 +1332,7 @@ register_diagnostics! {
13321332
// `#[lang = \"{}\"]` is allowed for the `{}` primitive
13331333
E0391, // unsupported cyclic reference between types/traits detected
13341334
E0392, // parameter `{}` is never used
1335-
E0393 // the type parameter `{}` must be explicitly specified in an object
1335+
E0393, // the type parameter `{}` must be explicitly specified in an object
13361336
// type because its default value `{}` references the type `Self`"
1337+
E0394
13371338
}

0 commit comments

Comments
 (0)