Skip to content
/ rust Public
forked from rust-lang/rust

Commit 0827f76

Browse files
Test define opaques in extern items
1 parent f8df298 commit 0827f76

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

compiler/rustc_builtin_macros/src/define_opaque.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ pub(crate) fn expand(
5252
.collect(),
5353
);
5454
} else {
55-
ecx.dcx().span_err(meta_item.span, "only functions and methods can define opaque types");
55+
ecx.dcx().span_err(
56+
meta_item.span,
57+
"only functions, statics, and consts can define opaque types",
58+
);
5659
}
5760

5861
vec![item]
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
type Hi = impl Sized;
4+
5+
extern "C" {
6+
#[define_opaque(Hi)] fn foo();
7+
//~^ ERROR only functions, statics, and consts can define opaque types
8+
9+
#[define_opaque(Hi)] static HI: Hi;
10+
//~^ ERROR only functions, statics, and consts can define opaque types
11+
}
12+
13+
#[define_opaque(Hi)]
14+
fn main() {
15+
let _: Hi = 0;
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: only functions, statics, and consts can define opaque types
2+
--> $DIR/define-via-extern.rs:6:5
3+
|
4+
LL | #[define_opaque(Hi)] fn foo();
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
7+
error: only functions, statics, and consts can define opaque types
8+
--> $DIR/define-via-extern.rs:9:5
9+
|
10+
LL | #[define_opaque(Hi)] static HI: Hi;
11+
| ^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 2 previous errors
14+

0 commit comments

Comments
 (0)