-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
missing_doc_code_examples
lint complains about foreign trait implementations
#76450
Comments
I think the current lint behavior is correct. The issue here is on the core lib side. I opened #76568 to fix it. |
Maybe the lint shouldn't warn when implementing a foreign trait? By the same rationale as #56922. |
Hmmm... I have shared feelings here: if a trait doesn't provided documentation "by default", doesn't it make sense to complain about it on the implementors? |
I guess if you can add docs on the implementation it makes sense - you have a way to fix it. |
That's mainly my position yes. :) |
Unfortunately, that drags with itself more issues. First of all, I have to implement said examples on all of the implementations I write. Second, I have to copy (and correctly maintain said copy) the original example-less documentation onto every instance so that it's not lost by the language server and/or While this isn't entirely impossible, it's a huge chore, especially when you implement multiple traits on tens of types at a time. While |
You can disable the lint on a specific implementation in the worst case. However, the goal is to enforce more documentation through the ecosystem. If users start to complain about it to the crates' maintainers, I'm pretty sure the situation will improve pretty quickly. |
I don't really like this approach - it should be fixable by you, not by bugging upstream maintainers. @Manishearth was saying something like that for #74563 I think. |
You can fix it on your side by adding the examples yourself in your implementation. So on that on point, even if not the best, it's still possible. |
I suppose in the worst case, I could fork the upstream project, add examples, and hope that it either gets merged or the developer doesn't cause too many conflicts so I can keep it up-to-date. But even then, it takes a lot of back-and-forth, a lot of time and effort on both ends to get from my linter complaining about missing examples to a new crate release that fixes it - even if everything goes quick and smooth. There should at least be a way for me to temporarily ignore warnings coming from (or rather because of) 3rd party and standard library crates, so that - at the minimum - I can fix my own linting issues without having to comb through thousands of lines of all too similar lines of warnings every time I generate documentation for testing purposes. |
|
Like I said, you can ignore the lint on the implementations, or directly on a module if it only contains such cases. Adding a |
Let it be known that I was today days old when I learned that you can apply |
I strongly feel that we should not warn on foreign trait implementations here. Firstly, as @jyn514 said, a lint should be fixable by you. Yes, you can add examples yourself, but that isn't actually the real fix here in most cases. In most cases trait implementations are lightweight and you rarely document them, so you're not actually giving the user a "fix", you're asking them to do something they don't actually want to shut the lint up. That's not good, that is not the actual fix, the actual fix is asking people to fix it upstream, and we should not lint that downstream. "The lint can be ignored" is not good enough for normal situations -- if it was some weird confluence of situations, then, sure, but a foreign trait impl is an extremely normal thing to do. |
…, r=jyn514 Add missing examples on core traits' method Linked to rust-lang#76450. r? @jyn514
Coming back on this after a while and I now agree with this issue: we shouldn't lint on foreign trait implementations. I'll send a fix in the following days. |
I just tried locally and it seems like this issue has already been fixed. Closing it then. |
@GuillaumeGomez we should still test that it behaves properly |
I'll send a test if there isn't already one then. |
…l-missing-doc-code-examples, r=jyn514 Add test to ensure that the missing_doc_code_examples is not triggered on foreign trait implementations Fixes rust-lang#76450. r? `@jyn514`
…l-missing-doc-code-examples, r=jyn514 Add test to ensure that the missing_doc_code_examples is not triggered on foreign trait implementations Fixes rust-lang#76450. r? ``@jyn514``
…l-missing-doc-code-examples, r=jyn514 Add test to ensure that the missing_doc_code_examples is not triggered on foreign trait implementations Fixes rust-lang#76450. r? ```@jyn514```
The
missing_doc_code_examples
lint seems to be erroneously complaining about missing documentation examples where local types implement foreign traits (both from 3rd party crates and the standard library).The example below should pass all checks as far as I can tell:
However, running
cargo doc
results in the following warnings:Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: