Skip to content

Commit 472c9f8

Browse files
Add test for export_stable in bin crate
1 parent 054d35b commit 472c9f8

3 files changed

Lines changed: 57 additions & 34 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: `#[export_stable]` attribute cannot be used on traits
2+
--> $DIR/exportable.rs:135:5
3+
|
4+
LL | #[export_stable]
5+
| ^^^^^^^^^^^^^^^^
6+
|
7+
= help: `#[export_stable]` can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements
8+
9+
error: `#[export_stable]` attribute cannot be used on constants
10+
--> $DIR/exportable.rs:139:5
11+
|
12+
LL | #[export_stable]
13+
| ^^^^^^^^^^^^^^^^
14+
|
15+
= help: `#[export_stable]` can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements
16+
17+
error: aborting due to 2 previous errors
18+

tests/ui/attributes/export/exportable.rs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,22 @@
1+
//@ revisions: sdylib binary
2+
// Currently the two revisions have different expectations, this is wrong.
3+
// There is an issue open to fix this: https://github.com/rust-lang/rust/issues/158227
4+
15
//@ compile-flags: -Zunstable-options -Csymbol-mangling-version=v0
6+
//@[sdylib] compile-flags: --crate-type=sdylib
7+
//@[binary] compile-flags: --crate-type=bin
28

3-
#![crate_type = "sdylib"]
49
#![allow(incomplete_features, improper_ctypes_definitions)]
510
#![feature(export_stable)]
611
#![feature(inherent_associated_types)]
712

813
mod m {
914
#[export_stable]
1015
pub struct S;
11-
//~^ ERROR private items are not exportable
16+
//[sdylib]~^ ERROR private items are not exportable
1217

1318
pub fn foo() -> i32 { 0 }
14-
//~^ ERROR only functions with "C" ABI are exportable
19+
//[sdylib]~^ ERROR only functions with "C" ABI are exportable
1520
}
1621

1722
#[export_stable]
@@ -25,13 +30,13 @@ pub mod m1 {
2530
struct S2;
2631

2732
pub struct S3;
28-
//~^ ERROR types with unstable layout are not exportable
33+
//[sdylib]~^ ERROR types with unstable layout are not exportable
2934
}
3035

