Skip to content

Commit 9292c0b

Browse files
committed
Properly feature gate all unstable ABIs
1 parent 06ca016 commit 9292c0b

File tree

6 files changed

+103
-73
lines changed

6 files changed

+103
-73
lines changed

src/doc/book/closures.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ trait system to overload operators. Calling functions is no different. We have
223223
three separate traits to overload with:
224224

225225
```rust
226+
# #![feature(unboxed_closures)]
226227
# mod foo {
227228
pub trait Fn<Args> : FnMut<Args> {
228229
extern "rust-call" fn call(&self, args: Args) -> Self::Output;

src/libsyntax/feature_gate.rs

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,29 @@ macro_rules! gate_feature_post {
800800
}}
801801
}
802802

803+
impl<'a> PostExpansionVisitor<'a> {
804+
fn check_abi(&self, abi: Abi, span: Span) {
805+
match abi {
806+
Abi::RustIntrinsic =>
807+
gate_feature_post!(&self, intrinsics, span,
808+
"intrinsics are subject to change"),
809+
Abi::PlatformIntrinsic => {
810+
gate_feature_post!(&self, platform_intrinsics, span,
811+
"platform intrinsics are experimental and possibly buggy")
812+
},
813+
Abi::Vectorcall => {
814+
gate_feature_post!(&self, abi_vectorcall, span,
815+
"vectorcall is experimental and subject to change")
816+
}
817+
Abi::RustCall => {
818+
gate_feature_post!(&self, unboxed_closures, span,
819+
"rust-call ABI is subject to change");
820+
}
821+
_ => {}
822+
}
823+
}
824+
}
825+
803826
impl<'a> Visitor for PostExpansionVisitor<'a> {
804827
fn visit_attribute(&mut self, attr: &ast::Attribute) {
805828
if !self.context.cm.span_allows_unstable(attr.span) {
@@ -831,21 +854,7 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
831854
across platforms, it is recommended to \
832855
use `#[link(name = \"foo\")]` instead")
833856
}
834-
match foreign_module.abi {
835-
Abi::RustIntrinsic =>
836-
gate_feature_post!(&self, intrinsics, i.span,
837-
"intrinsics are subject to change"),
838-
Abi::PlatformIntrinsic => {
839-
gate_feature_post!(&self, platform_intrinsics, i.span,
840-
"platform intrinsics are experimental \
841-
and possibly buggy")
842-
},
843-
Abi::Vectorcall => {
844-
gate_feature_post!(&self, abi_vectorcall, i.span,
845-
"vectorcall is experimental and subject to change")
846-
}
847-
_ => ()
848-
}
857+
self.check_abi(foreign_module.abi, i.span);
849858
}
850859

851860
ast::ItemKind::Fn(..) => {
@@ -928,6 +937,16 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
928937
visit::walk_foreign_item(self, i)
929938
}
930939

