From 6728f21d85d347bcd5e7ca919b4e9f0c2677572b Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Wed, 22 Nov 2017 16:16:55 -0500 Subject: Generate documentation for auto-trait impls A new section is added to both both struct and trait doc pages. On struct/enum pages, a new 'Auto Trait Implementations' section displays any synthetic implementations for auto traits. Currently, this is only done for Send and Sync. On trait pages, a new 'Auto Implementors' section displays all types which automatically implement the trait. Effectively, this is a list of all public types in the standard library. Synthesized impls for a particular auto trait ('synthetic impls') take into account generic bounds. For example, a type 'struct Foo(T)' will have 'impl Send for Foo where T: Send' generated for it. Manual implementations of auto traits are also taken into account. If we have the following types: 'struct Foo(T)' 'struct Wrapper(Foo)' 'unsafe impl Send for Wrapper' // pretend that Wrapper makes this sound somehow Then Wrapper will have the following impl generated: 'impl Send for Wrapper' reflecting the fact that 'T: Send' need not hold for 'Wrapper: Send' to hold Lifetimes, HRTBS, and projections (e.g. '::Item') are taken into account by synthetic impls However, if a type can *never* implement a particular auto trait (e.g. 'struct MyStruct(*const T)'), then a negative impl will be generated (in this case, 'impl !Send for MyStruct') All of this means that a user should be able to copy-paste a synthetic impl into their code, without any observable changes in behavior (assuming the rest of the program remains unchanged). --- src/test/rustdoc/duplicate_impls/issue-33054.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/test/rustdoc/duplicate_impls') diff --git a/src/test/rustdoc/duplicate_impls/issue-33054.rs b/src/test/rustdoc/duplicate_impls/issue-33054.rs index df6ebcae107..43a425d4c5e 100644 --- a/src/test/rustdoc/duplicate_impls/issue-33054.rs +++ b/src/test/rustdoc/duplicate_impls/issue-33054.rs @@ -11,7 +11,8 @@ // @has issue_33054/impls/struct.Foo.html // @has - '//code' 'impl Foo' // @has - '//code' 'impl Bar for Foo' -// @count - '//*[@class="impl"]' 2 +// @count - '//*[@id="implementations-list"]/*[@class="impl"]' 1 +// @count - '//*[@id="main"]/*[@class="impl"]' 1 // @has issue_33054/impls/bar/trait.Bar.html // @has - '//code' 'impl Bar for Foo' // @count - '//*[@class="struct"]' 1 -- cgit 1.4.1-3-g733a5