]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Hide `self: Box<Self>` in list of deref methods
authorOliver Middleton <olliemail27@gmail.com>
Fri, 2 Jun 2017 21:37:11 +0000 (22:37 +0100)
committerOliver Middleton <olliemail27@gmail.com>
Fri, 2 Jun 2017 21:37:11 +0000 (22:37 +0100)
These methods can never be called through deref so there is no point
including them. For example you can't call `into_boxed_bytes` or
`into_string` on `String`.

src/librustdoc/clean/mod.rs
src/librustdoc/html/render.rs
src/test/rustdoc/issue-35169-2.rs
src/test/rustdoc/issue-35169.rs

index 9464ac83870d92ba946be207c0970467281ebc7d..fcf7366e2b457cb814df040262b7b4f966cb9faa 100644 (file)
@@ -124,6 +124,7 @@ fn clean(&self, cx: &DocContext) -> Crate {
             let mut r = cx.renderinfo.borrow_mut();
             r.deref_trait_did = cx.tcx.lang_items.deref_trait();
             r.deref_mut_trait_did = cx.tcx.lang_items.deref_mut_trait();
+            r.owned_box_did = cx.tcx.lang_items.owned_box();
         }
 
         let mut externs = Vec::new();
index a588460d467d2cc6597acfc5214b90e0eea6708c..0d9f98e05d2c2c90980ea1aa4ee7f1f67c93a50c 100644 (file)
@@ -262,6 +262,7 @@ pub struct Cache {
     stripped_mod: bool,
     deref_trait_did: Option<DefId>,
     deref_mut_trait_did: Option<DefId>,
+    owned_box_did: Option<DefId>,
 
     // In rare case where a structure is defined in one module but implemented
     // in another, if the implementing module is parsed before defining module,
@@ -280,6 +281,7 @@ pub struct RenderInfo {
     pub external_typarams: FxHashMap<DefId, String>,
     pub deref_trait_did: Option<DefId>,
     pub deref_mut_trait_did: Option<DefId>,
+    pub owned_box_did: Option<DefId>,
 }
 
 /// Helper struct to render all source code to HTML pages
@@ -507,6 +509,7 @@ pub fn run(mut krate: clean::Crate,
         external_typarams,
         deref_trait_did,
         deref_mut_trait_did,
+        owned_box_did,
     } = renderinfo;
 
     let external_paths = external_paths.into_iter()
@@ -530,6 +533,7 @@ pub fn run(mut krate: clean::Crate,
         traits: mem::replace(&mut krate.external_traits, FxHashMap()),
         deref_trait_did: deref_trait_did,
         deref_mut_trait_did: deref_mut_trait_did,
+        owned_box_did: owned_box_did,
         typarams: external_typarams,
     };
 
@@ -2933,17 +2937,18 @@ fn doc_impl_item(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
                 };
 
                 if let Some(self_ty) = self_type_opt {
-                    let by_mut_ref = match self_ty {
-                        SelfTy::SelfBorrowed(_lifetime, mutability) => {
-                            mutability == Mutability::Mutable
-                        },
+                    let (by_mut_ref, by_box) = match self_ty {
+                        SelfTy::SelfBorrowed(_, mutability) |
                         SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
-                            mutability == Mutability::Mutable
+                            (mutability == Mutability::Mutable, false)
+                        },
+                        SelfTy::SelfExplicit(clean::ResolvedPath { did, .. }) => {
+                            (false, Some(did) == cache().owned_box_did)
                         },
-                        _ => false,
+                        _ => (false, false),
                     };
 
-                    deref_mut_ || !by_mut_ref
+                    (deref_mut_ || !by_mut_ref) && !by_box
                 } else {
                     false
                 }
index d738fb2925964cc539726df6aaf409347119b5e1..b19fbaa5b953538593cb9607338e20cf6e052603 100644 (file)
@@ -19,6 +19,8 @@ pub fn by_ref(&self) {}
     pub fn by_explicit_ref(self: &Foo) {}
     pub fn by_mut_ref(&mut self) {}
     pub fn by_explicit_mut_ref(self: &mut Foo) {}
+    pub fn by_explicit_box(self: Box<Foo>) {}
+    pub fn by_explicit_self_box(self: Box<Self>) {}
     pub fn static_foo() {}
 }
 
@@ -41,5 +43,9 @@ fn deref_mut(&mut self) -> &mut Foo { loop {} }
 // @has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)'
 // @has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)'
 // @has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)'
+// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box<Foo>)'
+// @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box<Foo>)'
+// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box<Self>)'
+// @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box<Self>)'
 // @!has - '//*[@id="static_foo.v"]' 'fn static_foo()'
 // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()'
index 8764e4a390f763616e3c7cff2fdd9be037685901..95231f282e3ed634e76b41854e09f679a823238a 100644 (file)
@@ -18,6 +18,8 @@ pub fn by_ref(&self) {}
     pub fn by_explicit_ref(self: &Foo) {}
     pub fn by_mut_ref(&mut self) {}
     pub fn by_explicit_mut_ref(self: &mut Foo) {}
+    pub fn by_explicit_box(self: Box<Foo>) {}
+    pub fn by_explicit_self_box(self: Box<Self>) {}
     pub fn static_foo() {}
 }
 
@@ -36,5 +38,9 @@ fn deref(&self) -> &Foo { loop {} }
 // @!has - '//*[@id="method.by_mut_ref"]' 'fn by_mut_ref(&mut self)'
 // @!has - '//*[@id="by_explicit_mut_ref.v"]' 'fn by_explicit_mut_ref(self: &mut Foo)'
 // @!has - '//*[@id="method.by_explicit_mut_ref"]' 'fn by_explicit_mut_ref(self: &mut Foo)'
+// @!has - '//*[@id="by_explicit_box.v"]' 'fn by_explicit_box(self: Box<Foo>)'
+// @!has - '//*[@id="method.by_explicit_box"]' 'fn by_explicit_box(self: Box<Foo>)'
+// @!has - '//*[@id="by_explicit_self_box.v"]' 'fn by_explicit_self_box(self: Box<Self>)'
+// @!has - '//*[@id="method.by_explicit_self_box"]' 'fn by_explicit_self_box(self: Box<Self>)'
 // @!has - '//*[@id="static_foo.v"]' 'fn static_foo()'
 // @!has - '//*[@id="method.static_foo"]' 'fn static_foo()'