Test define opaques in extern items

This commit is contained in:
Michael Goulet 2025-03-24 23:19:33 +00:00
parent f8df298d74
commit 0827f76586
3 changed files with 34 additions and 1 deletions

View file

@ -52,7 +52,10 @@ pub(crate) fn expand(
.collect(),
);
} else {
ecx.dcx().span_err(meta_item.span, "only functions and methods can define opaque types");
ecx.dcx().span_err(
meta_item.span,
"only functions, statics, and consts can define opaque types",
);
}
vec![item]

View file

@ -0,0 +1,16 @@
#![feature(type_alias_impl_trait)]
type Hi = impl Sized;
extern "C" {
#[define_opaque(Hi)] fn foo();
//~^ ERROR only functions, statics, and consts can define opaque types
#[define_opaque(Hi)] static HI: Hi;
//~^ ERROR only functions, statics, and consts can define opaque types
}
#[define_opaque(Hi)]
fn main() {
let _: Hi = 0;
}

View file

@ -0,0 +1,14 @@
error: only functions, statics, and consts can define opaque types
--> $DIR/define-via-extern.rs:6:5
|
LL | #[define_opaque(Hi)] fn foo();
| ^^^^^^^^^^^^^^^^^^^^
error: only functions, statics, and consts can define opaque types
--> $DIR/define-via-extern.rs:9:5
|
LL | #[define_opaque(Hi)] static HI: Hi;
| ^^^^^^^^^^^^^^^^^^^^
error: aborting due to 2 previous errors