-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Optional lint for functions that panic without mentioning panics in rustdoc #1974
Comments
Casual drive-by comment:
|
@killercup First: awesome, thank you! Can you give an example of the kind of "indirect panics" that you don't think need documentation? I do, for instance, want documentation that using an invalid array index would panic rather than generating an error. |
@joshtriplett sure. It may be that I have a different assumption on what I want to document than you do. Consider this function: fn foo(x: i32) {
assert!(x > 1, "Can only foo-ify things great than 1");
let y = vec![1, 2, 3,];
let z = helper_thing(&y, x);
// ...
} What I'm saying is this: The assert explicitly communicates a possible programmer error, where the API expects its user to check they supply a valid input. Requiring documentation for this assert is very valuable (IMHO) and hopefully not that hard. Analyzing that |
@killercup I actually do want that function to provide documentation that it panics if passed an index too large. As opposed to, for instance, returning an error. That said, there are occasional cases where a call to |
@rustbot claim |
@mgattozzi's excellent talk at RustConf just now made a really good point: functions that panic should document that panic in their documentation.
While we can't detect this in the completely general case, we could detect explicit calls to
panic!()
, and RFC 2091 would give the compiler enough information that it could detect calls to functions that (may) panic.I'd love to see an optional lint for functions that call panic, indirectly or directly, without documentation of that. (Having such documentation would require fairly fuzzy detection, unfortunately, but I still think this is worth considering..)
The text was updated successfully, but these errors were encountered: