librustdoc: adopt let else in more places
This commit is contained in:
parent
65f6d33b77
commit
565f644edf
@ -107,9 +107,9 @@ fn clean(&self, cx: &mut DocContext<'_>) -> Option<GenericBound> {
|
|||||||
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
|
let trait_ref = ty::TraitRef::identity(cx.tcx, def_id).skip_binder();
|
||||||
|
|
||||||
let generic_args = generic_args.clean(cx);
|
let generic_args = generic_args.clean(cx);
|
||||||
let bindings = match generic_args {
|
let GenericArgs::AngleBracketed { bindings, .. } = generic_args
|
||||||
GenericArgs::AngleBracketed { bindings, .. } => bindings,
|
else {
|
||||||
_ => bug!("clean: parenthesized `GenericBound::LangItemTrait`"),
|
bug!("clean: parenthesized `GenericBound::LangItemTrait`");
|
||||||
};
|
};
|
||||||
|
|
||||||
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
|
let trait_ = clean_trait_ref_with_bindings(cx, trait_ref, &bindings);
|
||||||
@ -1282,10 +1282,7 @@ fn param_eq_arg(param: &GenericParamDef, arg: &GenericArg) -> bool {
|
|||||||
|
|
||||||
fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
|
fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
|
||||||
let hir::Ty { hir_id: _, span, ref kind } = *hir_ty;
|
let hir::Ty { hir_id: _, span, ref kind } = *hir_ty;
|
||||||
let qpath = match kind {
|
let hir::TyKind::Path(qpath) = kind else { unreachable!() };
|
||||||
hir::TyKind::Path(qpath) => qpath,
|
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
|
|
||||||
match qpath {
|
match qpath {
|
||||||
hir::QPath::Resolved(None, ref path) => {
|
hir::QPath::Resolved(None, ref path) => {
|
||||||
|
@ -54,14 +54,8 @@
|
|||||||
let Some((self_, trait_did, name)) = lhs.projection() else {
|
let Some((self_, trait_did, name)) = lhs.projection() else {
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
let generic = match self_ {
|
let clean::Generic(generic) = self_ else { return true };
|
||||||
clean::Generic(s) => s,
|
let Some((bounds, _)) = params.get_mut(generic) else { return true };
|
||||||
_ => return true,
|
|
||||||
};
|
|
||||||
let (bounds, _) = match params.get_mut(generic) {
|
|
||||||
Some(bound) => bound,
|
|
||||||
None => return true,
|
|
||||||
};
|
|
||||||
|
|
||||||
merge_bounds(cx, bounds, trait_did, name, rhs)
|
merge_bounds(cx, bounds, trait_did, name, rhs)
|
||||||
});
|
});
|
||||||
|
@ -57,10 +57,8 @@
|
|||||||
let primitives = local_crate.primitives(cx.tcx);
|
let primitives = local_crate.primitives(cx.tcx);
|
||||||
let keywords = local_crate.keywords(cx.tcx);
|
let keywords = local_crate.keywords(cx.tcx);
|
||||||
{
|
{
|
||||||
let m = match *module.kind {
|
let ItemKind::ModuleItem(ref mut m) = *module.kind
|
||||||
ItemKind::ModuleItem(ref mut m) => m,
|
else { unreachable!() };
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
m.items.extend(primitives.iter().map(|&(def_id, prim)| {
|
m.items.extend(primitives.iter().map(|&(def_id, prim)| {
|
||||||
Item::from_def_id_and_parts(
|
Item::from_def_id_and_parts(
|
||||||
def_id,
|
def_id,
|
||||||
|
@ -562,7 +562,7 @@ fn println_condition(condition: Condition) {
|
|||||||
let edition = config::parse_crate_edition(matches);
|
let edition = config::parse_crate_edition(matches);
|
||||||
|
|
||||||
let mut id_map = html::markdown::IdMap::new();
|
let mut id_map = html::markdown::IdMap::new();
|
||||||
let external_html = match ExternalHtml::load(
|
let Some(external_html) = ExternalHtml::load(
|
||||||
&matches.opt_strs("html-in-header"),
|
&matches.opt_strs("html-in-header"),
|
||||||
&matches.opt_strs("html-before-content"),
|
&matches.opt_strs("html-before-content"),
|
||||||
&matches.opt_strs("html-after-content"),
|
&matches.opt_strs("html-after-content"),
|
||||||
@ -573,9 +573,8 @@ fn println_condition(condition: Condition) {
|
|||||||
&mut id_map,
|
&mut id_map,
|
||||||
edition,
|
edition,
|
||||||
&None,
|
&None,
|
||||||
) {
|
) else {
|
||||||
Some(eh) => eh,
|
return Err(3);
|
||||||
None => return Err(3),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
match matches.opt_str("r").as_deref() {
|
match matches.opt_str("r").as_deref() {
|
||||||
|
@ -614,13 +614,11 @@ fn drop(&mut self) {
|
|||||||
(found_main, found_extern_crate, found_macro)
|
(found_main, found_extern_crate, found_macro)
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
let (already_has_main, already_has_extern_crate, found_macro) = match result {
|
let Ok((already_has_main, already_has_extern_crate, found_macro)) = result
|
||||||
Ok(result) => result,
|
else {
|
||||||
Err(ErrorGuaranteed) => {
|
// If the parser panicked due to a fatal error, pass the test code through unchanged.
|
||||||
// If the parser panicked due to a fatal error, pass the test code through unchanged.
|
// The error will be reported during compilation.
|
||||||
// The error will be reported during compilation.
|
return (s.to_owned(), 0, false);
|
||||||
return (s.to_owned(), 0, false);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If a doctest's `fn main` is being masked by a wrapper macro, the parsing loop above won't
|
// If a doctest's `fn main` is being masked by a wrapper macro, the parsing loop above won't
|
||||||
|
@ -99,10 +99,7 @@ impl ExternalHtml {
|
|||||||
fn load_external_files(names: &[String], diag: &rustc_errors::Handler) -> Option<String> {
|
fn load_external_files(names: &[String], diag: &rustc_errors::Handler) -> Option<String> {
|
||||||
let mut out = String::new();
|
let mut out = String::new();
|
||||||
for name in names {
|
for name in names {
|
||||||
let s = match load_string(name, diag) {
|
let Ok(s) = load_string(name, diag) else { return None };
|
||||||
Ok(s) => s,
|
|
||||||
Err(_) => return None,
|
|
||||||
};
|
|
||||||
out.push_str(&s);
|
out.push_str(&s);
|
||||||
out.push('\n');
|
out.push('\n');
|
||||||
}
|
}
|
||||||
|
@ -77,10 +77,8 @@ fn mod_item_out(&mut self) -> Result<(), Error> {
|
|||||||
prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string());
|
prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string());
|
||||||
|
|
||||||
cx.mod_item_in(&item)?;
|
cx.mod_item_in(&item)?;
|
||||||
let module = match *item.kind {
|
let (clean::StrippedItem(box clean::ModuleItem(module)) | clean::ModuleItem(module)) = *item.kind
|
||||||
clean::StrippedItem(box clean::ModuleItem(m)) | clean::ModuleItem(m) => m,
|
else { unreachable!() };
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
for it in module.items {
|
for it in module.items {
|
||||||
debug!("Adding {:?} to worklist", it.name);
|
debug!("Adding {:?} to worklist", it.name);
|
||||||
work.push((cx.make_child_renderer(), it));
|
work.push((cx.make_child_renderer(), it));
|
||||||
|
@ -689,16 +689,12 @@ fn string<T: Display>(
|
|||||||
klass: Option<Class>,
|
klass: Option<Class>,
|
||||||
context_info: &Option<ContextInfo<'_, '_, '_>>,
|
context_info: &Option<ContextInfo<'_, '_, '_>>,
|
||||||
) {
|
) {
|
||||||
let klass = match klass {
|
let Some(klass) = klass
|
||||||
None => return write!(out, "{}", text),
|
else { return write!(out, "{}", text) };
|
||||||
Some(klass) => klass,
|
let Some(def_span) = klass.get_span()
|
||||||
};
|
else {
|
||||||
let def_span = match klass.get_span() {
|
write!(out, "<span class=\"{}\">{}</span>", klass.as_html(), text);
|
||||||
Some(d) => d,
|
return;
|
||||||
None => {
|
|
||||||
write!(out, "<span class=\"{}\">{}</span>", klass.as_html(), text);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let mut text_s = text.to_string();
|
let mut text_s = text.to_string();
|
||||||
if text_s.contains("::") {
|
if text_s.contains("::") {
|
||||||
|
@ -655,10 +655,8 @@ fn mod_item_in(&mut self, item: &clean::Item) -> Result<(), Error> {
|
|||||||
|
|
||||||
// Render sidebar-items.js used throughout this module.
|
// Render sidebar-items.js used throughout this module.
|
||||||
if !self.render_redirect_pages {
|
if !self.render_redirect_pages {
|
||||||
let module = match *item.kind {
|
let (clean::StrippedItem(box clean::ModuleItem(ref module)) | clean::ModuleItem(ref module)) = *item.kind
|
||||||
clean::StrippedItem(box clean::ModuleItem(ref m)) | clean::ModuleItem(ref m) => m,
|
else { unreachable!() };
|
||||||
_ => unreachable!(),
|
|
||||||
};
|
|
||||||
let items = self.build_sidebar_items(module);
|
let items = self.build_sidebar_items(module);
|
||||||
let js_dst = self.dst.join(&format!("sidebar-items{}.js", self.shared.resource_suffix));
|
let js_dst = self.dst.join(&format!("sidebar-items{}.js", self.shared.resource_suffix));
|
||||||
let v = format!("initSidebarItems({});", serde_json::to_string(&items).unwrap());
|
let v = format!("initSidebarItems({});", serde_json::to_string(&items).unwrap());
|
||||||
|
@ -1058,10 +1058,7 @@ fn render_assoc_items_inner(
|
|||||||
) {
|
) {
|
||||||
info!("Documenting associated items of {:?}", containing_item.name);
|
info!("Documenting associated items of {:?}", containing_item.name);
|
||||||
let cache = cx.cache();
|
let cache = cx.cache();
|
||||||
let v = match cache.impls.get(&it) {
|
let Some(v) = cache.impls.get(&it) else { return };
|
||||||
Some(v) => v,
|
|
||||||
None => return,
|
|
||||||
};
|
|
||||||
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
|
let (non_trait, traits): (Vec<_>, _) = v.iter().partition(|i| i.inner_impl().trait_.is_none());
|
||||||
if !non_trait.is_empty() {
|
if !non_trait.is_empty() {
|
||||||
let mut tmp_buf = Buffer::empty_from(w);
|
let mut tmp_buf = Buffer::empty_from(w);
|
||||||
@ -2654,12 +2651,7 @@ fn render_call_locations(w: &mut Buffer, cx: &Context<'_>, item: &clean::Item) {
|
|||||||
let tcx = cx.tcx();
|
let tcx = cx.tcx();
|
||||||
let def_id = item.def_id.expect_def_id();
|
let def_id = item.def_id.expect_def_id();
|
||||||
let key = tcx.def_path_hash(def_id);
|
let key = tcx.def_path_hash(def_id);
|
||||||
let call_locations = match cx.shared.call_locations.get(&key) {
|
let Some(call_locations) = cx.shared.call_locations.get(&key) else { return };
|
||||||
Some(call_locations) => call_locations,
|
|
||||||
_ => {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Generate a unique ID so users can link to this section for a given method
|
// Generate a unique ID so users can link to this section for a given method
|
||||||
let id = cx.id_map.borrow_mut().derive("scraped-examples");
|
let id = cx.id_map.borrow_mut().derive("scraped-examples");
|
||||||
|
@ -61,12 +61,10 @@ fn find_raw_urls(
|
|||||||
|
|
||||||
impl<'a, 'tcx> DocVisitor for BareUrlsLinter<'a, 'tcx> {
|
impl<'a, 'tcx> DocVisitor for BareUrlsLinter<'a, 'tcx> {
|
||||||
fn visit_item(&mut self, item: &Item) {
|
fn visit_item(&mut self, item: &Item) {
|
||||||
let hir_id = match DocContext::as_local_hir_id(self.cx.tcx, item.def_id) {
|
let Some(hir_id) = DocContext::as_local_hir_id(self.cx.tcx, item.def_id)
|
||||||
Some(hir_id) => hir_id,
|
else {
|
||||||
None => {
|
// If non-local, no need to check anything.
|
||||||
// If non-local, no need to check anything.
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let dox = item.attrs.collapsed_doc_value().unwrap_or_default();
|
let dox = item.attrs.collapsed_doc_value().unwrap_or_default();
|
||||||
if !dox.is_empty() {
|
if !dox.is_empty() {
|
||||||
|
@ -67,11 +67,11 @@ fn check_rust_syntax(&self, item: &clean::Item, dox: &str, code_block: RustCodeB
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let local_id = match item.def_id.as_def_id().and_then(|x| x.as_local()) {
|
let Some(local_id) = item.def_id.as_def_id().and_then(|x| x.as_local())
|
||||||
Some(id) => id,
|
else {
|
||||||
// We don't need to check the syntax for other crates so returning
|
// We don't need to check the syntax for other crates so returning
|
||||||
// without doing anything should not be a problem.
|
// without doing anything should not be a problem.
|
||||||
None => return,
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_id);
|
let hir_id = self.cx.tcx.hir().local_def_id_to_hir_id(local_id);
|
||||||
|
@ -107,12 +107,10 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
|
crate fn look_for_tests<'tcx>(cx: &DocContext<'tcx>, dox: &str, item: &Item) {
|
||||||
let hir_id = match DocContext::as_local_hir_id(cx.tcx, item.def_id) {
|
let Some(hir_id) = DocContext::as_local_hir_id(cx.tcx, item.def_id)
|
||||||
Some(hir_id) => hir_id,
|
else {
|
||||||
None => {
|
// If non-local, no need to check anything.
|
||||||
// If non-local, no need to check anything.
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tests = Tests { found_tests: 0 };
|
let mut tests = Tests { found_tests: 0 };
|
||||||
|
@ -1868,13 +1868,11 @@ fn report_diagnostic(
|
|||||||
DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>,
|
DiagnosticInfo { item, ori_link: _, dox, link_range }: &DiagnosticInfo<'_>,
|
||||||
decorate: impl FnOnce(&mut Diagnostic, Option<rustc_span::Span>),
|
decorate: impl FnOnce(&mut Diagnostic, Option<rustc_span::Span>),
|
||||||
) {
|
) {
|
||||||
let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) {
|
let Some(hir_id) = DocContext::as_local_hir_id(tcx, item.def_id)
|
||||||
Some(hir_id) => hir_id,
|
else {
|
||||||
None => {
|
// If non-local, no need to check anything.
|
||||||
// If non-local, no need to check anything.
|
info!("ignoring warning from parent crate: {}", msg);
|
||||||
info!("ignoring warning from parent crate: {}", msg);
|
return;
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let sp = item.attr_span(tcx);
|
let sp = item.attr_span(tcx);
|
||||||
|
@ -197,13 +197,9 @@ fn extract_tags(
|
|||||||
impl<'a, 'tcx> DocVisitor for InvalidHtmlTagsLinter<'a, 'tcx> {
|
impl<'a, 'tcx> DocVisitor for InvalidHtmlTagsLinter<'a, 'tcx> {
|
||||||
fn visit_item(&mut self, item: &Item) {
|
fn visit_item(&mut self, item: &Item) {
|
||||||
let tcx = self.cx.tcx;
|
let tcx = self.cx.tcx;
|
||||||
let hir_id = match DocContext::as_local_hir_id(tcx, item.def_id) {
|
let Some(hir_id) = DocContext::as_local_hir_id(tcx, item.def_id)
|
||||||
Some(hir_id) => hir_id,
|
// If non-local, no need to check anything.
|
||||||
None => {
|
else { return };
|
||||||
// If non-local, no need to check anything.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let dox = item.attrs.collapsed_doc_value().unwrap_or_default();
|
let dox = item.attrs.collapsed_doc_value().unwrap_or_default();
|
||||||
if !dox.is_empty() {
|
if !dox.is_empty() {
|
||||||
let report_diag = |msg: &str, range: &Range<usize>, is_open_tag: bool| {
|
let report_diag = |msg: &str, range: &Range<usize>, is_open_tag: bool| {
|
||||||
|
@ -80,7 +80,7 @@ fn unindent_fragments(docs: &mut Vec<DocFragment>) {
|
|||||||
// In here, the `min_indent` is 1 (because non-sugared fragment are always counted with minimum
|
// In here, the `min_indent` is 1 (because non-sugared fragment are always counted with minimum
|
||||||
// 1 whitespace), meaning that "hello!" will be considered a codeblock because it starts with 4
|
// 1 whitespace), meaning that "hello!" will be considered a codeblock because it starts with 4
|
||||||
// (5 - 1) whitespaces.
|
// (5 - 1) whitespaces.
|
||||||
let min_indent = match docs
|
let Some(min_indent) = docs
|
||||||
.iter()
|
.iter()
|
||||||
.map(|fragment| {
|
.map(|fragment| {
|
||||||
fragment.doc.as_str().lines().fold(usize::MAX, |min_indent, line| {
|
fragment.doc.as_str().lines().fold(usize::MAX, |min_indent, line| {
|
||||||
@ -96,9 +96,8 @@ fn unindent_fragments(docs: &mut Vec<DocFragment>) {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.min()
|
.min()
|
||||||
{
|
else {
|
||||||
Some(x) => x,
|
return;
|
||||||
None => return,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for fragment in docs {
|
for fragment in docs {
|
||||||
|
Loading…
Reference in New Issue
Block a user