Skip to content

Commit e53f2a0

Browse files
committed
Remove some kw::Empty uses in rustdoc.
Some `unwrap` uses here, but they are on paths involving item kinds that are known to have an identifier.
1 parent 990039e commit e53f2a0

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

Diff for: src/librustdoc/clean/mod.rs

+19-16
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,15 @@ pub(crate) fn clean_doc_module<'tcx>(doc: &DocModule<'tcx>, cx: &mut DocContext<
117117
hir::ItemKind::Use(path, kind) => {
118118
let hir::UsePath { segments, span, .. } = *path;
119119
let path = hir::Path { segments, res: *res, span };
120-
clean_use_statement_inner(import, name, &path, kind, cx, &mut Default::default())
120+
clean_use_statement_inner(import, Some(name), &path, kind, cx, &mut Default::default())
121121
}
122122
_ => unreachable!(),
123123
}
124124
}));
125125
items.extend(doc.items.values().flat_map(|(item, renamed, _)| {
126126
// Now we actually lower the imports, skipping everything else.
127127
if let hir::ItemKind::Use(path, hir::UseKind::Glob) = item.kind {
128-
let name = renamed.unwrap_or(kw::Empty); // using kw::Empty is a bit of a hack
129-
clean_use_statement(item, name, path, hir::UseKind::Glob, cx, &mut inserted)
128+
clean_use_statement(item, *renamed, path, hir::UseKind::Glob, cx, &mut inserted)
130129
} else {
131130
// skip everything else
132131
Vec::new()
@@ -2792,10 +2791,11 @@ fn clean_maybe_renamed_item<'tcx>(
27922791
use hir::ItemKind;
27932792

27942793
let def_id = item.owner_id.to_def_id();
2795-
let mut name = renamed.unwrap_or_else(|| {
2796-
// FIXME: using kw::Empty is a bit of a hack
2797-
cx.tcx.hir_opt_name(item.hir_id()).unwrap_or(kw::Empty)
2798-
});
2794+
let mut name = if renamed.is_some() {
2795+
renamed
2796+
} else {
2797+
cx.tcx.hir_opt_name(item.hir_id())
2798+
};
27992799

28002800
cx.with_param_env(def_id, |cx| {
28012801
let kind = match item.kind {
@@ -2836,7 +2836,7 @@ fn clean_maybe_renamed_item<'tcx>(
28362836
item_type: Some(type_),
28372837
})),
28382838
item.owner_id.def_id.to_def_id(),
2839-
name,
2839+
name.unwrap(),
28402840
import_id,
28412841
renamed,
28422842
));
@@ -2861,13 +2861,15 @@ fn clean_maybe_renamed_item<'tcx>(
28612861
}),
28622862
ItemKind::Impl(impl_) => return clean_impl(impl_, item.owner_id.def_id, cx),
28632863
ItemKind::Macro(_, macro_def, MacroKind::Bang) => MacroItem(Macro {
2864-
source: display_macro_source(cx, name, macro_def),
2864+
source: display_macro_source(cx, name.unwrap(), macro_def),
28652865
macro_rules: macro_def.macro_rules,
28662866
}),
2867-
ItemKind::Macro(_, _, macro_kind) => clean_proc_macro(item, &mut name, macro_kind, cx),
2867+
ItemKind::Macro(_, _, macro_kind) => {
2868+
clean_proc_macro(item, name.as_mut().unwrap(), macro_kind, cx)
2869+
}
28682870
// proc macros can have a name set by attributes
28692871
ItemKind::Fn { ref sig, generics, body: body_id, .. } => {
2870-
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
2872+
clean_fn_or_proc_macro(item, sig, generics, body_id, name.as_mut().unwrap(), cx)
28712873
}
28722874
ItemKind::Trait(_, _, _, generics, bounds, item_ids) => {
28732875
let items = item_ids
@@ -2883,7 +2885,7 @@ fn clean_maybe_renamed_item<'tcx>(
28832885
}))
28842886
}
28852887
ItemKind::ExternCrate(orig_name, _) => {
2886-
return clean_extern_crate(item, name, orig_name, cx);
2888+
return clean_extern_crate(item, name.unwrap(), orig_name, cx);
28872889
}
28882890
ItemKind::Use(path, kind) => {
28892891
return clean_use_statement(item, name, path, kind, cx, &mut FxHashSet::default());
@@ -2895,7 +2897,7 @@ fn clean_maybe_renamed_item<'tcx>(
28952897
cx,
28962898
kind,
28972899
item.owner_id.def_id.to_def_id(),
2898-
name,
2900+
name.unwrap(),
28992901
import_id,
29002902
renamed,
29012903
)]
@@ -3006,7 +3008,7 @@ fn clean_extern_crate<'tcx>(
30063008

30073009
fn clean_use_statement<'tcx>(
30083010
import: &hir::Item<'tcx>,
3009-
name: Symbol,
3011+
name: Option<Symbol>,
30103012
path: &hir::UsePath<'tcx>,
30113013
kind: hir::UseKind,
30123014
cx: &mut DocContext<'tcx>,
@@ -3023,7 +3025,7 @@ fn clean_use_statement<'tcx>(
30233025

30243026
fn clean_use_statement_inner<'tcx>(
30253027
import: &hir::Item<'tcx>,
3026-
name: Symbol,
3028+
name: Option<Symbol>,
30273029
path: &hir::Path<'tcx>,
30283030
kind: hir::UseKind,
30293031
cx: &mut DocContext<'tcx>,
@@ -3042,7 +3044,7 @@ fn clean_use_statement_inner<'tcx>(
30423044
let visibility = cx.tcx.visibility(import.owner_id);
30433045
let attrs = cx.tcx.hir_attrs(import.hir_id());
30443046
let inline_attr = hir_attr_lists(attrs, sym::doc).get_word_attr(sym::inline);
3045-
let pub_underscore = visibility.is_public() && name == kw::Underscore;
3047+
let pub_underscore = visibility.is_public() && name == Some(kw::Underscore);
30463048
let current_mod = cx.tcx.parent_module_from_def_id(import.owner_id.def_id);
30473049
let import_def_id = import.owner_id.def_id;
30483050

@@ -3108,6 +3110,7 @@ fn clean_use_statement_inner<'tcx>(
31083110
}
31093111
Import::new_glob(resolve_use_source(cx, path), true)
31103112
} else {
3113+
let name = name.unwrap();
31113114
if inline_attr.is_none()
31123115
&& let Res::Def(DefKind::Mod, did) = path.res
31133116
&& !did.is_local()

0 commit comments

Comments
 (0)