summaryrefslogtreecommitdiffstats
path: root/tests/ui/conditional-compilation
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/conditional-compilation')
-rw-r--r--tests/ui/conditional-compilation/auxiliary/namespaced_enums.rs10
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-1.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-2.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-2.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-3.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-3.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-4.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-4.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-5.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-5.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-6.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-7.rs5
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr4
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-8.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-9.rs4
-rw-r--r--tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-cfg-2.rs9
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-cfg-2.stderr9
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-crate-2.rs8
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-crate-2.stderr12
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-empty-is-unused.rs13
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-empty-is-unused.stderr21
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs4
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr9
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-false.rs19
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.rs7
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.stderr12
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.rs7
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.stderr12
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-true.rs21
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-multi-true.stderr40
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-parse.rs55
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-parse.stderr86
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs39
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr82
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.rs11
-rw-r--r--tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr13
-rw-r--r--tests/ui/conditional-compilation/cfg-empty-codemap.rs8
-rw-r--r--tests/ui/conditional-compilation/cfg-empty-codemap.stderr2
-rw-r--r--tests/ui/conditional-compilation/cfg-generic-params.rs40
-rw-r--r--tests/ui/conditional-compilation/cfg-generic-params.stderr50
-rw-r--r--tests/ui/conditional-compilation/cfg-in-crate-1.rs3
-rw-r--r--tests/ui/conditional-compilation/cfg-in-crate-1.stderr9
-rw-r--r--tests/ui/conditional-compilation/cfg-non-opt-expr.rs11
-rw-r--r--tests/ui/conditional-compilation/cfg-non-opt-expr.stderr20
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-bugs.rs18
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-bugs.stderr16
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-input-validation.rs24
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-input-validation.stderr44
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr122
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr122
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-not_sure.rs89
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-private.rs21
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-stuck.rs9
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-stuck.stderr8
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-unstable.rs2
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible-unstable.stderr12
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible.rs55
-rw-r--r--tests/ui/conditional-compilation/cfg_accessible.stderr27
-rw-r--r--tests/ui/conditional-compilation/cfg_attr_path.rs13
-rw-r--r--tests/ui/conditional-compilation/inner-cfg-non-inline-mod.rs7
-rw-r--r--tests/ui/conditional-compilation/issue-34028.rs10
-rw-r--r--tests/ui/conditional-compilation/module_with_cfg.rs3
-rw-r--r--tests/ui/conditional-compilation/test-cfg.rs8
-rw-r--r--tests/ui/conditional-compilation/test-cfg.stderr9
68 files changed, 1311 insertions, 0 deletions
diff --git a/tests/ui/conditional-compilation/auxiliary/namespaced_enums.rs b/tests/ui/conditional-compilation/auxiliary/namespaced_enums.rs
new file mode 100644
index 000000000..d3548c76c
--- /dev/null
+++ b/tests/ui/conditional-compilation/auxiliary/namespaced_enums.rs
@@ -0,0 +1,10 @@
+pub enum Foo {
+ A,
+ B(isize),
+ C { a: isize },
+}
+
+impl Foo {
+ pub fn foo() {}
+ pub fn bar(&self) {}
+}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-1.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-1.rs
new file mode 100644
index 000000000..d20e79b9d
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-1.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg a(b=c)
+// error-pattern: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr
new file mode 100644
index 000000000..3a12e9786
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-1.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `a(b=c)` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-2.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-2.rs
new file mode 100644
index 000000000..48d656a4a
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-2.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg a{b}
+// error-pattern: invalid `--cfg` argument: `a{b}` (expected `key` or `key="value"`)
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-2.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-2.stderr
new file mode 100644
index 000000000..b92e1fd3d
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-2.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `a{b}` (expected `key` or `key="value"`)
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-3.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-3.rs
new file mode 100644
index 000000000..96ac7828c
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-3.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg a::b
+// error-pattern: invalid `--cfg` argument: `a::b` (argument key must be an identifier)
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-3.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-3.stderr
new file mode 100644
index 000000000..5412f7ffd
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-3.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `a::b` (argument key must be an identifier)
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-4.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-4.rs
new file mode 100644
index 000000000..e7dfa17b4
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-4.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg a(b)
+// error-pattern: invalid `--cfg` argument: `a(b)` (expected `key` or `key="value"`)
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-4.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-4.stderr
new file mode 100644
index 000000000..6853a69b9
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-4.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `a(b)` (expected `key` or `key="value"`)
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-5.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-5.rs
new file mode 100644
index 000000000..a939f4510
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-5.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg a=10
+// error-pattern: invalid `--cfg` argument: `a=10` (argument value must be a string)
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-5.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-5.stderr
new file mode 100644
index 000000000..aafc4e898
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-5.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `a=10` (argument value must be a string)
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-6.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-6.rs
new file mode 100644
index 000000000..9fa726f93
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-6.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg a{
+// error-pattern: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr
new file mode 100644
index 000000000..7d2087b4b
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-6.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `a{` (expected `key` or `key="value"`)
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs
new file mode 100644
index 000000000..149142f63
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-7.rs
@@ -0,0 +1,5 @@
+// Regression test for issue #89358.
+
+// compile-flags: --cfg a"
+// error-pattern: unterminated double quote string
+// error-pattern: this error occurred on the command line
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr
new file mode 100644
index 000000000..919709c84
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-7.stderr
@@ -0,0 +1,4 @@
+error[E0765]: unterminated double quote string
+ |
+ = note: this error occurred on the command line: `--cfg=a"`
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-8.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-8.rs
new file mode 100644
index 000000000..1d7fa7885
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-8.rs
@@ -0,0 +1,3 @@
+// compile-flags: --cfg )
+// error-pattern: invalid `--cfg` argument: `)` (expected `key` or `key="value"`)
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr
new file mode 100644
index 000000000..7bb181412
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-8.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `)` (expected `key` or `key="value"`)
+
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-9.rs b/tests/ui/conditional-compilation/cfg-arg-invalid-9.rs
new file mode 100644
index 000000000..628b335c8
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-9.rs
@@ -0,0 +1,4 @@
+// Test for missing quotes around value, issue #66450.
+// compile-flags: --cfg key=value
+// error-pattern: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr b/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr
new file mode 100644
index 000000000..985b52522
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-arg-invalid-9.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `key=value` (expected `key` or `key="value"`, ensure escaping is appropriate for your shell, try 'key="value"' or key=\"value\")
+
diff --git a/tests/ui/conditional-compilation/cfg-attr-cfg-2.rs b/tests/ui/conditional-compilation/cfg-attr-cfg-2.rs
new file mode 100644
index 000000000..898c5bac8
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-cfg-2.rs
@@ -0,0 +1,9 @@
+//
+// error-pattern: `main` function not found
+// compile-flags: --cfg foo
+
+// main is conditionally compiled, but the conditional compilation
+// is conditional too!
+
+#[cfg_attr(foo, cfg(bar))]
+fn main() { }
diff --git a/tests/ui/conditional-compilation/cfg-attr-cfg-2.stderr b/tests/ui/conditional-compilation/cfg-attr-cfg-2.stderr
new file mode 100644
index 000000000..d61872c48
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-cfg-2.stderr
@@ -0,0 +1,9 @@
+error[E0601]: `main` function not found in crate `cfg_attr_cfg_2`
+ --> $DIR/cfg-attr-cfg-2.rs:9:14
+ |
+LL | fn main() { }
+ | ^ consider adding a `main` function to `$DIR/cfg-attr-cfg-2.rs`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0601`.
diff --git a/tests/ui/conditional-compilation/cfg-attr-crate-2.rs b/tests/ui/conditional-compilation/cfg-attr-crate-2.rs
new file mode 100644
index 000000000..7dbeba53a
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-crate-2.rs
@@ -0,0 +1,8 @@
+// https://github.com/rust-lang/rust/issues/21833#issuecomment-72353044
+
+// compile-flags: --cfg broken
+
+#![crate_type = "lib"]
+#![cfg_attr(broken, no_core)] //~ ERROR the `#[no_core]` attribute is an experimental feature
+
+pub struct S {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-crate-2.stderr b/tests/ui/conditional-compilation/cfg-attr-crate-2.stderr
new file mode 100644
index 000000000..4997ca4db
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-crate-2.stderr
@@ -0,0 +1,12 @@
+error[E0658]: the `#[no_core]` attribute is an experimental feature
+ --> $DIR/cfg-attr-crate-2.rs:6:21
+ |
+LL | #![cfg_attr(broken, no_core)]
+ | ^^^^^^^
+ |
+ = note: see issue #29639 <https://github.com/rust-lang/rust/issues/29639> for more information
+ = help: add `#![feature(no_core)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/conditional-compilation/cfg-attr-empty-is-unused.rs b/tests/ui/conditional-compilation/cfg-attr-empty-is-unused.rs
new file mode 100644
index 000000000..2600ec7c4
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-empty-is-unused.rs
@@ -0,0 +1,13 @@
+// Check that `#[cfg_attr($PREDICATE,)]` triggers the `unused_attribute` lint.
+
+// compile-flags: --cfg TRUE
+
+#![deny(unused)]
+
+#[cfg_attr(FALSE,)] //~ ERROR `#[cfg_attr]` does not expand to any attributes
+fn _f() {}
+
+#[cfg_attr(TRUE,)] //~ ERROR `#[cfg_attr]` does not expand to any attributes
+fn _g() {}
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-empty-is-unused.stderr b/tests/ui/conditional-compilation/cfg-attr-empty-is-unused.stderr
new file mode 100644
index 000000000..87b698813
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-empty-is-unused.stderr
@@ -0,0 +1,21 @@
+error: `#[cfg_attr]` does not expand to any attributes
+ --> $DIR/cfg-attr-empty-is-unused.rs:7:1
+ |
+LL | #[cfg_attr(FALSE,)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/cfg-attr-empty-is-unused.rs:5:9
+ |
+LL | #![deny(unused)]
+ | ^^^^^^
+ = note: `#[deny(unused_attributes)]` implied by `#[deny(unused)]`
+
+error: `#[cfg_attr]` does not expand to any attributes
+ --> $DIR/cfg-attr-empty-is-unused.rs:10:1
+ |
+LL | #[cfg_attr(TRUE,)]
+ | ^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs
new file mode 100644
index 000000000..496d196c9
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.rs
@@ -0,0 +1,4 @@
+#[cfg(foo(bar))] //~ ERROR invalid predicate `foo`
+fn check() {}
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr
new file mode 100644
index 000000000..96c571ebe
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-invalid-predicate.stderr
@@ -0,0 +1,9 @@
+error[E0537]: invalid predicate `foo`
+ --> $DIR/cfg-attr-invalid-predicate.rs:1:7
+ |
+LL | #[cfg(foo(bar))]
+ | ^^^^^^^^
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0537`.
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-false.rs b/tests/ui/conditional-compilation/cfg-attr-multi-false.rs
new file mode 100644
index 000000000..0c7e7cad0
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-false.rs
@@ -0,0 +1,19 @@
+// Test that cfg_attr doesn't emit any attributes when the
+// configuration variable is false. This mirrors `cfg-attr-multi-true.rs`
+
+// build-pass (FIXME(62277): could be check-pass?)
+
+#![warn(unused_must_use)]
+
+#[cfg_attr(any(), deprecated, must_use)]
+struct Struct {}
+
+impl Struct {
+ fn new() -> Struct {
+ Struct {}
+ }
+}
+
+fn main() {
+ Struct::new();
+}
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.rs b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.rs
new file mode 100644
index 000000000..42ffb71e3
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.rs
@@ -0,0 +1,7 @@
+// compile-flags: --cfg broken
+
+#![crate_type = "lib"]
+#![cfg_attr(broken, no_core, no_std)]
+//~^ ERROR the `#[no_core]` attribute is an experimental feature
+
+pub struct S {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.stderr b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.stderr
new file mode 100644
index 000000000..c8762d15d
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-1.stderr
@@ -0,0 +1,12 @@
+error[E0658]: the `#[no_core]` attribute is an experimental feature
+ --> $DIR/cfg-attr-multi-invalid-1.rs:4:21
+ |
+LL | #![cfg_attr(broken, no_core, no_std)]
+ | ^^^^^^^
+ |
+ = note: see issue #29639 <https://github.com/rust-lang/rust/issues/29639> for more information
+ = help: add `#![feature(no_core)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.rs b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.rs
new file mode 100644
index 000000000..29690e284
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.rs
@@ -0,0 +1,7 @@
+// compile-flags: --cfg broken
+
+#![crate_type = "lib"]
+#![cfg_attr(broken, no_std, no_core)]
+//~^ ERROR the `#[no_core]` attribute is an experimental feature
+
+pub struct S {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.stderr b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.stderr
new file mode 100644
index 000000000..e75b1c5b4
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-invalid-2.stderr
@@ -0,0 +1,12 @@
+error[E0658]: the `#[no_core]` attribute is an experimental feature
+ --> $DIR/cfg-attr-multi-invalid-2.rs:4:29
+ |
+LL | #![cfg_attr(broken, no_std, no_core)]
+ | ^^^^^^^
+ |
+ = note: see issue #29639 <https://github.com/rust-lang/rust/issues/29639> for more information
+ = help: add `#![feature(no_core)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-true.rs b/tests/ui/conditional-compilation/cfg-attr-multi-true.rs
new file mode 100644
index 000000000..876d8b079
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-true.rs
@@ -0,0 +1,21 @@
+// Test that cfg_attr with multiple attributes actually emits both attributes.
+// This is done by emitting two attributes that cause new warnings, and then
+// triggering those warnings.
+
+// build-pass (FIXME(62277): could be check-pass?)
+
+#![warn(unused_must_use)]
+
+#[cfg_attr(all(), deprecated, must_use)]
+struct MustUseDeprecated {}
+
+impl MustUseDeprecated { //~ warning: use of deprecated
+ fn new() -> MustUseDeprecated { //~ warning: use of deprecated
+ MustUseDeprecated {} //~ warning: use of deprecated
+ }
+}
+
+fn main() {
+ MustUseDeprecated::new(); //~ warning: use of deprecated
+ //~| warning: unused `MustUseDeprecated` that must be used
+}
diff --git a/tests/ui/conditional-compilation/cfg-attr-multi-true.stderr b/tests/ui/conditional-compilation/cfg-attr-multi-true.stderr
new file mode 100644
index 000000000..fbfcd4565
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-multi-true.stderr
@@ -0,0 +1,40 @@
+warning: use of deprecated struct `MustUseDeprecated`
+ --> $DIR/cfg-attr-multi-true.rs:12:6
+ |
+LL | impl MustUseDeprecated {
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: `#[warn(deprecated)]` on by default
+
+warning: use of deprecated struct `MustUseDeprecated`
+ --> $DIR/cfg-attr-multi-true.rs:19:5
+ |
+LL | MustUseDeprecated::new();
+ | ^^^^^^^^^^^^^^^^^
+
+warning: use of deprecated struct `MustUseDeprecated`
+ --> $DIR/cfg-attr-multi-true.rs:13:17
+ |
+LL | fn new() -> MustUseDeprecated {
+ | ^^^^^^^^^^^^^^^^^
+
+warning: use of deprecated struct `MustUseDeprecated`
+ --> $DIR/cfg-attr-multi-true.rs:14:9
+ |
+LL | MustUseDeprecated {}
+ | ^^^^^^^^^^^^^^^^^
+
+warning: unused `MustUseDeprecated` that must be used
+ --> $DIR/cfg-attr-multi-true.rs:19:5
+ |
+LL | MustUseDeprecated::new();
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/cfg-attr-multi-true.rs:7:9
+ |
+LL | #![warn(unused_must_use)]
+ | ^^^^^^^^^^^^^^^
+
+warning: 5 warnings emitted
+
diff --git a/tests/ui/conditional-compilation/cfg-attr-parse.rs b/tests/ui/conditional-compilation/cfg-attr-parse.rs
new file mode 100644
index 000000000..8ca31c118
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-parse.rs
@@ -0,0 +1,55 @@
+// Parse `cfg_attr` with varying numbers of attributes and trailing commas
+
+// Completely empty `cfg_attr` input
+#[cfg_attr()] //~ error: malformed `cfg_attr` attribute input
+struct NoConfigurationPredicate;
+
+// Zero attributes, zero trailing comma (comma manatory here)
+#[cfg_attr(all())] //~ error: expected `,`, found end of `cfg_attr`
+struct A0C0;
+
+// Zero attributes, one trailing comma
+#[cfg_attr(all(),)] // Ok
+struct A0C1;
+
+// Zero attributes, two trailing commas
+#[cfg_attr(all(),,)] //~ ERROR expected identifier
+struct A0C2;
+
+// One attribute, no trailing comma
+#[cfg_attr(all(), must_use)] // Ok
+struct A1C0;
+
+// One attribute, one trailing comma
+#[cfg_attr(all(), must_use,)] // Ok
+struct A1C1;
+
+// One attribute, two trailing commas
+#[cfg_attr(all(), must_use,,)] //~ ERROR expected identifier
+struct A1C2;
+
+// Two attributes, no trailing comma
+#[cfg_attr(all(), must_use, deprecated)] // Ok
+struct A2C0;
+
+// Two attributes, one trailing comma
+#[cfg_attr(all(), must_use, deprecated,)] // Ok
+struct A2C1;
+
+// Two attributes, two trailing commas
+#[cfg_attr(all(), must_use, deprecated,,)] //~ ERROR expected identifier
+struct A2C2;
+
+// Wrong delimiter `[`
+#[cfg_attr[all(),,]]
+//~^ ERROR wrong `cfg_attr` delimiters
+//~| ERROR expected identifier, found `,`
+struct BracketZero;
+
+// Wrong delimiter `{`
+#[cfg_attr{all(),,}]
+//~^ ERROR wrong `cfg_attr` delimiters
+//~| ERROR expected identifier, found `,`
+struct BraceZero;
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-parse.stderr b/tests/ui/conditional-compilation/cfg-attr-parse.stderr
new file mode 100644
index 000000000..8084a6220
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-parse.stderr
@@ -0,0 +1,86 @@
+error: malformed `cfg_attr` attribute input
+ --> $DIR/cfg-attr-parse.rs:4:1
+ |
+LL | #[cfg_attr()]
+ | ^^^^^^^^^^^^^ help: missing condition and attribute: `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ |
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: expected `,`, found end of `cfg_attr` input
+ --> $DIR/cfg-attr-parse.rs:8:17
+ |
+LL | #[cfg_attr(all())]
+ | ^ expected `,`
+ |
+ = help: the valid syntax is `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: expected identifier, found `,`
+ --> $DIR/cfg-attr-parse.rs:16:18
+ |
+LL | #[cfg_attr(all(),,)]
+ | ^ expected identifier
+ |
+ = help: the valid syntax is `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: expected identifier, found `,`
+ --> $DIR/cfg-attr-parse.rs:28:28
+ |
+LL | #[cfg_attr(all(), must_use,,)]
+ | ^ expected identifier
+ |
+ = help: the valid syntax is `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: expected identifier, found `,`
+ --> $DIR/cfg-attr-parse.rs:40:40
+ |
+LL | #[cfg_attr(all(), must_use, deprecated,,)]
+ | ^ expected identifier
+ |
+ = help: the valid syntax is `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: wrong `cfg_attr` delimiters
+ --> $DIR/cfg-attr-parse.rs:44:11
+ |
+LL | #[cfg_attr[all(),,]]
+ | ^^^^^^^^^
+ |
+help: the delimiters should be `(` and `)`
+ |
+LL | #[cfg_attr(all(),,)]
+ | ~ ~
+
+error: expected identifier, found `,`
+ --> $DIR/cfg-attr-parse.rs:44:18
+ |
+LL | #[cfg_attr[all(),,]]
+ | ^ expected identifier
+ |
+ = help: the valid syntax is `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: wrong `cfg_attr` delimiters
+ --> $DIR/cfg-attr-parse.rs:50:11
+ |
+LL | #[cfg_attr{all(),,}]
+ | ^^^^^^^^^
+ |
+help: the delimiters should be `(` and `)`
+ |
+LL | #[cfg_attr(all(),,)]
+ | ~ ~
+
+error: expected identifier, found `,`
+ --> $DIR/cfg-attr-parse.rs:50:18
+ |
+LL | #[cfg_attr{all(),,}]
+ | ^ expected identifier
+ |
+ = help: the valid syntax is `#[cfg_attr(condition, attribute, other_attribute, ...)]`
+ = note: for more information, visit <https://doc.rust-lang.org/reference/conditional-compilation.html#the-cfg_attr-attribute>
+
+error: aborting due to 9 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs
new file mode 100644
index 000000000..408eaffcc
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.rs
@@ -0,0 +1,39 @@
+#[cfg] //~ ERROR `cfg` is not followed by parentheses
+struct S1;
+
+#[cfg = 10] //~ ERROR `cfg` is not followed by parentheses
+struct S2;
+
+#[cfg()] //~ ERROR `cfg` predicate is not specified
+struct S3;
+
+#[cfg(a, b)] //~ ERROR multiple `cfg` predicates are specified
+struct S4;
+
+#[cfg("str")] //~ ERROR `cfg` predicate key cannot be a literal
+struct S5;
+
+#[cfg(a::b)] //~ ERROR `cfg` predicate key must be an identifier
+struct S6;
+
+#[cfg(a())] //~ ERROR invalid predicate `a`
+struct S7;
+
+#[cfg(a = 10)] //~ ERROR literal in `cfg` predicate value must be a string
+struct S8;
+
+#[cfg(a = b"hi")] //~ ERROR literal in `cfg` predicate value must be a string
+struct S9;
+
+macro_rules! generate_s10 {
+ ($expr: expr) => {
+ #[cfg(feature = $expr)]
+ //~^ ERROR expected unsuffixed literal or identifier, found `concat!("nonexistent")`
+ //~| ERROR expected unsuffixed literal or identifier, found `concat!("nonexistent")`
+ struct S10;
+ }
+}
+
+generate_s10!(concat!("nonexistent"));
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr
new file mode 100644
index 000000000..d5b4349c0
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr
@@ -0,0 +1,82 @@
+error: `cfg` is not followed by parentheses
+ --> $DIR/cfg-attr-syntax-validation.rs:1:1
+ |
+LL | #[cfg]
+ | ^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
+
+error: `cfg` is not followed by parentheses
+ --> $DIR/cfg-attr-syntax-validation.rs:4:1
+ |
+LL | #[cfg = 10]
+ | ^^^^^^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
+
+error: `cfg` predicate is not specified
+ --> $DIR/cfg-attr-syntax-validation.rs:7:1
+ |
+LL | #[cfg()]
+ | ^^^^^^^^ help: expected syntax is: `cfg(/* predicate */)`
+
+error: multiple `cfg` predicates are specified
+ --> $DIR/cfg-attr-syntax-validation.rs:10:10
+ |
+LL | #[cfg(a, b)]
+ | ^
+
+error: `cfg` predicate key cannot be a literal
+ --> $DIR/cfg-attr-syntax-validation.rs:13:7
+ |
+LL | #[cfg("str")]
+ | ^^^^^
+
+error: `cfg` predicate key must be an identifier
+ --> $DIR/cfg-attr-syntax-validation.rs:16:7
+ |
+LL | #[cfg(a::b)]
+ | ^^^^
+
+error[E0537]: invalid predicate `a`
+ --> $DIR/cfg-attr-syntax-validation.rs:19:7
+ |
+LL | #[cfg(a())]
+ | ^^^
+
+error[E0565]: literal in `cfg` predicate value must be a string
+ --> $DIR/cfg-attr-syntax-validation.rs:22:11
+ |
+LL | #[cfg(a = 10)]
+ | ^^
+
+error[E0565]: literal in `cfg` predicate value must be a string
+ --> $DIR/cfg-attr-syntax-validation.rs:25:11
+ |
+LL | #[cfg(a = b"hi")]
+ | -^^^^
+ | |
+ | help: consider removing the prefix
+
+error: expected unsuffixed literal or identifier, found `concat!("nonexistent")`
+ --> $DIR/cfg-attr-syntax-validation.rs:30:25
+ |
+LL | #[cfg(feature = $expr)]
+ | ^^^^^
+...
+LL | generate_s10!(concat!("nonexistent"));
+ | ------------------------------------- in this macro invocation
+ |
+ = note: this error originates in the macro `generate_s10` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: expected unsuffixed literal or identifier, found `concat!("nonexistent")`
+ --> $DIR/cfg-attr-syntax-validation.rs:30:25
+ |
+LL | #[cfg(feature = $expr)]
+ | ^^^^^
+...
+LL | generate_s10!(concat!("nonexistent"));
+ | ------------------------------------- in this macro invocation
+ |
+ = note: this error originates in the macro `generate_s10` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to 11 previous errors
+
+Some errors have detailed explanations: E0537, E0565.
+For more information about an error, try `rustc --explain E0537`.
diff --git a/tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.rs b/tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.rs
new file mode 100644
index 000000000..45b757e92
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.rs
@@ -0,0 +1,11 @@
+macro_rules! foo {
+ () => {
+ #[cfg_attr(all(), unknown)]
+ //~^ ERROR cannot find attribute `unknown` in this scope
+ fn foo() {}
+ }
+}
+
+foo!();
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr b/tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr
new file mode 100644
index 000000000..fc8df6552
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-attr-unknown-attribute-macro-expansion.stderr
@@ -0,0 +1,13 @@
+error: cannot find attribute `unknown` in this scope
+ --> $DIR/cfg-attr-unknown-attribute-macro-expansion.rs:3:27
+ |
+LL | #[cfg_attr(all(), unknown)]
+ | ^^^^^^^
+...
+LL | foo!();
+ | ------ in this macro invocation
+ |
+ = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info)
+
+error: aborting due to previous error
+
diff --git a/tests/ui/conditional-compilation/cfg-empty-codemap.rs b/tests/ui/conditional-compilation/cfg-empty-codemap.rs
new file mode 100644
index 000000000..9e34cacf7
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-empty-codemap.rs
@@ -0,0 +1,8 @@
+// Tests that empty source_maps don't ICE (#23301)
+
+// compile-flags: --cfg ""
+
+// error-pattern: invalid `--cfg` argument: `""` (expected `key` or `key="value"`)
+
+pub fn main() {
+}
diff --git a/tests/ui/conditional-compilation/cfg-empty-codemap.stderr b/tests/ui/conditional-compilation/cfg-empty-codemap.stderr
new file mode 100644
index 000000000..128e3cd73
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-empty-codemap.stderr
@@ -0,0 +1,2 @@
+error: invalid `--cfg` argument: `""` (expected `key` or `key="value"`)
+
diff --git a/tests/ui/conditional-compilation/cfg-generic-params.rs b/tests/ui/conditional-compilation/cfg-generic-params.rs
new file mode 100644
index 000000000..53aa35563
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-generic-params.rs
@@ -0,0 +1,40 @@
+// compile-flags:--cfg yes
+
+fn f_lt<#[cfg(yes)] 'a: 'a, #[cfg(no)] T>() {}
+fn f_ty<#[cfg(no)] 'a: 'a, #[cfg(yes)] T>() {}
+
+type FnGood = for<#[cfg(yes)] 'a, #[cfg(no)] T> fn(); // OK
+type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn();
+//~^ ERROR only lifetime parameters can be used in this context
+
+type PolyGood = dyn for<#[cfg(yes)] 'a, #[cfg(no)] T> Copy; // OK
+type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy;
+//~^ ERROR only lifetime parameters can be used in this context
+
+struct WhereGood where for<#[cfg(yes)] 'a, #[cfg(no)] T> u8: Copy; // OK
+struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
+//~^ ERROR only lifetime parameters can be used in this context
+
+fn f_lt_no<#[cfg_attr(no, unknown)] 'a>() {} // OK
+fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {}
+//~^ ERROR cannot find attribute `unknown` in this scope
+fn f_ty_no<#[cfg_attr(no, unknown)] T>() {} // OK
+fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {}
+//~^ ERROR cannot find attribute `unknown` in this scope
+
+type FnNo = for<#[cfg_attr(no, unknown)] 'a> fn(); // OK
+type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn();
+//~^ ERROR cannot find attribute `unknown` in this scope
+
+type PolyNo = dyn for<#[cfg_attr(no, unknown)] 'a> Copy; // OK
+type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy;
+//~^ ERROR cannot find attribute `unknown` in this scope
+
+struct WhereNo where for<#[cfg_attr(no, unknown)] 'a> u8: Copy; // OK
+struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy;
+//~^ ERROR cannot find attribute `unknown` in this scope
+
+fn main() {
+ f_lt::<'static>();
+ f_ty::<u8>();
+}
diff --git a/tests/ui/conditional-compilation/cfg-generic-params.stderr b/tests/ui/conditional-compilation/cfg-generic-params.stderr
new file mode 100644
index 000000000..4d6560e96
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-generic-params.stderr
@@ -0,0 +1,50 @@
+error: only lifetime parameters can be used in this context
+ --> $DIR/cfg-generic-params.rs:7:45
+ |
+LL | type FnBad = for<#[cfg(no)] 'a, #[cfg(yes)] T> fn();
+ | ^
+
+error: only lifetime parameters can be used in this context
+ --> $DIR/cfg-generic-params.rs:11:51
+ |
+LL | type PolyBad = dyn for<#[cfg(no)] 'a, #[cfg(yes)] T> Copy;
+ | ^
+
+error: only lifetime parameters can be used in this context
+ --> $DIR/cfg-generic-params.rs:15:54
+ |
+LL | struct WhereBad where for<#[cfg(no)] 'a, #[cfg(yes)] T> u8: Copy;
+ | ^
+
+error: cannot find attribute `unknown` in this scope
+ --> $DIR/cfg-generic-params.rs:19:29
+ |
+LL | fn f_lt_yes<#[cfg_attr(yes, unknown)] 'a>() {}
+ | ^^^^^^^
+
+error: cannot find attribute `unknown` in this scope
+ --> $DIR/cfg-generic-params.rs:22:29
+ |
+LL | fn f_ty_yes<#[cfg_attr(yes, unknown)] T>() {}
+ | ^^^^^^^
+
+error: cannot find attribute `unknown` in this scope
+ --> $DIR/cfg-generic-params.rs:26:34
+ |
+LL | type FnYes = for<#[cfg_attr(yes, unknown)] 'a> fn();
+ | ^^^^^^^
+
+error: cannot find attribute `unknown` in this scope
+ --> $DIR/cfg-generic-params.rs:30:40
+ |
+LL | type PolyYes = dyn for<#[cfg_attr(yes, unknown)] 'a> Copy;
+ | ^^^^^^^
+
+error: cannot find attribute `unknown` in this scope
+ --> $DIR/cfg-generic-params.rs:34:43
+ |
+LL | struct WhereYes where for<#[cfg_attr(yes, unknown)] 'a> u8: Copy;
+ | ^^^^^^^
+
+error: aborting due to 8 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg-in-crate-1.rs b/tests/ui/conditional-compilation/cfg-in-crate-1.rs
new file mode 100644
index 000000000..8561cd830
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-in-crate-1.rs
@@ -0,0 +1,3 @@
+// error-pattern: `main` function not found
+
+#![cfg(bar)]
diff --git a/tests/ui/conditional-compilation/cfg-in-crate-1.stderr b/tests/ui/conditional-compilation/cfg-in-crate-1.stderr
new file mode 100644
index 000000000..ff72c43ef
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-in-crate-1.stderr
@@ -0,0 +1,9 @@
+error[E0601]: `main` function not found in crate `cfg_in_crate_1`
+ --> $DIR/cfg-in-crate-1.rs:3:13
+ |
+LL | #![cfg(bar)]
+ | ^ consider adding a `main` function to `$DIR/cfg-in-crate-1.rs`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0601`.
diff --git a/tests/ui/conditional-compilation/cfg-non-opt-expr.rs b/tests/ui/conditional-compilation/cfg-non-opt-expr.rs
new file mode 100644
index 000000000..0ddbd8a15
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-non-opt-expr.rs
@@ -0,0 +1,11 @@
+#![feature(stmt_expr_attributes)]
+#![feature(custom_test_frameworks)]
+
+fn main() {
+ let _ = #[cfg(unset)] ();
+ //~^ ERROR removing an expression is not supported in this position
+ let _ = 1 + 2 + #[cfg(unset)] 3;
+ //~^ ERROR removing an expression is not supported in this position
+ let _ = [1, 2, 3][#[cfg(unset)] 1];
+ //~^ ERROR removing an expression is not supported in this position
+}
diff --git a/tests/ui/conditional-compilation/cfg-non-opt-expr.stderr b/tests/ui/conditional-compilation/cfg-non-opt-expr.stderr
new file mode 100644
index 000000000..933b7dc18
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg-non-opt-expr.stderr
@@ -0,0 +1,20 @@
+error: removing an expression is not supported in this position
+ --> $DIR/cfg-non-opt-expr.rs:5:13
+ |
+LL | let _ = #[cfg(unset)] ();
+ | ^^^^^^^^^^^^^
+
+error: removing an expression is not supported in this position
+ --> $DIR/cfg-non-opt-expr.rs:7:21
+ |
+LL | let _ = 1 + 2 + #[cfg(unset)] 3;
+ | ^^^^^^^^^^^^^
+
+error: removing an expression is not supported in this position
+ --> $DIR/cfg-non-opt-expr.rs:9:23
+ |
+LL | let _ = [1, 2, 3][#[cfg(unset)] 1];
+ | ^^^^^^^^^^^^^
+
+error: aborting due to 3 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg_accessible-bugs.rs b/tests/ui/conditional-compilation/cfg_accessible-bugs.rs
new file mode 100644
index 000000000..ae18bc55c
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-bugs.rs
@@ -0,0 +1,18 @@
+// This test is a collection of test that should pass.
+//
+// check-fail
+
+#![feature(cfg_accessible)]
+#![feature(trait_alias)]
+
+trait TraitAlias = std::fmt::Debug + Send;
+
+// FIXME: Currently shows "cannot determine" but should be `false`
+#[cfg_accessible(unresolved)] //~ ERROR cannot determine
+const C: bool = true;
+
+// FIXME: Currently shows "not sure" but should be `false`
+#[cfg_accessible(TraitAlias::unresolved)] //~ ERROR not sure whether the path is accessible or not
+const D: bool = true;
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg_accessible-bugs.stderr b/tests/ui/conditional-compilation/cfg_accessible-bugs.stderr
new file mode 100644
index 000000000..81f023878
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-bugs.stderr
@@ -0,0 +1,16 @@
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-bugs.rs:15:18
+ |
+LL | #[cfg_accessible(TraitAlias::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: cannot determine whether the path is accessible or not
+ --> $DIR/cfg_accessible-bugs.rs:11:1
+ |
+LL | #[cfg_accessible(unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to 2 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg_accessible-input-validation.rs b/tests/ui/conditional-compilation/cfg_accessible-input-validation.rs
new file mode 100644
index 000000000..c51c908a4
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-input-validation.rs
@@ -0,0 +1,24 @@
+#![feature(cfg_accessible)]
+
+#[cfg_accessible] //~ ERROR malformed `cfg_accessible` attribute input
+struct S1;
+
+#[cfg_accessible = "value"] //~ ERROR malformed `cfg_accessible` attribute input
+struct S2;
+
+#[cfg_accessible()] //~ ERROR `cfg_accessible` path is not specified
+struct S3;
+
+#[cfg_accessible(std, core)] //~ ERROR multiple `cfg_accessible` paths are specified
+struct S4;
+
+#[cfg_accessible("std")] //~ ERROR `cfg_accessible` path cannot be a literal
+struct S5;
+
+#[cfg_accessible(std = "value")] //~ ERROR `cfg_accessible` path cannot accept arguments
+struct S6;
+
+#[cfg_accessible(std(value))] //~ ERROR `cfg_accessible` path cannot accept arguments
+struct S7;
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg_accessible-input-validation.stderr b/tests/ui/conditional-compilation/cfg_accessible-input-validation.stderr
new file mode 100644
index 000000000..86706c766
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-input-validation.stderr
@@ -0,0 +1,44 @@
+error: malformed `cfg_accessible` attribute input
+ --> $DIR/cfg_accessible-input-validation.rs:3:1
+ |
+LL | #[cfg_accessible]
+ | ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[cfg_accessible(path)]`
+
+error: malformed `cfg_accessible` attribute input
+ --> $DIR/cfg_accessible-input-validation.rs:6:1
+ |
+LL | #[cfg_accessible = "value"]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[cfg_accessible(path)]`
+
+error: `cfg_accessible` path is not specified
+ --> $DIR/cfg_accessible-input-validation.rs:9:1
+ |
+LL | #[cfg_accessible()]
+ | ^^^^^^^^^^^^^^^^^^^
+
+error: multiple `cfg_accessible` paths are specified
+ --> $DIR/cfg_accessible-input-validation.rs:12:23
+ |
+LL | #[cfg_accessible(std, core)]
+ | ^^^^
+
+error: `cfg_accessible` path cannot be a literal
+ --> $DIR/cfg_accessible-input-validation.rs:15:18
+ |
+LL | #[cfg_accessible("std")]
+ | ^^^^^
+
+error: `cfg_accessible` path cannot accept arguments
+ --> $DIR/cfg_accessible-input-validation.rs:18:18
+ |
+LL | #[cfg_accessible(std = "value")]
+ | ^^^^^^^^^^^^^
+
+error: `cfg_accessible` path cannot accept arguments
+ --> $DIR/cfg_accessible-input-validation.rs:21:18
+ |
+LL | #[cfg_accessible(std(value))]
+ | ^^^^^^^^^^
+
+error: aborting due to 7 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr b/tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr
new file mode 100644
index 000000000..7d5dd5890
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2015.stderr
@@ -0,0 +1,122 @@
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:14:18
+ |
+LL | #[cfg_accessible(Struct::existing)]
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:16:18
+ |
+LL | #[cfg_accessible(Struct::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:25:18
+ |
+LL | #[cfg_accessible(Union::existing)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:27:18
+ |
+LL | #[cfg_accessible(Union::unresolved)]
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:36:18
+ |
+LL | #[cfg_accessible(Enum::Existing::existing)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:38:18
+ |
+LL | #[cfg_accessible(Enum::Existing::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:40:18
+ |
+LL | #[cfg_accessible(Enum::unresolved)]
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:50:18
+ |
+LL | #[cfg_accessible(Trait::existing)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:52:18
+ |
+LL | #[cfg_accessible(Trait::unresolved)]
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:59:18
+ |
+LL | #[cfg_accessible(TypeAlias::existing)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:61:18
+ |
+LL | #[cfg_accessible(TypeAlias::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:70:18
+ |
+LL | #[cfg_accessible(ForeignType::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:79:18
+ |
+LL | #[cfg_accessible(AssocType::AssocType::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:84:18
+ |
+LL | #[cfg_accessible(u8::unresolved)]
+ | ^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:86:18
+ |
+LL | #[cfg_accessible(u8::is_ascii)]
+ | ^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: aborting due to 15 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr b/tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr
new file mode 100644
index 000000000..7d5dd5890
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-not_sure.edition2021.stderr
@@ -0,0 +1,122 @@
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:14:18
+ |
+LL | #[cfg_accessible(Struct::existing)]
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:16:18
+ |
+LL | #[cfg_accessible(Struct::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:25:18
+ |
+LL | #[cfg_accessible(Union::existing)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:27:18
+ |
+LL | #[cfg_accessible(Union::unresolved)]
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:36:18
+ |
+LL | #[cfg_accessible(Enum::Existing::existing)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:38:18
+ |
+LL | #[cfg_accessible(Enum::Existing::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:40:18
+ |
+LL | #[cfg_accessible(Enum::unresolved)]
+ | ^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:50:18
+ |
+LL | #[cfg_accessible(Trait::existing)]
+ | ^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:52:18
+ |
+LL | #[cfg_accessible(Trait::unresolved)]
+ | ^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:59:18
+ |
+LL | #[cfg_accessible(TypeAlias::existing)]
+ | ^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:61:18
+ |
+LL | #[cfg_accessible(TypeAlias::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:70:18
+ |
+LL | #[cfg_accessible(ForeignType::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:79:18
+ |
+LL | #[cfg_accessible(AssocType::AssocType::unresolved)]
+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:84:18
+ |
+LL | #[cfg_accessible(u8::unresolved)]
+ | ^^^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: not sure whether the path is accessible or not
+ --> $DIR/cfg_accessible-not_sure.rs:86:18
+ |
+LL | #[cfg_accessible(u8::is_ascii)]
+ | ^^^^^^^^^^^^
+ |
+ = note: the type may have associated items, but we are currently not checking them
+
+error: aborting due to 15 previous errors
+
diff --git a/tests/ui/conditional-compilation/cfg_accessible-not_sure.rs b/tests/ui/conditional-compilation/cfg_accessible-not_sure.rs
new file mode 100644
index 000000000..99a7949db
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-not_sure.rs
@@ -0,0 +1,89 @@
+// revisions: edition2015 edition2021
+// [edition2015]compile-flags: --edition=2015
+// [edition2021]compile-flags: --edition=2021
+
+#![feature(extern_types)]
+#![feature(cfg_accessible)]
+
+// Struct::unresolved - error
+
+struct Struct {
+ existing: u8,
+}
+
+#[cfg_accessible(Struct::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Struct::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// Union::unresolved - error
+
+struct Union {
+ existing: u8,
+}
+
+#[cfg_accessible(Union::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Union::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// Enum::unresolved - error
+
+enum Enum {
+ Existing { existing: u8 },
+}
+
+#[cfg_accessible(Enum::Existing::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Enum::Existing::unresolved)] //~ ERROR not sure
+const B: bool = true;
+#[cfg_accessible(Enum::unresolved)] //~ ERROR not sure
+const C: bool = true;
+
+// Trait::unresolved - false or error, depending on edition (error if you can write Trait::foo
+// instead of <dyn Trait>::foo for methods like impl dyn Trait { fn foo() {} })
+
+trait Trait {}
+impl dyn Trait { fn existing() {} }
+
+// FIXME: Should be an error for edition > 2015
+#[cfg_accessible(Trait::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(Trait::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// TypeAlias::unresolved - error
+
+type TypeAlias = Struct;
+
+#[cfg_accessible(TypeAlias::existing)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(TypeAlias::unresolved)] //~ ERROR not sure
+const B: bool = true;
+
+// ForeignType::unresolved - error
+
+extern {
+ type ForeignType;
+}
+
+#[cfg_accessible(ForeignType::unresolved)] //~ ERROR not sure
+const A: bool = true;
+
+// AssocType::unresolved - error
+
+trait AssocType {
+ type AssocType;
+}
+
+#[cfg_accessible(AssocType::AssocType::unresolved)] //~ ERROR not sure
+const A: bool = true;
+
+// PrimitiveType::unresolved - error
+
+#[cfg_accessible(u8::unresolved)] //~ ERROR not sure
+const A: bool = true;
+#[cfg_accessible(u8::is_ascii)] //~ ERROR not sure
+const B: bool = true;
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg_accessible-private.rs b/tests/ui/conditional-compilation/cfg_accessible-private.rs
new file mode 100644
index 000000000..5b095675c
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-private.rs
@@ -0,0 +1,21 @@
+// check-pass
+
+#![feature(cfg_accessible)]
+
+mod private {
+ struct Struct;
+ enum Enum{}
+ union Union{_a:u8}
+}
+
+#[cfg_accessible(private::Struct)]
+const A: bool = true;
+
+#[cfg_accessible(private::Enum)]
+const A: bool = true;
+
+#[cfg_accessible(private::Union)]
+const A: bool = true;
+
+const A: bool = false; // Will conflict if any of those is accessible
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg_accessible-stuck.rs b/tests/ui/conditional-compilation/cfg_accessible-stuck.rs
new file mode 100644
index 000000000..50504a44c
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-stuck.rs
@@ -0,0 +1,9 @@
+#![feature(cfg_accessible)]
+
+#[cfg_accessible(Z)] // OK, recovered after the other `cfg_accessible` produces an error.
+struct S;
+
+#[cfg_accessible(S)] //~ ERROR cannot determine whether the path is accessible or not
+struct Z;
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg_accessible-stuck.stderr b/tests/ui/conditional-compilation/cfg_accessible-stuck.stderr
new file mode 100644
index 000000000..33af7d625
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-stuck.stderr
@@ -0,0 +1,8 @@
+error: cannot determine whether the path is accessible or not
+ --> $DIR/cfg_accessible-stuck.rs:6:1
+ |
+LL | #[cfg_accessible(S)]
+ | ^^^^^^^^^^^^^^^^^^^^
+
+error: aborting due to previous error
+
diff --git a/tests/ui/conditional-compilation/cfg_accessible-unstable.rs b/tests/ui/conditional-compilation/cfg_accessible-unstable.rs
new file mode 100644
index 000000000..e9247e67a
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-unstable.rs
@@ -0,0 +1,2 @@
+#[cfg_accessible(std)] //~ ERROR use of unstable library feature 'cfg_accessible'
+fn main() {}
diff --git a/tests/ui/conditional-compilation/cfg_accessible-unstable.stderr b/tests/ui/conditional-compilation/cfg_accessible-unstable.stderr
new file mode 100644
index 000000000..2f55b9559
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible-unstable.stderr
@@ -0,0 +1,12 @@
+error[E0658]: use of unstable library feature 'cfg_accessible': `cfg_accessible` is not fully implemented
+ --> $DIR/cfg_accessible-unstable.rs:1:3
+ |
+LL | #[cfg_accessible(std)]
+ | ^^^^^^^^^^^^^^
+ |
+ = note: see issue #64797 <https://github.com/rust-lang/rust/issues/64797> for more information
+ = help: add `#![feature(cfg_accessible)]` to the crate attributes to enable
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0658`.
diff --git a/tests/ui/conditional-compilation/cfg_accessible.rs b/tests/ui/conditional-compilation/cfg_accessible.rs
new file mode 100644
index 000000000..df380d0d1
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible.rs
@@ -0,0 +1,55 @@
+#![feature(cfg_accessible)]
+
+mod m {
+ pub struct ExistingPublic;
+ struct ExistingPrivate;
+}
+
+trait Trait {
+ type Assoc;
+}
+
+enum Enum {
+ Existing,
+}
+
+#[cfg_accessible(Enum)]
+struct ExistingResolved;
+
+#[cfg_accessible(Enum::Existing)]
+struct ExistingResolvedVariant;
+
+#[cfg_accessible(m::ExistingPublic)]
+struct ExistingPublic;
+
+#[cfg_accessible(m::ExistingPrivate)]
+struct ExistingPrivate;
+
+#[cfg_accessible(m::NonExistent)]
+struct NonExistingPrivate;
+
+#[cfg_accessible(n::AccessibleExpanded)] // OK, `cfg_accessible` can wait and retry.
+struct AccessibleExpanded;
+
+#[cfg_accessible(Trait::Assoc)]
+struct AccessibleTraitAssoc;
+
+macro_rules! generate_accessible_expanded {
+ () => {
+ mod n {
+ pub struct AccessibleExpanded;
+ }
+ };
+}
+
+generate_accessible_expanded!();
+
+fn main() {
+ ExistingPublic;
+ AccessibleExpanded;
+ AccessibleTraitAssoc;
+
+ ExistingPrivate; //~ ERROR cannot find
+ NonExistingPrivate; //~ ERROR cannot find
+ NonExistingTraitAlias; //~ ERROR cannot find
+}
diff --git a/tests/ui/conditional-compilation/cfg_accessible.stderr b/tests/ui/conditional-compilation/cfg_accessible.stderr
new file mode 100644
index 000000000..e3731a1ad
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_accessible.stderr
@@ -0,0 +1,27 @@
+error[E0425]: cannot find value `ExistingPrivate` in this scope
+ --> $DIR/cfg_accessible.rs:52:5
+ |
+LL | ExistingPrivate;
+ | ^^^^^^^^^^^^^^^ not found in this scope
+ |
+note: unit struct `m::ExistingPrivate` exists but is inaccessible
+ --> $DIR/cfg_accessible.rs:5:5
+ |
+LL | struct ExistingPrivate;
+ | ^^^^^^^^^^^^^^^^^^^^^^^ not accessible
+
+error[E0425]: cannot find value `NonExistingPrivate` in this scope
+ --> $DIR/cfg_accessible.rs:53:5
+ |
+LL | NonExistingPrivate;
+ | ^^^^^^^^^^^^^^^^^^ not found in this scope
+
+error[E0425]: cannot find value `NonExistingTraitAlias` in this scope
+ --> $DIR/cfg_accessible.rs:54:5
+ |
+LL | NonExistingTraitAlias;
+ | ^^^^^^^^^^^^^^^^^^^^^ not found in this scope
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/tests/ui/conditional-compilation/cfg_attr_path.rs b/tests/ui/conditional-compilation/cfg_attr_path.rs
new file mode 100644
index 000000000..efb718b78
--- /dev/null
+++ b/tests/ui/conditional-compilation/cfg_attr_path.rs
@@ -0,0 +1,13 @@
+// check-pass
+
+#![deny(unused_attributes)] // c.f #35584
+
+mod auxiliary {
+ #[cfg_attr(any(), path = "nonexistent_file.rs")] pub mod namespaced_enums;
+ #[cfg_attr(all(), path = "namespaced_enums.rs")] pub mod nonexistent_file;
+}
+
+fn main() {
+ let _ = auxiliary::namespaced_enums::Foo::A;
+ let _ = auxiliary::nonexistent_file::Foo::A;
+}
diff --git a/tests/ui/conditional-compilation/inner-cfg-non-inline-mod.rs b/tests/ui/conditional-compilation/inner-cfg-non-inline-mod.rs
new file mode 100644
index 000000000..af5a6462e
--- /dev/null
+++ b/tests/ui/conditional-compilation/inner-cfg-non-inline-mod.rs
@@ -0,0 +1,7 @@
+// check-pass
+
+mod module_with_cfg;
+
+mod module_with_cfg {} // Ok, the module above is configured away by an inner attribute.
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/issue-34028.rs b/tests/ui/conditional-compilation/issue-34028.rs
new file mode 100644
index 000000000..d761c0c82
--- /dev/null
+++ b/tests/ui/conditional-compilation/issue-34028.rs
@@ -0,0 +1,10 @@
+// check-pass
+
+macro_rules! m {
+ () => { #[cfg(any())] fn f() {} }
+}
+
+trait T {}
+impl T for () { m!(); }
+
+fn main() {}
diff --git a/tests/ui/conditional-compilation/module_with_cfg.rs b/tests/ui/conditional-compilation/module_with_cfg.rs
new file mode 100644
index 000000000..56c4baadf
--- /dev/null
+++ b/tests/ui/conditional-compilation/module_with_cfg.rs
@@ -0,0 +1,3 @@
+// ignore-test
+
+#![cfg_attr(all(), cfg(FALSE))]
diff --git a/tests/ui/conditional-compilation/test-cfg.rs b/tests/ui/conditional-compilation/test-cfg.rs
new file mode 100644
index 000000000..8750bae00
--- /dev/null
+++ b/tests/ui/conditional-compilation/test-cfg.rs
@@ -0,0 +1,8 @@
+// compile-flags: --cfg foo
+
+#[cfg(all(foo, bar))] // foo AND bar
+fn foo() {}
+
+fn main() {
+ foo(); //~ ERROR cannot find function `foo` in this scope
+}
diff --git a/tests/ui/conditional-compilation/test-cfg.stderr b/tests/ui/conditional-compilation/test-cfg.stderr
new file mode 100644
index 000000000..c35fe2f94
--- /dev/null
+++ b/tests/ui/conditional-compilation/test-cfg.stderr
@@ -0,0 +1,9 @@
+error[E0425]: cannot find function `foo` in this scope
+ --> $DIR/test-cfg.rs:7:5
+ |
+LL | foo();
+ | ^^^ not found in this scope
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.