summaryrefslogtreecommitdiffstats
path: root/tests/ui/cfg
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-30 03:57:31 +0000
commitdc0db358abe19481e475e10c32149b53370f1a1c (patch)
treeab8ce99c4b255ce46f99ef402c27916055b899ee /tests/ui/cfg
parentReleasing progress-linux version 1.71.1+dfsg1-2~progress7.99u1. (diff)
downloadrustc-dc0db358abe19481e475e10c32149b53370f1a1c.tar.xz
rustc-dc0db358abe19481e475e10c32149b53370f1a1c.zip
Merging upstream version 1.72.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/cfg')
-rw-r--r--tests/ui/cfg/auxiliary/cfg_false_lib.rs6
-rw-r--r--tests/ui/cfg/auxiliary/cfg_false_lib_no_std_after.rs5
-rw-r--r--tests/ui/cfg/auxiliary/cfg_false_lib_no_std_before.rs8
-rw-r--r--tests/ui/cfg/auxiliary/cfged_out.rs22
-rw-r--r--tests/ui/cfg/cfg-false-feature.rs6
-rw-r--r--tests/ui/cfg/cfg-false-feature.stderr17
-rw-r--r--tests/ui/cfg/cfg_false_no_std-1.rs10
-rw-r--r--tests/ui/cfg/cfg_false_no_std-2.rs11
-rw-r--r--tests/ui/cfg/cfg_false_no_std.rs3
-rw-r--r--tests/ui/cfg/cfg_stmt_expr.rs2
-rw-r--r--tests/ui/cfg/diagnostics-cross-crate.rs31
-rw-r--r--tests/ui/cfg/diagnostics-cross-crate.stderr53
-rw-r--r--tests/ui/cfg/diagnostics-not-a-def.rs12
-rw-r--r--tests/ui/cfg/diagnostics-not-a-def.stderr9
-rw-r--r--tests/ui/cfg/diagnostics-reexport.rs40
-rw-r--r--tests/ui/cfg/diagnostics-reexport.stderr47
-rw-r--r--tests/ui/cfg/diagnostics-same-crate.rs51
-rw-r--r--tests/ui/cfg/diagnostics-same-crate.stderr47
18 files changed, 355 insertions, 25 deletions
diff --git a/tests/ui/cfg/auxiliary/cfg_false_lib.rs b/tests/ui/cfg/auxiliary/cfg_false_lib.rs
index 3c011d72b..6c2dbb44d 100644
--- a/tests/ui/cfg/auxiliary/cfg_false_lib.rs
+++ b/tests/ui/cfg/auxiliary/cfg_false_lib.rs
@@ -1,6 +1,4 @@
-// It is unclear whether a fully unconfigured crate should link to standard library,
-// or what its `no_std`/`no_core`/`compiler_builtins` status, more precisely.
-// Currently the usual standard library prelude is added to such crates,
-// and therefore they link to libstd.
+// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
+// This crate has no such attribute, therefore this crate does link to libstd.
#![cfg(FALSE)]
diff --git a/tests/ui/cfg/auxiliary/cfg_false_lib_no_std_after.rs b/tests/ui/cfg/auxiliary/cfg_false_lib_no_std_after.rs
new file mode 100644
index 000000000..3cfa6c510
--- /dev/null
+++ b/tests/ui/cfg/auxiliary/cfg_false_lib_no_std_after.rs
@@ -0,0 +1,5 @@
+// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
+// Therefore this crate does link to libstd.
+
+#![cfg(FALSE)]
+#![no_std]
diff --git a/tests/ui/cfg/auxiliary/cfg_false_lib_no_std_before.rs b/tests/ui/cfg/auxiliary/cfg_false_lib_no_std_before.rs
new file mode 100644
index 000000000..8e89545b8
--- /dev/null
+++ b/tests/ui/cfg/auxiliary/cfg_false_lib_no_std_before.rs
@@ -0,0 +1,8 @@
+// `#![no_std]` on a fully unconfigured crate is respected if it's placed before `cfg(FALSE)`.
+// Therefore this crate doesn't link to libstd.
+
+// no-prefer-dynamic
+
+#![no_std]
+#![crate_type = "lib"]
+#![cfg(FALSE)]
diff --git a/tests/ui/cfg/auxiliary/cfged_out.rs b/tests/ui/cfg/auxiliary/cfged_out.rs
new file mode 100644
index 000000000..f6a9089cf
--- /dev/null
+++ b/tests/ui/cfg/auxiliary/cfged_out.rs
@@ -0,0 +1,22 @@
+pub mod inner {
+ #[cfg(FALSE)]
+ pub fn uwu() {}
+
+ #[cfg(FALSE)]
+ pub mod doesnt_exist {
+ pub fn hello() {}
+ }
+
+ pub mod wrong {
+ #[cfg(feature = "suggesting me fails the test!!")]
+ pub fn meow() {}
+ }
+
+ pub mod right {
+ #[cfg(feature = "what-a-cool-feature")]
+ pub fn meow() {}
+ }
+}
+
+#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)]
+pub fn vanished() {}
diff --git a/tests/ui/cfg/cfg-false-feature.rs b/tests/ui/cfg/cfg-false-feature.rs
index 21ea3ec79..84c231562 100644
--- a/tests/ui/cfg/cfg-false-feature.rs
+++ b/tests/ui/cfg/cfg-false-feature.rs
@@ -1,5 +1,4 @@
-// It is unclear which features should be in effect in a fully unconfigured crate (issue #104633).
-// Currently none on the features are in effect, so we get the feature gates reported.
+// Features above `cfg(FALSE)` are in effect in a fully unconfigured crate (issue #104633).
// check-pass
// compile-flags: --crate-type lib
@@ -8,8 +7,7 @@
#![cfg(FALSE)]
#![feature(box_syntax)]
-macro mac() {} //~ WARN `macro` is experimental
- //~| WARN unstable syntax can change at any point in the future
+macro mac() {} // OK
trait A = Clone; //~ WARN trait aliases are experimental
//~| WARN unstable syntax can change at any point in the future
diff --git a/tests/ui/cfg/cfg-false-feature.stderr b/tests/ui/cfg/cfg-false-feature.stderr
index 14673fbdb..340930362 100644
--- a/tests/ui/cfg/cfg-false-feature.stderr
+++ b/tests/ui/cfg/cfg-false-feature.stderr
@@ -1,5 +1,5 @@
warning: trait aliases are experimental
- --> $DIR/cfg-false-feature.rs:14:1
+ --> $DIR/cfg-false-feature.rs:12:1
|
LL | trait A = Clone;
| ^^^^^^^^^^^^^^^^
@@ -9,19 +9,8 @@ LL | trait A = Clone;
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
-warning: `macro` is experimental
- --> $DIR/cfg-false-feature.rs:11:1
- |
-LL | macro mac() {}
- | ^^^^^^^^^^^^^^
- |
- = note: see issue #39412 <https://github.com/rust-lang/rust/issues/39412> for more information
- = help: add `#![feature(decl_macro)]` to the crate attributes to enable
- = warning: unstable syntax can change at any point in the future, causing a hard error!
- = note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
-
warning: box pattern syntax is experimental
- --> $DIR/cfg-false-feature.rs:18:9
+ --> $DIR/cfg-false-feature.rs:16:9
|
LL | let box _ = Box::new(0);
| ^^^^^
@@ -31,5 +20,5 @@ LL | let box _ = Box::new(0);
= warning: unstable syntax can change at any point in the future, causing a hard error!
= note: for more information, see issue #65860 <https://github.com/rust-lang/rust/issues/65860>
-warning: 3 warnings emitted
+warning: 2 warnings emitted
diff --git a/tests/ui/cfg/cfg_false_no_std-1.rs b/tests/ui/cfg/cfg_false_no_std-1.rs
new file mode 100644
index 000000000..bcb49e513
--- /dev/null
+++ b/tests/ui/cfg/cfg_false_no_std-1.rs
@@ -0,0 +1,10 @@
+// No error, panic handler is supplied by libstd linked though the empty library.
+
+// check-pass
+// aux-build: cfg_false_lib_no_std_after.rs
+
+#![no_std]
+
+extern crate cfg_false_lib_no_std_after as _;
+
+fn main() {}
diff --git a/tests/ui/cfg/cfg_false_no_std-2.rs b/tests/ui/cfg/cfg_false_no_std-2.rs
new file mode 100644
index 000000000..0a2bfd5f6
--- /dev/null
+++ b/tests/ui/cfg/cfg_false_no_std-2.rs
@@ -0,0 +1,11 @@
+// Error, the linked empty library is `no_std` and doesn't provide a panic handler.
+
+// dont-check-compiler-stderr
+// error-pattern: `#[panic_handler]` function required, but not found
+// aux-build: cfg_false_lib_no_std_before.rs
+
+#![no_std]
+
+extern crate cfg_false_lib_no_std_before as _;
+
+fn main() {}
diff --git a/tests/ui/cfg/cfg_false_no_std.rs b/tests/ui/cfg/cfg_false_no_std.rs
index 319ea0781..4fa831715 100644
--- a/tests/ui/cfg/cfg_false_no_std.rs
+++ b/tests/ui/cfg/cfg_false_no_std.rs
@@ -1,5 +1,4 @@
-// Currently no error because the panic handler is supplied by libstd linked though the empty
-// library, but the desirable behavior is unclear (see comments in cfg_false_lib.rs).
+// No error, panic handler is supplied by libstd linked though the empty library.
// check-pass
// aux-build: cfg_false_lib.rs
diff --git a/tests/ui/cfg/cfg_stmt_expr.rs b/tests/ui/cfg/cfg_stmt_expr.rs
index 6381bb2d5..f9f4c9810 100644
--- a/tests/ui/cfg/cfg_stmt_expr.rs
+++ b/tests/ui/cfg/cfg_stmt_expr.rs
@@ -81,7 +81,7 @@ fn main() {
// check that lints work
#[allow(non_snake_case)]
- let FOOBAR = {
+ let FOOBAR: () = {
fn SYLADEX() {}
};
diff --git a/tests/ui/cfg/diagnostics-cross-crate.rs b/tests/ui/cfg/diagnostics-cross-crate.rs
new file mode 100644
index 000000000..d2725c94b
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-cross-crate.rs
@@ -0,0 +1,31 @@
+// aux-build:cfged_out.rs
+
+extern crate cfged_out;
+
+fn main() {
+ // There is no uwu at this path - no diagnostic.
+ cfged_out::uwu(); //~ ERROR cannot find function
+ //~^ NOTE not found in `cfged_out`
+
+ // It does exist here - diagnostic.
+ cfged_out::inner::uwu(); //~ ERROR cannot find function
+ //~^ NOTE found an item that was configured out
+ //~| NOTE not found in `cfged_out::inner`
+
+ // The module isn't found - we would like to get a diagnostic, but currently don't due to
+ // the awkward way the resolver diagnostics are currently implemented.
+ // FIXME(Nilstrieb): Also add a note to the cfg diagnostic here
+ cfged_out::inner::doesnt_exist::hello(); //~ ERROR failed to resolve
+ //~^ NOTE could not find `doesnt_exist` in `inner`
+
+ // It should find the one in the right module, not the wrong one.
+ cfged_out::inner::right::meow(); //~ ERROR cannot find function
+ //~^ NOTE found an item that was configured out
+ //~| NOTE not found in `cfged_out::inner::right
+ //~| NOTE the item is gated behind the `what-a-cool-feature` feature
+
+ // Exists in the crate root - diagnostic.
+ cfged_out::vanished(); //~ ERROR cannot find function
+ //~^ NOTE found an item that was configured out
+ //~| NOTE not found in `cfged_out`
+}
diff --git a/tests/ui/cfg/diagnostics-cross-crate.stderr b/tests/ui/cfg/diagnostics-cross-crate.stderr
new file mode 100644
index 000000000..046929bc2
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-cross-crate.stderr
@@ -0,0 +1,53 @@
+error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
+ --> $DIR/diagnostics-cross-crate.rs:18:23
+ |
+LL | cfged_out::inner::doesnt_exist::hello();
+ | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
+
+error[E0425]: cannot find function `uwu` in crate `cfged_out`
+ --> $DIR/diagnostics-cross-crate.rs:7:16
+ |
+LL | cfged_out::uwu();
+ | ^^^ not found in `cfged_out`
+
+error[E0425]: cannot find function `uwu` in module `cfged_out::inner`
+ --> $DIR/diagnostics-cross-crate.rs:11:23
+ |
+LL | cfged_out::inner::uwu();
+ | ^^^ not found in `cfged_out::inner`
+ |
+note: found an item that was configured out
+ --> $DIR/auxiliary/cfged_out.rs:3:12
+ |
+LL | pub fn uwu() {}
+ | ^^^
+
+error[E0425]: cannot find function `meow` in module `cfged_out::inner::right`
+ --> $DIR/diagnostics-cross-crate.rs:22:30
+ |
+LL | cfged_out::inner::right::meow();
+ | ^^^^ not found in `cfged_out::inner::right`
+ |
+note: found an item that was configured out
+ --> $DIR/auxiliary/cfged_out.rs:17:16
+ |
+LL | pub fn meow() {}
+ | ^^^^
+ = note: the item is gated behind the `what-a-cool-feature` feature
+
+error[E0425]: cannot find function `vanished` in crate `cfged_out`
+ --> $DIR/diagnostics-cross-crate.rs:28:16
+ |
+LL | cfged_out::vanished();
+ | ^^^^^^^^ not found in `cfged_out`
+ |
+note: found an item that was configured out
+ --> $DIR/auxiliary/cfged_out.rs:22:8
+ |
+LL | pub fn vanished() {}
+ | ^^^^^^^^
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0425, E0433.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/tests/ui/cfg/diagnostics-not-a-def.rs b/tests/ui/cfg/diagnostics-not-a-def.rs
new file mode 100644
index 000000000..729394712
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-not-a-def.rs
@@ -0,0 +1,12 @@
+pub mod inner {
+ pub fn i_am_here() {
+ #[cfg(feature = "another one that doesn't exist")]
+ loop {}
+ }
+}
+
+fn main() {
+ inner::i_am_here();
+ // ensure that nothing bad happens when we are checking for cfgs
+ inner::i_am_not(); //~ ERROR cannot find function
+}
diff --git a/tests/ui/cfg/diagnostics-not-a-def.stderr b/tests/ui/cfg/diagnostics-not-a-def.stderr
new file mode 100644
index 000000000..af0e1a172
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-not-a-def.stderr
@@ -0,0 +1,9 @@
+error[E0425]: cannot find function `i_am_not` in module `inner`
+ --> $DIR/diagnostics-not-a-def.rs:11:12
+ |
+LL | inner::i_am_not();
+ | ^^^^^^^^ not found in `inner`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0425`.
diff --git a/tests/ui/cfg/diagnostics-reexport.rs b/tests/ui/cfg/diagnostics-reexport.rs
new file mode 100644
index 000000000..b9548e911
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-reexport.rs
@@ -0,0 +1,40 @@
+pub mod inner {
+ #[cfg(FALSE)]
+ mod gone {
+ pub fn uwu() {}
+ }
+
+ #[cfg(FALSE)]
+ pub use super::uwu;
+ //~^ NOTE found an item that was configured out
+}
+
+pub use a::x;
+//~^ ERROR unresolved import `a::x`
+//~| NOTE no `x` in `a`
+
+mod a {
+ #[cfg(no)]
+ pub fn x() {}
+ //~^ NOTE found an item that was configured out
+}
+
+pub use b::{x, y};
+//~^ ERROR unresolved imports `b::x`, `b::y`
+//~| NOTE no `x` in `b`
+//~| NOTE no `y` in `b`
+
+mod b {
+ #[cfg(no)]
+ pub fn x() {}
+ //~^ NOTE found an item that was configured out
+ #[cfg(no)]
+ pub fn y() {}
+ //~^ NOTE found an item that was configured out
+}
+
+fn main() {
+ // There is no uwu at this path - no diagnostic.
+ inner::uwu(); //~ ERROR cannot find function
+ //~^ NOTE not found in `inner`
+}
diff --git a/tests/ui/cfg/diagnostics-reexport.stderr b/tests/ui/cfg/diagnostics-reexport.stderr
new file mode 100644
index 000000000..e25b7cf86
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-reexport.stderr
@@ -0,0 +1,47 @@
+error[E0432]: unresolved import `a::x`
+ --> $DIR/diagnostics-reexport.rs:12:9
+ |
+LL | pub use a::x;
+ | ^^^^ no `x` in `a`
+ |
+note: found an item that was configured out
+ --> $DIR/diagnostics-reexport.rs:18:12
+ |
+LL | pub fn x() {}
+ | ^
+
+error[E0432]: unresolved imports `b::x`, `b::y`
+ --> $DIR/diagnostics-reexport.rs:22:13
+ |
+LL | pub use b::{x, y};
+ | ^ ^ no `y` in `b`
+ | |
+ | no `x` in `b`
+ |
+note: found an item that was configured out
+ --> $DIR/diagnostics-reexport.rs:29:12
+ |
+LL | pub fn x() {}
+ | ^
+note: found an item that was configured out
+ --> $DIR/diagnostics-reexport.rs:32:12
+ |
+LL | pub fn y() {}
+ | ^
+
+error[E0425]: cannot find function `uwu` in module `inner`
+ --> $DIR/diagnostics-reexport.rs:38:12
+ |
+LL | inner::uwu();
+ | ^^^ not found in `inner`
+ |
+note: found an item that was configured out
+ --> $DIR/diagnostics-reexport.rs:8:20
+ |
+LL | pub use super::uwu;
+ | ^^^
+
+error: aborting due to 3 previous errors
+
+Some errors have detailed explanations: E0425, E0432.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/tests/ui/cfg/diagnostics-same-crate.rs b/tests/ui/cfg/diagnostics-same-crate.rs
new file mode 100644
index 000000000..f76ace06a
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-same-crate.rs
@@ -0,0 +1,51 @@
+pub mod inner {
+ #[cfg(FALSE)]
+ pub fn uwu() {}
+ //~^ NOTE found an item that was configured out
+
+ #[cfg(FALSE)]
+ pub mod doesnt_exist {
+ pub fn hello() {}
+ }
+
+ pub mod wrong {
+ #[cfg(feature = "suggesting me fails the test!!")]
+ pub fn meow() {}
+ }
+
+ pub mod right {
+ #[cfg(feature = "what-a-cool-feature")]
+ pub fn meow() {}
+ //~^ NOTE found an item that was configured out
+ }
+}
+
+#[cfg(i_dont_exist_and_you_can_do_nothing_about_it)]
+pub fn vanished() {}
+
+fn main() {
+ // There is no uwu at this path - no diagnostic.
+ uwu(); //~ ERROR cannot find function
+ //~^ NOTE not found in this scope
+
+ // It does exist here - diagnostic.
+ inner::uwu(); //~ ERROR cannot find function
+ //~| NOTE not found in `inner`
+
+ // The module isn't found - we would like to get a diagnostic, but currently don't due to
+ // the awkward way the resolver diagnostics are currently implemented.
+ // FIXME(Nilstrieb): Also add a note to the cfg diagnostic here
+ inner::doesnt_exist::hello(); //~ ERROR failed to resolve
+ //~| NOTE could not find `doesnt_exist` in `inner`
+
+ // It should find the one in the right module, not the wrong one.
+ inner::right::meow(); //~ ERROR cannot find function
+ //~| NOTE not found in `inner::right
+ //~| NOTE the item is gated behind the `what-a-cool-feature` feature
+
+ // Exists in the crate root - we would generally want a diagnostic,
+ // but currently don't have one.
+ // Not that it matters much though, this is highly unlikely to confuse anyone.
+ vanished(); //~ ERROR cannot find function
+ //~^ NOTE not found in this scope
+}
diff --git a/tests/ui/cfg/diagnostics-same-crate.stderr b/tests/ui/cfg/diagnostics-same-crate.stderr
new file mode 100644
index 000000000..30ee6479b
--- /dev/null
+++ b/tests/ui/cfg/diagnostics-same-crate.stderr
@@ -0,0 +1,47 @@
+error[E0433]: failed to resolve: could not find `doesnt_exist` in `inner`
+ --> $DIR/diagnostics-same-crate.rs:38:12
+ |
+LL | inner::doesnt_exist::hello();
+ | ^^^^^^^^^^^^ could not find `doesnt_exist` in `inner`
+
+error[E0425]: cannot find function `uwu` in module `inner`
+ --> $DIR/diagnostics-same-crate.rs:32:12
+ |
+LL | inner::uwu();
+ | ^^^ not found in `inner`
+ |
+note: found an item that was configured out
+ --> $DIR/diagnostics-same-crate.rs:3:12
+ |
+LL | pub fn uwu() {}
+ | ^^^
+
+error[E0425]: cannot find function `meow` in module `inner::right`
+ --> $DIR/diagnostics-same-crate.rs:42:19
+ |
+LL | inner::right::meow();
+ | ^^^^ not found in `inner::right`
+ |
+note: found an item that was configured out
+ --> $DIR/diagnostics-same-crate.rs:18:16
+ |
+LL | pub fn meow() {}
+ | ^^^^
+ = note: the item is gated behind the `what-a-cool-feature` feature
+
+error[E0425]: cannot find function `uwu` in this scope
+ --> $DIR/diagnostics-same-crate.rs:28:5
+ |
+LL | uwu();
+ | ^^^ not found in this scope
+
+error[E0425]: cannot find function `vanished` in this scope
+ --> $DIR/diagnostics-same-crate.rs:49:5
+ |
+LL | vanished();
+ | ^^^^^^^^ not found in this scope
+
+error: aborting due to 5 previous errors
+
+Some errors have detailed explanations: E0425, E0433.
+For more information about an error, try `rustc --explain E0425`.