rust/tests/ui/feature-gates/stmt_expr_attrs_no_feature.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

142 lines
2.7 KiB
Rust
Raw Normal View History

#![feature(rustc_attrs)]
2015-11-24 21:56:20 +08:00
macro_rules! stmt_mac {
() => {
fn b() {}
}
}
fn main() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
fn a() {}
// Bug: built-in attrs like `rustc_dummy` are not gated on blocks, but other attrs are.
#[rustfmt::skip] //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
{
}
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
5;
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
stmt_mac!();
}
// Check that cfg works right
#[cfg(FALSE)]
2015-11-24 21:56:20 +08:00
fn c() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
5;
}
#[cfg(not(FALSE))]
2015-11-24 21:56:20 +08:00
fn j() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
5;
}
#[cfg_attr(not(FALSE), cfg(FALSE))]
2015-11-24 21:56:20 +08:00
fn d() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
8;
}
#[cfg_attr(not(FALSE), cfg(not(FALSE)))]
2015-11-24 21:56:20 +08:00
fn i() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
8;
}
// check that macro expansion and cfg works right
macro_rules! item_mac {
($e:ident) => {
fn $e() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
42;
#[cfg(FALSE)]
2015-11-24 21:56:20 +08:00
fn f() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
5;
}
#[cfg(not(FALSE))]
2015-11-24 21:56:20 +08:00
fn k() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
5;
}
#[cfg_attr(not(FALSE), cfg(FALSE))]
2015-11-24 21:56:20 +08:00
fn g() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
8;
}
#[cfg_attr(not(FALSE), cfg(not(FALSE)))]
2015-11-24 21:56:20 +08:00
fn h() {
#[rustc_dummy]
2015-11-24 21:56:20 +08:00
8;
}
}
}
}
item_mac!(e);
// check that the gate visitor works right:
2020-09-02 05:12:52 +08:00
extern "C" {
#[cfg(FALSE)]
fn x(a: [u8; #[rustc_dummy] 5]);
fn y(a: [u8; #[rustc_dummy] 5]); //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
}
struct Foo;
impl Foo {
#[cfg(FALSE)]
const X: u8 = #[rustc_dummy] 5;
const Y: u8 = #[rustc_dummy] 5; //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
}
trait Bar {
#[cfg(FALSE)]
const X: [u8; #[rustc_dummy] 5];
const Y: [u8; #[rustc_dummy] 5]; //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
}
struct Joyce {
#[cfg(FALSE)]
field: [u8; #[rustc_dummy] 5],
field2: [u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
}
struct Walky(
#[cfg(FALSE)] [u8; #[rustc_dummy] 5],
[u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
);
enum Mike {
Happy(
#[cfg(FALSE)] [u8; #[rustc_dummy] 5],
[u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
),
Angry {
#[cfg(FALSE)]
field: [u8; #[rustc_dummy] 5],
field2: [u8; #[rustc_dummy] 5] //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
}
}
fn pat() {
match 5 {
#[cfg(FALSE)]
5 => #[rustc_dummy] (),
6 => #[rustc_dummy] (), //~ ERROR attributes on expressions are experimental
2015-11-24 21:56:20 +08:00
_ => (),
}
}