about summary refs log tree commit diff
path: root/src/test/ui/lint
diff options
context:
space:
mode:
authorltdk <usr@ltdk.xyz>2022-05-28 17:20:43 -0400
committerltdk <usr@ltdk.xyz>2022-05-28 17:20:43 -0400
commit5fabdb8f7fd0c2c48d47ce08126d27ade5beefd9 (patch)
tree199a872e51d4105c51ab4ee1dbec2a0de02af34d /src/test/ui/lint
parentebbcbfc236ced21d5e6a92269edb704692ff26b8 (diff)
downloadrust-5fabdb8f7fd0c2c48d47ce08126d27ade5beefd9.tar.gz
rust-5fabdb8f7fd0c2c48d47ce08126d27ade5beefd9.zip
Add E0788 for improper #[no_coverage] usage
Diffstat (limited to 'src/test/ui/lint')
-rw-r--r--src/test/ui/lint/no-coverage.rs46
-rw-r--r--src/test/ui/lint/no-coverage.stderr83
2 files changed, 129 insertions, 0 deletions
diff --git a/src/test/ui/lint/no-coverage.rs b/src/test/ui/lint/no-coverage.rs
new file mode 100644
index 00000000000..c02cd976bc9
--- /dev/null
+++ b/src/test/ui/lint/no-coverage.rs
@@ -0,0 +1,46 @@
+#![feature(extern_types)]
+#![feature(no_coverage)]
+#![feature(type_alias_impl_trait)]
+#![warn(unused_attributes)]
+
+trait Trait {
+    #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
+    const X: u32;
+
+    #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
+    type T;
+
+    type U;
+}
+
+impl Trait for () {
+    const X: u32 = 0;
+
+    #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
+    type T = Self;
+
+    #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
+    type U = impl Trait; //~ ERROR unconstrained opaque type
+}
+
+extern "C" {
+    #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
+    static X: u32;
+
+    #[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
+    type T;
+}
+
+#[no_coverage]
+fn main() {
+    #[no_coverage] //~ WARN `#[no_coverage]` can only be applied at the function level, not on code directly
+    let _ = ();
+
+    match () {
+        #[no_coverage] //~ WARN `#[no_coverage]` can only be applied at the function level, not on code directly
+        () => (),
+    }
+
+    #[no_coverage] //~ WARN `#[no_coverage]` can only be applied at the function level, not on code directly
+    return ();
+}
diff --git a/src/test/ui/lint/no-coverage.stderr b/src/test/ui/lint/no-coverage.stderr
new file mode 100644
index 00000000000..8549eb699ee
--- /dev/null
+++ b/src/test/ui/lint/no-coverage.stderr
@@ -0,0 +1,83 @@
+warning: `#[no_coverage]` can only be applied at the function level, not on code directly
+  --> $DIR/no-coverage.rs:36:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+   |
+note: the lint level is defined here
+  --> $DIR/no-coverage.rs:4:9
+   |
+LL | #![warn(unused_attributes)]
+   |         ^^^^^^^^^^^^^^^^^
+
+warning: `#[no_coverage]` can only be applied at the function level, not on code directly
+  --> $DIR/no-coverage.rs:40:9
+   |
+LL |         #[no_coverage]
+   |         ^^^^^^^^^^^^^^
+
+warning: `#[no_coverage]` can only be applied at the function level, not on code directly
+  --> $DIR/no-coverage.rs:44:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+
+error[E0788]: `#[no_coverage]` must be applied to coverable code
+  --> $DIR/no-coverage.rs:7:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+LL |     const X: u32;
+   |     ------------- not coverable code
+
+error[E0788]: `#[no_coverage]` must be applied to coverable code
+  --> $DIR/no-coverage.rs:10:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+LL |     type T;
+   |     ------- not coverable code
+
+error[E0788]: `#[no_coverage]` must be applied to coverable code
+  --> $DIR/no-coverage.rs:19:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+LL |     type T = Self;
+   |     -------------- not coverable code
+
+error[E0788]: `#[no_coverage]` must be applied to coverable code
+  --> $DIR/no-coverage.rs:22:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+LL |     type U = impl Trait;
+   |     -------------------- not coverable code
+
+error[E0788]: `#[no_coverage]` must be applied to coverable code
+  --> $DIR/no-coverage.rs:27:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+LL |     static X: u32;
+   |     -------------- not coverable code
+
+error[E0788]: `#[no_coverage]` must be applied to coverable code
+  --> $DIR/no-coverage.rs:30:5
+   |
+LL |     #[no_coverage]
+   |     ^^^^^^^^^^^^^^
+LL |     type T;
+   |     ------- not coverable code
+
+error: unconstrained opaque type
+  --> $DIR/no-coverage.rs:23:14
+   |
+LL |     type U = impl Trait;
+   |              ^^^^^^^^^^
+   |
+   = note: `U` must be used in combination with a concrete type within the same module
+
+error: aborting due to 7 previous errors; 3 warnings emitted
+
+For more information about this error, try `rustc --explain E0788`.