diff options
| -rw-r--r-- | tests/ui/coverage-attr/allowed-positions.rs | 80 | ||||
| -rw-r--r-- | tests/ui/coverage-attr/allowed-positions.stderr | 116 |
2 files changed, 148 insertions, 48 deletions
diff --git a/tests/ui/coverage-attr/allowed-positions.rs b/tests/ui/coverage-attr/allowed-positions.rs index 3c400761948..d4345c8d443 100644 --- a/tests/ui/coverage-attr/allowed-positions.rs +++ b/tests/ui/coverage-attr/allowed-positions.rs @@ -8,35 +8,68 @@ #![warn(unused_attributes)] #![coverage(off)] +#[coverage(off)] +mod submod {} + #[coverage(off)] //~ ERROR [E0788] -trait Trait { - #[coverage(off)] //~ ERROR [E0788] - const X: u32; +type MyTypeAlias = (); +#[coverage(off)] //~ ERROR [E0788] +trait MyTrait { #[coverage(off)] //~ ERROR [E0788] - type T; + const TRAIT_ASSOC_CONST: u32; - type U; + #[coverage(off)] //~ ERROR [E0788] + type TraitAssocType; #[coverage(off)] //~ ERROR [E0788] - fn f(&self); + fn trait_method(&self); + + #[coverage(off)] + fn trait_method_with_default(&self) {} #[coverage(off)] //~ ERROR [E0788] - fn g(); + fn trait_assoc_fn(); } #[coverage(off)] -impl Trait for () { - const X: u32 = 0; +impl MyTrait for () { + const TRAIT_ASSOC_CONST: u32 = 0; #[coverage(off)] //~ ERROR [E0788] - type T = Self; + type TraitAssocType = Self; + + #[coverage(off)] + fn trait_method(&self) {} + #[coverage(off)] + fn trait_method_with_default(&self) {} + #[coverage(off)] + fn trait_assoc_fn() {} +} + +trait HasAssocType { + type T; + fn constrain_assoc_type() -> Self::T; +} +impl HasAssocType for () { #[coverage(off)] //~ ERROR [E0788] - type U = impl Trait; //~ ERROR unconstrained opaque type + type T = impl Copy; + fn constrain_assoc_type() -> Self::T {} +} + +#[coverage(off)] //~ ERROR [E0788] +struct MyStruct { + #[coverage(off)] //~ ERROR [E0788] + field: u32, +} - fn f(&self) {} - fn g() {} +#[coverage(off)] +impl MyStruct { + #[coverage(off)] + fn method(&self) {} + #[coverage(off)] + fn assoc_fn() {} } extern "C" { @@ -45,6 +78,9 @@ extern "C" { #[coverage(off)] //~ ERROR [E0788] type T; + + #[coverage(off)] //~ ERROR [E0788] + fn foreign_fn(); } #[coverage(off)] @@ -52,6 +88,24 @@ fn main() { #[coverage(off)] //~ ERROR [E0788] let _ = (); + // Currently not allowed on let statements, even if they bind to a closure. + // It might be nice to support this as a special case someday, but trying + // to define the precise boundaries of that special case might be tricky. + #[coverage(off)] //~ ERROR [E0788] + let _let_closure = || (); + + // In situations where attributes can already be applied to expressions, + // the coverage attribute is allowed on closure expressions. + let _closure_tail_expr = { + #[coverage(off)] + || () + }; + + // Applying attributes to arbitrary expressions requires an unstable + // feature, but if that feature were enabled then this would be allowed. + let _closure_expr = #[coverage(off)] || (); + //~^ ERROR attributes on expressions are experimental [E0658] + match () { #[coverage(off)] //~ ERROR [E0788] () => (), diff --git a/tests/ui/coverage-attr/allowed-positions.stderr b/tests/ui/coverage-attr/allowed-positions.stderr index 80099fbd6dd..08a578ddd83 100644 --- a/tests/ui/coverage-attr/allowed-positions.stderr +++ b/tests/ui/coverage-attr/allowed-positions.stderr @@ -1,18 +1,55 @@ +error[E0658]: attributes on expressions are experimental + --> $DIR/allowed-positions.rs:106:25 + | +LL | let _closure_expr = #[coverage(off)] || (); + | ^^^^^^^^^^^^^^^^ + | + = note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information + = help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:11:1 + --> $DIR/allowed-positions.rs:14:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | type MyTypeAlias = (); + | ---------------------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/allowed-positions.rs:17:1 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | / trait Trait { +LL | / trait MyTrait { LL | | #[coverage(off)] -LL | | const X: u32; +LL | | const TRAIT_ASSOC_CONST: u32; ... | -LL | | fn g(); +LL | | fn trait_assoc_fn(); +LL | | } + | |_- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/allowed-positions.rs:61:1 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | / struct MyStruct { +LL | | #[coverage(off)] +LL | | field: u32, LL | | } | |_- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:52:5 + --> $DIR/allowed-positions.rs:63:5 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | field: u32, + | ---------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/allowed-positions.rs:88:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -20,7 +57,15 @@ LL | let _ = (); | ----------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:56:9 + --> $DIR/allowed-positions.rs:94:5 + | +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | let _let_closure = || (); + | ------------------------- not a function or closure + +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/allowed-positions.rs:110:9 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -28,7 +73,7 @@ LL | () => (), | -------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:60:5 + --> $DIR/allowed-positions.rs:114:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -36,55 +81,55 @@ LL | return (); | --------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:13:5 + --> $DIR/allowed-positions.rs:19:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | const X: u32; - | ------------- not a function or closure +LL | const TRAIT_ASSOC_CONST: u32; + | ----------------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:16:5 + --> $DIR/allowed-positions.rs:22:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | type T; - | ------- not a function or closure +LL | type TraitAssocType; + | -------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:21:5 + --> $DIR/allowed-positions.rs:25:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | fn f(&self); - | ------------ not a function or closure +LL | fn trait_method(&self); + | ----------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:24:5 + --> $DIR/allowed-positions.rs:31:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | fn g(); - | ------- not a function or closure +LL | fn trait_assoc_fn(); + | -------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:32:5 + --> $DIR/allowed-positions.rs:39:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | type T = Self; - | -------------- not a function or closure +LL | type TraitAssocType = Self; + | --------------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:35:5 + --> $DIR/allowed-positions.rs:56:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ -LL | type U = impl Trait; - | -------------------- not a function or closure +LL | type T = impl Copy; + | ------------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:43:5 + --> $DIR/allowed-positions.rs:76:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ @@ -92,21 +137,22 @@ LL | static X: u32; | -------------- not a function or closure error[E0788]: attribute should be applied to a function definition or closure - --> $DIR/allowed-positions.rs:46:5 + --> $DIR/allowed-positions.rs:79:5 | LL | #[coverage(off)] | ^^^^^^^^^^^^^^^^ LL | type T; | ------- not a function or closure -error: unconstrained opaque type - --> $DIR/allowed-positions.rs:36:14 - | -LL | type U = impl Trait; - | ^^^^^^^^^^ +error[E0788]: attribute should be applied to a function definition or closure + --> $DIR/allowed-positions.rs:82:5 | - = note: `U` must be used in combination with a concrete type within the same impl +LL | #[coverage(off)] + | ^^^^^^^^^^^^^^^^ +LL | fn foreign_fn(); + | ---------------- not a function or closure -error: aborting due to 13 previous errors +error: aborting due to 18 previous errors -For more information about this error, try `rustc --explain E0788`. +Some errors have detailed explanations: E0658, E0788. +For more information about an error, try `rustc --explain E0658`. |
