From 0d7a49d3563246f193e11ae63e713c0a65319f8c Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 21 Dec 2019 15:47:27 +0100 Subject: [PATCH] Implement PrintWithSpace trait on hir::Mutability --- src/librustdoc/clean/inline.rs | 2 +- src/librustdoc/html/format.rs | 22 +++++++++++----------- src/librustdoc/html/render.rs | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 0f43555fd74c3..b7e01708fbfcf 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -472,7 +472,7 @@ fn build_const(cx: &DocContext<'_>, did: DefId) -> clean::Constant { fn build_static(cx: &DocContext<'_>, did: DefId, mutable: bool) -> clean::Static { clean::Static { type_: cx.tcx.type_of(did).clean(cx), - mutability: if mutable { Mutability::Mutable } else { Mutability::Immutable }, + mutability: if mutable { Mutability::Mut } else { Mutability::Not }, expr: "\n\n\n".to_string(), // trigger the "[definition]" links } } diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index fd620d467de48..501147ed4593b 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -670,8 +670,8 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) -> clean::Never => primitive_link(f, PrimitiveType::Never, "!"), clean::RawPointer(m, ref t) => { let m = match m { - clean::Immutable => "const", - clean::Mutable => "mut", + hir::Mutability::Mut => "mut", + hir::Mutability::Not => "const", }; match **t { clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => { @@ -1082,6 +1082,15 @@ impl PrintWithSpace for hir::IsAsync { } } +impl PrintWithSpace for hir::Mutability { + fn print_with_space(&self) -> &str { + match self { + hir::Mutability::Not => "", + hir::Mutability::Mut => "mut ", + } + } +} + impl clean::Import { crate fn print(&self) -> impl fmt::Display + '_ { display_fn(move |f| { @@ -1151,15 +1160,6 @@ impl clean::TypeBinding { } } -impl clean::Mutability { - crate fn print_with_space(&self) -> &str { - match self { - clean::Immutable => "", - clean::Mutable => "mut ", - } - } -} - crate fn print_abi_with_space(abi: Abi) -> impl fmt::Display { display_fn(move |f| { let quot = if f.alternate() { "\"" } else { """ }; diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index e822ada0fb9b1..100aed1af193a 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -3298,7 +3298,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool { let (by_mut_ref, by_box, by_value) = match self_ty { SelfTy::SelfBorrowed(_, mutability) | SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => { - (mutability == Mutability::Mutable, false, false) + (mutability == Mutability::Mut, false, false) }, SelfTy::SelfExplicit(clean::ResolvedPath { did, .. }) => { (false, Some(did) == cache().owned_box_did, false)