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

Document what Default does for each type in libstd #36265

Closed
bluss opened this issue Sep 4, 2016 · 11 comments
Closed

Document what Default does for each type in libstd #36265

bluss opened this issue Sep 4, 2016 · 11 comments
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@bluss
Copy link
Member

bluss commented Sep 4, 2016

Document what Default does for each type in libstd.

For example, for the Default impl for i32, mention that it returns 0. For slice, mention it returns an empty slice.

@bluss bluss added A-docs E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. labels Sep 4, 2016
@cbreeden
Copy link
Contributor

cbreeden commented Sep 4, 2016

I'm thinking about where a good place would be to document this behavior. I'm leaning towards documenting these behaviors in the documents for each individual type, as opposed to in the docs for Default.

@durka
Copy link
Contributor

durka commented Sep 4, 2016

It would be nice if the comments were near the Default impl so they don't become stale (obviously they won't for primitive types, but this would be a good convention for user types as well). It could be a good addition to the "built-in traits section" that's been occasionally suggested for Rustdoc. Somewhere near the top it would say, e.g.:

  • This type is not Copy.
  • This type is Clone-able.
  • This type is not Send nor Sync.
  • This type has a Default and it is 0.

And it would somehow gather this information from comments on the impl.

@bluss
Copy link
Member Author

bluss commented Sep 4, 2016

@cbreeden I was thinking on the Default-impl for each type. For example for a slice, it would show up on this impl or on this method (depending on what works right now). https://doc.rust-lang.org/std/primitive.slice.html#method.default

You can see that the Index impls for slice have specific documentation for the slice itself.

@cbreeden
Copy link
Contributor

cbreeden commented Sep 4, 2016

Interesting. I gave it a little test run to see how it would look:

image

The fact that we are missing the [Read More] originally present doesn't bother me much since it's the same link as if you were to click the default function itself. I like it (modulo a rewording if other people felt as such).

@athulappadan
Copy link
Contributor

I would like to take up this task and would like to get an explanation of how to go about it.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Sep 7, 2016

@athulappadan: Find all the Default implementations and explain in the doc comments what it's doing. For example:

impl Default for String {
    /// Create an empty `String`.
    fn default() -> String {
        String::new() // I guess it's doing this
    }
}

So in the example above, the thing you need to add is "Create an empty String."

@bluss
Copy link
Member Author

bluss commented Sep 7, 2016

@athulappadan Don't miss this document when starting out. And feel free to ask questions https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md

@matthew-piziak
Copy link
Contributor

@athulappadan Any update on this issue? If not I might like to work on it.

@athulappadan
Copy link
Contributor

I was a bit busy. Will submit a PR tomorrow.

matthew-piziak added a commit to matthew-piziak/rust that referenced this issue Sep 12, 2016
Part of rust-lang#36265.

These are all the instances of `Default` in this repository that are of the form `impl Default for X`. The default for `i32`, for example, is not of this form.

@GuillaumeGomez
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Sep 14, 2016
Documentation of what Default does for each type

Addresses rust-lang#36265
I haven't changed the following types due to doubts:

1)src/libstd/ffi/c_str.rs
2)src/libcore/iter/sources.rs
3)src/libcore/hash/mod.rs
4)src/libcore/hash/mod.rs
5)src/librustc/middle/privacy.rs

r? @steveklabnik
@caipre
Copy link
Contributor

caipre commented Sep 19, 2016

@athulappadan : Can this be closed?

@frewsxcv
Copy link
Member

frewsxcv commented Dec 5, 2016

@athulappadan : Can this be closed?

One more in #38186

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Dec 7, 2016
Add docs for last undocumented `Default` `impl`.

Add doc comment for `Default` `impl` on `DefaultHasher`.

Fixes rust-lang#36265.
cuviper pushed a commit to cuviper/rayon that referenced this issue Mar 28, 2017
Add docs for last undocumented `Default` `impl`.

Add doc comment for `Default` `impl` on `DefaultHasher`.

Fixes rust-lang/rust#36265.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

8 participants