Implement PrintWithSpace trait on hir::Mutability

This commit is contained in:
Guillaume Gomez 2019-12-21 15:47:27 +01:00
parent 5a0d747eef
commit 0d7a49d356
3 changed files with 13 additions and 13 deletions

View File

@ -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
}
}

View File

@ -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 { "&quot;" };

View File

@ -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)