Use more let chain
This commit is contained in:
parent
9bb6e60d1f
commit
86fd5a1b44
16 changed files with 223 additions and 254 deletions
|
@ -164,11 +164,11 @@ impl Cfg {
|
|||
/// Renders the configuration for human display, as a short HTML description.
|
||||
pub(crate) fn render_short_html(&self) -> String {
|
||||
let mut msg = Display(self, Format::ShortHtml).to_string();
|
||||
if self.should_capitalize_first_letter() {
|
||||
if let Some(i) = msg.find(|c: char| c.is_ascii_alphanumeric()) {
|
||||
if self.should_capitalize_first_letter() &&
|
||||
let Some(i) = msg.find(|c: char| c.is_ascii_alphanumeric())
|
||||
{
|
||||
msg[i..i + 1].make_ascii_uppercase();
|
||||
}
|
||||
}
|
||||
msg
|
||||
}
|
||||
|
||||
|
|
|
@ -390,20 +390,19 @@ pub(crate) fn build_impl(
|
|||
|
||||
// Only inline impl if the implemented trait is
|
||||
// reachable in rustdoc generated documentation
|
||||
if !did.is_local() {
|
||||
if let Some(traitref) = associated_trait {
|
||||
if !did.is_local() && let Some(traitref) = associated_trait {
|
||||
let did = traitref.def_id;
|
||||
if !cx.cache.effective_visibilities.is_directly_public(tcx, did) {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Some(stab) = tcx.lookup_stability(did) {
|
||||
if stab.is_unstable() && stab.feature == sym::rustc_private {
|
||||
if let Some(stab) = tcx.lookup_stability(did) &&
|
||||
stab.is_unstable() &&
|
||||
stab.feature == sym::rustc_private
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let impl_item = match did.as_local() {
|
||||
Some(did) => match &tcx.hir().expect_item(did).kind {
|
||||
|
@ -525,11 +524,9 @@ pub(crate) fn build_impl(
|
|||
}
|
||||
|
||||
while let Some(ty) = stack.pop() {
|
||||
if let Some(did) = ty.def_id(&cx.cache) {
|
||||
if tcx.is_doc_hidden(did) {
|
||||
if let Some(did) = ty.def_id(&cx.cache) && tcx.is_doc_hidden(did) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if let Some(generics) = ty.generics() {
|
||||
stack.extend(generics);
|
||||
}
|
||||
|
|
|
@ -787,8 +787,9 @@ fn clean_ty_generics<'tcx>(
|
|||
None
|
||||
})();
|
||||
|
||||
if let Some(param_idx) = param_idx {
|
||||
if let Some(b) = impl_trait.get_mut(¶m_idx.into()) {
|
||||
if let Some(param_idx) = param_idx
|
||||
&& let Some(b) = impl_trait.get_mut(¶m_idx.into())
|
||||
{
|
||||
let p: WherePredicate = clean_predicate(*p, cx)?;
|
||||
|
||||
b.extend(
|
||||
|
@ -824,7 +825,6 @@ fn clean_ty_generics<'tcx>(
|
|||
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
Some(p)
|
||||
})
|
||||
|
@ -1461,11 +1461,11 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
|
|||
// Try to normalize `<X as Y>::T` to a type
|
||||
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
|
||||
// `hir_to_ty` can return projection types with escaping vars for GATs, e.g. `<() as Trait>::Gat<'_>`
|
||||
if !ty.has_escaping_bound_vars() {
|
||||
if let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty)) {
|
||||
if !ty.has_escaping_bound_vars()
|
||||
&& let Some(normalized_value) = normalize(cx, ty::Binder::dummy(ty))
|
||||
{
|
||||
return clean_middle_ty(normalized_value, cx, None);
|
||||
}
|
||||
}
|
||||
|
||||
let trait_segments = &p.segments[..p.segments.len() - 1];
|
||||
let trait_def = cx.tcx.associated_item(p.res.def_id()).container_id(cx.tcx);
|
||||
|
@ -1878,12 +1878,10 @@ fn clean_middle_opaque_bounds<'tcx>(
|
|||
_ => return None,
|
||||
};
|
||||
|
||||
if let Some(sized) = cx.tcx.lang_items().sized_trait() {
|
||||
if trait_ref.def_id() == sized {
|
||||
if let Some(sized) = cx.tcx.lang_items().sized_trait() && trait_ref.def_id() == sized {
|
||||
has_sized = true;
|
||||
return None;
|
||||
}
|
||||
}
|
||||
|
||||
let bindings: ThinVec<_> = bounds
|
||||
.iter()
|
||||
|
@ -2392,8 +2390,7 @@ fn clean_use_statement_inner<'tcx>(
|
|||
let is_visible_from_parent_mod =
|
||||
visibility.is_accessible_from(parent_mod, cx.tcx) && !current_mod.is_top_level_module();
|
||||
|
||||
if pub_underscore {
|
||||
if let Some(ref inline) = inline_attr {
|
||||
if pub_underscore && let Some(ref inline) = inline_attr {
|
||||
rustc_errors::struct_span_err!(
|
||||
cx.tcx.sess,
|
||||
inline.span(),
|
||||
|
@ -2403,7 +2400,6 @@ fn clean_use_statement_inner<'tcx>(
|
|||
.span_label(import.span, "anonymous import")
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
// We consider inlining the documentation of `pub use` statements, but we
|
||||
// forcefully don't inline if this is not public or if the
|
||||
|
@ -2438,15 +2434,14 @@ fn clean_use_statement_inner<'tcx>(
|
|||
}
|
||||
Import::new_glob(resolve_use_source(cx, path), true)
|
||||
} else {
|
||||
if inline_attr.is_none() {
|
||||
if let Res::Def(DefKind::Mod, did) = path.res {
|
||||
if !did.is_local() && did.is_crate_root() {
|
||||
if inline_attr.is_none()
|
||||
&& let Res::Def(DefKind::Mod, did) = path.res
|
||||
&& !did.is_local() && did.is_crate_root()
|
||||
{
|
||||
// if we're `pub use`ing an extern crate root, don't inline it unless we
|
||||
// were specifically asked for it
|
||||
denied = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if !denied {
|
||||
let mut visited = DefIdSet::default();
|
||||
let import_def_id = import.owner_id.to_def_id();
|
||||
|
|
|
@ -182,11 +182,9 @@ impl ExternalCrate {
|
|||
return Local;
|
||||
}
|
||||
|
||||
if extern_url_takes_precedence {
|
||||
if let Some(url) = extern_url {
|
||||
if extern_url_takes_precedence && let Some(url) = extern_url {
|
||||
return to_remote(url);
|
||||
}
|
||||
}
|
||||
|
||||
// Failing that, see if there's an attribute specifying where to find this
|
||||
// external crate
|
||||
|
@ -1172,11 +1170,11 @@ impl GenericBound {
|
|||
|
||||
pub(crate) fn is_sized_bound(&self, cx: &DocContext<'_>) -> bool {
|
||||
use rustc_hir::TraitBoundModifier as TBM;
|
||||
if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self {
|
||||
if Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait() {
|
||||
if let GenericBound::TraitBound(PolyTrait { ref trait_, .. }, TBM::None) = *self &&
|
||||
Some(trait_.def_id()) == cx.tcx.lang_items().sized_trait()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
|
|
|
@ -345,12 +345,12 @@ pub(crate) fn is_literal_expr(tcx: TyCtxt<'_>, hir_id: hir::HirId) -> bool {
|
|||
return true;
|
||||
}
|
||||
|
||||
if let hir::ExprKind::Unary(hir::UnOp::Neg, expr) = &expr.kind {
|
||||
if let hir::ExprKind::Lit(_) = &expr.kind {
|
||||
if let hir::ExprKind::Unary(hir::UnOp::Neg, expr) = &expr.kind &&
|
||||
let hir::ExprKind::Lit(_) = &expr.kind
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
|
|
|
@ -229,14 +229,14 @@ fn scrape_test_config(attrs: &[ast::Attribute]) -> GlobalTestOptions {
|
|||
if attr.has_name(sym::no_crate_inject) {
|
||||
opts.no_crate_inject = true;
|
||||
}
|
||||
if attr.has_name(sym::attr) {
|
||||
if let Some(l) = attr.meta_item_list() {
|
||||
if attr.has_name(sym::attr)
|
||||
&& let Some(l) = attr.meta_item_list()
|
||||
{
|
||||
for item in l {
|
||||
opts.attrs.push(pprust::meta_list_item_to_string(item));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
opts
|
||||
}
|
||||
|
@ -594,16 +594,16 @@ pub(crate) fn make_test(
|
|||
loop {
|
||||
match parser.parse_item(ForceCollect::No) {
|
||||
Ok(Some(item)) => {
|
||||
if !found_main {
|
||||
if let ast::ItemKind::Fn(..) = item.kind {
|
||||
if item.ident.name == sym::main {
|
||||
if !found_main &&
|
||||
let ast::ItemKind::Fn(..) = item.kind &&
|
||||
item.ident.name == sym::main
|
||||
{
|
||||
found_main = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found_extern_crate {
|
||||
if let ast::ItemKind::ExternCrate(original) = item.kind {
|
||||
if !found_extern_crate &&
|
||||
let ast::ItemKind::ExternCrate(original) = item.kind
|
||||
{
|
||||
// This code will never be reached if `crate_name` is none because
|
||||
// `found_extern_crate` is initialized to `true` if it is none.
|
||||
let crate_name = crate_name.unwrap();
|
||||
|
@ -613,13 +613,10 @@ pub(crate) fn make_test(
|
|||
None => found_extern_crate = item.ident.as_str() == crate_name,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !found_macro {
|
||||
if let ast::ItemKind::MacCall(..) = item.kind {
|
||||
if !found_macro && let ast::ItemKind::MacCall(..) = item.kind {
|
||||
found_macro = true;
|
||||
}
|
||||
}
|
||||
|
||||
if found_main && found_extern_crate {
|
||||
break;
|
||||
|
@ -972,15 +969,13 @@ impl Collector {
|
|||
fn get_filename(&self) -> FileName {
|
||||
if let Some(ref source_map) = self.source_map {
|
||||
let filename = source_map.span_to_filename(self.position);
|
||||
if let FileName::Real(ref filename) = filename {
|
||||
if let Ok(cur_dir) = env::current_dir() {
|
||||
if let Some(local_path) = filename.local_path() {
|
||||
if let Ok(path) = local_path.strip_prefix(&cur_dir) {
|
||||
if let FileName::Real(ref filename) = filename &&
|
||||
let Ok(cur_dir) = env::current_dir() &&
|
||||
let Some(local_path) = filename.local_path() &&
|
||||
let Ok(path) = local_path.strip_prefix(&cur_dir)
|
||||
{
|
||||
return path.to_owned().into();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
filename
|
||||
} else if let Some(ref filename) = self.filename {
|
||||
filename.clone().into()
|
||||
|
|
|
@ -229,17 +229,16 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
|
|||
}
|
||||
|
||||
// Collect all the implementors of traits.
|
||||
if let clean::ImplItem(ref i) = *item.kind {
|
||||
if let Some(trait_) = &i.trait_ {
|
||||
if !i.kind.is_blanket() {
|
||||
if let clean::ImplItem(ref i) = *item.kind &&
|
||||
let Some(trait_) = &i.trait_ &&
|
||||
!i.kind.is_blanket()
|
||||
{
|
||||
self.cache
|
||||
.implementors
|
||||
.entry(trait_.def_id())
|
||||
.or_default()
|
||||
.push(Impl { impl_item: item.clone() });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Index this method for searching later on.
|
||||
if let Some(s) = item.name.or_else(|| {
|
||||
|
|
|
@ -709,12 +709,10 @@ pub(crate) fn href_with_root_path(
|
|||
}
|
||||
}
|
||||
};
|
||||
if !is_remote {
|
||||
if let Some(root_path) = root_path {
|
||||
if !is_remote && let Some(root_path) = root_path {
|
||||
let root = root_path.trim_end_matches('/');
|
||||
url_parts.push_front(root);
|
||||
}
|
||||
}
|
||||
debug!(?url_parts);
|
||||
match shortty {
|
||||
ItemType::Module => {
|
||||
|
|
|
@ -466,11 +466,9 @@ impl<'a> PeekIter<'a> {
|
|||
}
|
||||
/// Returns the next item after the current one. It doesn't interfere with `peek_next` output.
|
||||
fn peek(&mut self) -> Option<&(TokenKind, &'a str)> {
|
||||
if self.stored.is_empty() {
|
||||
if let Some(next) = self.iter.next() {
|
||||
if self.stored.is_empty() && let Some(next) = self.iter.next() {
|
||||
self.stored.push_back(next);
|
||||
}
|
||||
}
|
||||
self.stored.front()
|
||||
}
|
||||
/// Returns the next item after the last one peeked. It doesn't interfere with `peek` output.
|
||||
|
|
|
@ -705,15 +705,13 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
|
|||
shared.fs.write(scrape_examples_help_file, v)?;
|
||||
}
|
||||
|
||||
if let Some(ref redirections) = shared.redirections {
|
||||
if !redirections.borrow().is_empty() {
|
||||
if let Some(ref redirections) = shared.redirections && !redirections.borrow().is_empty() {
|
||||
let redirect_map_path =
|
||||
self.dst.join(crate_name.as_str()).join("redirect-map.json");
|
||||
let paths = serde_json::to_string(&*redirections.borrow()).unwrap();
|
||||
shared.ensure_dir(&self.dst.join(crate_name.as_str()))?;
|
||||
shared.fs.write(redirect_map_path, paths)?;
|
||||
}
|
||||
}
|
||||
|
||||
// No need for it anymore.
|
||||
drop(shared);
|
||||
|
|
|
@ -2225,15 +2225,14 @@ fn sidebar_deref_methods(
|
|||
})
|
||||
{
|
||||
debug!("found target, real_target: {:?} {:?}", target, real_target);
|
||||
if let Some(did) = target.def_id(c) {
|
||||
if let Some(type_did) = impl_.inner_impl().for_.def_id(c) {
|
||||
if let Some(did) = target.def_id(c) &&
|
||||
let Some(type_did) = impl_.inner_impl().for_.def_id(c) &&
|
||||
// `impl Deref<Target = S> for S`
|
||||
if did == type_did || !derefs.insert(did) {
|
||||
(did == type_did || !derefs.insert(did))
|
||||
{
|
||||
// Avoid infinite cycles
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
let deref_mut = v.iter().any(|i| i.trait_did() == cx.tcx().lang_items().deref_mut_trait());
|
||||
let inner_impl = target
|
||||
.def_id(c)
|
||||
|
@ -2266,15 +2265,16 @@ fn sidebar_deref_methods(
|
|||
}
|
||||
|
||||
// Recurse into any further impls that might exist for `target`
|
||||
if let Some(target_did) = target.def_id(c) {
|
||||
if let Some(target_impls) = c.impls.get(&target_did) {
|
||||
if let Some(target_deref_impl) = target_impls.iter().find(|i| {
|
||||
if let Some(target_did) = target.def_id(c) &&
|
||||
let Some(target_impls) = c.impls.get(&target_did) &&
|
||||
let Some(target_deref_impl) = target_impls.iter().find(|i| {
|
||||
i.inner_impl()
|
||||
.trait_
|
||||
.as_ref()
|
||||
.map(|t| Some(t.def_id()) == cx.tcx().lang_items().deref_trait())
|
||||
.unwrap_or(false)
|
||||
}) {
|
||||
})
|
||||
{
|
||||
sidebar_deref_methods(
|
||||
cx,
|
||||
out,
|
||||
|
@ -2285,8 +2285,6 @@ fn sidebar_deref_methods(
|
|||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn sidebar_struct(cx: &Context<'_>, buf: &mut Buffer, it: &clean::Item, s: &clean::Struct) {
|
||||
|
|
|
@ -80,13 +80,12 @@ impl<'tcx> JsonRenderer<'tcx> {
|
|||
// document primitive items in an arbitrary crate by using
|
||||
// `doc(primitive)`.
|
||||
let mut is_primitive_impl = false;
|
||||
if let clean::types::ItemKind::ImplItem(ref impl_) = *item.kind {
|
||||
if impl_.trait_.is_none() {
|
||||
if let clean::types::Type::Primitive(_) = impl_.for_ {
|
||||
if let clean::types::ItemKind::ImplItem(ref impl_) = *item.kind &&
|
||||
impl_.trait_.is_none() &&
|
||||
let clean::types::Type::Primitive(_) = impl_.for_
|
||||
{
|
||||
is_primitive_impl = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if item.item_id.is_local() || is_primitive_impl {
|
||||
self.item(item.clone()).unwrap();
|
||||
|
|
|
@ -82,19 +82,18 @@ pub(crate) fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -
|
|||
let def_id = item.item_id.expect_def_id().expect_local();
|
||||
|
||||
// check if parent is trait impl
|
||||
if let Some(parent_def_id) = cx.tcx.opt_local_parent(def_id) {
|
||||
if let Some(parent_node) = cx.tcx.hir().find_by_def_id(parent_def_id) {
|
||||
if matches!(
|
||||
if let Some(parent_def_id) = cx.tcx.opt_local_parent(def_id) &&
|
||||
let Some(parent_node) = cx.tcx.hir().find_by_def_id(parent_def_id) &&
|
||||
matches!(
|
||||
parent_node,
|
||||
hir::Node::Item(hir::Item {
|
||||
kind: hir::ItemKind::Impl(hir::Impl { of_trait: Some(_), .. }),
|
||||
..
|
||||
})
|
||||
) {
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cx.tcx.is_doc_hidden(def_id.to_def_id())
|
||||
|| inherits_doc_hidden(cx.tcx, def_id)
|
||||
|
|
|
@ -156,9 +156,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
|||
|
||||
// scan through included items ahead of time to splice in Deref targets to the "valid" sets
|
||||
for it in new_items_external.iter().chain(new_items_local.iter()) {
|
||||
if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind {
|
||||
if trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait()
|
||||
&& cleaner.keep_impl(for_, true)
|
||||
if let ImplItem(box Impl { ref for_, ref trait_, ref items, .. }) = *it.kind &&
|
||||
trait_.as_ref().map(|t| t.def_id()) == cx.tcx.lang_items().deref_trait() &&
|
||||
cleaner.keep_impl(for_, true)
|
||||
{
|
||||
let target = items
|
||||
.iter()
|
||||
|
@ -193,7 +193,6 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filter out external items that are not needed
|
||||
new_items_external.retain(|it| {
|
||||
|
|
|
@ -210,12 +210,10 @@ fn extract_path_backwards(text: &str, end_pos: usize) -> Option<usize> {
|
|||
.take_while(|(_, c)| is_id_start(*c) || is_id_continue(*c))
|
||||
.reduce(|_accum, item| item)
|
||||
.and_then(|(new_pos, c)| is_id_start(c).then_some(new_pos));
|
||||
if let Some(new_pos) = new_pos {
|
||||
if current_pos != new_pos {
|
||||
if let Some(new_pos) = new_pos && current_pos != new_pos {
|
||||
current_pos = new_pos;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
if current_pos == end_pos { None } else { Some(current_pos) }
|
||||
|
|
|
@ -201,22 +201,21 @@ impl<'a> DocFolder for ImplStripper<'a, '_> {
|
|||
// Because we don't inline in `maybe_inline_local` if the output format is JSON,
|
||||
// we need to make a special check for JSON output: we want to keep it unless it has
|
||||
// a `#[doc(hidden)]` attribute if the `for_` type is exported.
|
||||
if let Some(did) = imp.for_.def_id(self.cache) {
|
||||
if !imp.for_.is_assoc_ty() && !self.should_keep_impl(&i, did) {
|
||||
if let Some(did) = imp.for_.def_id(self.cache) &&
|
||||
!imp.for_.is_assoc_ty() && !self.should_keep_impl(&i, did)
|
||||
{
|
||||
debug!("ImplStripper: impl item for stripped type; removing");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
if let Some(did) = imp.trait_.as_ref().map(|t| t.def_id()) {
|
||||
if !self.should_keep_impl(&i, did) {
|
||||
if let Some(did) = imp.trait_.as_ref().map(|t| t.def_id()) &&
|
||||
!self.should_keep_impl(&i, did) {
|
||||
debug!("ImplStripper: impl item for stripped trait; removing");
|
||||
return None;
|
||||
}
|
||||
}
|
||||
if let Some(generics) = imp.trait_.as_ref().and_then(|t| t.generics()) {
|
||||
for typaram in generics {
|
||||
if let Some(did) = typaram.def_id(self.cache) {
|
||||
if !self.should_keep_impl(&i, did) {
|
||||
if let Some(did) = typaram.def_id(self.cache) && !self.should_keep_impl(&i, did)
|
||||
{
|
||||
debug!(
|
||||
"ImplStripper: stripped item in trait's generics; removing impl"
|
||||
);
|
||||
|
@ -225,7 +224,6 @@ impl<'a> DocFolder for ImplStripper<'a, '_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some(self.fold_item_recur(i))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue