-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Throw errors when doc comments are added where they're unused #43009
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this needs a warning cycle... or at least a crater run.
src/test/compile-fail/issue-34222.rs
Outdated
@@ -13,6 +13,6 @@ | |||
|
|||
#[rustc_error] | |||
fn main() { //~ ERROR compilation successful | |||
/// crash | |||
// crash | |||
let x = 0; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might as well remove this test -- it now tests nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this test still needs removing
f7b7ad7
to
3cf53fc
Compare
@Mark-Simulacrum: I remember that we talked about it but can't remember where and when so couldn't find the discussion... But putting warnings instead is fine for me. |
6c369c7
to
8134ab4
Compare
I was still unable to build one of the toolchains (toolchain 1, if you follow the links above):
|
So I need to make a lint out of this. Looking into https://github.com/rust-lang/rust/blob/master/src/librustc_lint/builtin.rs#L725 |
src/libsyntax/parse/parser.rs
Outdated
true | ||
} else { false } { | ||
return expr; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😨
Why not simply
if let Some(ref doc) = ... {
self.span_fatal_err(...).emit();
return expr;
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tired I was.
c16d3fe
to
553c0b8
Compare
@nikomatsakis: You can start the crater run (if all tests are fine) with |
@GuillaumeGomez I can't easily set settings on a crater run, unfortunately --- though making it a lint (usually with deny-by-default) is actually the right way to do these tests (which I had forgotten). Specifically because this way we find out the full impact (otherwise, if any dep has an error, you get an error). And now that you mention it: this should mean that the compiler keeps working too, because the errors were in our dependencies. Duh. |
Errors from travis:
|
7113883
to
f5a11d3
Compare
@nikomatsakis: oups, I removed your commits by mistake. :-/ Can you put it back please? |
Huh, we encountered an error, I guess because one of our primary targets makes use of this feature. Seems to be actually a use in error-chain... |
See failure here. |
I think @nikomatsakis is on vacation now, so changing to r? @nrc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. I had a couple of nits about the phrasing, plus simulacrum's comment could be addressed. Otherwise r+ (iiuc, crater showed an issue, but if this is just a warning lint, that is OK. If I'm wrong, we'll want to fix that first).
src/librustc_lint/builtin.rs
Outdated
@@ -723,6 +723,45 @@ impl EarlyLintPass for IllegalFloatLiteralPattern { | |||
} | |||
|
|||
declare_lint! { | |||
pub UNUSED_DOC_COMMENT, | |||
Deny, | |||
"detects use of useless doc comments" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not say "useless", rather that they will be ignored by rustdoc (theoretically, another tool could use them).
src/librustc_lint/builtin.rs
Outdated
I: Iterator<Item=&'a ast::Attribute>, | ||
C: LintContext<'tcx>>(&self, mut attrs: I, cx: &C) { | ||
if let Some(attr) = attrs.find(|a| a.is_value_str() && a.check_name("doc")) { | ||
cx.struct_span_lint(UNUSED_DOC_COMMENT, attr.span, "unused doc comment").emit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, I'd prefer to be explicit that unused means unused by rustdoc
src/librustc_lint/builtin.rs
Outdated
@@ -724,7 +724,7 @@ impl EarlyLintPass for IllegalFloatLiteralPattern { | |||
|
|||
declare_lint! { | |||
pub UNUSED_DOC_COMMENT, | |||
Warn, | |||
Deny, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be Warn
now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll just remove @nikomatsakis's commits.
24ed34c
to
af94f8a
Compare
@nrc: Updated and applied your comments. |
#![deny(unused_doc_comment)] | ||
|
||
fn foo() { | ||
/// a //~ ERROR unused doc comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this test needs updating now
src/test/compile-fail/issue-34222.rs
Outdated
@@ -13,6 +13,6 @@ | |||
|
|||
#[rustc_error] | |||
fn main() { //~ ERROR compilation successful | |||
/// crash | |||
// crash | |||
let x = 0; | |||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this test still needs removing
25814ce
to
1cebf98
Compare
Update to rc error chain In order to make rust-lang/rust#43009 works, I needed some small updates that are now in error-chain.
d9b356d
to
5636d32
Compare
With all the external issues fixed, let's give it another try! @bors: r=nrc |
📌 Commit 5636d32 has been approved by |
Throw errors when doc comments are added where they're unused #42617
dist stage2-rls failed. Legit.
(Travis link, because bors is dead or something: https://travis-ci.org/rust-lang/rust/builds/258881061) |
And let's retry! @bors: r=nrc |
@GuillaumeGomez Err no, the current |
Ah indeed! Thanks! @bors: r- |
@bors: retry r- |
7a52c78
to
3142ca0
Compare
Ok, so it has been updated to new cargo version. Let's give it another try! :) @bors: r=nrc |
📌 Commit 3142ca0 has been approved by |
Throw errors when doc comments are added where they're unused #42617
☀️ Test successful - status-appveyor, status-travis |
@bors retry p=-2 (trying to get bors running properly) |
#42617