Skip to content

rustdoc: Hide self: Box<Self> in list of deref methods #42394

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

Merged
merged 1 commit into from
Jun 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ impl<'a, 'tcx> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tcx> {
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();
Expand Down
19 changes: 12 additions & 7 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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,
};

Expand Down Expand Up @@ -2933,17 +2937,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
};

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
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc/issue-35169-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ impl Foo {
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() {}
}

Expand All @@ -41,5 +43,9 @@ impl DerefMut for Bar {
// @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()'
6 changes: 6 additions & 0 deletions src/test/rustdoc/issue-35169.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ impl Foo {
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() {}
}

Expand All @@ -36,5 +38,9 @@ impl Deref for Bar {
// @!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()'