Skip to content

Commit

Permalink
Implement PrintWithSpace trait on hir::Mutability
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Dec 22, 2019
1 parent 5a0d747 commit 0d7a49d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
22 changes: 11 additions & 11 deletions src/librustdoc/html/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, ..} => {
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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;" };
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0d7a49d

Please sign in to comment.