Skip to content

Commit

Permalink
Style nit: replace for_each & return with for & continue
Browse files Browse the repository at this point in the history
Co-Authored-By: Joshua Nelson <[email protected]>
  • Loading branch information
danielhenrymantilla and jyn514 committed Jan 6, 2021
1 parent d3a33eb commit aa863ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
8 changes: 4 additions & 4 deletions library/std/src/prelude/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
12 changes: 11 additions & 1 deletion src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
};
Expand Down
13 changes: 6 additions & 7 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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;

Expand Down

0 comments on commit aa863ca

Please sign in to comment.