diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/cfg | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/cfg')
34 files changed, 880 insertions, 0 deletions
diff --git a/tests/ui/cfg/assume-incomplete-release/assume-incomplete.rs b/tests/ui/cfg/assume-incomplete-release/assume-incomplete.rs new file mode 100644 index 000000000..24d2dc645 --- /dev/null +++ b/tests/ui/cfg/assume-incomplete-release/assume-incomplete.rs @@ -0,0 +1,38 @@ +// run-pass +// aux-build:ver-cfg-rel.rs +// revisions: assume no_assume +// [assume]compile-flags: -Z assume-incomplete-release + +#![feature(cfg_version)] + +extern crate ver_cfg_rel; + +use ver_cfg_rel::ver_cfg_rel; + +#[ver_cfg_rel("-2")] +fn foo_2() { } + +#[ver_cfg_rel("-1")] +fn foo_1() { } + +#[cfg(assume)] +#[ver_cfg_rel("0")] +fn foo() { compile_error!("wrong+0") } + +#[cfg(no_assume)] +#[ver_cfg_rel("0")] +fn foo() { } + +#[ver_cfg_rel("1")] +fn bar() { compile_error!("wrong+1") } + +#[ver_cfg_rel("2")] +fn bar() { compile_error!("wrong+2") } + +fn main() { + foo_2(); + foo_1(); + + #[cfg(no_assume)] + foo(); +} diff --git a/tests/ui/cfg/assume-incomplete-release/auxiliary/ver-cfg-rel.rs b/tests/ui/cfg/assume-incomplete-release/auxiliary/ver-cfg-rel.rs new file mode 100644 index 000000000..067c620f5 --- /dev/null +++ b/tests/ui/cfg/assume-incomplete-release/auxiliary/ver-cfg-rel.rs @@ -0,0 +1,56 @@ +// force-host +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; +use proc_macro::{TokenStream, TokenTree as Tt}; +use std::str::FromStr; + +// String containing the current version number of the tip, i.e. "1.41.2" +static VERSION_NUMBER: &str = include_str!("../../../../../src/version"); + +#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +struct Version { + major: i16, + minor: i16, + patch: i16, +} + +fn parse_version(s: &str) -> Option<Version> { + let mut digits = s.splitn(3, '.'); + let major = digits.next()?.parse().ok()?; + let minor = digits.next()?.parse().ok()?; + let patch = digits.next().unwrap_or("0").trim().parse().ok()?; + Some(Version { major, minor, patch }) +} + +#[proc_macro_attribute] +/// Emits a #[cfg(version)] relative to the current one, so passing +/// -1 as argument on compiler 1.50 will emit #[cfg(version("1.49.0"))], +/// while 1 will emit #[cfg(version("1.51.0"))] +pub fn ver_cfg_rel(attr: TokenStream, input: TokenStream) -> TokenStream { + let mut v_rel = None; + for a in attr.into_iter() { + match a { + Tt::Literal(l) => { + let mut s = l.to_string(); + let s = s.trim_matches('"'); + let v: i16 = s.parse().unwrap(); + v_rel = Some(v); + break; + }, + _ => panic!("{:?}", a), + } + } + let v_rel = v_rel.unwrap(); + + let mut v = parse_version(VERSION_NUMBER).unwrap(); + v.minor += v_rel; + + let attr_str = format!("#[cfg(version(\"{}.{}.{}\"))]", v.major, v.minor, v.patch); + let mut res = Vec::<Tt>::new(); + res.extend(TokenStream::from_str(&attr_str).unwrap().into_iter()); + res.extend(input.into_iter()); + res.into_iter().collect() +} diff --git a/tests/ui/cfg/auxiliary/cfg_inner_static.rs b/tests/ui/cfg/auxiliary/cfg_inner_static.rs new file mode 100644 index 000000000..6a619a4e7 --- /dev/null +++ b/tests/ui/cfg/auxiliary/cfg_inner_static.rs @@ -0,0 +1,7 @@ +// this used to just ICE on compiling +pub fn foo() { + if cfg!(foo) { + static a: isize = 3; + a + } else { 3 }; +} diff --git a/tests/ui/cfg/cfg-attr-cfg.rs b/tests/ui/cfg/cfg-attr-cfg.rs new file mode 100644 index 000000000..61794e0bf --- /dev/null +++ b/tests/ui/cfg/cfg-attr-cfg.rs @@ -0,0 +1,8 @@ +// run-pass +// main is conditionally compiled, but the conditional compilation +// is conditional too! + +// pretty-expanded FIXME #23616 + +#[cfg_attr(foo, cfg(bar))] +fn main() { } diff --git a/tests/ui/cfg/cfg-attr-crate.rs b/tests/ui/cfg/cfg-attr-crate.rs new file mode 100644 index 000000000..1d70f2f84 --- /dev/null +++ b/tests/ui/cfg/cfg-attr-crate.rs @@ -0,0 +1,8 @@ +// run-pass +// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044 + +// pretty-expanded FIXME #23616 + +#![cfg_attr(not_used, no_core)] + +fn main() { } diff --git a/tests/ui/cfg/cfg-family.rs b/tests/ui/cfg/cfg-family.rs new file mode 100644 index 000000000..c7d196a2a --- /dev/null +++ b/tests/ui/cfg/cfg-family.rs @@ -0,0 +1,12 @@ +// build-pass +// pretty-expanded FIXME #23616 +// ignore-wasm32-bare no bare family +// ignore-sgx + +#[cfg(windows)] +pub fn main() { +} + +#[cfg(unix)] +pub fn main() { +} diff --git a/tests/ui/cfg/cfg-in-crate-1.rs b/tests/ui/cfg/cfg-in-crate-1.rs new file mode 100644 index 000000000..e84300aa3 --- /dev/null +++ b/tests/ui/cfg/cfg-in-crate-1.rs @@ -0,0 +1,5 @@ +// run-pass +// compile-flags: --cfg bar -D warnings +#![cfg(bar)] + +fn main() {} diff --git a/tests/ui/cfg/cfg-macros-foo.rs b/tests/ui/cfg/cfg-macros-foo.rs new file mode 100644 index 000000000..8b112c796 --- /dev/null +++ b/tests/ui/cfg/cfg-macros-foo.rs @@ -0,0 +1,26 @@ +// run-pass +// compile-flags: --cfg foo + +// check that cfg correctly chooses between the macro impls (see also +// cfg-macros-notfoo.rs) + + +#[cfg(foo)] +#[macro_use] +mod foo { + macro_rules! bar { + () => { true } + } +} + +#[cfg(not(foo))] +#[macro_use] +mod foo { + macro_rules! bar { + () => { false } + } +} + +pub fn main() { + assert!(bar!()) +} diff --git a/tests/ui/cfg/cfg-macros-notfoo.rs b/tests/ui/cfg/cfg-macros-notfoo.rs new file mode 100644 index 000000000..292d97821 --- /dev/null +++ b/tests/ui/cfg/cfg-macros-notfoo.rs @@ -0,0 +1,26 @@ +// run-pass +// compile-flags: + +// check that cfg correctly chooses between the macro impls (see also +// cfg-macros-foo.rs) + + +#[cfg(foo)] +#[macro_use] +mod foo { + macro_rules! bar { + () => { true } + } +} + +#[cfg(not(foo))] +#[macro_use] +mod foo { + macro_rules! bar { + () => { false } + } +} + +pub fn main() { + assert!(!bar!()) +} diff --git a/tests/ui/cfg/cfg-match-arm.rs b/tests/ui/cfg/cfg-match-arm.rs new file mode 100644 index 000000000..071008f9e --- /dev/null +++ b/tests/ui/cfg/cfg-match-arm.rs @@ -0,0 +1,20 @@ +// run-pass +#![allow(dead_code)] +// pretty-expanded FIXME #23616 + +enum Foo { + Bar, + Baz, +} + +fn foo(f: Foo) { + match f { + Foo::Bar => {}, + #[cfg(not(asdfa))] + Foo::Baz => {}, + #[cfg(afsd)] + Basdfwe => {} + } +} + +pub fn main() {} diff --git a/tests/ui/cfg/cfg-method-receiver-ok.rs b/tests/ui/cfg/cfg-method-receiver-ok.rs new file mode 100644 index 000000000..61ad3b8c1 --- /dev/null +++ b/tests/ui/cfg/cfg-method-receiver-ok.rs @@ -0,0 +1,14 @@ +// check-pass + +macro_rules! foo { + () => { + #[allow(unreachable_patterns)] + { + 123i32 + } + }; +} + +fn main() { + let _ = foo!().abs(); +} diff --git a/tests/ui/cfg/cfg-method-receiver.rs b/tests/ui/cfg/cfg-method-receiver.rs new file mode 100644 index 000000000..71134ff17 --- /dev/null +++ b/tests/ui/cfg/cfg-method-receiver.rs @@ -0,0 +1,11 @@ +macro_rules! cbor_map { + ($key:expr) => { + $key.signum(); + //~^ ERROR can't call method `signum` on ambiguous numeric type `{integer}` [E0689] + }; +} + +fn main() { + cbor_map! { #[cfg(test)] 4}; + //~^ ERROR removing an expression is not supported in this position +} diff --git a/tests/ui/cfg/cfg-method-receiver.stderr b/tests/ui/cfg/cfg-method-receiver.stderr new file mode 100644 index 000000000..5767a7c1b --- /dev/null +++ b/tests/ui/cfg/cfg-method-receiver.stderr @@ -0,0 +1,24 @@ +error: removing an expression is not supported in this position + --> $DIR/cfg-method-receiver.rs:9:17 + | +LL | cbor_map! { #[cfg(test)] 4}; + | ^^^^^^^^^^^^ + +error[E0689]: can't call method `signum` on ambiguous numeric type `{integer}` + --> $DIR/cfg-method-receiver.rs:3:14 + | +LL | $key.signum(); + | ^^^^^^ +... +LL | cbor_map! { #[cfg(test)] 4}; + | --------------------------- in this macro invocation + | + = note: this error originates in the macro `cbor_map` (in Nightly builds, run with -Z macro-backtrace for more info) +help: you must specify a concrete type for this numeric value, like `i32` + | +LL | cbor_map! { #[cfg(test)] 4_i32}; + | ~~~~~ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0689`. diff --git a/tests/ui/cfg/cfg-panic-abort.rs b/tests/ui/cfg/cfg-panic-abort.rs new file mode 100644 index 000000000..3853b598a --- /dev/null +++ b/tests/ui/cfg/cfg-panic-abort.rs @@ -0,0 +1,16 @@ +// build-pass +// compile-flags: -C panic=abort +// no-prefer-dynamic + + +#[cfg(panic = "unwind")] +pub fn bad() -> i32 { } + +#[cfg(not(panic = "abort"))] +pub fn bad() -> i32 { } + +#[cfg(panic = "some_imaginary_future_panic_handler")] +pub fn bad() -> i32 { } + +#[cfg(panic = "abort")] +pub fn main() { } diff --git a/tests/ui/cfg/cfg-panic.rs b/tests/ui/cfg/cfg-panic.rs new file mode 100644 index 000000000..2de72d54a --- /dev/null +++ b/tests/ui/cfg/cfg-panic.rs @@ -0,0 +1,16 @@ +// build-pass +// compile-flags: -C panic=unwind +// needs-unwind + + +#[cfg(panic = "abort")] +pub fn bad() -> i32 { } + +#[cfg(not(panic = "unwind"))] +pub fn bad() -> i32 { } + +#[cfg(panic = "some_imaginary_future_panic_handler")] +pub fn bad() -> i32 { } + +#[cfg(panic = "unwind")] +pub fn main() { } diff --git a/tests/ui/cfg/cfg-path-error.rs b/tests/ui/cfg/cfg-path-error.rs new file mode 100644 index 000000000..5bf80bd74 --- /dev/null +++ b/tests/ui/cfg/cfg-path-error.rs @@ -0,0 +1,19 @@ +// check-fail + +#[cfg(any(foo, foo::bar))] +//~^ERROR `cfg` predicate key must be an identifier +fn foo1() {} + +#[cfg(any(foo::bar, foo))] +//~^ERROR `cfg` predicate key must be an identifier +fn foo2() {} + +#[cfg(all(foo, foo::bar))] +//~^ERROR `cfg` predicate key must be an identifier +fn foo3() {} + +#[cfg(all(foo::bar, foo))] +//~^ERROR `cfg` predicate key must be an identifier +fn foo4() {} + +fn main() {} diff --git a/tests/ui/cfg/cfg-path-error.stderr b/tests/ui/cfg/cfg-path-error.stderr new file mode 100644 index 000000000..84b44b2b0 --- /dev/null +++ b/tests/ui/cfg/cfg-path-error.stderr @@ -0,0 +1,26 @@ +error: `cfg` predicate key must be an identifier + --> $DIR/cfg-path-error.rs:3:16 + | +LL | #[cfg(any(foo, foo::bar))] + | ^^^^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/cfg-path-error.rs:7:11 + | +LL | #[cfg(any(foo::bar, foo))] + | ^^^^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/cfg-path-error.rs:11:16 + | +LL | #[cfg(all(foo, foo::bar))] + | ^^^^^^^^ + +error: `cfg` predicate key must be an identifier + --> $DIR/cfg-path-error.rs:15:11 + | +LL | #[cfg(all(foo::bar, foo))] + | ^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/tests/ui/cfg/cfg-target-abi.rs b/tests/ui/cfg/cfg-target-abi.rs new file mode 100644 index 000000000..acc570fc8 --- /dev/null +++ b/tests/ui/cfg/cfg-target-abi.rs @@ -0,0 +1,10 @@ +// run-pass +#![feature(cfg_target_abi)] + +#[cfg(target_abi = "eabihf")] +pub fn main() { +} + +#[cfg(not(target_abi = "eabihf"))] +pub fn main() { +} diff --git a/tests/ui/cfg/cfg-target-compact-errors.rs b/tests/ui/cfg/cfg-target-compact-errors.rs new file mode 100644 index 000000000..bca2275b1 --- /dev/null +++ b/tests/ui/cfg/cfg-target-compact-errors.rs @@ -0,0 +1,17 @@ +// check-fail + +#![feature(cfg_target_compact)] + +#[cfg(target(o::o))] +//~^ ERROR `cfg` predicate key must be an identifier +fn one() {} + +#[cfg(target(os = 8))] +//~^ ERROR literal in `cfg` predicate value must be a string +fn two() {} + +#[cfg(target(os = "linux", pointer(width = "64")))] +//~^ ERROR invalid predicate `target_pointer` +fn three() {} + +fn main() {} diff --git a/tests/ui/cfg/cfg-target-compact-errors.stderr b/tests/ui/cfg/cfg-target-compact-errors.stderr new file mode 100644 index 000000000..bb858301e --- /dev/null +++ b/tests/ui/cfg/cfg-target-compact-errors.stderr @@ -0,0 +1,22 @@ +error: `cfg` predicate key must be an identifier + --> $DIR/cfg-target-compact-errors.rs:5:14 + | +LL | #[cfg(target(o::o))] + | ^^^^ + +error[E0565]: literal in `cfg` predicate value must be a string + --> $DIR/cfg-target-compact-errors.rs:9:19 + | +LL | #[cfg(target(os = 8))] + | ^ + +error[E0537]: invalid predicate `target_pointer` + --> $DIR/cfg-target-compact-errors.rs:13:28 + | +LL | #[cfg(target(os = "linux", pointer(width = "64")))] + | ^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 3 previous errors + +Some errors have detailed explanations: E0537, E0565. +For more information about an error, try `rustc --explain E0537`. diff --git a/tests/ui/cfg/cfg-target-compact.rs b/tests/ui/cfg/cfg-target-compact.rs new file mode 100644 index 000000000..dc95a8091 --- /dev/null +++ b/tests/ui/cfg/cfg-target-compact.rs @@ -0,0 +1,10 @@ +// run-pass +#![feature(cfg_target_compact)] + +#[cfg(target(os = "linux", pointer_width = "64"))] +pub fn main() { +} + +#[cfg(not(target(os = "linux", pointer_width = "64")))] +pub fn main() { +} diff --git a/tests/ui/cfg/cfg-target-family.rs b/tests/ui/cfg/cfg-target-family.rs new file mode 100644 index 000000000..5182cdc89 --- /dev/null +++ b/tests/ui/cfg/cfg-target-family.rs @@ -0,0 +1,13 @@ +// build-pass +// ignore-sgx + +// pretty-expanded FIXME #23616 + +#[cfg(target_family = "windows")] +pub fn main() {} + +#[cfg(target_family = "unix")] +pub fn main() {} + +#[cfg(all(target_family = "wasm", not(target_os = "emscripten")))] +pub fn main() {} diff --git a/tests/ui/cfg/cfg-target-vendor.rs b/tests/ui/cfg/cfg-target-vendor.rs new file mode 100644 index 000000000..782458516 --- /dev/null +++ b/tests/ui/cfg/cfg-target-vendor.rs @@ -0,0 +1,8 @@ +// run-pass +#[cfg(target_vendor = "unknown")] +pub fn main() { +} + +#[cfg(not(target_vendor = "unknown"))] +pub fn main() { +} diff --git a/tests/ui/cfg/cfg_attr.rs b/tests/ui/cfg/cfg_attr.rs new file mode 100644 index 000000000..c959e68ac --- /dev/null +++ b/tests/ui/cfg/cfg_attr.rs @@ -0,0 +1,50 @@ +// run-pass +// compile-flags:--cfg set1 --cfg set2 +#![allow(dead_code)] +use std::fmt::Debug; + +struct NotDebugable; + +#[cfg_attr(set1, derive(Debug))] +struct Set1; + +#[cfg_attr(notset, derive(Debug))] +struct Notset(NotDebugable); + +#[cfg_attr(not(notset), derive(Debug))] +struct NotNotset; + +#[cfg_attr(not(set1), derive(Debug))] +struct NotSet1(NotDebugable); + +#[cfg_attr(all(set1, set2), derive(Debug))] +struct AllSet1Set2; + +#[cfg_attr(all(set1, notset), derive(Debug))] +struct AllSet1Notset(NotDebugable); + +#[cfg_attr(any(set1, notset), derive(Debug))] +struct AnySet1Notset; + +#[cfg_attr(any(notset, notset2), derive(Debug))] +struct AnyNotsetNotset2(NotDebugable); + +#[cfg_attr(all(not(notset), any(set1, notset)), derive(Debug))] +struct Complex; + +#[cfg_attr(any(notset, not(any(set1, notset))), derive(Debug))] +struct ComplexNot(NotDebugable); + +#[cfg_attr(any(target_endian = "little", target_endian = "big"), derive(Debug))] +struct KeyValue; + +fn is_show<T: Debug>() {} + +fn main() { + is_show::<Set1>(); + is_show::<NotNotset>(); + is_show::<AllSet1Set2>(); + is_show::<AnySet1Notset>(); + is_show::<Complex>(); + is_show::<KeyValue>(); +} diff --git a/tests/ui/cfg/cfg_inner_static.rs b/tests/ui/cfg/cfg_inner_static.rs new file mode 100644 index 000000000..45dbbcc10 --- /dev/null +++ b/tests/ui/cfg/cfg_inner_static.rs @@ -0,0 +1,10 @@ +// run-pass +// aux-build:cfg_inner_static.rs + +// pretty-expanded FIXME #23616 + +extern crate cfg_inner_static; + +pub fn main() { + cfg_inner_static::foo(); +} diff --git a/tests/ui/cfg/cfg_stmt_expr.rs b/tests/ui/cfg/cfg_stmt_expr.rs new file mode 100644 index 000000000..6381bb2d5 --- /dev/null +++ b/tests/ui/cfg/cfg_stmt_expr.rs @@ -0,0 +1,92 @@ +// run-pass +#![allow(dead_code)] +#![allow(unused_mut)] +#![allow(unused_variables)] +#![deny(non_snake_case)] +#![feature(stmt_expr_attributes)] + +fn main() { + let a = 413; + #[cfg(unset)] + let a = (); + assert_eq!(a, 413); + + let mut b = 612; + #[cfg(unset)] + { + b = 1111; + } + assert_eq!(b, 612); + + #[cfg(unset)] + undefined_fn(); + + #[cfg(unset)] + undefined_macro!(); + #[cfg(unset)] + undefined_macro![]; + #[cfg(unset)] + undefined_macro!{}; + + // pretty printer bug... + // #[cfg(unset)] + // undefined_macro!{} + + let () = (#[cfg(unset)] 341,); // Should this also work on parens? + let t = (1, #[cfg(unset)] 3, 4); + assert_eq!(t, (1, 4)); + + let f = |_: u32, _: u32| (); + f(2, 1, #[cfg(unset)] 6); + + let _: u32 = a.clone(#[cfg(unset)] undefined); + + let _: [(); 0] = [#[cfg(unset)] 126]; + let t = [#[cfg(unset)] 1, 2, 6]; + assert_eq!(t, [2, 6]); + + { + let r; + #[cfg(unset)] + (r = 5); + #[cfg(not(unset))] + (r = 10); + assert_eq!(r, 10); + } + + // check that macro expanded code works + + macro_rules! if_cfg { + ($cfg:meta? $ib:block else $eb:block) => { + { + let r; + #[cfg($cfg)] + (r = $ib); + #[cfg(not($cfg))] + (r = $eb); + r + } + } + } + + let n = if_cfg!(unset? { + 413 + } else { + 612 + }); + + assert_eq!((#[cfg(unset)] 1, #[cfg(not(unset))] 2), (2,)); + assert_eq!(n, 612); + + // check that lints work + + #[allow(non_snake_case)] + let FOOBAR = { + fn SYLADEX() {} + }; + + #[allow(non_snake_case)] + { + fn CRUXTRUDER() {} + } +} diff --git a/tests/ui/cfg/cfgs-on-items.rs b/tests/ui/cfg/cfgs-on-items.rs new file mode 100644 index 000000000..9f2fc4942 --- /dev/null +++ b/tests/ui/cfg/cfgs-on-items.rs @@ -0,0 +1,29 @@ +// run-pass +// compile-flags: --cfg fooA --cfg fooB + +// fooA AND !bar + +#[cfg(all(fooA, not(bar)))] +fn foo1() -> isize { 1 } + +// !fooA AND !bar +#[cfg(all(not(fooA), not(bar)))] +fn foo2() -> isize { 2 } + +// fooC OR (fooB AND !bar) +#[cfg(any(fooC, all(fooB, not(bar))))] +fn foo2() -> isize { 3 } + +// fooA AND bar +#[cfg(all(fooA, bar))] +fn foo3() -> isize { 2 } + +// !(fooA AND bar) +#[cfg(not(all(fooA, bar)))] +fn foo3() -> isize { 3 } + +pub fn main() { + assert_eq!(1, foo1()); + assert_eq!(3, foo2()); + assert_eq!(3, foo3()); +} diff --git a/tests/ui/cfg/conditional-compile-arch.rs b/tests/ui/cfg/conditional-compile-arch.rs new file mode 100644 index 000000000..7de561df1 --- /dev/null +++ b/tests/ui/cfg/conditional-compile-arch.rs @@ -0,0 +1,41 @@ +// run-pass +// pretty-expanded FIXME #23616 + +#[cfg(target_arch = "x86")] +pub fn main() { } + +#[cfg(target_arch = "x86_64")] +pub fn main() { } + +#[cfg(target_arch = "arm")] +pub fn main() { } + +#[cfg(target_arch = "aarch64")] +pub fn main() { } + +#[cfg(target_arch = "mips")] +pub fn main() { } + +#[cfg(target_arch = "mips64")] +pub fn main() { } + +#[cfg(target_arch = "powerpc")] +pub fn main() { } + +#[cfg(target_arch = "powerpc64")] +pub fn main() { } + +#[cfg(target_arch = "s390x")] +pub fn main() { } + +#[cfg(target_arch = "asmjs")] +pub fn main() { } + +#[cfg(target_arch = "wasm32")] +pub fn main() { } + +#[cfg(target_arch = "sparc64")] +pub fn main() { } + +#[cfg(target_arch = "riscv64")] +pub fn main() { } diff --git a/tests/ui/cfg/conditional-compile.rs b/tests/ui/cfg/conditional-compile.rs new file mode 100644 index 000000000..69f4de431 --- /dev/null +++ b/tests/ui/cfg/conditional-compile.rs @@ -0,0 +1,155 @@ +// run-pass +#![allow(dead_code)] +#![allow(non_upper_case_globals)] +#![allow(non_camel_case_types)] +#![allow(improper_ctypes)] + +// Crate use statements + +#[cfg(bogus)] +use flippity; + +#[cfg(bogus)] +static b: bool = false; + +static b: bool = true; + +mod rustrt { + #[cfg(bogus)] + extern "C" { + // This symbol doesn't exist and would be a link error if this + // module was codegened + pub fn bogus(); + } + + extern "C" {} +} + +#[cfg(bogus)] +type t = isize; + +type t = bool; + +#[cfg(bogus)] +enum tg { + foo, +} + +enum tg { + bar, +} + +#[cfg(bogus)] +struct r { + i: isize, +} + +#[cfg(bogus)] +fn r(i: isize) -> r { + r { i: i } +} + +struct r { + i: isize, +} + +fn r(i: isize) -> r { + r { i: i } +} + +#[cfg(bogus)] +mod m { + // This needs to parse but would fail in typeck. Since it's not in + // the current config it should not be typechecked. + pub fn bogus() { + return 0; + } +} + +mod m { + // Submodules have slightly different code paths than the top-level + // module, so let's make sure this jazz works here as well + #[cfg(bogus)] + pub fn f() {} + + pub fn f() {} +} + +// Since the bogus configuration isn't defined main will just be +// parsed, but nothing further will be done with it +#[cfg(bogus)] +pub fn main() { + panic!() +} + +pub fn main() { + // Exercise some of the configured items in ways that wouldn't be possible + // if they had the bogus definition + assert!((b)); + let _x: t = true; + let _y: tg = tg::bar; + + test_in_fn_ctxt(); +} + +fn test_in_fn_ctxt() { + #[cfg(bogus)] + fn f() { + panic!() + } + fn f() {} + f(); + + #[cfg(bogus)] + static i: isize = 0; + static i: isize = 1; + assert_eq!(i, 1); +} + +mod test_foreign_items { + pub mod rustrt { + extern "C" { + #[cfg(bogus)] + pub fn write() -> String; + pub fn write() -> String; + } + } +} + +mod test_use_statements { + #[cfg(bogus)] + use flippity_foo; +} + +mod test_methods { + struct Foo { + bar: usize, + } + + impl Fooable for Foo { + #[cfg(bogus)] + fn what(&self) {} + + fn what(&self) {} + + #[cfg(bogus)] + fn the(&self) {} + + fn the(&self) {} + } + + trait Fooable { + #[cfg(bogus)] + fn what(&self); + + fn what(&self); + + #[cfg(bogus)] + fn the(&self); + + fn the(&self); + } +} + +#[cfg(any())] +mod nonexistent_file; // Check that unconfigured non-inline modules are not loaded or parsed. diff --git a/tests/ui/cfg/crt-static-off-works.rs b/tests/ui/cfg/crt-static-off-works.rs new file mode 100644 index 000000000..911467ee5 --- /dev/null +++ b/tests/ui/cfg/crt-static-off-works.rs @@ -0,0 +1,10 @@ +// run-pass + +#![allow(stable_features)] +// compile-flags:-C target-feature=-crt-static -Z unstable-options +// ignore-musl - requires changing the linker which is hard + +#![feature(cfg_target_feature)] + +#[cfg(not(target_feature = "crt-static"))] +fn main() {} diff --git a/tests/ui/cfg/crt-static-on-works.rs b/tests/ui/cfg/crt-static-on-works.rs new file mode 100644 index 000000000..f89d1edd6 --- /dev/null +++ b/tests/ui/cfg/crt-static-on-works.rs @@ -0,0 +1,6 @@ +// run-pass +// compile-flags:-C target-feature=+crt-static +// only-msvc + +#[cfg(target_feature = "crt-static")] +fn main() {} diff --git a/tests/ui/cfg/expanded-cfg.rs b/tests/ui/cfg/expanded-cfg.rs new file mode 100644 index 000000000..baa161af7 --- /dev/null +++ b/tests/ui/cfg/expanded-cfg.rs @@ -0,0 +1,21 @@ +// check-pass + +macro_rules! mac { + {} => { + #[cfg(attr)] + mod m { + #[lang_item] + fn f() {} + + #[cfg_attr(target_thread_local, custom)] + fn g() {} + } + + #[cfg(attr)] + unconfigured_invocation!(); + } +} + +mac! {} + +fn main() {} diff --git a/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs b/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs new file mode 100644 index 000000000..1f23dadc4 --- /dev/null +++ b/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.rs @@ -0,0 +1,15 @@ +// check-fail +// compile-flags:--cfg foo + +#![cfg_attr(foo, crate_type="bin")] +//~^ERROR `crate_type` within +//~| WARN this was previously accepted +//~|ERROR `crate_type` within +//~| WARN this was previously accepted +#![cfg_attr(foo, crate_name="bar")] +//~^ERROR `crate_name` within +//~| WARN this was previously accepted +//~|ERROR `crate_name` within +//~| WARN this was previously accepted + +fn main() {} diff --git a/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr b/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr new file mode 100644 index 000000000..9ce4710d6 --- /dev/null +++ b/tests/ui/cfg/future-compat-crate-attributes-using-cfg_attr.stderr @@ -0,0 +1,39 @@ +error: `crate_type` within an `#![cfg_attr] attribute is deprecated` + --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:4:18 + | +LL | #![cfg_attr(foo, crate_type="bin")] + | ^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632> + = note: `#[deny(deprecated_cfg_attr_crate_type_name)]` on by default + +error: `crate_name` within an `#![cfg_attr] attribute is deprecated` + --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:9:18 + | +LL | #![cfg_attr(foo, crate_name="bar")] + | ^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632> + +error: `crate_type` within an `#![cfg_attr] attribute is deprecated` + --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:4:18 + | +LL | #![cfg_attr(foo, crate_type="bin")] + | ^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632> + +error: `crate_name` within an `#![cfg_attr] attribute is deprecated` + --> $DIR/future-compat-crate-attributes-using-cfg_attr.rs:9:18 + | +LL | #![cfg_attr(foo, crate_name="bar")] + | ^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #91632 <https://github.com/rust-lang/rust/issues/91632> + +error: aborting due to 4 previous errors + |