940+
fn visit_ty(&mut self, ty: &ast::Ty) {
941+
match ty.node {
942+
ast::TyKind::BareFn(ref bare_fn_ty) => {
943+
self.check_abi(bare_fn_ty.abi, ty.span);
944+
}
945+
_ => {}
946+
}
947+
visit::walk_ty(self, ty)
948+
}
949+
931950
fn visit_expr(&mut self, e: &ast::Expr) {
932951
match e.node {
933952
ast::ExprKind::Box(_) => {
@@ -1015,23 +1034,10 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
10151034
}
10161035

10171036
match fn_kind {
1018-
FnKind::ItemFn(_, _, _, _, abi, _) if abi == Abi::RustIntrinsic => {
1019-
gate_feature_post!(&self, intrinsics,
1020-
span,
1021-
"intrinsics are subject to change")
1022-
}
10231037
FnKind::ItemFn(_, _, _, _, abi, _) |
1024-
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) => match abi {
1025-
Abi::RustCall => {
1026-
gate_feature_post!(&self, unboxed_closures, span,
1027-
"rust-call ABI is subject to change");
1028-
},
1029-
Abi::Vectorcall => {
1030-
gate_feature_post!(&self, abi_vectorcall, span,
1031-
"vectorcall is experimental and subject to change");
1032-
},
1033-
_ => {}
1034-
},
1038+
FnKind::Method(_, &ast::MethodSig { abi, .. }, _) => {
1039+
self.check_abi(abi, span);
1040+
}
10351041
_ => {}
10361042
}
10371043
visit::walk_fn(self, fn_kind, fn_decl, block, span);
@@ -1044,7 +1050,10 @@ impl<'a> Visitor for PostExpansionVisitor<'a> {
10441050
ti.span,
10451051
"associated constants are experimental")
10461052
}
1047-
ast::TraitItemKind::Method(ref sig, _) => {
1053+
ast::TraitItemKind::Method(ref sig, ref block) => {
1054+
if block.is_none() {
1055+
self.check_abi(sig.abi, ti.span);
1056+
}
10481057
if sig.constness == ast::Constness::Const {
10491058
gate_feature_post!(&self, const_fn, ti.span, "const fn is unstable");
10501059
}

src/test/compile-fail/E0045.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
extern "rust-call" { fn foo(x: u8, ...); } //~ ERROR E0045
11+
extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045
1212

1313
fn main() {
1414
}

src/test/compile-fail/feature-gate-abi-vectorcall.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2016 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+
// Functions
12+
extern "rust-intrinsic" fn f1() {} //~ ERROR intrinsics are subject to change
13+
extern "platform-intrinsic" fn f2() {} //~ ERROR platform intrinsics are experimental
14+
extern "vectorcall" fn f3() {} //~ ERROR vectorcall is experimental and subject to change
15+
extern "rust-call" fn f4() {} //~ ERROR rust-call ABI is subject to change
16+
17+
// Methods in trait definition
18+
trait Tr {
19+
extern "rust-intrinsic" fn m1(); //~ ERROR intrinsics are subject to change
20+
extern "platform-intrinsic" fn m2(); //~ ERROR platform intrinsics are experimental
21+
extern "vectorcall" fn m3(); //~ ERROR vectorcall is experimental and subject to change
22+
extern "rust-call" fn m4(); //~ ERROR rust-call ABI is subject to change
23+
24+
extern "rust-intrinsic" fn dm1() {} //~ ERROR intrinsics are subject to change
25+
extern "platform-intrinsic" fn dm2() {} //~ ERROR platform intrinsics are experimental
26+
extern "vectorcall" fn dm3() {} //~ ERROR vectorcall is experimental and subject to change
27+
extern "rust-call" fn dm4() {} //~ ERROR rust-call ABI is subject to change
28+
}
29+
30+
struct S;
31+
32+
// Methods in trait impl
33+
impl Tr for S {
34+
extern "rust-intrinsic" fn m1() {} //~ ERROR intrinsics are subject to change
35+
extern "platform-intrinsic" fn m2() {} //~ ERROR platform intrinsics are experimental
36+
extern "vectorcall" fn m3() {} //~ ERROR vectorcall is experimental and subject to change
37+
extern "rust-call" fn m4() {} //~ ERROR rust-call ABI is subject to change
38+
}
39+
40+
// Methods in inherent impl
41+
impl S {
42+
extern "rust-intrinsic" fn im1() {} //~ ERROR intrinsics are subject to change
43+
extern "platform-intrinsic" fn im2() {} //~ ERROR platform intrinsics are experimental
44+
extern "vectorcall" fn im3() {} //~ ERROR vectorcall is experimental and subject to change
45+
extern "rust-call" fn im4() {} //~ ERROR rust-call ABI is subject to change
46+
}
47+
48+
// Function pointer types
49+
type A1 = extern "rust-intrinsic" fn(); //~ ERROR intrinsics are subject to change
50+
type A2 = extern "platform-intrinsic" fn(); //~ ERROR platform intrinsics are experimental
51+
type A3 = extern "vectorcall" fn(); //~ ERROR vectorcall is experimental and subject to change
52+
type A4 = extern "rust-call" fn(); //~ ERROR rust-call ABI is subject to change
53+
54+
// Foreign modules
55+
extern "rust-intrinsic" {} //~ ERROR intrinsics are subject to change
56+
extern "platform-intrinsic" {} //~ ERROR platform intrinsics are experimental
57+
extern "vectorcall" {} //~ ERROR vectorcall is experimental and subject to change
58+
extern "rust-call" {} //~ ERROR rust-call ABI is subject to change
59+
60+
fn main() {}

src/test/compile-fail/feature-gate-rust-call.rs

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)