Skip to content

Commit 9ce2a07

Browse files
authoredJun 24, 2024
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
2 parents 49bdf46 + 1852141 commit 9ce2a07

18 files changed

+687
-358
lines changed
 

Diff for: ‎compiler/rustc_codegen_ssa/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ codegen_ssa_create_temp_dir = couldn't create a temp dir: {$error}
2727
2828
codegen_ssa_error_creating_remark_dir = failed to create remark directory: {$error}
2929
30-
codegen_ssa_expected_coverage_symbol = expected `coverage(off)` or `coverage(on)`
31-
3230
codegen_ssa_expected_used_symbol = expected `used`, `used(compiler)` or `used(linker)`
3331
3432
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

Diff for: ‎compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,7 @@ use rustc_span::{sym, Span};
1515
use rustc_target::spec::{abi, SanitizerSet};
1616

1717
use crate::errors;
18-
use crate::target_features::from_target_feature;
19-
use crate::{
20-
errors::{ExpectedCoverageSymbol, ExpectedUsedSymbol},
21-
target_features::check_target_feature_trait_unsafe,
22-
};
18+
use crate::target_features::{check_target_feature_trait_unsafe, from_target_feature};
2319

2420
fn linkage_by_name(tcx: TyCtxt<'_>, def_id: LocalDefId, name: &str) -> Linkage {
2521
use rustc_middle::mir::mono::Linkage::*;
@@ -139,7 +135,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
139135
// coverage on a smaller scope within an excluded larger scope.
140136
}
141137
Some(_) | None => {
142-
tcx.dcx().emit_err(ExpectedCoverageSymbol { span: attr.span });
138+
tcx.dcx()
139+
.span_delayed_bug(attr.span, "unexpected value of coverage attribute");
143140
}
144141
}
145142
}
@@ -174,7 +171,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
174171
codegen_fn_attrs.flags |= CodegenFnAttrFlags::USED;
175172
}
176173
Some(_) => {
177-
tcx.dcx().emit_err(ExpectedUsedSymbol { span: attr.span });
174+
tcx.dcx().emit_err(errors::ExpectedUsedSymbol { span: attr.span });
178175
}
179176
None => {
180177
// Unfortunately, unconditionally using `llvm.used` causes

Diff for: ‎compiler/rustc_codegen_ssa/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -564,13 +564,6 @@ pub struct UnknownArchiveKind<'a> {
564564
pub kind: &'a str,
565565
}
566566

567-
#[derive(Diagnostic)]
568-
#[diag(codegen_ssa_expected_coverage_symbol)]
569-
pub struct ExpectedCoverageSymbol {
570-
#[primary_span]
571-
pub span: Span,
572-
}
573-
574567
#[derive(Diagnostic)]
575568
#[diag(codegen_ssa_expected_used_symbol)]
576569
pub struct ExpectedUsedSymbol {

Diff for: ‎compiler/rustc_feature/src/builtin_attrs.rs

+15-11
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub struct AttributeTemplate {
105105
pub word: bool,
106106
/// If `Some`, the attribute is allowed to take a list of items like `#[allow(..)]`.
107107
pub list: Option<&'static str>,
108+
/// If non-empty, the attribute is allowed to take a list containing exactly
109+
/// one of the listed words, like `#[coverage(off)]`.
110+
pub one_of: &'static [Symbol],
108111
/// If `Some`, the attribute is allowed to be a name/value pair where the
109112
/// value is a string, like `#[must_use = "reason"]`.
110113
pub name_value_str: Option<&'static str>,
@@ -165,19 +168,20 @@ pub enum AttributeDuplicates {
165168
/// E.g., `template!(Word, List: "description")` means that the attribute
166169
/// supports forms `#[attr]` and `#[attr(description)]`.
167170
macro_rules! template {
168-
(Word) => { template!(@ true, None, None) };
169-
(List: $descr: expr) => { template!(@ false, Some($descr), None) };
170-
(NameValueStr: $descr: expr) => { template!(@ false, None, Some($descr)) };
171-
(Word, List: $descr: expr) => { template!(@ true, Some($descr), None) };
172-
(Word, NameValueStr: $descr: expr) => { template!(@ true, None, Some($descr)) };
171+
(Word) => { template!(@ true, None, &[], None) };
172+
(List: $descr: expr) => { template!(@ false, Some($descr), &[], None) };
173+
(OneOf: $one_of: expr) => { template!(@ false, None, $one_of, None) };
174+
(NameValueStr: $descr: expr) => { template!(@ false, None, &[], Some($descr)) };
175+
(Word, List: $descr: expr) => { template!(@ true, Some($descr), &[], None) };
176+
(Word, NameValueStr: $descr: expr) => { template!(@ true, None, &[], Some($descr)) };
173177
(List: $descr1: expr, NameValueStr: $descr2: expr) => {
174-
template!(@ false, Some($descr1), Some($descr2))
178+
template!(@ false, Some($descr1), &[], Some($descr2))
175179
};
176180
(Word, List: $descr1: expr, NameValueStr: $descr2: expr) => {
177-
template!(@ true, Some($descr1), Some($descr2))
181+
template!(@ true, Some($descr1), &[], Some($descr2))
178182
};
179-
(@ $word: expr, $list: expr, $name_value_str: expr) => { AttributeTemplate {
180-
word: $word, list: $list, name_value_str: $name_value_str
183+
(@ $word: expr, $list: expr, $one_of: expr, $name_value_str: expr) => { AttributeTemplate {
184+
word: $word, list: $list, one_of: $one_of, name_value_str: $name_value_str
181185
} };
182186
}
183187

@@ -478,8 +482,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
478482
EncodeCrossCrate::No, experimental!(no_sanitize)
479483
),
480484
gated!(
481-
coverage, Normal, template!(Word, List: "on|off"),
482-
WarnFollowing, EncodeCrossCrate::No,
485+
coverage, Normal, template!(OneOf: &[sym::off, sym::on]),
486+
ErrorPreceding, EncodeCrossCrate::No,
483487
coverage_attribute, experimental!(coverage)
484488
),
485489

Diff for: ‎compiler/rustc_parse/src/validate_attr.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ use crate::{errors, parse_in};
44

55
use rustc_ast::token::Delimiter;
66
use rustc_ast::tokenstream::DelimSpan;
7-
use rustc_ast::MetaItemKind;
8-
use rustc_ast::{self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, Safety};
7+
use rustc_ast::{
8+
self as ast, AttrArgs, AttrArgsEq, Attribute, DelimArgs, MetaItem, MetaItemKind,
9+
NestedMetaItem, Safety,
10+
};
911
use rustc_errors::{Applicability, FatalError, PResult};
1012
use rustc_feature::{
1113
AttributeSafety, AttributeTemplate, BuiltinAttribute, Features, BUILTIN_ATTRIBUTE_MAP,
@@ -184,9 +186,13 @@ pub(super) fn check_cfg_attr_bad_delim(psess: &ParseSess, span: DelimSpan, delim
184186

185187
/// Checks that the given meta-item is compatible with this `AttributeTemplate`.
186188
fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaItemKind) -> bool {
189+
let is_one_allowed_subword = |items: &[NestedMetaItem]| match items {
190+
[item] => item.is_word() && template.one_of.iter().any(|&word| item.has_name(word)),
191+
_ => false,
192+
};
187193
match meta {
188194
MetaItemKind::Word => template.word,
189-
MetaItemKind::List(..) => template.list.is_some(),
195+
MetaItemKind::List(items) => template.list.is_some() || is_one_allowed_subword(items),
190196
MetaItemKind::NameValue(lit) if lit.kind.is_str() => template.name_value_str.is_some(),
191197
MetaItemKind::NameValue(..) => false,
192198
}
@@ -230,6 +236,7 @@ fn emit_malformed_attribute(
230236
if let Some(descr) = template.list {
231237
suggestions.push(format!("#{inner}[{name}({descr})]"));
232238
}
239+
suggestions.extend(template.one_of.iter().map(|&word| format!("#{inner}[{name}({word})]")));
233240
if let Some(descr) = template.name_value_str {
234241
suggestions.push(format!("#{inner}[{name} = \"{descr}\"]"));
235242
}

Diff for: ‎compiler/rustc_passes/messages.ftl

+3-12
Original file line numberDiff line numberDiff line change
@@ -103,18 +103,9 @@ passes_continue_labeled_block =
103103
.label = labeled blocks cannot be `continue`'d
104104
.block_label = labeled block the `continue` points to
105105
106-
passes_coverage_fn_defn =
107-
`#[coverage]` may only be applied to function definitions
108-
109-
passes_coverage_ignored_function_prototype =
110-
`#[coverage]` is ignored on function prototypes
111-
112-
passes_coverage_not_coverable =
113-
`#[coverage]` must be applied to coverable code
114-
.label = not coverable code
115-
116-
passes_coverage_propagate =
117-
`#[coverage]` does not propagate into items and must be applied to the contained functions directly
106+
passes_coverage_not_fn_or_closure =
107+
attribute should be applied to a function definition or closure
108+
.label = not a function or closure
118109
119110
passes_dead_codes =
120111
{ $multiple ->

Diff for: ‎compiler/rustc_passes/src/check_attr.rs

+5-37
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
122122
self.check_diagnostic_on_unimplemented(attr.span, hir_id, target)
123123
}
124124
[sym::inline] => self.check_inline(hir_id, attr, span, target),
125-
[sym::coverage] => self.check_coverage(hir_id, attr, span, target),
125+
[sym::coverage] => self.check_coverage(attr, span, target),
126126
[sym::non_exhaustive] => self.check_non_exhaustive(hir_id, attr, span, target),
127127
[sym::marker] => self.check_marker(hir_id, attr, span, target),
128128
[sym::target_feature] => {
@@ -369,47 +369,15 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
369369
}
370370
}
371371

372-
/// Checks if a `#[coverage]` is applied directly to a function
373-
fn check_coverage(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) -> bool {
372+
/// Checks that `#[coverage(..)]` is applied to a function or closure.
373+
fn check_coverage(&self, attr: &Attribute, span: Span, target: Target) -> bool {
374374
match target {
375-
// #[coverage] on function is fine
375+
// #[coverage(..)] on function is fine
376376
Target::Fn
377377
| Target::Closure
378378
| Target::Method(MethodKind::Trait { body: true } | MethodKind::Inherent) => true,
379-
380-
// function prototypes can't be covered
381-
Target::Method(MethodKind::Trait { body: false }) | Target::ForeignFn => {
382-
self.tcx.emit_node_span_lint(
383-
UNUSED_ATTRIBUTES,
384-
hir_id,
385-
attr.span,
386-
errors::IgnoredCoverageFnProto,
387-
);
388-
true
389-
}
390-
391-
Target::Mod | Target::ForeignMod | Target::Impl | Target::Trait => {
392-
self.tcx.emit_node_span_lint(
393-
UNUSED_ATTRIBUTES,
394-
hir_id,
395-
attr.span,
396-
errors::IgnoredCoveragePropagate,
397-
);
398-
true
399-
}
400-
401-
Target::Expression | Target::Statement | Target::Arm => {
402-
self.tcx.emit_node_span_lint(
403-
UNUSED_ATTRIBUTES,
404-
hir_id,
405-
attr.span,
406-
errors::IgnoredCoverageFnDefn,
407-
);
408-
true
409-
}
410-
411379
_ => {
412-
self.dcx().emit_err(errors::IgnoredCoverageNotCoverable {
380+
self.dcx().emit_err(errors::CoverageNotFnOrClosure {
413381
attr_span: attr.span,
414382
defn_span: span,
415383
});

Diff for: ‎compiler/rustc_passes/src/errors.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,9 @@ pub struct InlineNotFnOrClosure {
6060
pub defn_span: Span,
6161
}
6262

63-
#[derive(LintDiagnostic)]
64-
#[diag(passes_coverage_ignored_function_prototype)]
65-
pub struct IgnoredCoverageFnProto;
66-
67-
#[derive(LintDiagnostic)]
68-
#[diag(passes_coverage_propagate)]
69-
pub struct IgnoredCoveragePropagate;
70-
71-
#[derive(LintDiagnostic)]
72-
#[diag(passes_coverage_fn_defn)]
73-
pub struct IgnoredCoverageFnDefn;
74-
7563
#[derive(Diagnostic)]
76-
#[diag(passes_coverage_not_coverable, code = E0788)]
77-
pub struct IgnoredCoverageNotCoverable {
64+
#[diag(passes_coverage_not_fn_or_closure, code = E0788)]
65+
pub struct CoverageNotFnOrClosure {
7866
#[primary_span]
7967
pub attr_span: Span,
8068
#[label]

Diff for: ‎tests/ui/coverage-attr/bad-syntax.rs

+13-26
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,45 @@
11
#![feature(coverage_attribute)]
2+
//@ edition: 2021
23

34
// Tests the error messages produced (or not produced) by various unusual
45
// uses of the `#[coverage(..)]` attribute.
56

6-
// FIXME(#126658): Multiple coverage attributes with the same value are useless,
7-
// and should probably produce a diagnostic.
8-
#[coverage(off)]
7+
#[coverage(off)] //~ ERROR multiple `coverage` attributes
98
#[coverage(off)]
109
fn multiple_consistent() {}
1110

12-
// FIXME(#126658): When there are multiple inconsistent coverage attributes,
13-
// it's unclear which one will prevail.
14-
#[coverage(off)]
11+
#[coverage(off)] //~ ERROR multiple `coverage` attributes
1512
#[coverage(on)]
1613
fn multiple_inconsistent() {}
1714

18-
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
15+
#[coverage] //~ ERROR malformed `coverage` attribute input
1916
fn bare_word() {}
2017

21-
// FIXME(#126658): This shows as multiple different errors, one of which suggests
22-
// writing bare `#[coverage]`, which is not allowed.
23-
#[coverage = true]
24-
//~^ ERROR expected `coverage(off)` or `coverage(on)`
25-
//~| ERROR malformed `coverage` attribute input
26-
//~| HELP the following are the possible correct uses
27-
//~| SUGGESTION #[coverage(on|off)]
18+
#[coverage = true] //~ ERROR malformed `coverage` attribute input
2819
fn key_value() {}
2920

30-
#[coverage()] //~ ERROR expected `coverage(off)` or `coverage(on)`
21+
#[coverage()] //~ ERROR malformed `coverage` attribute input
3122
fn list_empty() {}
3223

33-
#[coverage(off, off)] //~ ERROR expected `coverage(off)` or `coverage(on)`
24+
#[coverage(off, off)] //~ ERROR malformed `coverage` attribute input
3425
fn list_consistent() {}
3526

36-
#[coverage(off, on)] //~ ERROR expected `coverage(off)` or `coverage(on)`
27+
#[coverage(off, on)] //~ ERROR malformed `coverage` attribute input
3728
fn list_inconsistent() {}
3829

39-
#[coverage(bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)`
30+
#[coverage(bogus)] //~ ERROR malformed `coverage` attribute input
4031
fn bogus_word() {}
4132

42-
#[coverage(bogus, off)] //~ ERROR expected `coverage(off)` or `coverage(on)`
33+
#[coverage(bogus, off)] //~ ERROR malformed `coverage` attribute input
4334
fn bogus_word_before() {}
4435

45-
#[coverage(off, bogus)] //~ ERROR expected `coverage(off)` or `coverage(on)`
36+
#[coverage(off, bogus)] //~ ERROR malformed `coverage` attribute input
4637
fn bogus_word_after() {}
4738

48-
#[coverage(off,)]
39+
#[coverage(off,)] // (OK!)
4940
fn comma_after() {}
5041

51-
// FIXME(#126658): This shows as multiple different errors.
52-
#[coverage(,off)]
53-
//~^ ERROR expected identifier, found `,`
54-
//~| HELP remove this comma
55-
//~| ERROR expected `coverage(off)` or `coverage(on)`
42+
#[coverage(,off)] //~ ERROR expected identifier, found `,`
5643
fn comma_before() {}
5744

5845
fn main() {}

Diff for: ‎tests/ui/coverage-attr/bad-syntax.stderr

+99-38
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,139 @@
11
error: malformed `coverage` attribute input
2-
--> $DIR/bad-syntax.rs:23:1
3-
|
4-
LL | #[coverage = true]
5-
| ^^^^^^^^^^^^^^^^^^
6-
|
7-
help: the following are the possible correct uses
8-
|
9-
LL | #[coverage(on|off)]
2+
--> $DIR/bad-syntax.rs:15:1
103
|
114
LL | #[coverage]
5+
| ^^^^^^^^^^^
126
|
13-
14-
error: expected identifier, found `,`
15-
--> $DIR/bad-syntax.rs:52:12
7+
help: the following are the possible correct uses
168
|
17-
LL | #[coverage(,off)]
18-
| ^
19-
| |
20-
| expected identifier
21-
| help: remove this comma
9+
LL | #[coverage(off)]
10+
| ~~~~~~~~~~~~~~~~
11+
LL | #[coverage(on)]
12+
| ~~~~~~~~~~~~~~~
2213

23-
error: expected `coverage(off)` or `coverage(on)`
14+
error: malformed `coverage` attribute input
2415
--> $DIR/bad-syntax.rs:18:1
2516
|
26-
LL | #[coverage]
27-
| ^^^^^^^^^^^
28-
29-
error: expected `coverage(off)` or `coverage(on)`
30-
--> $DIR/bad-syntax.rs:23:1
31-
|
3217
LL | #[coverage = true]
3318
| ^^^^^^^^^^^^^^^^^^
19+
|
20+
help: the following are the possible correct uses
21+
|
22+
LL | #[coverage(off)]
23+
| ~~~~~~~~~~~~~~~~
24+
LL | #[coverage(on)]
25+
| ~~~~~~~~~~~~~~~
3426

35-
error: expected `coverage(off)` or `coverage(on)`
36-
--> $DIR/bad-syntax.rs:30:1
27+
error: malformed `coverage` attribute input
28+
--> $DIR/bad-syntax.rs:21:1
3729
|
3830
LL | #[coverage()]
3931
| ^^^^^^^^^^^^^
32+
|
33+
help: the following are the possible correct uses
34+
|
35+
LL | #[coverage(off)]
36+
| ~~~~~~~~~~~~~~~~
37+
LL | #[coverage(on)]
38+
| ~~~~~~~~~~~~~~~
4039

41-
error: expected `coverage(off)` or `coverage(on)`
42-
--> $DIR/bad-syntax.rs:33:1
40+
error: malformed `coverage` attribute input
41+
--> $DIR/bad-syntax.rs:24:1
4342
|
4443
LL | #[coverage(off, off)]
4544
| ^^^^^^^^^^^^^^^^^^^^^
45+
|
46+
help: the following are the possible correct uses
47+
|
48+
LL | #[coverage(off)]
49+
| ~~~~~~~~~~~~~~~~
50+
LL | #[coverage(on)]
51+
| ~~~~~~~~~~~~~~~
4652

47-
error: expected `coverage(off)` or `coverage(on)`
48-
--> $DIR/bad-syntax.rs:36:1
53+
error: malformed `coverage` attribute input
54+
--> $DIR/bad-syntax.rs:27:1
4955
|
5056
LL | #[coverage(off, on)]
5157
| ^^^^^^^^^^^^^^^^^^^^
58+
|
59+
help: the following are the possible correct uses
60+
|
61+
LL | #[coverage(off)]
62+
| ~~~~~~~~~~~~~~~~
63+
LL | #[coverage(on)]
64+
| ~~~~~~~~~~~~~~~
5265

53-
error: expected `coverage(off)` or `coverage(on)`
54-
--> $DIR/bad-syntax.rs:39:1
66+
error: malformed `coverage` attribute input
67+
--> $DIR/bad-syntax.rs:30:1
5568
|
5669
LL | #[coverage(bogus)]
5770
| ^^^^^^^^^^^^^^^^^^
71+
|
72+
help: the following are the possible correct uses
73+
|
74+
LL | #[coverage(off)]
75+
| ~~~~~~~~~~~~~~~~
76+
LL | #[coverage(on)]
77+
| ~~~~~~~~~~~~~~~
5878

59-
error: expected `coverage(off)` or `coverage(on)`
60-
--> $DIR/bad-syntax.rs:42:1
79+
error: malformed `coverage` attribute input
80+
--> $DIR/bad-syntax.rs:33:1
6181
|
6282
LL | #[coverage(bogus, off)]
6383
| ^^^^^^^^^^^^^^^^^^^^^^^
84+
|
85+
help: the following are the possible correct uses
86+
|
87+
LL | #[coverage(off)]
88+
| ~~~~~~~~~~~~~~~~
89+
LL | #[coverage(on)]
90+
| ~~~~~~~~~~~~~~~
6491

65-
error: expected `coverage(off)` or `coverage(on)`
66-
--> $DIR/bad-syntax.rs:45:1
92+
error: malformed `coverage` attribute input
93+
--> $DIR/bad-syntax.rs:36:1
6794
|
6895
LL | #[coverage(off, bogus)]
6996
| ^^^^^^^^^^^^^^^^^^^^^^^
97+
|
98+
help: the following are the possible correct uses
99+
|
100+
LL | #[coverage(off)]
101+
| ~~~~~~~~~~~~~~~~
102+
LL | #[coverage(on)]
103+
| ~~~~~~~~~~~~~~~
70104

71-
error: expected `coverage(off)` or `coverage(on)`
72-
--> $DIR/bad-syntax.rs:52:1
105+
error: expected identifier, found `,`
106+
--> $DIR/bad-syntax.rs:42:12
73107
|
74108
LL | #[coverage(,off)]
75-
| ^^^^^^^^^^^^^^^^^
109+
| ^
110+
| |
111+
| expected identifier
112+
| help: remove this comma
113+
114+
error: multiple `coverage` attributes
115+
--> $DIR/bad-syntax.rs:7:1
116+
|
117+
LL | #[coverage(off)]
118+
| ^^^^^^^^^^^^^^^^ help: remove this attribute
119+
|
120+
note: attribute also specified here
121+
--> $DIR/bad-syntax.rs:8:1
122+
|
123+
LL | #[coverage(off)]
124+
| ^^^^^^^^^^^^^^^^
125+
126+
error: multiple `coverage` attributes
127+
--> $DIR/bad-syntax.rs:11:1
128+
|
129+
LL | #[coverage(off)]
130+
| ^^^^^^^^^^^^^^^^ help: remove this attribute
131+
|
132+
note: attribute also specified here
133+
--> $DIR/bad-syntax.rs:12:1
134+
|
135+
LL | #[coverage(on)]
136+
| ^^^^^^^^^^^^^^^
76137

77138
error: aborting due to 11 previous errors
78139

Diff for: ‎tests/ui/coverage-attr/name-value.rs

+28-23
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,62 @@
88
// and in places that cannot have a coverage attribute, to demonstrate the
99
// interaction between multiple errors.
1010

11-
// FIXME(#126658): The error messages for using this syntax are inconsistent
12-
// with the error message in other cases. They also sometimes appear together
13-
// with other errors, and they suggest using the incorrect `#[coverage]` syntax.
14-
15-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
11+
#[coverage = "off"]
12+
//~^ ERROR malformed `coverage` attribute input
13+
//~| ERROR attribute should be applied to a function definition or closure
1614
mod my_mod {}
1715

1816
mod my_mod_inner {
19-
#![coverage = "off"] //~ ERROR malformed `coverage` attribute input
17+
#![coverage = "off"]
18+
//~^ ERROR malformed `coverage` attribute input
19+
//~| ERROR attribute should be applied to a function definition or closure
2020
}
2121

2222
#[coverage = "off"]
23-
//~^ ERROR `#[coverage]` must be applied to coverable code
24-
//~| ERROR malformed `coverage` attribute input
23+
//~^ ERROR malformed `coverage` attribute input
24+
//~| ERROR attribute should be applied to a function definition or closure
2525
struct MyStruct;
2626

27-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
27+
#[coverage = "off"]
28+
//~^ ERROR malformed `coverage` attribute input
29+
//~| ERROR attribute should be applied to a function definition or closure
2830
impl MyStruct {
2931
#[coverage = "off"]
30-
//~^ ERROR `#[coverage]` must be applied to coverable code
31-
//~| ERROR malformed `coverage` attribute input
32+
//~^ ERROR malformed `coverage` attribute input
33+
//~| ERROR attribute should be applied to a function definition or closure
3234
const X: u32 = 7;
3335
}
3436

35-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
37+
#[coverage = "off"]
38+
//~^ ERROR malformed `coverage` attribute input
39+
//~| ERROR attribute should be applied to a function definition or closure
3640
trait MyTrait {
3741
#[coverage = "off"]
38-
//~^ ERROR `#[coverage]` must be applied to coverable code
39-
//~| ERROR malformed `coverage` attribute input
42+
//~^ ERROR malformed `coverage` attribute input
43+
//~| ERROR attribute should be applied to a function definition or closure
4044
const X: u32;
4145

4246
#[coverage = "off"]
43-
//~^ ERROR `#[coverage]` must be applied to coverable code
44-
//~| ERROR malformed `coverage` attribute input
47+
//~^ ERROR malformed `coverage` attribute input
48+
//~| ERROR attribute should be applied to a function definition or closure
4549
type T;
4650
}
4751

48-
#[coverage = "off"] //~ ERROR malformed `coverage` attribute input
52+
#[coverage = "off"]
53+
//~^ ERROR malformed `coverage` attribute input
54+
//~| ERROR attribute should be applied to a function definition or closure
4955
impl MyTrait for MyStruct {
5056
#[coverage = "off"]
51-
//~^ ERROR `#[coverage]` must be applied to coverable code
52-
//~| ERROR malformed `coverage` attribute input
57+
//~^ ERROR malformed `coverage` attribute input
58+
//~| ERROR attribute should be applied to a function definition or closure
5359
const X: u32 = 8;
5460

5561
#[coverage = "off"]
56-
//~^ ERROR `#[coverage]` must be applied to coverable code
57-
//~| ERROR malformed `coverage` attribute input
62+
//~^ ERROR malformed `coverage` attribute input
63+
//~| ERROR attribute should be applied to a function definition or closure
5864
type T = ();
5965
}
6066

6167
#[coverage = "off"]
62-
//~^ ERROR expected `coverage(off)` or `coverage(on)`
63-
//~| ERROR malformed `coverage` attribute input
68+
//~^ ERROR malformed `coverage` attribute input
6469
fn main() {}

Diff for: ‎tests/ui/coverage-attr/name-value.stderr

+126-68
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
error: malformed `coverage` attribute input
2-
--> $DIR/name-value.rs:15:1
2+
--> $DIR/name-value.rs:11:1
33
|
44
LL | #[coverage = "off"]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
77
help: the following are the possible correct uses
88
|
9-
LL | #[coverage(on|off)]
10-
| ~~~~~~~~~~~~~~~~~~~
11-
LL | #[coverage]
12-
| ~~~~~~~~~~~
9+
LL | #[coverage(off)]
10+
|
11+
LL | #[coverage(on)]
12+
|
1313

1414
error: malformed `coverage` attribute input
15-
--> $DIR/name-value.rs:19:5
15+
--> $DIR/name-value.rs:17:5
1616
|
1717
LL | #![coverage = "off"]
1818
| ^^^^^^^^^^^^^^^^^^^^
1919
|
2020
help: the following are the possible correct uses
2121
|
22-
LL | #![coverage(on|off)]
23-
| ~~~~~~~~~~~~~~~~~~~~
24-
LL | #![coverage]
25-
| ~~~~~~~~~~~~
22+
LL | #![coverage(off)]
23+
|
24+
LL | #![coverage(on)]
25+
|
2626

2727
error: malformed `coverage` attribute input
2828
--> $DIR/name-value.rs:22:1
@@ -32,22 +32,22 @@ LL | #[coverage = "off"]
3232
|
3333
help: the following are the possible correct uses
3434
|
35-
LL | #[coverage(on|off)]
35+
LL | #[coverage(off)]
3636
|
37-
LL | #[coverage]
37+
LL | #[coverage(on)]
3838
|
3939

4040
error: malformed `coverage` attribute input
41-
--> $DIR/name-value.rs:29:5
41+
--> $DIR/name-value.rs:31:5
4242
|
4343
LL | #[coverage = "off"]
4444
| ^^^^^^^^^^^^^^^^^^^
4545
|
4646
help: the following are the possible correct uses
4747
|
48-
LL | #[coverage(on|off)]
48+
LL | #[coverage(off)]
4949
|
50-
LL | #[coverage]
50+
LL | #[coverage(on)]
5151
|
5252

5353
error: malformed `coverage` attribute input
@@ -58,162 +58,220 @@ LL | #[coverage = "off"]
5858
|
5959
help: the following are the possible correct uses
6060
|
61-
LL | #[coverage(on|off)]
62-
| ~~~~~~~~~~~~~~~~~~~
63-
LL | #[coverage]
64-
| ~~~~~~~~~~~
61+
LL | #[coverage(off)]
62+
|
63+
LL | #[coverage(on)]
64+
|
6565

6666
error: malformed `coverage` attribute input
67-
--> $DIR/name-value.rs:37:5
67+
--> $DIR/name-value.rs:41:5
6868
|
6969
LL | #[coverage = "off"]
7070
| ^^^^^^^^^^^^^^^^^^^
7171
|
7272
help: the following are the possible correct uses
7373
|
74-
LL | #[coverage(on|off)]
74+
LL | #[coverage(off)]
7575
|
76-
LL | #[coverage]
76+
LL | #[coverage(on)]
7777
|
7878

7979
error: malformed `coverage` attribute input
80-
--> $DIR/name-value.rs:42:5
80+
--> $DIR/name-value.rs:46:5
8181
|
8282
LL | #[coverage = "off"]
8383
| ^^^^^^^^^^^^^^^^^^^
8484
|
8585
help: the following are the possible correct uses
8686
|
87-
LL | #[coverage(on|off)]
87+
LL | #[coverage(off)]
8888
|
89-
LL | #[coverage]
89+
LL | #[coverage(on)]
9090
|
9191

9292
error: malformed `coverage` attribute input
93-
--> $DIR/name-value.rs:35:1
93+
--> $DIR/name-value.rs:37:1
9494
|
9595
LL | #[coverage = "off"]
9696
| ^^^^^^^^^^^^^^^^^^^
9797
|
9898
help: the following are the possible correct uses
9999
|
100-
LL | #[coverage(on|off)]
101-
| ~~~~~~~~~~~~~~~~~~~
102-
LL | #[coverage]
103-
| ~~~~~~~~~~~
100+
LL | #[coverage(off)]
101+
|
102+
LL | #[coverage(on)]
103+
|
104104

105105
error: malformed `coverage` attribute input
106-
--> $DIR/name-value.rs:50:5
106+
--> $DIR/name-value.rs:56:5
107107
|
108108
LL | #[coverage = "off"]
109109
| ^^^^^^^^^^^^^^^^^^^
110110
|
111111
help: the following are the possible correct uses
112112
|
113-
LL | #[coverage(on|off)]
113+
LL | #[coverage(off)]
114114
|
115-
LL | #[coverage]
115+
LL | #[coverage(on)]
116116
|
117117

118118
error: malformed `coverage` attribute input
119-
--> $DIR/name-value.rs:55:5
119+
--> $DIR/name-value.rs:61:5
120120
|
121121
LL | #[coverage = "off"]
122122
| ^^^^^^^^^^^^^^^^^^^
123123
|
124124
help: the following are the possible correct uses
125125
|
126-
LL | #[coverage(on|off)]
126+
LL | #[coverage(off)]
127127
|
128-
LL | #[coverage]
128+
LL | #[coverage(on)]
129129
|
130130

131131
error: malformed `coverage` attribute input
132-
--> $DIR/name-value.rs:48:1
132+
--> $DIR/name-value.rs:52:1
133133
|
134134
LL | #[coverage = "off"]
135135
| ^^^^^^^^^^^^^^^^^^^
136136
|
137137
help: the following are the possible correct uses
138138
|
139-
LL | #[coverage(on|off)]
140-
| ~~~~~~~~~~~~~~~~~~~
141-
LL | #[coverage]
142-
| ~~~~~~~~~~~
139+
LL | #[coverage(off)]
140+
|
141+
LL | #[coverage(on)]
142+
|
143143

144144
error: malformed `coverage` attribute input
145-
--> $DIR/name-value.rs:61:1
145+
--> $DIR/name-value.rs:67:1
146146
|
147147
LL | #[coverage = "off"]
148148
| ^^^^^^^^^^^^^^^^^^^
149149
|
150150
help: the following are the possible correct uses
151151
|
152-
LL | #[coverage(on|off)]
152+
LL | #[coverage(off)]
153153
|
154-
LL | #[coverage]
154+
LL | #[coverage(on)]
155+
|
156+
157+
error[E0788]: attribute should be applied to a function definition or closure
158+
--> $DIR/name-value.rs:11:1
155159
|
160+
LL | #[coverage = "off"]
161+
| ^^^^^^^^^^^^^^^^^^^
162+
...
163+
LL | mod my_mod {}
164+
| ------------- not a function or closure
156165

157-
error[E0788]: `#[coverage]` must be applied to coverable code
166+
error[E0788]: attribute should be applied to a function definition or closure
167+
--> $DIR/name-value.rs:17:5
168+
|
169+
LL | / mod my_mod_inner {
170+
LL | | #![coverage = "off"]
171+
| | ^^^^^^^^^^^^^^^^^^^^
172+
LL | |
173+
LL | |
174+
LL | | }
175+
| |_- not a function or closure
176+
177+
error[E0788]: attribute should be applied to a function definition or closure
158178
--> $DIR/name-value.rs:22:1
159179
|
160180
LL | #[coverage = "off"]
161181
| ^^^^^^^^^^^^^^^^^^^
162182
...
163183
LL | struct MyStruct;
164-
| ---------------- not coverable code
184+
| ---------------- not a function or closure
185+
186+
error[E0788]: attribute should be applied to a function definition or closure
187+
--> $DIR/name-value.rs:27:1
188+
|
189+
LL | #[coverage = "off"]
190+
| ^^^^^^^^^^^^^^^^^^^
191+
...
192+
LL | / impl MyStruct {
193+
LL | | #[coverage = "off"]
194+
LL | |
195+
LL | |
196+
LL | | const X: u32 = 7;
197+
LL | | }
198+
| |_- not a function or closure
199+
200+
error[E0788]: attribute should be applied to a function definition or closure
201+
--> $DIR/name-value.rs:37:1
202+
|
203+
LL | #[coverage = "off"]
204+
| ^^^^^^^^^^^^^^^^^^^
205+
...
206+
LL | / trait MyTrait {
207+
LL | | #[coverage = "off"]
208+
LL | |
209+
LL | |
210+
... |
211+
LL | | type T;
212+
LL | | }
213+
| |_- not a function or closure
165214

166-
error[E0788]: `#[coverage]` must be applied to coverable code
167-
--> $DIR/name-value.rs:37:5
215+
error[E0788]: attribute should be applied to a function definition or closure
216+
--> $DIR/name-value.rs:52:1
217+
|
218+
LL | #[coverage = "off"]
219+
| ^^^^^^^^^^^^^^^^^^^
220+
...
221+
LL | / impl MyTrait for MyStruct {
222+
LL | | #[coverage = "off"]
223+
LL | |
224+
LL | |
225+
... |
226+
LL | | type T = ();
227+
LL | | }
228+
| |_- not a function or closure
229+
230+
error[E0788]: attribute should be applied to a function definition or closure
231+
--> $DIR/name-value.rs:41:5
168232
|
169233
LL | #[coverage = "off"]
170234
| ^^^^^^^^^^^^^^^^^^^
171235
...
172236
LL | const X: u32;
173-
| ------------- not coverable code
237+
| ------------- not a function or closure
174238

175-
error[E0788]: `#[coverage]` must be applied to coverable code
176-
--> $DIR/name-value.rs:42:5
239+
error[E0788]: attribute should be applied to a function definition or closure
240+
--> $DIR/name-value.rs:46:5
177241
|
178242
LL | #[coverage = "off"]
179243
| ^^^^^^^^^^^^^^^^^^^
180244
...
181245
LL | type T;
182-
| ------- not coverable code
246+
| ------- not a function or closure
183247

184-
error[E0788]: `#[coverage]` must be applied to coverable code
185-
--> $DIR/name-value.rs:29:5
248+
error[E0788]: attribute should be applied to a function definition or closure
249+
--> $DIR/name-value.rs:31:5
186250
|
187251
LL | #[coverage = "off"]
188252
| ^^^^^^^^^^^^^^^^^^^
189253
...
190254
LL | const X: u32 = 7;
191-
| ----------------- not coverable code
255+
| ----------------- not a function or closure
192256

193-
error[E0788]: `#[coverage]` must be applied to coverable code
194-
--> $DIR/name-value.rs:50:5
257+
error[E0788]: attribute should be applied to a function definition or closure
258+
--> $DIR/name-value.rs:56:5
195259
|
196260
LL | #[coverage = "off"]
197261
| ^^^^^^^^^^^^^^^^^^^
198262
...
199263
LL | const X: u32 = 8;
200-
| ----------------- not coverable code
264+
| ----------------- not a function or closure
201265

202-
error[E0788]: `#[coverage]` must be applied to coverable code
203-
--> $DIR/name-value.rs:55:5
266+
error[E0788]: attribute should be applied to a function definition or closure
267+
--> $DIR/name-value.rs:61:5
204268
|
205269
LL | #[coverage = "off"]
206270
| ^^^^^^^^^^^^^^^^^^^
207271
...
208272
LL | type T = ();
209-
| ------------ not coverable code
210-
211-
error: expected `coverage(off)` or `coverage(on)`
212-
--> $DIR/name-value.rs:61:1
213-
|
214-
LL | #[coverage = "off"]
215-
| ^^^^^^^^^^^^^^^^^^^
273+
| ------------ not a function or closure
216274

217-
error: aborting due to 19 previous errors
275+
error: aborting due to 23 previous errors
218276

219277
For more information about this error, try `rustc --explain E0788`.

Diff for: ‎tests/ui/coverage-attr/no-coverage.rs

+12-18
Original file line numberDiff line numberDiff line change
@@ -2,54 +2,48 @@
22
#![feature(coverage_attribute)]
33
#![feature(impl_trait_in_assoc_type)]
44
#![warn(unused_attributes)]
5-
#![coverage(off)]
6-
//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
5+
#![coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
76

8-
#[coverage(off)]
9-
//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
7+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
108
trait Trait {
11-
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code
9+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
1210
const X: u32;
1311

14-
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code
12+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
1513
type T;
1614

1715
type U;
1816
}
1917

20-
#[coverage(off)]
21-
//~^ WARN: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
18+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
2219
impl Trait for () {
2320
const X: u32 = 0;
2421

25-
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code
22+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
2623
type T = Self;
2724

28-
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code
25+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
2926
type U = impl Trait; //~ ERROR unconstrained opaque type
3027
}
3128

3229
extern "C" {
33-
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code
30+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
3431
static X: u32;
3532

36-
#[coverage(off)] //~ ERROR `#[coverage]` must be applied to coverable code
33+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
3734
type T;
3835
}
3936

4037
#[coverage(off)]
4138
fn main() {
42-
#[coverage(off)]
43-
//~^ WARN `#[coverage]` may only be applied to function definitions
39+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
4440
let _ = ();
4541

4642
match () {
47-
#[coverage(off)]
48-
//~^ WARN `#[coverage]` may only be applied to function definitions
43+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
4944
() => (),
5045
}
5146

52-
#[coverage(off)]
53-
//~^ WARN `#[coverage]` may only be applied to function definitions
47+
#[coverage(off)] //~ ERROR attribute should be applied to a function definition or closure
5448
return ();
5549
}

Diff for: ‎tests/ui/coverage-attr/no-coverage.stderr

+59-44
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,116 @@
1-
warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
2-
--> $DIR/no-coverage.rs:8:1
3-
|
4-
LL | #[coverage(off)]
5-
| ^^^^^^^^^^^^^^^^
6-
|
7-
note: the lint level is defined here
8-
--> $DIR/no-coverage.rs:4:9
9-
|
10-
LL | #![warn(unused_attributes)]
11-
| ^^^^^^^^^^^^^^^^^
1+
error[E0788]: attribute should be applied to a function definition or closure
2+
--> $DIR/no-coverage.rs:7:1
3+
|
4+
LL | #[coverage(off)]
5+
| ^^^^^^^^^^^^^^^^
6+
LL | / trait Trait {
7+
LL | | #[coverage(off)]
8+
LL | | const X: u32;
9+
... |
10+
LL | | type U;
11+
LL | | }
12+
| |_- not a function or closure
1213

13-
warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
14-
--> $DIR/no-coverage.rs:20:1
15-
|
16-
LL | #[coverage(off)]
17-
| ^^^^^^^^^^^^^^^^
14+
error[E0788]: attribute should be applied to a function definition or closure
15+
--> $DIR/no-coverage.rs:18:1
16+
|
17+
LL | #[coverage(off)]
18+
| ^^^^^^^^^^^^^^^^
19+
LL | / impl Trait for () {
20+
LL | | const X: u32 = 0;
21+
LL | |
22+
LL | | #[coverage(off)]
23+
... |
24+
LL | | type U = impl Trait;
25+
LL | | }
26+
| |_- not a function or closure
1827

19-
warning: `#[coverage]` may only be applied to function definitions
20-
--> $DIR/no-coverage.rs:42:5
28+
error[E0788]: attribute should be applied to a function definition or closure
29+
--> $DIR/no-coverage.rs:39:5
2130
|
2231
LL | #[coverage(off)]
2332
| ^^^^^^^^^^^^^^^^
33+
LL | let _ = ();
34+
| ----------- not a function or closure
2435

25-
warning: `#[coverage]` may only be applied to function definitions
26-
--> $DIR/no-coverage.rs:47:9
36+
error[E0788]: attribute should be applied to a function definition or closure
37+
--> $DIR/no-coverage.rs:43:9
2738
|
2839
LL | #[coverage(off)]
2940
| ^^^^^^^^^^^^^^^^
41+
LL | () => (),
42+
| -------- not a function or closure
3043

31-
warning: `#[coverage]` may only be applied to function definitions
32-
--> $DIR/no-coverage.rs:52:5
44+
error[E0788]: attribute should be applied to a function definition or closure
45+
--> $DIR/no-coverage.rs:47:5
3346
|
3447
LL | #[coverage(off)]
3548
| ^^^^^^^^^^^^^^^^
49+
LL | return ();
50+
| --------- not a function or closure
3651

37-
error[E0788]: `#[coverage]` must be applied to coverable code
38-
--> $DIR/no-coverage.rs:11:5
52+
error[E0788]: attribute should be applied to a function definition or closure
53+
--> $DIR/no-coverage.rs:9:5
3954
|
4055
LL | #[coverage(off)]
4156
| ^^^^^^^^^^^^^^^^
4257
LL | const X: u32;
43-
| ------------- not coverable code
58+
| ------------- not a function or closure
4459

45-
error[E0788]: `#[coverage]` must be applied to coverable code
46-
--> $DIR/no-coverage.rs:14:5
60+
error[E0788]: attribute should be applied to a function definition or closure
61+
--> $DIR/no-coverage.rs:12:5
4762
|
4863
LL | #[coverage(off)]
4964
| ^^^^^^^^^^^^^^^^
5065
LL | type T;
51-
| ------- not coverable code
66+
| ------- not a function or closure
5267

53-
error[E0788]: `#[coverage]` must be applied to coverable code
54-
--> $DIR/no-coverage.rs:25:5
68+
error[E0788]: attribute should be applied to a function definition or closure
69+
--> $DIR/no-coverage.rs:22:5
5570
|
5671
LL | #[coverage(off)]
5772
| ^^^^^^^^^^^^^^^^
5873
LL | type T = Self;
59-
| -------------- not coverable code
74+
| -------------- not a function or closure
6075

61-
error[E0788]: `#[coverage]` must be applied to coverable code
62-
--> $DIR/no-coverage.rs:28:5
76+
error[E0788]: attribute should be applied to a function definition or closure
77+
--> $DIR/no-coverage.rs:25:5
6378
|
6479
LL | #[coverage(off)]
6580
| ^^^^^^^^^^^^^^^^
6681
LL | type U = impl Trait;
67-
| -------------------- not coverable code
82+
| -------------------- not a function or closure
6883

69-
error[E0788]: `#[coverage]` must be applied to coverable code
70-
--> $DIR/no-coverage.rs:33:5
84+
error[E0788]: attribute should be applied to a function definition or closure
85+
--> $DIR/no-coverage.rs:30:5
7186
|
7287
LL | #[coverage(off)]
7388
| ^^^^^^^^^^^^^^^^
7489
LL | static X: u32;
75-
| -------------- not coverable code
90+
| -------------- not a function or closure
7691

77-
error[E0788]: `#[coverage]` must be applied to coverable code
78-
--> $DIR/no-coverage.rs:36:5
92+
error[E0788]: attribute should be applied to a function definition or closure
93+
--> $DIR/no-coverage.rs:33:5
7994
|
8095
LL | #[coverage(off)]
8196
| ^^^^^^^^^^^^^^^^
8297
LL | type T;
83-
| ------- not coverable code
98+
| ------- not a function or closure
8499

85-
warning: `#[coverage]` does not propagate into items and must be applied to the contained functions directly
100+
error[E0788]: attribute should be applied to a function definition or closure
86101
--> $DIR/no-coverage.rs:5:1
87102
|
88103
LL | #![coverage(off)]
89-
| ^^^^^^^^^^^^^^^^^
104+
| ^^^^^^^^^^^^^^^^^ not a function or closure
90105

91106
error: unconstrained opaque type
92-
--> $DIR/no-coverage.rs:29:14
107+
--> $DIR/no-coverage.rs:26:14
93108
|
94109
LL | type U = impl Trait;
95110
| ^^^^^^^^^^
96111
|
97112
= note: `U` must be used in combination with a concrete type within the same impl
98113

99-
error: aborting due to 7 previous errors; 6 warnings emitted
114+
error: aborting due to 13 previous errors
100115

101116
For more information about this error, try `rustc --explain E0788`.

Diff for: ‎tests/ui/coverage-attr/subword.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
// Check that yes/no in `#[coverage(yes)]` and `#[coverage(no)]` must be bare
55
// words, not part of a more complicated substructure.
66

7-
#[coverage(yes(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)`
7+
#[coverage(yes(milord))] //~ ERROR malformed `coverage` attribute input
88
fn yes_list() {}
99

10-
#[coverage(no(milord))] //~ ERROR expected `coverage(off)` or `coverage(on)`
10+
#[coverage(no(milord))] //~ ERROR malformed `coverage` attribute input
1111
fn no_list() {}
1212

13-
#[coverage(yes = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)`
13+
#[coverage(yes = "milord")] //~ ERROR malformed `coverage` attribute input
1414
fn yes_key() {}
1515

16-
#[coverage(no = "milord")] //~ ERROR expected `coverage(off)` or `coverage(on)`
16+
#[coverage(no = "milord")] //~ ERROR malformed `coverage` attribute input
1717
fn no_key() {}
1818

1919
fn main() {}

Diff for: ‎tests/ui/coverage-attr/subword.stderr

+32-4
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,54 @@
1-
error: expected `coverage(off)` or `coverage(on)`
1+
error: malformed `coverage` attribute input
22
--> $DIR/subword.rs:7:1
33
|
44
LL | #[coverage(yes(milord))]
55
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: the following are the possible correct uses
8+
|
9+
LL | #[coverage(off)]
10+
| ~~~~~~~~~~~~~~~~
11+
LL | #[coverage(on)]
12+
| ~~~~~~~~~~~~~~~
613

7-
error: expected `coverage(off)` or `coverage(on)`
14+
error: malformed `coverage` attribute input
815
--> $DIR/subword.rs:10:1
916
|
1017
LL | #[coverage(no(milord))]
1118
| ^^^^^^^^^^^^^^^^^^^^^^^
19+
|
20+
help: the following are the possible correct uses
21+
|
22+
LL | #[coverage(off)]
23+
| ~~~~~~~~~~~~~~~~
24+
LL | #[coverage(on)]
25+
| ~~~~~~~~~~~~~~~
1226

13-
error: expected `coverage(off)` or `coverage(on)`
27+
error: malformed `coverage` attribute input
1428
--> $DIR/subword.rs:13:1
1529
|
1630
LL | #[coverage(yes = "milord")]
1731
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
32+
|
33+
help: the following are the possible correct uses
34+
|
35+
LL | #[coverage(off)]
36+
| ~~~~~~~~~~~~~~~~
37+
LL | #[coverage(on)]
38+
| ~~~~~~~~~~~~~~~
1839

19-
error: expected `coverage(off)` or `coverage(on)`
40+
error: malformed `coverage` attribute input
2041
--> $DIR/subword.rs:16:1
2142
|
2243
LL | #[coverage(no = "milord")]
2344
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
45+
|
46+
help: the following are the possible correct uses
47+
|
48+
LL | #[coverage(off)]
49+
| ~~~~~~~~~~~~~~~~
50+
LL | #[coverage(on)]
51+
| ~~~~~~~~~~~~~~~
2452

2553
error: aborting due to 4 previous errors
2654

Diff for: ‎tests/ui/coverage-attr/word-only.rs

+30-15
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,62 @@
88
// and in places that cannot have a coverage attribute, to demonstrate the
99
// interaction between multiple errors.
1010

11-
// FIXME(#126658): The error messages for using this syntax give the impression
12-
// that it is legal, even though it should never be legal.
13-
14-
// FIXME(#126658): This is silently allowed, but should not be.
1511
#[coverage]
12+
//~^ ERROR malformed `coverage` attribute input
13+
//~| ERROR attribute should be applied to a function definition or closure
1614
mod my_mod {}
1715

18-
// FIXME(#126658): This is silently allowed, but should not be.
1916
mod my_mod_inner {
2017
#![coverage]
18+
//~^ ERROR malformed `coverage` attribute input
19+
//~| ERROR attribute should be applied to a function definition or closure
2120
}
2221

23-
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
22+
#[coverage]
23+
//~^ ERROR malformed `coverage` attribute input
24+
//~| ERROR attribute should be applied to a function definition or closure
2425
struct MyStruct;
2526

26-
// FIXME(#126658): This is silently allowed, but should not be.
2727
#[coverage]
28+
//~^ ERROR malformed `coverage` attribute input
29+
//~| ERROR attribute should be applied to a function definition or closure
2830
impl MyStruct {
29-
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
31+
#[coverage]
32+
//~^ ERROR malformed `coverage` attribute input
33+
//~| ERROR attribute should be applied to a function definition or closure
3034
const X: u32 = 7;
3135
}
3236

33-
// FIXME(#126658): This is silently allowed, but should not be.
3437
#[coverage]
38+
//~^ ERROR malformed `coverage` attribute input
39+
//~| ERROR attribute should be applied to a function definition or closure
3540
trait MyTrait {
36-
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
41+
#[coverage]
42+
//~^ ERROR malformed `coverage` attribute input
43+
//~| ERROR attribute should be applied to a function definition or closure
3744
const X: u32;
3845

39-
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
46+
#[coverage]
47+
//~^ ERROR malformed `coverage` attribute input
48+
//~| ERROR attribute should be applied to a function definition or closure
4049
type T;
4150
}
4251

43-
// FIXME(#126658): This is silently allowed, but should not be.
4452
#[coverage]
53+
//~^ ERROR malformed `coverage` attribute input
54+
//~| ERROR attribute should be applied to a function definition or closure
4555
impl MyTrait for MyStruct {
46-
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
56+
#[coverage]
57+
//~^ ERROR malformed `coverage` attribute input
58+
//~| ERROR attribute should be applied to a function definition or closure
4759
const X: u32 = 8;
4860

49-
#[coverage] //~ ERROR `#[coverage]` must be applied to coverable code
61+
#[coverage]
62+
//~^ ERROR malformed `coverage` attribute input
63+
//~| ERROR attribute should be applied to a function definition or closure
5064
type T = ();
5165
}
5266

53-
#[coverage] //~ ERROR expected `coverage(off)` or `coverage(on)`
67+
#[coverage]
68+
//~^ ERROR malformed `coverage` attribute input
5469
fn main() {}

Diff for: ‎tests/ui/coverage-attr/word-only.stderr

+245-25
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,277 @@
1-
error[E0788]: `#[coverage]` must be applied to coverable code
2-
--> $DIR/word-only.rs:23:1
1+
error: malformed `coverage` attribute input
2+
--> $DIR/word-only.rs:11:1
33
|
44
LL | #[coverage]
55
| ^^^^^^^^^^^
6+
|
7+
help: the following are the possible correct uses
8+
|
9+
LL | #[coverage(off)]
10+
|
11+
LL | #[coverage(on)]
12+
|
13+
14+
error: malformed `coverage` attribute input
15+
--> $DIR/word-only.rs:17:5
16+
|
17+
LL | #![coverage]
18+
| ^^^^^^^^^^^^
19+
|
20+
help: the following are the possible correct uses
21+
|
22+
LL | #![coverage(off)]
23+
|
24+
LL | #![coverage(on)]
25+
|
26+
27+
error: malformed `coverage` attribute input
28+
--> $DIR/word-only.rs:22:1
29+
|
30+
LL | #[coverage]
31+
| ^^^^^^^^^^^
32+
|
33+
help: the following are the possible correct uses
34+
|
35+
LL | #[coverage(off)]
36+
|
37+
LL | #[coverage(on)]
38+
|
39+
40+
error: malformed `coverage` attribute input
41+
--> $DIR/word-only.rs:31:5
42+
|
43+
LL | #[coverage]
44+
| ^^^^^^^^^^^
45+
|
46+
help: the following are the possible correct uses
47+
|
48+
LL | #[coverage(off)]
49+
|
50+
LL | #[coverage(on)]
51+
|
52+
53+
error: malformed `coverage` attribute input
54+
--> $DIR/word-only.rs:27:1
55+
|
56+
LL | #[coverage]
57+
| ^^^^^^^^^^^
58+
|
59+
help: the following are the possible correct uses
60+
|
61+
LL | #[coverage(off)]
62+
|
63+
LL | #[coverage(on)]
64+
|
65+
66+
error: malformed `coverage` attribute input
67+
--> $DIR/word-only.rs:41:5
68+
|
69+
LL | #[coverage]
70+
| ^^^^^^^^^^^
71+
|
72+
help: the following are the possible correct uses
73+
|
74+
LL | #[coverage(off)]
75+
|
76+
LL | #[coverage(on)]
77+
|
78+
79+
error: malformed `coverage` attribute input
80+
--> $DIR/word-only.rs:46:5
81+
|
82+
LL | #[coverage]
83+
| ^^^^^^^^^^^
84+
|
85+
help: the following are the possible correct uses
86+
|
87+
LL | #[coverage(off)]
88+
|
89+
LL | #[coverage(on)]
90+
|
91+
92+
error: malformed `coverage` attribute input
93+
--> $DIR/word-only.rs:37:1
94+
|
95+
LL | #[coverage]
96+
| ^^^^^^^^^^^
97+
|
98+
help: the following are the possible correct uses
99+
|
100+
LL | #[coverage(off)]
101+
|
102+
LL | #[coverage(on)]
103+
|
104+
105+
error: malformed `coverage` attribute input
106+
--> $DIR/word-only.rs:56:5
107+
|
108+
LL | #[coverage]
109+
| ^^^^^^^^^^^
110+
|
111+
help: the following are the possible correct uses
112+
|
113+
LL | #[coverage(off)]
114+
|
115+
LL | #[coverage(on)]
116+
|
117+
118+
error: malformed `coverage` attribute input
119+
--> $DIR/word-only.rs:61:5
120+
|
121+
LL | #[coverage]
122+
| ^^^^^^^^^^^
123+
|
124+
help: the following are the possible correct uses
125+
|
126+
LL | #[coverage(off)]
127+
|
128+
LL | #[coverage(on)]
129+
|
130+
131+
error: malformed `coverage` attribute input
132+
--> $DIR/word-only.rs:52:1
133+
|
134+
LL | #[coverage]
135+
| ^^^^^^^^^^^
136+
|
137+
help: the following are the possible correct uses
138+
|
139+
LL | #[coverage(off)]
140+
|
141+
LL | #[coverage(on)]
142+
|
143+
144+
error: malformed `coverage` attribute input
145+
--> $DIR/word-only.rs:67:1
146+
|
147+
LL | #[coverage]
148+
| ^^^^^^^^^^^
149+
|
150+
help: the following are the possible correct uses
151+
|
152+
LL | #[coverage(off)]
153+
|
154+
LL | #[coverage(on)]
155+
|
156+
157+
error[E0788]: attribute should be applied to a function definition or closure
158+
--> $DIR/word-only.rs:11:1
159+
|
160+
LL | #[coverage]
161+
| ^^^^^^^^^^^
162+
...
163+
LL | mod my_mod {}
164+
| ------------- not a function or closure
165+
166+
error[E0788]: attribute should be applied to a function definition or closure
167+
--> $DIR/word-only.rs:17:5
168+
|
169+
LL | / mod my_mod_inner {
170+
LL | | #![coverage]
171+
| | ^^^^^^^^^^^^
172+
LL | |
173+
LL | |
174+
LL | | }
175+
| |_- not a function or closure
176+
177+
error[E0788]: attribute should be applied to a function definition or closure
178+
--> $DIR/word-only.rs:22:1
179+
|
180+
LL | #[coverage]
181+
| ^^^^^^^^^^^
182+
...
6183
LL | struct MyStruct;
7-
| ---------------- not coverable code
184+
| ---------------- not a function or closure
185+
186+
error[E0788]: attribute should be applied to a function definition or closure
187+
--> $DIR/word-only.rs:27:1
188+
|
189+
LL | #[coverage]
190+
| ^^^^^^^^^^^
191+
...
192+
LL | / impl MyStruct {
193+
LL | | #[coverage]
194+
LL | |
195+
LL | |
196+
LL | | const X: u32 = 7;
197+
LL | | }
198+
| |_- not a function or closure
199+
200+
error[E0788]: attribute should be applied to a function definition or closure
201+
--> $DIR/word-only.rs:37:1
202+
|
203+
LL | #[coverage]
204+
| ^^^^^^^^^^^
205+
...
206+
LL | / trait MyTrait {
207+
LL | | #[coverage]
208+
LL | |
209+
LL | |
210+
... |
211+
LL | | type T;
212+
LL | | }
213+
| |_- not a function or closure
214+
215+
error[E0788]: attribute should be applied to a function definition or closure
216+
--> $DIR/word-only.rs:52:1
217+
|
218+
LL | #[coverage]
219+
| ^^^^^^^^^^^
220+
...
221+
LL | / impl MyTrait for MyStruct {
222+
LL | | #[coverage]
223+
LL | |
224+
LL | |
225+
... |
226+
LL | | type T = ();
227+
LL | | }
228+
| |_- not a function or closure
8229

9-
error[E0788]: `#[coverage]` must be applied to coverable code
10-
--> $DIR/word-only.rs:36:5
230+
error[E0788]: attribute should be applied to a function definition or closure
231+
--> $DIR/word-only.rs:41:5
11232
|
12233
LL | #[coverage]
13234
| ^^^^^^^^^^^
235+
...
14236
LL | const X: u32;
15-
| ------------- not coverable code
237+
| ------------- not a function or closure
16238

17-
error[E0788]: `#[coverage]` must be applied to coverable code
18-
--> $DIR/word-only.rs:39:5
239+
error[E0788]: attribute should be applied to a function definition or closure
240+
--> $DIR/word-only.rs:46:5
19241
|
20242
LL | #[coverage]
21243
| ^^^^^^^^^^^
244+
...
22245
LL | type T;
23-
| ------- not coverable code
246+
| ------- not a function or closure
24247

25-
error[E0788]: `#[coverage]` must be applied to coverable code
26-
--> $DIR/word-only.rs:29:5
248+
error[E0788]: attribute should be applied to a function definition or closure
249+
--> $DIR/word-only.rs:31:5
27250
|
28251
LL | #[coverage]
29252
| ^^^^^^^^^^^
253+
...
30254
LL | const X: u32 = 7;
31-
| ----------------- not coverable code
255+
| ----------------- not a function or closure
32256

33-
error[E0788]: `#[coverage]` must be applied to coverable code
34-
--> $DIR/word-only.rs:46:5
257+
error[E0788]: attribute should be applied to a function definition or closure
258+
--> $DIR/word-only.rs:56:5
35259
|
36260
LL | #[coverage]
37261
| ^^^^^^^^^^^
262+
...
38263
LL | const X: u32 = 8;
39-
| ----------------- not coverable code
264+
| ----------------- not a function or closure
40265

41-
error[E0788]: `#[coverage]` must be applied to coverable code
42-
--> $DIR/word-only.rs:49:5
266+
error[E0788]: attribute should be applied to a function definition or closure
267+
--> $DIR/word-only.rs:61:5
43268
|
44269
LL | #[coverage]
45270
| ^^^^^^^^^^^
271+
...
46272
LL | type T = ();
47-
| ------------ not coverable code
48-
49-
error: expected `coverage(off)` or `coverage(on)`
50-
--> $DIR/word-only.rs:53:1
51-
|
52-
LL | #[coverage]
53-
| ^^^^^^^^^^^
273+
| ------------ not a function or closure
54274

55-
error: aborting due to 7 previous errors
275+
error: aborting due to 23 previous errors
56276

57277
For more information about this error, try `rustc --explain E0788`.

0 commit comments

Comments
 (0)
Please sign in to comment.