Style nit: replace `for_each` & `return` with `for` & `continue`

Co-Authored-By: Joshua Nelson <jyn514@gmail.com>
This commit is contained in:
Daniel Henry-Mantilla 2020-10-18 02:26:31 +02:00
parent d3a33eb1f9
commit aa863caebe
3 changed files with 21 additions and 12 deletions

View File

@ -41,17 +41,17 @@ pub use crate::result::Result::{self, Err, Ok};
pub use core::prelude::v1::{
asm, assert, cfg, column, compile_error, concat, concat_idents, env, file, format_args,
format_args_nl, global_asm, include, include_bytes, include_str, line, llvm_asm, log_syntax,
module_path, option_env, stringify, trace_macros,
module_path, option_env, stringify, trace_macros, Clone, Copy, Debug, Default, Eq, Hash, Ord,
PartialEq, PartialOrd,
};
// FIXME: Attribute and derive macros are not documented because for them rustdoc generates
// FIXME: Attribute and internal derive macros are not documented because for them rustdoc generates
// dead links which fail link checker testing.
#[stable(feature = "builtin_macro_prelude", since = "1.38.0")]
#[allow(deprecated)]
#[doc(hidden)]
pub use core::prelude::v1::{
bench, global_allocator, test, test_case, Clone, Copy, Debug, Default, Eq, Hash, Ord,
PartialEq, PartialOrd, RustcDecodable, RustcEncodable,
bench, global_allocator, test, test_case, RustcDecodable, RustcEncodable,
};
#[unstable(

View File

@ -169,7 +169,17 @@ crate fn record_extern_fqn(cx: &DocContext<'_>, did: DefId, kind: clean::TypeKin
if !s.is_empty() { Some(s) } else { None }
});
let fqn = if let clean::TypeKind::Macro = kind {
vec![crate_name, relative.last().expect("relative was empty")]
// Check to see if it is a macro 2.0 or built-in macro
if matches!(
cx.enter_resolver(|r| r.cstore().load_macro_untracked(did, cx.sess())),
LoadedMacro::MacroDef(def, _)
if matches!(&def.kind, ast::ItemKind::MacroDef(def)
if !def.macro_rules)
) {
once(crate_name).chain(relative).collect()
} else {
vec![crate_name, relative.last().expect("relative was empty")]
}
} else {
once(crate_name).chain(relative).collect()
};

View File

@ -73,16 +73,15 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// In the case of macros 2.0 (`pub macro`), and for built-in `derive`s or attributes as
// well (_e.g._, `Copy`), these are wrongly bundled in there too, so we need to fix that by
// moving them back to their correct locations.
krate.exported_macros.iter().for_each(|def| {
let visit_macro = || self.visit_local_macro(def, None);
'exported_macros: for def in krate.exported_macros {
// The `def` of a macro in `exported_macros` should correspond to either:
// - a `#[macro-export] macro_rules!` macro,
// - a built-in `derive` (or attribute) macro such as the ones in `::core`,
// - a `pub macro`.
// Only the last two need to be fixed, thus:
if def.ast.macro_rules {
top_level_module.macros.push(visit_macro());
return;
top_level_module.macros.push((def, None));
continue 'exported_macros;
}
let tcx = self.cx.tcx;
/* Because of #77828 we cannot do the simpler:
@ -104,7 +103,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
// `fn f() { pub macro m() {} }`
// then the item is not accessible, and should thus act as if it didn't
// exist (unless "associated macros" (inside an `impl`) were a thing…).
return;
continue 'exported_macros;
}
};
cur_mod = cur_mod
@ -113,8 +112,8 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
.find(|module| module.name == Some(path_segment_ty_ns))
.unwrap();
}
cur_mod.macros.push(visit_macro());
});
cur_mod.macros.push((def, None));
}
self.cx.renderinfo.get_mut().exact_paths = self.exact_paths;