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 why std docs have many apparent duplicates #16645

Closed
mdinger opened this issue Aug 21, 2014 · 5 comments · Fixed by #22132
Closed

Document why std docs have many apparent duplicates #16645

mdinger opened this issue Aug 21, 2014 · 5 comments · Fixed by #22132

Comments

@mdinger
Copy link
Contributor

mdinger commented Aug 21, 2014

Reddit thread:

Why are data structures generally duplicated in the rust standard library, or at least apparently so in the API documentation?

e.g. std::string::String vs. collections::string::String, std:fmt::String vs. core::fmt::String, std::vec::Vec vs. collections::vec::Vec?

I'm not certain which of these the user was referring to but both could be possibly weird at first appearance:

  • Why is String in std::string and collections::string and others
  • Why is String in string and Vec in vec

It was suggested that this be included in a How to read this documentation somewhere. If it was written, I would imagine it should be automatically included in the rust std documentation system so that it is included in all rust derived projects like gfx-rs and piston documentation.

cc: @steveklabnik

@sfackler
Copy link
Member

I think what would make sense here is to move the documentation for all of the std reexported crates (core, alloc, etc) out of the "main" API docs into a separate set. That way the "normal" use case of just using std will be more straightforward, as will the other use case of running with #[no_std], since both groups will only be searching the docs that apply to them.

@mdinger
Copy link
Contributor Author

mdinger commented Aug 21, 2014

Sounds fine to me. If that is the consensus or desired approach, let me know and I'll try to update the Title/description accordingly if it matters as I won't be able to help with much else for this. I don't know how much discussion is needed before a decision is made anyhow.

@rpjohnst
Copy link
Contributor

A more general solution might be to link re-exports in the docs to their original source, so that you can look in the std docs and see everything labeled as a re-export specifically from core or collections or wherever.

The only issue might be when something is re-exported from somewhere private, which could just be special-cased. Or maybe the documentation could be placed at the re-export that the library writer wants it at.

I'd prefer that over separating the docs, and it would work better for third party libraries as well.

@Kimundi
Copy link
Member

Kimundi commented Aug 23, 2014

Whether or not a definition is a re-export from a different crate is a user visible property, because all possible paths to the same item are interchangeable:

extern crate core;
let _: std::option::Option<uint> = core::option::Some(0u);

Because of that it is my opinion that the docs should always provide a full chain of links for each reexport step, skipping/hiding all private ones in the chain:

// my_crate
pub use self::pub_mod::Foo;
pub mod pub_mod {
     pub use self::priv_mod::Foo;
     mod priv_mod {
         pub struct Foo;
    }
}

This should show you both ::Foo and ::pub_mod::Foo in the docs, mention that ::Foo is a reexport of ::pub_mod::Foo and mention that that is a reexport of a private type as well (Or just tread the last public link in the chain as the original definition)

For ergonomic reasons every reexport should probably show the docs of their item directly inline in the documentation as if the item where defined there, but also put a clearly visible info at the top that this is a reexport, including links to the the next link in the reexport chain:

Enum std::option::Option

Reexported from core::option::Option

Original docs...

Related to this, the rustdoc search should group things that are exports of each other together, or hide them by default.

Instead of this:

Results for Option

std::option
std::option::Option
std::os::MapOption
std::ptr::RawPtr::to_option
core::iter::MinMaxResult::into_option
std::option_env!
std::sync::atomic::AtomicOption
std::sync::atomics::AtomicOption
std::rand::Rng::choose_option
rand::XorShiftRng::choose_option
rand::isaac::IsaacRng::choose_option
rand::reseeding::ReseedingRng::choose_option
core::option
core::option::Option
rustc::driver::config::Options
getopts::Occur::Optional
core::ptr::RawPtr::to_option

It should look kinda like this:

Results for Option

std::option

  • core::option

std::option::Option

  • core::option::Option

std::os::MapOption
std::ptr::RawPtr::to_option

  • core::ptr::RawPtr::to_option

core::iter::MinMaxResult::into_option
std::option_env!
std::sync::atomic::AtomicOption

  • std::sync::atomics::AtomicOption

std::rand::Rng::choose_option
rand::XorShiftRng::choose_option
rand::isaac::IsaacRng::choose_option
rand::reseeding::ReseedingRng::choose_option
rustc::driver::config::Options
getopts::Occur::Optional

@thestinger
Copy link
Contributor

I don't think we should explain why the standard library is poorly designed. The problem should be fixed by not making confusing mazes of re-exports. Crates should just be used directly and the prelude could include those crates and use directly from them instead of the current mess.

steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 13, 2015
steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 14, 2015
Fixes rust-lang#16645

Fixing this in any deeper way will require an RFC, so let's just document the current behavior.
steveklabnik added a commit to steveklabnik/rust that referenced this issue Feb 15, 2015
Fixes rust-lang#16645

Fixing this in any deeper way will require an RFC, so let's just document the current behavior.
Manishearth added a commit to Manishearth/rust that referenced this issue Feb 15, 2015
Fixes rust-lang#16645

Fixing this in any deeper way will require an RFC, so let's just document the current behavior.
bors added a commit to rust-lang-ci/rust that referenced this issue Feb 25, 2024
fix: Fix deadlock in `recreate_crate_graph` <-> `file_line_index`

Fixes rust-lang/rust-analyzer#16614
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants