Skip to content

Commit 9473e21

Browse files
committed
Changes from code review
1 parent 5fabdb8 commit 9473e21

File tree

4 files changed

+56
-23
lines changed

4 files changed

+56
-23
lines changed

compiler/rustc_error_codes/src/error_codes/E0788.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
A `#[no_coverage]` attribute was incorrectly placed on something that couldn't
2-
be covered.
1+
A `#[no_coverage]` attribute was applied to something which does not show up
2+
in code coverage, or is too granular to be excluded from the coverage report.
3+
4+
For now, this attribute can only be applied to function, method, and closure
5+
definitions. In the future, it may be added to statements, blocks, and
6+
expressions, and for the time being, using this attribute in those places
7+
will just emit an `unused_attributes` lint instead of this error.
38

49
Example of erroneous code:
510

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,15 @@ impl CheckAttrVisitor<'_> {
317317

318318
Target::Mod | Target::ForeignMod | Target::Impl | Target::Trait => {
319319
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
320-
lint.build("`#[no_coverage]` cannot be done recursively and must be applied to functions directly").emit();
320+
lint.build("`#[no_coverage]` does not propagate into items and must be applied to the contained functions directly").emit();
321321
});
322322
true
323323
}
324324

325325
Target::Expression | Target::Statement | Target::Arm => {
326326
self.tcx.struct_span_lint_hir(UNUSED_ATTRIBUTES, hir_id, attr.span, |lint| {
327-
lint.build("`#[no_coverage]` can only be applied at the function level, not on code directly").emit();
327+
lint.build("`#[no_coverage]` may only be applied to function definitions")
328+
.emit();
328329
});
329330
true
330331
}

src/test/ui/lint/no-coverage.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
#![feature(no_coverage)]
33
#![feature(type_alias_impl_trait)]
44
#![warn(unused_attributes)]
5+
#![no_coverage]
6+
//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly
57

8+
#[no_coverage]
9+
//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly
610
trait Trait {
711
#[no_coverage] //~ ERROR `#[no_coverage]` must be applied to coverable code
812
const X: u32;
@@ -13,6 +17,8 @@ trait Trait {
1317
type U;
1418
}
1519

20+
#[no_coverage]
21+
//~^ WARN: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly
1622
impl Trait for () {
1723
const X: u32 = 0;
1824

@@ -33,14 +39,17 @@ extern "C" {
3339

3440
#[no_coverage]
3541
fn main() {
36-
#[no_coverage] //~ WARN `#[no_coverage]` can only be applied at the function level, not on code directly
42+
#[no_coverage]
43+
//~^ WARN `#[no_coverage]` may only be applied to function definitions
3744
let _ = ();
3845

3946
match () {
40-
#[no_coverage] //~ WARN `#[no_coverage]` can only be applied at the function level, not on code directly
47+
#[no_coverage]
48+
//~^ WARN `#[no_coverage]` may only be applied to function definitions
4149
() => (),
4250
}
4351

44-
#[no_coverage] //~ WARN `#[no_coverage]` can only be applied at the function level, not on code directly
52+
#[no_coverage]
53+
//~^ WARN `#[no_coverage]` may only be applied to function definitions
4554
return ();
4655
}

src/test/ui/lint/no-coverage.stderr

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,101 @@
1-
warning: `#[no_coverage]` can only be applied at the function level, not on code directly
2-
--> $DIR/no-coverage.rs:36:5
1+
warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly
2+
--> $DIR/no-coverage.rs:8:1
33
|
4-
LL | #[no_coverage]
5-
| ^^^^^^^^^^^^^^
4+
LL | #[no_coverage]
5+
| ^^^^^^^^^^^^^^
66
|
77
note: the lint level is defined here
88
--> $DIR/no-coverage.rs:4:9
99
|
1010
LL | #![warn(unused_attributes)]
1111
| ^^^^^^^^^^^^^^^^^
1212

13-
warning: `#[no_coverage]` can only be applied at the function level, not on code directly
14-
--> $DIR/no-coverage.rs:40:9
13+
warning: `#[no_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 | #[no_coverage]
17+
| ^^^^^^^^^^^^^^
18+
19+
warning: `#[no_coverage]` may only be applied to function definitions
20+
--> $DIR/no-coverage.rs:42:5
21+
|
22+
LL | #[no_coverage]
23+
| ^^^^^^^^^^^^^^
24+
25+
warning: `#[no_coverage]` may only be applied to function definitions
26+
--> $DIR/no-coverage.rs:47:9
1527
|
1628
LL | #[no_coverage]
1729
| ^^^^^^^^^^^^^^
1830

19-
warning: `#[no_coverage]` can only be applied at the function level, not on code directly
20-
--> $DIR/no-coverage.rs:44:5
31+
warning: `#[no_coverage]` may only be applied to function definitions
32+
--> $DIR/no-coverage.rs:52:5
2133
|
2234
LL | #[no_coverage]
2335
| ^^^^^^^^^^^^^^
2436

2537
error[E0788]: `#[no_coverage]` must be applied to coverable code
26-
--> $DIR/no-coverage.rs:7:5
38+
--> $DIR/no-coverage.rs:11:5
2739
|
2840
LL | #[no_coverage]
2941
| ^^^^^^^^^^^^^^
3042
LL | const X: u32;
3143
| ------------- not coverable code
3244

3345
error[E0788]: `#[no_coverage]` must be applied to coverable code
34-
--> $DIR/no-coverage.rs:10:5
46+
--> $DIR/no-coverage.rs:14:5
3547
|
3648
LL | #[no_coverage]
3749
| ^^^^^^^^^^^^^^
3850
LL | type T;
3951
| ------- not coverable code
4052

4153
error[E0788]: `#[no_coverage]` must be applied to coverable code
42-
--> $DIR/no-coverage.rs:19:5
54+
--> $DIR/no-coverage.rs:25:5
4355
|
4456
LL | #[no_coverage]
4557
| ^^^^^^^^^^^^^^
4658
LL | type T = Self;
4759
| -------------- not coverable code
4860

4961
error[E0788]: `#[no_coverage]` must be applied to coverable code
50-
--> $DIR/no-coverage.rs:22:5
62+
--> $DIR/no-coverage.rs:28:5
5163
|
5264
LL | #[no_coverage]
5365
| ^^^^^^^^^^^^^^
5466
LL | type U = impl Trait;
5567
| -------------------- not coverable code
5668

5769
error[E0788]: `#[no_coverage]` must be applied to coverable code
58-
--> $DIR/no-coverage.rs:27:5
70+
--> $DIR/no-coverage.rs:33:5
5971
|
6072
LL | #[no_coverage]
6173
| ^^^^^^^^^^^^^^
6274
LL | static X: u32;
6375
| -------------- not coverable code
6476

6577
error[E0788]: `#[no_coverage]` must be applied to coverable code
66-
--> $DIR/no-coverage.rs:30:5
78+
--> $DIR/no-coverage.rs:36:5
6779
|
6880
LL | #[no_coverage]
6981
| ^^^^^^^^^^^^^^
7082
LL | type T;
7183
| ------- not coverable code
7284

85+
warning: `#[no_coverage]` does not propagate into items and must be applied to the contained functions directly
86+
--> $DIR/no-coverage.rs:5:1
87+
|
88+
LL | #![no_coverage]
89+
| ^^^^^^^^^^^^^^^
90+
7391
error: unconstrained opaque type
74-
--> $DIR/no-coverage.rs:23:14
92+
--> $DIR/no-coverage.rs:29:14
7593
|
7694
LL | type U = impl Trait;
7795
| ^^^^^^^^^^
7896
|
7997
= note: `U` must be used in combination with a concrete type within the same module
8098

81-
error: aborting due to 7 previous errors; 3 warnings emitted
99+
error: aborting due to 7 previous errors; 6 warnings emitted
82100

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

0 commit comments

Comments
 (0)