1
Fork 0

Rollup merge of #126682 - Zalathar:coverage-attr, r=lcnr

coverage: Overhaul validation of the `#[coverage(..)]` attribute

This PR makes sweeping changes to how the (currently-unstable) coverage attribute is validated:
- Multiple coverage attributes on the same item/expression are now treated as an error.
- The attribute must always be `#[coverage(off)]` or `#[coverage(on)]`, and the error messages for this are more consistent.
  -  A trailing comma is still allowed after off/on, since that's part of the normal attribute syntax.
- Some places that silently ignored a coverage attribute now produce an error instead.
  - These cases were all clearly bugs.
- Some places that ignored a coverage attribute (with a warning) now produce an error instead.
  - These were originally added as lints, but I don't think it makes much sense to knowingly allow new attributes to be used in meaningless places.
  - Some of these errors might soon disappear, if it's easy to extend recursive coverage attributes to things like modules and impl blocks.

---

One of the goals of this PR is to lay a more solid foundation for making the coverage attribute recursive, so that it applies to all nested functions/closures instead of just the one it is directly attached to.

Fixes #126658.

This PR incorporates #126659, which adds more tests for validation of the coverage attribute.

`@rustbot` label +A-code-coverage
This commit is contained in:
Michael Goulet 2024-06-24 15:51:03 -04:00 committed by GitHub
commit 9ce2a070b3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 706 additions and 377 deletions

View file

@ -27,8 +27,6 @@ codegen_ssa_create_temp_dir = couldn't create a temp dir: {$error}
codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error} codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error}
codegen_ssa_expected_coverage_symbol = expected `coverage(off)` or `coverage(on)`
codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)` codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`
codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified codegen_ssa_extern_funcs_not_found = some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified

View file

@ -15,11 +15,7 @@ use rustc_span::{sym, Span};
use rustc_target::spec::{abi, SanitizerSet}; use rustc_target::spec::{abi, SanitizerSet};
use crate::errors; use crate::errors;
use crate::target_features::from_target_feature; use crate::target_features::{check_target_feature_trait_unsafe, from_target_feature};
use crate::{
errors::{ExpectedCoverageSymbol, ExpectedUsedSymbol},
target_features::check_target_feature_trait_unsafe,
};
fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage { fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
use rustc_middle::mir::mono::Linkage::*; use rustc_middle::mir::mono::Linkage::*;
@ -139,7 +135,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
// coverage on a smaller scope within an excluded larger scope. // coverage on a smaller scope within an excluded larger scope.
} }
Some(_) | None => { Some(_) | None => {
tcx.dcx().emit_err(ExpectedCoverageSymbol { span: attr.span }); tcx.dcx()
.span_delayed_bug(attr.span, "unexpected value of coverage attribute");
} }
} }
} }
@ -174,7 +171,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED; codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
} }
Some(_) => { Some(_) => {
tcx.dcx().emit_err(ExpectedUsedSymbol { span: attr.span }); tcx.dcx().emit_err(errors::ExpectedUsedSymbol { span: attr.span });
} }
None => { None => {
// Unfortunately, unconditionally using `llvm.used` causes // Unfortunately, unconditionally using `llvm.used` causes

View file

@ -564,13 +564,6 @@ pub struct UnknownArchiveKind<'a> {
pub kind: &'a str, pub kind: &'a str,
} }
#[derive(Diagnostic)]
#[diag(codegen_ssa_expected_coverage_symbol)]
pub struct ExpectedCoverageSymbol {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(codegen_ssa_expected_used_symbol)] #[diag(codegen_ssa_expected_used_symbol)]
pub struct ExpectedUsedSymbol { pub struct ExpectedUsedSymbol {

View file

@ -105,6 +105,9 @@ pub struct AttributeTemplate {
pub word: bool, pub word: bool,
/// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`. /// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`.
pub list: Option<&'static str>, pub list: Option<&'static str>,
/// If non-empty, the attribute is allowed to take a list containing exactly
/// one of the listed words, like `#[coverage(off)]`.
pub one_of: &'static [Symbol],
/// If `Some`, the attribute is allowed to be a name/value pair where the /// If `Some`, the attribute is allowed to be a name/value pair where the
/// value is a string, like `#[must_use = "reason"]`. /// value is a string, like `#[must_use = "reason"]`.
pub name_value_str: Option<&'static str>, pub name_value_str: Option<&'static str>,
@ -165,19 +168,20 @@ pub enum AttributeDuplicates {
/// E.g., `template!(Word, List: "description")` means that the attribute /// E.g., `template!(Word, List: "description")` means that the attribute
/// supports forms `#[attr]` and `#[attr(description)]`. /// supports forms `#[attr]` and `#[attr(description)]`.
macro_rules! template { macro_rules! template {
(Word) => { template!(@ true, None, None) }; (Word) => { template!(@ true, None, &[], None) };
(List: $descr: expr) => { template!(@ false, Some($descr), None) }; (List: $descr: expr) => { template!(@ false, Some($descr), &[], None) };
(NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) }; (OneOf: $one_of: expr) => { template!(@ false, None, $one_of, None) };
(Word, List: $descr: expr) => { template!(@ true, Some($descr), None) }; (NameValueStr: $descr: expr) => { template!(@ false, None, &[], Some($descr)) };
(Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) }; (Word, List: $descr: expr) => { template!(@ true, Some($descr), &[], None) };
(Word, NameValueStr: $descr: expr) => { template!(@ true, None, &[], Some($descr)) };
(List: $descr1: expr, NameValueStr: $descr2: expr) => { (List: $descr1: expr, NameValueStr: $descr2: expr) => {
template!(@ false, Some($descr1), Some($descr2)) template!(@ false, Some($descr1), &[], Some($descr2))
}; };
(Word, List: $descr1: expr, NameValueStr: $descr2: expr) => { (Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
template!(@ true, Some($descr1), Some($descr2)) template!(@ true, Some($descr1), &[], Some($descr2))
}; };
(@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate { (@ $word: expr, $list: expr, $one_of: expr, $name_value_str: expr) => { AttributeTemplate {
word: $word, list: $list, name_value_str: $name_value_str word: $word, list: $list, one_of: $one_of, name_value_str: $name_value_str
} }; } };
} }
@ -478,8 +482,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
EncodeCrossCrate::No, experimental!(no_sanitize) EncodeCrossCrate::No, experimental!(no_sanitize)
), ),
gated!( gated!(
coverage, Normal, template!(Word, List: "on|off"), coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
WarnFollowing, EncodeCrossCrate::No, ErrorPreceding, EncodeCrossCrate::No,
coverage_attribute, experimental!(coverage) coverage_attribute, experimental!(coverage)
), ),

