Skip to content

Commit 6c5d212

Browse files
Make exact_paths a non-optional field on RustdocVisitor
Also privatizes needlessly public methods to enforce which methods callers are intended to call, i.e., only `new` and `visit`.
1 parent 2fadc45 commit 6c5d212

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

src/librustdoc/visit_ast.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub struct RustdocVisitor<'a, 'tcx> {
2929
inlining: bool,
3030
/// Are the current module and all of its parents public?
3131
inside_public_path: bool,
32-
exact_paths: Option<FxHashMap<DefId, Vec<String>>>,
32+
exact_paths: FxHashMap<DefId, Vec<String>>,
3333
}
3434

3535
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
@@ -44,17 +44,16 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
4444
view_item_stack: stack,
4545
inlining: false,
4646
inside_public_path: true,
47-
exact_paths: Some(FxHashMap::default()),
47+
exact_paths: FxHashMap::default(),
4848
}
4949
}
5050

5151
fn store_path(&mut self, did: DefId) {
5252
// We can't use the entry API, as that keeps the mutable borrow of `self` active
5353
// when we try to use `cx`.
54-
let exact_paths = self.exact_paths.as_mut().unwrap();
55-
if exact_paths.get(&did).is_none() {
54+
if self.exact_paths.get(&did).is_none() {
5655
let path = def_id_to_path(self.cx, did, self.cx.crate_name.clone());
57-
exact_paths.insert(did, path);
56+
self.exact_paths.insert(did, path);
5857
}
5958
}
6059

@@ -82,12 +81,12 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
8281
);
8382
module.is_crate = true;
8483

85-
self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths.take().unwrap();
84+
self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths;
8685

8786
module
8887
}
8988

90-
pub fn visit_variant_data(&mut self, item: &'tcx hir::Item,
89+
fn visit_variant_data(&mut self, item: &'tcx hir::Item,
9190
name: ast::Name, sd: &'tcx hir::VariantData,
9291
generics: &'tcx hir::Generics) -> Struct<'tcx> {
9392
debug!("visiting struct");
@@ -106,7 +105,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
106105
}
107106
}
108107

109-
pub fn visit_union_data(&mut self, item: &'tcx hir::Item,
108+
fn visit_union_data(&mut self, item: &'tcx hir::Item,
110109
name: ast::Name, sd: &'tcx hir::VariantData,
111110
generics: &'tcx hir::Generics) -> Union<'tcx> {
112111
debug!("visiting union");
@@ -125,7 +124,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
125124
}
126125
}
127126

128-
pub fn visit_enum_def(&mut self, it: &'tcx hir::Item,
127+
fn visit_enum_def(&mut self, it: &'tcx hir::Item,
129128
name: ast::Name, def: &'tcx hir::EnumDef,
130129
generics: &'tcx hir::Generics) -> Enum<'tcx> {
131130
debug!("visiting enum");
@@ -150,7 +149,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
150149
}
151150
}
152151

153-
pub fn visit_fn(&mut self, om: &mut Module<'tcx>, item: &'tcx hir::Item,
152+
fn visit_fn(&mut self, om: &mut Module<'tcx>, item: &'tcx hir::Item,
154153
name: ast::Name, decl: &'tcx hir::FnDecl,
155154
header: hir::FnHeader,
156155
generics: &'tcx hir::Generics,
@@ -223,7 +222,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
223222
}
224223
}
225224

226-
pub fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx hir::HirVec<ast::Attribute>,
225+
fn visit_mod_contents(&mut self, span: Span, attrs: &'tcx hir::HirVec<ast::Attribute>,
227226
vis: &'tcx hir::Visibility, id: hir::HirId,
228227
m: &'tcx hir::Mod,
229228
name: Option<ast::Name>) -> Module<'tcx> {
@@ -363,7 +362,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
363362
ret
364363
}
365364

366-
pub fn visit_item(&mut self, item: &'tcx hir::Item,
365+
fn visit_item(&mut self, item: &'tcx hir::Item,
367366
renamed: Option<ast::Ident>, om: &mut Module<'tcx>) {
368367
debug!("visiting item {:?}", item);
369368
let ident = renamed.unwrap_or(item.ident);

0 commit comments

Comments
 (0)