Skip to content

Commit 76db2e3

Browse files
authored
Rollup merge of rust-lang#67487 - GuillaumeGomez:rustdoc-mutability-removal, r=Centril
Rustdoc mutability removal Fixes rust-lang#67470. As discussed in another PR, the `clean::Mutability` type in rustdoc is useless. So let's remove it! r? @Centril
2 parents 2b2cc38 + 0d7a49d commit 76db2e3

File tree

5 files changed

+23
-40
lines changed

5 files changed

+23
-40
lines changed

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use syntax::symbol::sym;
77
use syntax_pos::hygiene::MacroKind;
88
use syntax_pos::Span;
99

10-
use rustc::hir;
10+
use rustc::hir::{self, Mutability};
1111
use rustc::hir::def::{Res, DefKind, CtorKind};
1212
use rustc::hir::def_id::DefId;
1313
use rustc_metadata::creader::LoadedMacro;
@@ -472,7 +472,7 @@ fn build_const(cx: &DocContext<'_>, did: DefId) -> clean::Constant {
472472
fn build_static(cx: &DocContext<'_>, did: DefId, mutable: bool) -> clean::Static {
473473
clean::Static {
474474
type_: cx.tcx.type_of(did).clean(cx),
475-
mutability: if mutable {clean::Mutable} else {clean::Immutable},
475+
mutability: if mutable { Mutability::Mut } else { Mutability::Not },
476476
expr: "\n\n\n".to_string(), // trigger the "[definition]" links
477477
}
478478
}

src/librustdoc/clean/mod.rs

+6-17
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ pub use utils::{get_auto_trait_and_blanket_impls, krate, register_res};
4545

4646
pub use self::types::*;
4747
pub use self::types::Type::*;
48-
pub use self::types::Mutability::*;
4948
pub use self::types::ItemEnum::*;
5049
pub use self::types::SelfTy::*;
5150
pub use self::types::FunctionRetTy::*;
@@ -1327,15 +1326,14 @@ impl Clean<Type> for hir::Ty {
13271326

13281327
match self.kind {
13291328
TyKind::Never => Never,
1330-
TyKind::Ptr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)),
1329+
TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)),
13311330
TyKind::Rptr(ref l, ref m) => {
13321331
let lifetime = if l.is_elided() {
13331332
None
13341333
} else {
13351334
Some(l.clean(cx))
13361335
};
1337-
BorrowedRef {lifetime, mutability: m.mutbl.clean(cx),
1338-
type_: box m.ty.clean(cx)}
1336+
BorrowedRef {lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx)}
13391337
}
13401338
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
13411339
TyKind::Array(ref ty, ref length) => {
@@ -1538,10 +1536,10 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
15381536
let n = print_const(cx, n);
15391537
Array(box ty.clean(cx), n)
15401538
}
1541-
ty::RawPtr(mt) => RawPointer(mt.mutbl.clean(cx), box mt.ty.clean(cx)),
1539+
ty::RawPtr(mt) => RawPointer(mt.mutbl, box mt.ty.clean(cx)),
15421540
ty::Ref(r, ty, mutbl) => BorrowedRef {
15431541
lifetime: r.clean(cx),
1544-
mutability: mutbl.clean(cx),
1542+
mutability: mutbl,
15451543
type_: box ty.clean(cx),
15461544
},
15471545
ty::FnDef(..) |
@@ -2064,7 +2062,7 @@ impl Clean<Item> for doctree::Static<'_> {
20642062
deprecation: cx.deprecation(self.id).clean(cx),
20652063
inner: StaticItem(Static {
20662064
type_: self.type_.clean(cx),
2067-
mutability: self.mutability.clean(cx),
2065+
mutability: self.mutability,
20682066
expr: print_const_expr(cx, self.expr),
20692067
}),
20702068
}
@@ -2089,15 +2087,6 @@ impl Clean<Item> for doctree::Constant<'_> {
20892087
}
20902088
}
20912089