View file

@ -4,8 +4,10 @@ use crate::{errors, parse_in};
use rustc_ast::token::Delimiter; use rustc_ast::token::Delimiter;
use rustc_ast::tokenstream::DelimSpan; use rustc_ast::tokenstream::DelimSpan;
use rustc_ast::MetaItemKind; use rustc_ast::{
use rustc_ast::{self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, Safety}; self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemKind,
NestedMetaItem, Safety,
};
use rustc_errors::{Applicability, FatalError, PResult}; use rustc_errors::{Applicability, FatalError, PResult};
use rustc_feature::{ use rustc_feature::{
AttributeSafety, AttributeTemplate, BuiltinAttribute, Features, BUILTIN_ATTRIBUTE_MAP, AttributeSafety, AttributeTemplate, BuiltinAttribute, Features, BUILTIN_ATTRIBUTE_MAP,
@ -184,9 +186,13 @@ pub(super) fn check_cfg_attr_bad_delim(psess: &ParseSess, span: DelimSpan, delim
/// Checks that the given meta-item is compatible with this `AttributeTemplate`. /// Checks that the given meta-item is compatible with this `AttributeTemplate`.
fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool { fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool {
let is_one_allowed_subword = |items: &[NestedMetaItem]| match items {
[item] => item.is_word() && template.one_of.iter().any(|&word| item.has_name(word)),
_ => false,
};
match meta { match meta {
MetaItemKind::Word => template.word, MetaItemKind::Word => template.word,
MetaItemKind::List(..) => template.list.is_some(), MetaItemKind::List(items) => template.list.is_some() || is_one_allowed_subword(items),
MetaItemKind::NameValue(lit) if lit.kind.is_str() => template.name_value_str.is_some(), MetaItemKind::NameValue(lit) if lit.kind.is_str() => template.name_value_str.is_some(),
MetaItemKind::NameValue(..) => false, MetaItemKind::NameValue(..) => false,
} }
@ -230,6 +236,7 @@ fn emit_malformed_attribute(
if let Some(descr) = template.list { if let Some(descr) = template.list {
suggestions.push(format!("#{inner}[{name}({descr})]")); suggestions.push(format!("#{inner}[{name}({descr})]"));
} }
suggestions.extend(template.one_of.iter().map(|&word| format!("#{inner}[{name}({word})]")));
if let Some(descr) = template.name_value_str { if let Some(descr) = template.name_value_str {
suggestions.push(format!("#{inner}[{name} = \"{descr}\"]")); suggestions.push(format!("#{inner}[{name} = \"{descr}\"]"));
} }

View file

@ -103,18 +103,9 @@ passes_continue_labeled_block =
.label = labeled blocks cannot be `continue`'d .label = labeled blocks cannot be `continue`'d
.block_label = labeled block the `continue` points to .block_label = labeled block the `continue` points to
passes_coverage_fn_defn = passes_coverage_not_fn_or_closure =
`#[coverage]` may only be applied to function definitions attribute should be applied to a function definition or closure
.label = not a function or closure
passes_coverage_ignored_function_prototype =
`#[coverage]` is ignored on function prototypes
passes_coverage_not_coverable =
`#[coverage]` must be applied to coverable code
.label = not coverable code
passes_coverage_propagate =
`#[coverage]` does not propagate into items and must be applied to the contained functions directly
passes_dead_codes = passes_dead_codes =
{ $multiple -> { $multiple ->

View file

@ -122,7 +122,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target) self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
} }
[sym::inline] => self.check_inline(hir_id, attr, span, target), [sym::inline] => self.check_inline(hir_id, attr, span, target),
[sym::coverage] => self.check_coverage(hir_id, attr, span, target), [sym::coverage] => self.check_coverage(attr, span, target),
[sym::non_exhaustive] => self.check_non_exhaustive(hir_id, attr, span, target), [sym::non_exhaustive] => self.check_non_exhaustive(hir_id, attr, span, target),
[sym::marker] => self.check_marker(hir_id, attr, span, target), [sym::marker] => self.check_marker(hir_id, attr, span, target),
[sym::target_feature] => { [sym::target_feature] => {
@ -369,47 +369,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
} }
} }
/// Checks if a `#[coverage]` is applied directly to a function /// Checks that `#[coverage(..)]` is applied to a function or closure.
fn check_coverage(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool { fn check_coverage(&self, attr: &Attribute, span: Span, target: Target) -> bool {
match target { match target {
// #[coverage] on function is fine // #[coverage(..)] on function is fine
Target::Fn Target::Fn
| Target::Closure | Target::Closure
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true, | Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
// function prototypes can't be covered
Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::IgnoredCoverageFnProto,
);
true
}
Target::Mod | Target::ForeignMod | Target::Impl | Target::Trait => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::IgnoredCoveragePropagate,
);
true
}
Target::Expression | Target::Statement | Target::Arm => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr.span,
errors::IgnoredCoverageFnDefn,
);
true
}
_ => { _ => {
self.dcx().emit_err(errors::IgnoredCoverageNotCoverable { self.dcx().emit_err(errors::CoverageNotFnOrClosure {
attr_span: attr.span, attr_span: attr.span,
defn_span: span, defn_span: span,
}); });

View file

@ -60,21 +60,9 @@ pub struct InlineNotFnOrClosure {
pub defn_span: Span, pub defn_span: Span,
} }
#[derive(LintDiagnostic)]
#[diag(passes_coverage_ignored_function_prototype)]
pub struct IgnoredCoverageFnProto;
#[derive(LintDiagnostic)]
#[diag(passes_coverage_propagate)]
pub struct IgnoredCoveragePropagate;
#[derive(LintDiagnostic)]
#[diag(passes_coverage_fn_defn)]
pub struct IgnoredCoverageFnDefn;
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(passes_coverage_not_coverable, code = E0788)] #[diag(passes_coverage_not_fn_or_closure, code = E0788)]
pub struct IgnoredCoverageNotCoverable { pub struct CoverageNotFnOrClosure {
#[primary_span] #[primary_span]
pub attr_span: Span, pub attr_span: Span,
#[label] #[label]

View file

@ -1,58 +1,45 @@
#![feature(coverage_attribute)] #![feature(coverage_attribute)]
//@ edition: 2021
// Tests the error messages produced (or not produced) by various unusual // Tests the error messages produced (or not produced) by various unusual
// uses of the `#[coverage(..)]` attribute. // uses of the `#[coverage(..)]` attribute.
// FIXME(#126658): Multiple coverage attributes with the same value are useless, #[coverage(off)] //~ ERROR multiple `coverage` attributes
// and should probably produce a diagnostic.
#[coverage(off)]
#[coverage(off)] #[coverage(off)]
fn multiple_consistent() {} fn multiple_consistent() {}
// FIXME(#126658): When there are multiple inconsistent coverage attributes, #[coverage(off)] //~ ERROR multiple `coverage` attributes
// it's unclear which one will prevail.
#[coverage(off)]
#[coverage(on)] #[coverage(on)]
fn multiple_inconsistent() {} fn multiple_inconsistent() {}
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage] //~ ERROR malformed `coverage` attribute input
fn bare_word() {} fn bare_word() {}
// FIXME(#126658): This shows as multiple different errors, one of which suggests #[coverage = true] //~ ERROR malformed `coverage` attribute input
// writing bare `#[coverage]`, which is not allowed.
#[coverage = true]
//~^ ERROR expected `coverage(off)` or `coverage(on)`
//~| ERROR malformed `coverage` attribute input
//~| HELP the following are the possible correct uses
//~| SUGGESTION #[coverage(on|off)]
fn key_value() {} fn key_value() {}
#[coverage()] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage()] //~ ERROR malformed `coverage` attribute input
fn list_empty() {} fn list_empty() {}
#[coverage(off, off)] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(off, off)] //~ ERROR malformed `coverage` attribute input
fn list_consistent() {} fn list_consistent() {}
#[coverage(off, on)] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(off, on)] //~ ERROR malformed `coverage` attribute input
fn list_inconsistent() {} fn list_inconsistent() {}
#[coverage(bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(bogus)] //~ ERROR malformed `coverage` attribute input
fn bogus_word() {} fn bogus_word() {}
#[coverage(bogus, off)] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(bogus, off)] //~ ERROR malformed `coverage` attribute input
fn bogus_word_before() {} fn bogus_word_before() {}
#[coverage(off, bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(off, bogus)] //~ ERROR malformed `coverage` attribute input
fn bogus_word_after() {} fn bogus_word_after() {}
#[coverage(off,)] #[coverage(off,)] // (OK!)
fn comma_after() {} fn comma_after() {}
// FIXME(#126658): This shows as multiple different errors. #[coverage(,off)] //~ ERROR expected identifier, found `,`
#[coverage(,off)]
//~^ ERROR expected identifier, found `,`
//~| HELP remove this comma
//~| ERROR expected `coverage(off)` or `coverage(on)`
fn comma_before() {} fn comma_before() {}
fn main() {} fn main() {}

View file

@ -1,18 +1,109 @@
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:23:1 --> $DIR/bad-syntax.rs:15:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:18:1
| |
LL | #[coverage = true] LL | #[coverage = true]
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:21:1
| |
LL | #[coverage] LL | #[coverage()]
| ^^^^^^^^^^^^^
| |
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:24:1
|
LL | #[coverage(off, off)]
| ^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:27:1
|
LL | #[coverage(off, on)]
| ^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:30:1
|
LL | #[coverage(bogus)]
| ^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:33:1
|
LL | #[coverage(bogus, off)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: malformed `coverage` attribute input
--> $DIR/bad-syntax.rs:36:1
|
LL | #[coverage(off, bogus)]
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: expected identifier, found `,` error: expected identifier, found `,`
--> $DIR/bad-syntax.rs:52:12 --> $DIR/bad-syntax.rs:42:12
| |
LL | #[coverage(,off)] LL | #[coverage(,off)]
| ^ | ^
@ -20,59 +111,29 @@ LL | #[coverage(,off)]
| expected identifier | expected identifier
| help: remove this comma | help: remove this comma
error: expected `coverage(off)` or `coverage(on)` error: multiple `coverage` attributes
--> $DIR/bad-syntax.rs:18:1 --> $DIR/bad-syntax.rs:7:1
| |
LL | #[coverage] LL | #[coverage(off)]
| ^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/bad-syntax.rs:8:1
|
LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^
error: expected `coverage(off)` or `coverage(on)` error: multiple `coverage` attributes
--> $DIR/bad-syntax.rs:23:1 --> $DIR/bad-syntax.rs:11:1
| |
LL | #[coverage = true] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^ help: remove this attribute
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:30:1
| |
LL | #[coverage()] note: attribute also specified here
| ^^^^^^^^^^^^^ --> $DIR/bad-syntax.rs:12:1
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:33:1
| |
LL | #[coverage(off, off)] LL | #[coverage(on)]
| ^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:36:1
|
LL | #[coverage(off, on)]
| ^^^^^^^^^^^^^^^^^^^^
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:39:1
|
LL | #[coverage(bogus)]
| ^^^^^^^^^^^^^^^^^^
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:42:1
|
LL | #[coverage(bogus, off)]
| ^^^^^^^^^^^^^^^^^^^^^^^
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:45:1
|
LL | #[coverage(off, bogus)]
| ^^^^^^^^^^^^^^^^^^^^^^^
error: expected `coverage(off)` or `coverage(on)`
--> $DIR/bad-syntax.rs:52:1
|
LL | #[coverage(,off)]
| ^^^^^^^^^^^^^^^^^
error: aborting due to 11 previous errors error: aborting due to 11 previous errors

View file

@ -8,57 +8,62 @@
// and in places that cannot have a coverage attribute, to demonstrate the // and in places that cannot have a coverage attribute, to demonstrate the
// interaction between multiple errors. // interaction between multiple errors.
// FIXME(#126658): The error messages for using this syntax are inconsistent #[coverage = "off"]
// with the error message in other cases. They also sometimes appear together //~^ ERROR malformed `coverage` attribute input
// with other errors, and they suggest using the incorrect `#[coverage]` syntax. //~| ERROR attribute should be applied to a function definition or closure
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
mod my_mod {} mod my_mod {}
mod my_mod_inner { 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
} }
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input //~| ERROR attribute should be applied to a function definition or closure
struct MyStruct; struct MyStruct;
#[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
impl MyStruct { impl MyStruct {
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input //~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 7; const X: u32 = 7;
} }
#[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
trait MyTrait { trait MyTrait {
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input //~| ERROR attribute should be applied to a function definition or closure
const X: u32; const X: u32;
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input //~| ERROR attribute should be applied to a function definition or closure
type T; type T;
} }
#[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
impl MyTrait for MyStruct { impl MyTrait for MyStruct {
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input //~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 8; const X: u32 = 8;
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR `#[coverage]` must be applied to coverable code //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input //~| ERROR attribute should be applied to a function definition or closure
type T = (); type T = ();
} }
#[coverage = "off"] #[coverage = "off"]
//~^ ERROR expected `coverage(off)` or `coverage(on)` //~^ ERROR malformed `coverage` attribute input
//~| ERROR malformed `coverage` attribute input
fn main() {} fn main() {}

View file

@ -1,28 +1,28 @@
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:15:1 --> $DIR/name-value.rs:11:1
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~~~~ |
LL | #[coverage] LL | #[coverage(on)]
| ~~~~~~~~~~~ |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:19:5 --> $DIR/name-value.rs:17:5
| |
LL | #![coverage = "off"] LL | #![coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #![coverage(on|off)] LL | #![coverage(off)]
| ~~~~~~~~~~~~~~~~~~~~ |
LL | #![coverage] LL | #![coverage(on)]
| ~~~~~~~~~~~~ |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:22:1 --> $DIR/name-value.rs:22:1
@ -32,22 +32,22 @@ LL | #[coverage = "off"]
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:29:5 --> $DIR/name-value.rs:31:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
@ -58,162 +58,220 @@ LL | #[coverage = "off"]
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~~~~ |
LL | #[coverage] LL | #[coverage(on)]
| ~~~~~~~~~~~ |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:37:5 --> $DIR/name-value.rs:41:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:42:5 --> $DIR/name-value.rs:46:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:35:1 --> $DIR/name-value.rs:37:1
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~~~~ |
LL | #[coverage] LL | #[coverage(on)]
| ~~~~~~~~~~~ |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:50:5 --> $DIR/name-value.rs:56:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:55:5 --> $DIR/name-value.rs:61:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:48:1 --> $DIR/name-value.rs:52:1
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~~~~ |
LL | #[coverage] LL | #[coverage(on)]
| ~~~~~~~~~~~ |
error: malformed `coverage` attribute input error: malformed `coverage` attribute input
--> $DIR/name-value.rs:61:1 --> $DIR/name-value.rs:67:1
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
| |
help: the following are the possible correct uses help: the following are the possible correct uses
| |
LL | #[coverage(on|off)] LL | #[coverage(off)]
| |
LL | #[coverage] LL | #[coverage(on)]
| |
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:11:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | mod my_mod {}
| ------------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:17:5
|
LL | / mod my_mod_inner {
LL | | #![coverage = "off"]
| | ^^^^^^^^^^^^^^^^^^^^
LL | |
LL | |
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:22:1 --> $DIR/name-value.rs:22:1
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
... ...
LL | struct MyStruct; LL | struct MyStruct;
| ---------------- not coverable code | ---------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:37:5 --> $DIR/name-value.rs:27:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | / impl MyStruct {
LL | | #[coverage = "off"]
LL | |
LL | |
LL | | const X: u32 = 7;
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:37:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | / trait MyTrait {
LL | | #[coverage = "off"]
LL | |
LL | |
... |
LL | | type T;
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:52:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
...
LL | / impl MyTrait for MyStruct {
LL | | #[coverage = "off"]
LL | |
LL | |
... |
LL | | type T = ();
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:41:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
... ...
LL | const X: u32; LL | const X: u32;
| ------------- not coverable code | ------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:42:5 --> $DIR/name-value.rs:46:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
... ...
LL | type T; LL | type T;
| ------- not coverable code | ------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:29:5 --> $DIR/name-value.rs:31:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
... ...
LL | const X: u32 = 7; LL | const X: u32 = 7;
| ----------------- not coverable code | ----------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:50:5 --> $DIR/name-value.rs:56:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
... ...
LL | const X: u32 = 8; LL | const X: u32 = 8;
| ----------------- not coverable code | ----------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/name-value.rs:55:5 --> $DIR/name-value.rs:61:5
| |
LL | #[coverage = "off"] LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^
... ...
LL | type T = (); LL | type T = ();
| ------------ not coverable code | ------------ not a function or closure
error: expected `coverage(off)` or `coverage(on)` error: aborting due to 23 previous errors
--> $DIR/name-value.rs:61:1
|
LL | #[coverage = "off"]
| ^^^^^^^^^^^^^^^^^^^
error: aborting due to 19 previous errors
For more information about this error, try `rustc --explain E0788`. For more information about this error, try `rustc --explain E0788`.

View file

@ -2,54 +2,48 @@
#![feature(coverage_attribute)] #![feature(coverage_attribute)]
#![feature(impl_trait_in_assoc_type)] #![feature(impl_trait_in_assoc_type)]
#![warn(unused_attributes)] #![warn(unused_attributes)]
#![coverage(off)] #![coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
#[coverage(off)] #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
trait Trait { trait Trait {
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
const X: u32; const X: u32;
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
type T; type T;
type U; type U;
} }
#[coverage(off)] #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
impl Trait for () { impl Trait for () {
const X: u32 = 0; const X: u32 = 0;
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
type T = Self; type T = Self;
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
type U = impl Trait; //~ ERROR unconstrained opaque type type U = impl Trait; //~ ERROR unconstrained opaque type
} }
extern "C" { extern "C" {
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
static X: u32; static X: u32;
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
type T; type T;
} }
#[coverage(off)] #[coverage(off)]
fn main() { fn main() {
#[coverage(off)] #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
//~^ WARN `#[coverage]` may only be applied to function definitions
let _ = (); let _ = ();
match () { match () {
#[coverage(off)] #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
//~^ WARN `#[coverage]` may only be applied to function definitions
() => (), () => (),
} }
#[coverage(off)] #[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
//~^ WARN `#[coverage]` may only be applied to function definitions
return (); return ();
} }

View file

@ -1,101 +1,116 @@
warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:8:1 --> $DIR/no-coverage.rs:7:1
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| LL | / trait Trait {
note: the lint level is defined here LL | | #[coverage(off)]
--> $DIR/no-coverage.rs:4:9 LL | | const X: u32;
| ... |
LL | #![warn(unused_attributes)] LL | | type U;
| ^^^^^^^^^^^^^^^^^ LL | | }
| |_- not a function or closure
warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:20:1 --> $DIR/no-coverage.rs:18:1
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | / impl Trait for () {
LL | | const X: u32 = 0;
LL | |
LL | | #[coverage(off)]
... |
LL | | type U = impl Trait;
LL | | }
| |_- not a function or closure
warning: `#[coverage]` may only be applied to function definitions error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:42:5 --> $DIR/no-coverage.rs:39:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | let _ = ();
| ----------- not a function or closure
warning: `#[coverage]` may only be applied to function definitions error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:47:9 --> $DIR/no-coverage.rs:43:9
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | () => (),
| -------- not a function or closure
warning: `#[coverage]` may only be applied to function definitions error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:52:5 --> $DIR/no-coverage.rs:47:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | return ();
| --------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:11:5 --> $DIR/no-coverage.rs:9:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | const X: u32; LL | const X: u32;
| ------------- not coverable code | ------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:14:5 --> $DIR/no-coverage.rs:12:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | type T; LL | type T;
| ------- not coverable code | ------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:25:5 --> $DIR/no-coverage.rs:22:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | type T = Self; LL | type T = Self;
| -------------- not coverable code | -------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:28:5 --> $DIR/no-coverage.rs:25:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | type U = impl Trait; LL | type U = impl Trait;
| -------------------- not coverable code | -------------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:33:5 --> $DIR/no-coverage.rs:30:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | static X: u32; LL | static X: u32;
| -------------- not coverable code | -------------- not a function or closure
error[E0788]: `#[coverage]` must be applied to coverable code error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:36:5 --> $DIR/no-coverage.rs:33:5
| |
LL | #[coverage(off)] LL | #[coverage(off)]
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
LL | type T; LL | type T;
| ------- not coverable code | ------- not a function or closure
warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/no-coverage.rs:5:1 --> $DIR/no-coverage.rs:5:1
| |
LL | #![coverage(off)] LL | #![coverage(off)]
| ^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^ not a function or closure
error: unconstrained opaque type error: unconstrained opaque type
--> $DIR/no-coverage.rs:29:14 --> $DIR/no-coverage.rs:26:14
| |
LL | type U = impl Trait; LL | type U = impl Trait;
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: `U` must be used in combination with a concrete type within the same impl = note: `U` must be used in combination with a concrete type within the same impl
error: aborting due to 7 previous errors; 6 warnings emitted error: aborting due to 13 previous errors
For more information about this error, try `rustc --explain E0788`. For more information about this error, try `rustc --explain E0788`.

View file

@ -4,16 +4,16 @@
// Check that yes/no in `#[coverage(yes)]` and `#[coverage(no)]` must be bare // Check that yes/no in `#[coverage(yes)]` and `#[coverage(no)]` must be bare
// words, not part of a more complicated substructure. // words, not part of a more complicated substructure.
#[coverage(yes(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(yes(milord))] //~ ERROR malformed `coverage` attribute input
fn yes_list() {} fn yes_list() {}
#[coverage(no(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(no(milord))] //~ ERROR malformed `coverage` attribute input
fn no_list() {} fn no_list() {}
#[coverage(yes = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(yes = "milord")] //~ ERROR malformed `coverage` attribute input
fn yes_key() {} fn yes_key() {}
#[coverage(no = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage(no = "milord")] //~ ERROR malformed `coverage` attribute input
fn no_key() {} fn no_key() {}
fn main() {} fn main() {}

View file

@ -1,26 +1,54 @@
error: expected `coverage(off)` or `coverage(on)` error: malformed `coverage` attribute input
--> $DIR/subword.rs:7:1 --> $DIR/subword.rs:7:1
| |
LL | #[coverage(yes(milord))] LL | #[coverage(yes(milord))]
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: expected `coverage(off)` or `coverage(on)` error: malformed `coverage` attribute input
--> $DIR/subword.rs:10:1 --> $DIR/subword.rs:10:1
| |
LL | #[coverage(no(milord))] LL | #[coverage(no(milord))]
| ^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: expected `coverage(off)` or `coverage(on)` error: malformed `coverage` attribute input
--> $DIR/subword.rs:13:1 --> $DIR/subword.rs:13:1
| |
LL | #[coverage(yes = "milord")] LL | #[coverage(yes = "milord")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: expected `coverage(off)` or `coverage(on)` error: malformed `coverage` attribute input
--> $DIR/subword.rs:16:1 --> $DIR/subword.rs:16:1
| |
LL | #[coverage(no = "milord")] LL | #[coverage(no = "milord")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
| ~~~~~~~~~~~~~~~~
LL | #[coverage(on)]
| ~~~~~~~~~~~~~~~
error: aborting due to 4 previous errors error: aborting due to 4 previous errors

View file

@ -8,47 +8,62 @@
// and in places that cannot have a coverage attribute, to demonstrate the // and in places that cannot have a coverage attribute, to demonstrate the
// interaction between multiple errors. // interaction between multiple errors.
// FIXME(#126658): The error messages for using this syntax give the impression
// that it is legal, even though it should never be legal.
// FIXME(#126658): This is silently allowed, but should not be.
#[coverage] #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
mod my_mod {} mod my_mod {}
// FIXME(#126658): This is silently allowed, but should not be.
mod my_mod_inner { mod my_mod_inner {
#![coverage] #![coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
} }
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
struct MyStruct; struct MyStruct;
// FIXME(#126658): This is silently allowed, but should not be.
#[coverage] #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
impl MyStruct { impl MyStruct {
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 7; const X: u32 = 7;
} }
// FIXME(#126658): This is silently allowed, but should not be.
#[coverage] #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
trait MyTrait { trait MyTrait {
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
const X: u32; const X: u32;
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
type T; type T;
} }
// FIXME(#126658): This is silently allowed, but should not be.
#[coverage] #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
impl MyTrait for MyStruct { impl MyTrait for MyStruct {
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
const X: u32 = 8; const X: u32 = 8;
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code #[coverage]
//~^ ERROR malformed `coverage` attribute input
//~| ERROR attribute should be applied to a function definition or closure
type T = (); type T = ();
} }
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)` #[coverage]
//~^ ERROR malformed `coverage` attribute input
fn main() {} fn main() {}

View file

@ -1,57 +1,277 @@
error[E0788]: `#[coverage]` must be applied to coverable code error: malformed `coverage` attribute input
--> $DIR/word-only.rs:23:1 --> $DIR/word-only.rs:11:1
| |
LL | #[coverage] LL | #[coverage]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
LL | struct MyStruct; |
| ---------------- not coverable code help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error[E0788]: `#[coverage]` must be applied to coverable code error: malformed `coverage` attribute input
--> $DIR/word-only.rs:36:5 --> $DIR/word-only.rs:17:5
|
LL | #![coverage]
| ^^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #![coverage(off)]
|
LL | #![coverage(on)]
|
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:22:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:31:5
| |
LL | #[coverage] LL | #[coverage]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
LL | const X: u32; |
| ------------- not coverable code help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error[E0788]: `#[coverage]` must be applied to coverable code error: malformed `coverage` attribute input
--> $DIR/word-only.rs:39:5 --> $DIR/word-only.rs:27:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:41:5
| |
LL | #[coverage] LL | #[coverage]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
LL | type T;
| ------- not coverable code
error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/word-only.rs:29:5
| |
LL | #[coverage] help: the following are the possible correct uses
| ^^^^^^^^^^^ |
LL | const X: u32 = 7; LL | #[coverage(off)]
| ----------------- not coverable code |
LL | #[coverage(on)]
|
error[E0788]: `#[coverage]` must be applied to coverable code error: malformed `coverage` attribute input
--> $DIR/word-only.rs:46:5 --> $DIR/word-only.rs:46:5
| |
LL | #[coverage] LL | #[coverage]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
LL | const X: u32 = 8;
| ----------------- not coverable code
error[E0788]: `#[coverage]` must be applied to coverable code
--> $DIR/word-only.rs:49:5
| |
LL | #[coverage] help: the following are the possible correct uses
| ^^^^^^^^^^^ |
LL | type T = (); LL | #[coverage(off)]
| ------------ not coverable code |
LL | #[coverage(on)]
|
error: expected `coverage(off)` or `coverage(on)` error: malformed `coverage` attribute input
--> $DIR/word-only.rs:53:1 --> $DIR/word-only.rs:37:1
| |
LL | #[coverage] LL | #[coverage]
| ^^^^^^^^^^^ | ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error: aborting due to 7 previous errors error: malformed `coverage` attribute input
--> $DIR/word-only.rs:56:5
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:61:5
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:52:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error: malformed `coverage` attribute input
--> $DIR/word-only.rs:67:1
|
LL | #[coverage]
| ^^^^^^^^^^^
|
help: the following are the possible correct uses
|
LL | #[coverage(off)]
|
LL | #[coverage(on)]
|
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:11:1
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | mod my_mod {}
| ------------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:17:5
|
LL | / mod my_mod_inner {
LL | | #![coverage]
| | ^^^^^^^^^^^^
LL | |
LL | |
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:22:1
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | struct MyStruct;
| ---------------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:27:1
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | / impl MyStruct {
LL | | #[coverage]
LL | |
LL | |
LL | | const X: u32 = 7;
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:37:1
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | / trait MyTrait {
LL | | #[coverage]
LL | |
LL | |
... |
LL | | type T;
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:52:1
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | / impl MyTrait for MyStruct {
LL | | #[coverage]
LL | |
LL | |
... |
LL | | type T = ();
LL | | }
| |_- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:41:5
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | const X: u32;
| ------------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:46:5
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | type T;
| ------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:31:5
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | const X: u32 = 7;
| ----------------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:56:5
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | const X: u32 = 8;
| ----------------- not a function or closure
error[E0788]: attribute should be applied to a function definition or closure
--> $DIR/word-only.rs:61:5
|
LL | #[coverage]
| ^^^^^^^^^^^
...
LL | type T = ();
| ------------ not a function or closure
error: aborting due to 23 previous errors
For more information about this error, try `rustc --explain E0788`. For more information about this error, try `rustc --explain E0788`.