Rust: Rustdoc should show which marker traits a type implements

Created on 28 Sep 2014  Â·  18Comments  Â·  Source: rust-lang/rust

I don't think there's any way right now to find out if some type is e.g. Sync without trying to compile code that depends on it.

C-feature-request P-low T-dev-tools T-rustdoc

Most helpful comment

Thanks to https://github.com/rust-lang/rust/pull/47833 this issue is now resolved! Starting in tomorrow's nightly docs, there will be a new "Auto Trait Implementations" section showing off under what conditions a type impls Send or Sync.

All 18 comments

cc https://github.com/rust-lang/rust/issues/13231

(this is one of the motivating reasons for opt-in built-in bounds.)

Will this simply fall out naturally from OIBIT?

Now that Copy is opt-in, the impl shows up! Huzzah!

OIBITs didn't solve this. Well, it solved it for Copy, but the traits that have default impls (e.g. unsafe impl Sync for .. { }) still don't show up in rustdoc. A trait will show the negative impl if it has one, but not if it inherits its negative impl from a field.

Nominating. I really think this needs to be fixed. Not having Sync/Send properly documented on types can be a real source of confusion. As this is a documentation issue, it could come after 1.0, but if we're expecting a bunch of people to start jumping into Rust as soon as 1.0 is released (which seems reasonable), then we should really try and have this done before then.

I think the easiest solution is to walk all the impls for the type and check whether !Sized or !Share are among them. If not, synthesize a positive impl for documentation purposes. 

—
Sent from Mailbox

On Sat, Apr 11, 2015 at 4:22 PM, Kevin Ballard [email protected]
wrote:

Nominating. I really think this needs to be fixed. Not having Sync/Send properly documented on types can be a real source of confusion. As this is a documentation issue, it could come after 1.0, but if we're expecting a bunch of people to start jumping into Rust as soon as 1.0 is released (which seems reasonable), then we should really try and have this done before then.

Reply to this email directly or view it on GitHub:
https://github.com/rust-lang/rust/issues/17606#issuecomment-91943601

Not 1.0; P-low. (Also, not clear how to solve this, since most of the time the presence/absence of an impl is dependent on the particular type parameters you are instantiated with.)

Hm, I would prefer P-medium here; I think this is a very important piece of documentation to provide.

As an additional urge to boost the priority on this: as someone who has been learning Rust, this is still super bewildering for Copy. i32 and i64 both implement Copy (as far as I can tell), but https://doc.rust-lang.org/nightly/std/primitive.i32.html and https://doc.rust-lang.org/std/marker/trait.Copy.html don't list the integer types as being copy-able.

This is mostly confusing when I'm trying to explain to other people the difference between a type which implements move semantics and a type which implements copy semantics; some of the core types don't expose their underlying behavior in the documentation.

So it looks like Copy is working OK _except_ for primitive types, which suggests there's just a bug in the handling there. (Whereas "auto traits" like Send are trickier)

@jonathandturner, if you wanted to do some rustdoc hacking, fixing the issue around Copy might be a reasonable place to dive in.

Still an issue.

Worth mention this issue: https://github.com/rust-lang/rust/issues/33772

Not directly related, but remotely similar

My issue has been closed as a dupe of this one, so let me add that implemented kinds are not the only missing bit of information: Other things that rustdoc should show include variance of lifetime/type parameters and whether type parameters appear only below a pointer indirection (the latter being relevant for recursive types).

I'd like to work on this.

I wasted a reasonable amount of time today because I thought some type wasn't Send + Sync because rustdoc did not show this to me :/

Thanks to https://github.com/rust-lang/rust/pull/47833 this issue is now resolved! Starting in tomorrow's nightly docs, there will be a new "Auto Trait Implementations" section showing off under what conditions a type impls Send or Sync.

Great work on this! I’ve been waiting for this feature for a while now. :-)

Was this page helpful?
0 / 5 - 0 ratings