2092-
impl Clean<Mutability> for hir::Mutability {
2093-
fn clean(&self, _: &DocContext<'_>) -> Mutability {
2094-
match self {
2095-
&hir::Mutability::Mut => Mutable,
2096-
&hir::Mutability::Not => Immutable,
2097-
}
2098-
}
2099-
}
2100-
21012090
impl Clean<ImplPolarity> for ty::ImplPolarity {
21022091
fn clean(&self, _: &DocContext<'_>) -> ImplPolarity {
21032092
match self {
@@ -2287,7 +2276,7 @@ impl Clean<Item> for doctree::ForeignItem<'_> {
22872276
hir::ForeignItemKind::Static(ref ty, mutbl) => {
22882277
ForeignStaticItem(Static {
22892278
type_: ty.clean(cx),
2290-
mutability: mutbl.clean(cx),
2279+
mutability: *mutbl,
22912280
expr: String::new(),
22922281
})
22932282
}

src/librustdoc/clean/types.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::sync::Arc;
1010

1111
use rustc::middle::lang_items;
1212
use rustc::middle::stability;
13-
use rustc::hir;
13+
use rustc::hir::{self, Mutability};
1414
use rustc::hir::def::Res;
1515
use rustc::hir::def_id::{CrateNum, DefId};
1616
use rustc::ty::layout::VariantIdx;
@@ -1450,12 +1450,6 @@ pub struct Constant {
14501450
pub expr: String,
14511451
}
14521452

1453-
#[derive(Debug, Clone, PartialEq, Eq, Copy, Hash)]
1454-
pub enum Mutability {
1455-
Mutable,
1456-
Immutable,
1457-
}
1458-
14591453
#[derive(Clone, PartialEq, Debug)]
14601454
pub enum ImplPolarity {
14611455
Positive,

src/librustdoc/html/format.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) ->
670670
clean::Never => primitive_link(f, PrimitiveType::Never, "!"),
671671
clean::RawPointer(m, ref t) => {
672672
let m = match m {
673-
clean::Immutable => "const",
674-
clean::Mutable => "mut",
673+
hir::Mutability::Mut => "mut",
674+
hir::Mutability::Not => "const",
675675
};
676676
match **t {
677677
clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => {
@@ -1082,6 +1082,15 @@ impl PrintWithSpace for hir::IsAsync {
10821082
}
10831083
}
10841084

1085+
impl PrintWithSpace for hir::Mutability {
1086+
fn print_with_space(&self) -> &str {
1087+
match self {
1088+
hir::Mutability::Not => "",
1089+
hir::Mutability::Mut => "mut ",
1090+
}
1091+
}
1092+
}
1093+
10851094
impl clean::Import {
10861095
crate fn print(&self) -> impl fmt::Display + '_ {
10871096
display_fn(move |f| {
@@ -1151,15 +1160,6 @@ impl clean::TypeBinding {
11511160
}
11521161
}
11531162

1154-
impl clean::Mutability {
1155-
crate fn print_with_space(&self) -> &str {
1156-
match self {
1157-
clean::Immutable => "",
1158-
clean::Mutable => "mut ",
1159-
}
1160-
}
1161-
}
1162-
11631163
crate fn print_abi_with_space(abi: Abi) -> impl fmt::Display {
11641164
display_fn(move |f| {
11651165
let quot = if f.alternate() { "\"" } else { "&quot;" };

src/librustdoc/html/render.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ use syntax_pos::hygiene::MacroKind;
5454
use rustc::hir::def_id::DefId;
5555
use rustc::middle::privacy::AccessLevels;
5656
use rustc::middle::stability;
57-
use rustc::hir;
57+
use rustc::hir::{self, Mutability};
5858
use rustc::util::nodemap::{FxHashMap, FxHashSet};
5959
use rustc_data_structures::flock;
6060
use rustc_feature::UnstableFeatures;
6161

62-
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy, Mutability};
62+
use crate::clean::{self, AttributesExt, Deprecation, GetDefId, SelfTy};
6363
use crate::config::RenderOptions;
6464
use crate::docfs::{DocFS, ErrorStorage, PathError};
6565
use crate::doctree;
@@ -3298,7 +3298,7 @@ fn should_render_item(item: &clean::Item, deref_mut_: bool) -> bool {
32983298
let (by_mut_ref, by_box, by_value) = match self_ty {
32993299
SelfTy::SelfBorrowed(_, mutability) |
33003300
SelfTy::SelfExplicit(clean::BorrowedRef { mutability, .. }) => {
3301-
(mutability == Mutability::Mutable, false, false)
3301+
(mutability == Mutability::Mut, false, false)
33023302
},
33033303
SelfTy::SelfExplicit(clean::ResolvedPath { did, .. }) => {
33043304
(false, Some(did) == cache().owned_box_did, false)

0 commit comments

Comments
 (0)