rust/tests/ui/cfg/conditional-compile.rs

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

156 lines
2.4 KiB
Rust
Raw Normal View History

// run-pass
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(improper_ctypes)]
2012-11-01 22:48:37 +00:00
// Crate use statements
2012-11-01 22:48:37 +00:00
#[cfg(bogus)]
use flippity;
#[cfg(bogus)]
static b: bool = false;
static b: bool = true;
mod rustrt {
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
extern "C" {
// This symbol doesn't exist and would be a link error if this
2018-05-08 13:10:16 +00:00
// module was codegened
pub fn bogus();
}
2020-09-01 21:12:52 +00:00
extern "C" {}
}
#[cfg(bogus)]
type t = isize;
type t = bool;
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
enum tg {
foo,
}
2020-09-01 21:12:52 +00:00
enum tg {
bar,
}
#[cfg(bogus)]
2012-08-16 01:46:55 +00:00
struct r {
2020-09-01 21:12:52 +00:00
i: isize,
2012-09-05 22:58:43 +00:00
}
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
fn r(i: isize) -> r {
r { i: i }
}
2012-08-16 01:46:55 +00:00
struct r {
2020-09-01 21:12:52 +00:00
i: isize,
2012-09-05 22:58:43 +00:00
}
2020-09-01 21:12:52 +00:00
fn r(i: isize) -> r {
r { i: i }
}
#[cfg(bogus)]
mod m {
2011-07-27 12:19:39 +00:00
// This needs to parse but would fail in typeck. Since it's not in
// the current config it should not be typechecked.
2020-09-01 21:12:52 +00:00
pub fn bogus() {
return 0;
}
}
mod m {
2011-07-27 12:19:39 +00:00
// Submodules have slightly different code paths than the top-level
// module, so let's make sure this jazz works here as well
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
pub fn f() {}
2020-09-01 21:12:52 +00:00
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)]
2020-09-01 21:12:52 +00:00
pub fn main() {
panic!()
}
pub fn main() {
2011-07-27 12:19:39 +00:00
// Exercise some of the configured items in ways that wouldn't be possible
// if they had the bogus definition
2013-03-29 01:39:09 +00:00
assert!((b));
2013-08-17 15:37:42 +00:00
let _x: t = true;
let _y: tg = tg::bar;
2011-07-27 12:19:39 +00:00
test_in_fn_ctxt();
}
fn test_in_fn_ctxt() {
2011-07-27 12:19:39 +00:00
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
fn f() {
panic!()
}
fn f() {}
2011-07-27 12:19:39 +00:00
f();
#[cfg(bogus)]
static i: isize = 0;
static i: isize = 1;
assert_eq!(i, 1);
}
mod test_foreign_items {
pub mod rustrt {
2020-09-01 21:12:52 +00:00
extern "C" {
#[cfg(bogus)]
pub fn write() -> String;
pub fn write() -> String;
}
2011-07-27 12:19:39 +00:00
}
}
mod test_use_statements {
#[cfg(bogus)]
use flippity_foo;
2012-11-01 22:48:37 +00:00
}
mod test_methods {
struct Foo {
2020-09-01 21:12:52 +00:00
bar: usize,
2012-11-01 22:48:37 +00:00
}
impl Fooable for Foo {
2012-11-01 22:48:37 +00:00
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
fn what(&self) {}
2012-11-01 22:48:37 +00:00
2020-09-01 21:12:52 +00:00
fn what(&self) {}
2012-11-01 22:48:37 +00:00
#[cfg(bogus)]
2020-09-01 21:12:52 +00:00
fn the(&self) {}
2012-11-01 22:48:37 +00:00
2020-09-01 21:12:52 +00:00
fn the(&self) {}
2012-11-01 22:48:37 +00:00
}
trait Fooable {
#[cfg(bogus)]
fn what(&self);
2012-11-01 22:48:37 +00:00
fn what(&self);
2012-11-01 22:48:37 +00:00
#[cfg(bogus)]
fn the(&self);
2012-11-01 22:48:37 +00:00
fn the(&self);
2012-11-01 22:48:37 +00:00
}
}
2016-09-14 22:40:56 +00:00
#[cfg(any())]
mod nonexistent_file; // Check that unconfigured non-inline modules are not loaded or parsed.