rust/tests/ui/coverage-attr/name-value.rs
Zalathar 7f37f8af5f coverage: Allow #[coverage(..)] on impl and mod
These attributes apply to all enclosed functions/methods/closures, unless
explicitly overridden by another coverage attribute.
2024-06-26 10:08:05 +10:00

66 lines
2.0 KiB
Rust

#![feature(coverage_attribute)]
//@ edition: 2021
// Demonstrates the diagnostics produced when using the syntax
// `#[coverage = "off"]`, which should not be allowed.
//
// The syntax is tested both in places that can have a coverage attribute,
// and in places that cannot have a coverage attribute, to demonstrate the
// interaction between multiple errors.
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
mod my_mod {}
mod my_mod_inner {
#![coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
}
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
struct MyStruct;
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
impl MyStruct {
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 7;
}
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
trait MyTrait {
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
const X: u32;
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
type T;
}
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
impl MyTrait for MyStruct {
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 8;
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
type T = ();
}
#[coverage = "off"]
//~^ ERROR malformed `coverage` attribute input
fn main() {}