3136
pub mod fn_sig {
3237
#[export_stable]
3338
pub fn foo1() {}
34-
//~^ ERROR only functions with "C" ABI are exportable
39+
//[sdylib]~^ ERROR only functions with "C" ABI are exportable
3540

3641
#[export_stable]
3742
#[repr(C)]
@@ -42,7 +47,7 @@ pub mod fn_sig {
4247

4348
#[export_stable]
4449
pub extern "C" fn foo3(x: Box<S>) -> i32 { 0 }
45-
//~^ ERROR function with `#[export_stable]` attribute uses type `Box<fn_sig::S>`, which is not exportable
50+
//[sdylib]~^ ERROR function with `#[export_stable]` attribute uses type `Box<fn_sig::S>`, which is not exportable
4651
}
4752

4853
pub mod impl_item {
@@ -51,19 +56,19 @@ pub mod impl_item {
5156
impl S {
5257
#[export_stable]
5358
pub extern "C" fn foo1(&self) -> i32 { 0 }
54-
//~^ ERROR method with `#[export_stable]` attribute uses type `&impl_item::S`, which is not exportable
59+
//[sdylib]~^ ERROR method with `#[export_stable]` attribute uses type `&impl_item::S`, which is not exportable
5560

5661
#[export_stable]
5762
pub extern "C" fn foo2(self) -> i32 { 0 }
58-
//~^ ERROR method with `#[export_stable]` attribute uses type `impl_item::S`, which is not exportable
63+
//[sdylib]~^ ERROR method with `#[export_stable]` attribute uses type `impl_item::S`, which is not exportable
5964
}
6065

6166
pub struct S2<T>(T);
6267

6368
impl<T> S2<T> {
6469
#[export_stable]
6570
pub extern "C" fn foo1(&self) {}
66-
//~^ ERROR generic functions are not exportable
71+
//[sdylib]~^ ERROR generic functions are not exportable
6772
}
6873
}
6974

@@ -79,14 +84,14 @@ pub mod tys {
7984

8085
#[export_stable]
8186
pub extern "C" fn foo1(x: <S as Trait>::Type) -> u32 { x.0 }
82-
//~^ ERROR function with `#[export_stable]` attribute uses type `(u32,)`, which is not exportable
87+
//[sdylib]~^ ERROR function with `#[export_stable]` attribute uses type `(u32,)`, which is not exportable
8388

8489
#[export_stable]
8590
pub type Type = [i32; 4];
8691

8792
#[export_stable]
8893
pub extern "C" fn foo2(_x: Type) {}
89-
//~^ ERROR function with `#[export_stable]` attribute uses type `[i32; 4]`, which is not exportable
94+
//[sdylib]~^ ERROR function with `#[export_stable]` attribute uses type `[i32; 4]`, which is not exportable
9095

9196
impl S {
9297
#[export_stable]
@@ -95,11 +100,11 @@ pub mod tys {
95100

96101
#[export_stable]
97102
pub extern "C" fn foo3(_x: S::Type) {}
98-
//~^ ERROR function with `#[export_stable]` attribute uses type `extern "C" fn()`, which is not exportable
103+
//[sdylib]~^ ERROR function with `#[export_stable]` attribute uses type `extern "C" fn()`, which is not exportable
99104

100105
#[export_stable]
101106
pub extern "C" fn foo4() -> impl Copy {
102-
//~^ ERROR function with `#[export_stable]` attribute uses type `impl Copy`, which is not exportable
107+
//[sdylib]~^ ERROR function with `#[export_stable]` attribute uses type `impl Copy`, which is not exportable
103108
0
104109
}
105110
}
@@ -114,14 +119,14 @@ pub mod privacy {
114119
#[export_stable]
115120
#[repr(C)]
116121
pub struct S2 {
117-
//~^ ERROR ADT types with private fields are not exportable
122+
//[sdylib]~^ ERROR ADT types with private fields are not exportable
118123
x: i32
119124
}
120125

121126
#[export_stable]
122127
#[repr(i32)]
123128
enum E {
124-
//~^ ERROR private items are not exportable
129+
//[sdylib]~^ ERROR private items are not exportable
125130
Variant1 { x: i32 }
126131
}
127132
}

tests/ui/attributes/export/exportable.stderr renamed to tests/ui/attributes/export/exportable.sdylib.stderr

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,131 +1,131 @@
11
error: `#[export_stable]` attribute cannot be used on traits
2-
--> $DIR/exportable.rs:130:5
2+
--> $DIR/exportable.rs:135:5
33
|
44
LL | #[export_stable]
55
| ^^^^^^^^^^^^^^^^
66
|
77
= help: `#[export_stable]` can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements
88

99
error: `#[export_stable]` attribute cannot be used on constants
10-
--> $DIR/exportable.rs:134:5
10+
--> $DIR/exportable.rs:139:5
1111
|
1212
LL | #[export_stable]
1313
| ^^^^^^^^^^^^^^^^
1414
|
1515
= help: `#[export_stable]` can be applied to associated types, data types, functions, inherent impl blocks, modules, type aliases, and use statements
1616

1717
error: private items are not exportable
18-
--> $DIR/exportable.rs:10:5
18+
--> $DIR/exportable.rs:15:5
1919
|
2020
LL | pub struct S;
2121
| ^^^^^^^^^^^^
2222
|
2323
note: is only usable at visibility `pub(crate)`
24-
--> $DIR/exportable.rs:10:5
24+
--> $DIR/exportable.rs:15:5
2525
|
2626
LL | pub struct S;
2727
| ^^^^^^^^^^^^
2828

2929
error: private items are not exportable
30-
--> $DIR/exportable.rs:123:5
30+
--> $DIR/exportable.rs:128:5
3131
|
3232
LL | enum E {
3333
| ^^^^^^
3434
|
3535
note: is only usable at visibility `pub(self)`
36-
--> $DIR/exportable.rs:123:5
36+
--> $DIR/exportable.rs:128:5
3737
|
3838
LL | enum E {
3939
| ^^^^^^
4040

4141
error: only functions with "C" ABI are exportable
42-
--> $DIR/exportable.rs:13:5
42+
--> $DIR/exportable.rs:18:5
4343
|
4444
LL | pub fn foo() -> i32 { 0 }
4545
| ^^^^^^^^^^^^^^^^^^^
4646

4747
error: types with unstable layout are not exportable
48-
--> $DIR/exportable.rs:27:5
48+
--> $DIR/exportable.rs:32:5
4949
|
5050
LL | pub struct S3;
5151
| ^^^^^^^^^^^^^
5252

5353
error: only functions with "C" ABI are exportable
54-
--> $DIR/exportable.rs:33:5
54+
--> $DIR/exportable.rs:38:5
5555
|
5656
LL | pub fn foo1() {}
5757
| ^^^^^^^^^^^^^
5858

5959
error: function with `#[export_stable]` attribute uses type `Box<fn_sig::S>`, which is not exportable
60-
--> $DIR/exportable.rs:44:5
60+
--> $DIR/exportable.rs:49:5
6161
|
6262
LL | pub extern "C" fn foo3(x: Box<S>) -> i32 { 0 }
6363
| ^^^^^^^^^^^^^^^^^^^^^^^^^^------^^^^^^^^
6464
| |
6565
| not exportable
6666

6767
error: method with `#[export_stable]` attribute uses type `&impl_item::S`, which is not exportable
68-
--> $DIR/exportable.rs:53:9
68+
--> $DIR/exportable.rs:58:9
6969
|
7070
LL | pub extern "C" fn foo1(&self) -> i32 { 0 }
7171
| ^^^^^^^^^^^^^^^^^^^^^^^-----^^^^^^^^
7272
| |
7373
| not exportable
7474

7575
error: method with `#[export_stable]` attribute uses type `impl_item::S`, which is not exportable
76-
--> $DIR/exportable.rs:57:9
76+
--> $DIR/exportable.rs:62:9
7777
|
7878
LL | pub extern "C" fn foo2(self) -> i32 { 0 }
7979
| ^^^^^^^^^^^^^^^^^^^^^^^----^^^^^^^^
8080
| |
8181
| not exportable
8282

8383
error: generic functions are not exportable
84-
--> $DIR/exportable.rs:65:9
84+
--> $DIR/exportable.rs:70:9
8585
|
8686
LL | pub extern "C" fn foo1(&self) {}
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8888

8989
error: function with `#[export_stable]` attribute uses type `(u32,)`, which is not exportable
90-
--> $DIR/exportable.rs:81:5
90+
--> $DIR/exportable.rs:86:5
9191
|
9292
LL | pub extern "C" fn foo1(x: <S as Trait>::Type) -> u32 { x.0 }
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^------------------^^^^^^^^
9494
| |
9595
| not exportable
9696

9797
error: function with `#[export_stable]` attribute uses type `[i32; 4]`, which is not exportable
98-
--> $DIR/exportable.rs:88:5
98+
--> $DIR/exportable.rs:93:5
9999
|
100100
LL | pub extern "C" fn foo2(_x: Type) {}
101101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^----^
102102
| |
103103
| not exportable
104104

105105
error: function with `#[export_stable]` attribute uses type `extern "C" fn()`, which is not exportable
106-
--> $DIR/exportable.rs:97:5
106+
--> $DIR/exportable.rs:102:5
107107
|
108108
LL | pub extern "C" fn foo3(_x: S::Type) {}
109109
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^-------^
110110
| |
111111
| not exportable
112112

113113
error: function with `#[export_stable]` attribute uses type `impl Copy`, which is not exportable
114-
--> $DIR/exportable.rs:101:5
114+
--> $DIR/exportable.rs:106:5
115115
|
116116
LL | pub extern "C" fn foo4() -> impl Copy {
117117
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^---------
118118
| |
119119
| not exportable
120120

121121
error: ADT types with private fields are not exportable
122-
--> $DIR/exportable.rs:116:5
122+
--> $DIR/exportable.rs:121:5
123123
|
124124
LL | pub struct S2 {
125125
| ^^^^^^^^^^^^^
126126
|
127127
note: `x` is private
128-
--> $DIR/exportable.rs:118:9
128+
--> $DIR/exportable.rs:123:9
129129
|
130130
LL | x: i32
131131
| ^^^^^^

0 commit comments

Comments
 (0)