-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #86813 - JohnTitor:unused-doc-comments-help, r=jackh726
Add a help message to `unused_doc_comments` lint Fixes #83492 This adds a help message to suggest a plain comment like the E0658 error. I've yet to come up with the best message about the doc attribute but the current shouldn't harm anything. I was thinking of recovering in the `doc_comment_between_if_else` case, but I came to the conclusion that it unlikely happened and was an overkill.
- Loading branch information
Showing
4 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#![deny(unused_doc_comments)] | ||
|
||
fn doc_comment_on_match_arms(num: u8) -> bool { | ||
match num { | ||
3 => true, | ||
/// useless doc comment | ||
//~^ ERROR: unused doc comment | ||
_ => false, | ||
} | ||
} | ||
|
||
fn doc_comment_between_if_else(num: u8) -> bool { | ||
if num == 3 { | ||
true //~ ERROR: mismatched types | ||
} | ||
/// useless doc comment | ||
else { //~ ERROR: expected expression, found keyword `else` | ||
false | ||
} | ||
} | ||
|
||
fn doc_comment_on_expr(num: u8) -> bool { | ||
/// useless doc comment | ||
//~^ ERROR: attributes on expressions are experimental | ||
//~| ERROR: unused doc comment | ||
num == 3 | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
error: expected expression, found keyword `else` | ||
--> $DIR/unused-doc-comments-edge-cases.rs:17:5 | ||
| | ||
LL | else { | ||
| ^^^^ expected expression | ||
|
||
error[E0658]: attributes on expressions are experimental | ||
--> $DIR/unused-doc-comments-edge-cases.rs:23:5 | ||
| | ||
LL | /// useless doc comment | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: see issue #15701 <https://github.com/rust-lang/rust/issues/15701> for more information | ||
= help: add `#![feature(stmt_expr_attributes)]` to the crate attributes to enable | ||
= help: `///` is for documentation comments. For a plain comment, use `//`. | ||
|
||
error: unused doc comment | ||
--> $DIR/unused-doc-comments-edge-cases.rs:6:9 | ||
| | ||
LL | /// useless doc comment | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
LL | | ||
LL | _ => false, | ||
| ---------- rustdoc does not generate documentation for match arms | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/unused-doc-comments-edge-cases.rs:1:9 | ||
| | ||
LL | #![deny(unused_doc_comments)] | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
= help: use `//` for a plain comment | ||
|
||
error: unused doc comment | ||
--> $DIR/unused-doc-comments-edge-cases.rs:23:5 | ||
| | ||
LL | /// useless doc comment | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
... | ||
LL | num == 3 | ||
| --- rustdoc does not generate documentation for expressions | ||
| | ||
= help: use `//` for a plain comment | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/unused-doc-comments-edge-cases.rs:14:9 | ||
| | ||
LL | / if num == 3 { | ||
LL | | true | ||
| | ^^^^ expected `()`, found `bool` | ||
LL | | } | ||
| |_____- expected this to be `()` | ||
| | ||
help: you might have meant to return this value | ||
| | ||
LL | return true; | ||
| ^^^^^^ ^ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors have detailed explanations: E0308, E0658. | ||
For more information about an error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters