Bump bootstrap compiler to new beta by Mark-Simulacrum · Pull Request #128083 · rust-lang/rust (original) (raw)
fn item_module(w: &mut Buffer, cx: &mut Context<'_>, item: &clean::Item, items: &[clean::Item]) { | |
---|---|
write!(w, "{}", document(cx, item, None, HeadingOffset::H2)); | |
let mut indices = (0..items.len()).filter(|i | !items[*i].is_stripped()).collect::<Vec<usize>>(); |
// the order of item types in the listing | |
fn reorder(ty: ItemType) -> u8 { | |
match ty { | |
ItemType::ExternCrate => 0, | |
ItemType::Import => 1, | |
ItemType::Primitive => 2, | |
ItemType::Module => 3, | |
ItemType::Macro => 4, | |
ItemType::Struct => 5, | |
ItemType::Enum => 6, | |
ItemType::Constant => 7, | |
ItemType::Static => 8, | |
ItemType::Trait => 9, | |
ItemType::Function => 10, | |
ItemType::TypeAlias => 12, | |
ItemType::Union => 13, | |
_ => 14 + ty as u8, | |
} | |
} | |
fn cmp( | |
i1: &clean::Item, | |
i2: &clean::Item, | |
idx1: usize, | |
idx2: usize, | |
tcx: TyCtxt<'_>, | |
) -> Ordering { | |
let ty1 = i1.type_(); | |
let ty2 = i2.type_(); | |
if item_ty_to_section(ty1) != item_ty_to_section(ty2) | |
| | (ty1 != ty2 && (ty1 == ItemType::ExternCrate |
{ | |
return (reorder(ty1), idx1).cmp(&(reorder(ty2), idx2)); | |
} | |
let s1 = i1.stability(tcx).as_ref().map(|s | s.level); |
let s2 = i2.stability(tcx).as_ref().map(|s | s.level); |
if let (Some(a), Some(b)) = (s1, s2) { | |
match (a.is_stable(), b.is_stable()) { | |
(true, true) | (false, false) => {} | |
(false, true) => return Ordering::Greater, | |
(true, false) => return Ordering::Less, | |
} | |
} | |
let lhs = i1.name.unwrap_or(kw::Empty); | |
let rhs = i2.name.unwrap_or(kw::Empty); | |
compare_names(lhs.as_str(), rhs.as_str()) | |
} | |
match cx.shared.module_sorting { | |
ModuleSorting::Alphabetical => { | |
indices.sort_by(|&i1, &i2 | cmp(&items[i1], &items[i2], i1, i2, cx.tcx())); |
} | |
ModuleSorting::DeclarationOrder => {} | |
} | |
// This call is to remove re-export duplicates in cases such as: | |
// | |
// ``` | |
// pub(crate) mod foo { | |
// pub(crate) mod bar { | |
// pub(crate) trait Double { fn foo(); } | |
// } | |
// } | |
// | |
// pub(crate) use foo::bar::*; | |
// pub(crate) use foo::*; | |
// ``` | |
// | |
// `Double` will appear twice in the generated docs. | |
// | |
// FIXME: This code is quite ugly and could be improved. Small issue: DefId | |
// can be identical even if the elements are different (mostly in imports). | |
// So in case this is an import, we keep everything by adding a "unique id" | |
// (which is the position in the vector). | |
indices.dedup_by_key(|i | { |
( | |
items[*i].item_id, | |
if items[*i].name.is_some() { Some(full_path(cx, &items[*i])) } else { None }, | |
items[*i].type_(), | |
if items[*i].is_import() { *i } else { 0 }, | |
) | |
}); | |
debug!("{indices:?}"); | |
let mut last_section = None; | |
for &idx in &indices { | |
let myitem = &items[idx]; | |
if myitem.is_stripped() { | |
continue; | |
} | |
let my_section = item_ty_to_section(myitem.type_()); | |
if Some(my_section) != last_section { | |
if last_section.is_some() { | |
w.write_str(ITEM_TABLE_CLOSE); | |
} | |
last_section = Some(my_section); | |
write_section_heading( | |
w, | |
my_section.name(), | |
&cx.derive_id(my_section.id()), | |
None, | |
ITEM_TABLE_OPEN, | |
); | |
} | |
let tcx = cx.tcx(); | |
match *myitem.kind { | |
clean::ExternCrateItem { ref src } => { | |
use crate::html::format::anchor; | |
w.write_str(ITEM_TABLE_ROW_OPEN); | |
match *src { | |
Some(src) => write!( | |
w, | |
"<div class=\"item-name\">{}extern crate {} as {};", |
|
visibility_print_with_space(myitem, cx), | |
anchor(myitem.item_id.expect_def_id(), src, cx), | |
myitem.name.unwrap(), | |
), | |
None => write!( | |
w, | |
" {}extern crate {};", |
|
visibility_print_with_space(myitem, cx), | |
anchor(myitem.item_id.expect_def_id(), myitem.name.unwrap(), cx), | |
), | |
} | |
w.write_str(""); | |
w.write_str(ITEM_TABLE_ROW_CLOSE); | |
} | |
clean::ImportItem(ref import) => { | |
let stab_tags = if let Some(import_def_id) = import.source.did { | |
// Just need an item with the correct def_id and attrs | |
let import_item = | |
clean::Item { item_id: import_def_id.into(), ..myitem.clone() }; | |
let stab_tags = Some(extra_info_tags(&import_item, item, tcx).to_string()); | |
stab_tags | |
} else { | |
None | |
}; | |
w.write_str(ITEM_TABLE_ROW_OPEN); | |
let id = match import.kind { | |
clean::ImportKind::Simple(s) => { | |
format!(" id=\"{}\"", cx.derive_id(format!("reexport.{s}"))) | |
} | |
clean::ImportKind::Glob => String::new(), | |
}; | |
let stab_tags = stab_tags.unwrap_or_default(); | |
let (stab_tags_before, stab_tags_after) = if stab_tags.is_empty() { | |
("", "") | |
} else { | |
("<div class=\"desc docblock-short\">", "") | |
}; | |
write!( | |
w, | |
"<div class=\"item-name\"{id}>\ | |
{vis}{imp} \ |
|
\ | |
{stab_tags_before}{stab_tags}{stab_tags_after}", | |
vis = visibility_print_with_space(myitem, cx), | |
imp = import.print(cx), | |
); | |
w.write_str(ITEM_TABLE_ROW_CLOSE); | |
} | |
_ => { | |
if myitem.name.is_none() { | |
continue; | |
} | |
let unsafety_flag = match *myitem.kind { | |
clean::FunctionItem(_) | clean::ForeignFunctionItem(..) | |
if myitem.fn_header(tcx).unwrap().safety == hir::Safety::Unsafe => | |
{ | |
"<sup title=\"unsafe function\">⚠" | |
} | |
clean::ForeignStaticItem(_, hir::Safety::Unsafe) => { | |
"<sup title=\"unsafe static\">⚠" | |
} | |
_ => "", | |
}; | |
let visibility_and_hidden = match myitem.visibility(tcx) { | |
Some(ty::Visibility::Restricted(_)) => { | |
if myitem.is_doc_hidden() { | |
// Don't separate with a space when there are two of them | |
"<span title=\"Restricted Visibility\"> 🔒<span title=\"Hidden item\">👻 " | |
} else { | |
"<span title=\"Restricted Visibility\"> 🔒 " | |
} | |
} | |
_ if myitem.is_doc_hidden() => "<span title=\"Hidden item\"> 👻 ", | |
_ => "", | |
}; | |
w.write_str(ITEM_TABLE_ROW_OPEN); | |
let docs = | |
MarkdownSummaryLine(&myitem.doc_value(), &myitem.links(cx)).into_string(); | |
let (docs_before, docs_after) = if docs.is_empty() { | |
("", "") | |
} else { | |
("<div class=\"desc docblock-short\">", "") | |
}; | |
write!( | |
w, | |
"<div class=\"item-name\">\ | |
<a class=\"{class}\" href=\"{href}\" title=\"{title}\">{name}\ | |
{visibility_and_hidden}\ | |
{unsafety_flag}\ | |
{stab_tags}\ | |
\ | |
{docs_before}{docs}{docs_after}", | |
name = myitem.name.unwrap(), | |
visibility_and_hidden = visibility_and_hidden, | |
stab_tags = extra_info_tags(myitem, item, tcx), | |
class = myitem.type_(), | |
unsafety_flag = unsafety_flag, | |
href = item_path(myitem.type_(), myitem.name.unwrap().as_str()), | |
title = [myitem.type_().to_string(), full_path(cx, myitem)] | |
.iter() | |
.filter_map(|s | if !s.is_empty() { Some(s.as_str()) } else { None }) |
.collect::<Vec<_>>() | |
.join(" "), | |
); | |
w.write_str(ITEM_TABLE_ROW_CLOSE); | |
} | |
} | |
} | |
if last_section.is_some() { | |
w.write_str(ITEM_TABLE_CLOSE); | |
} | |
} |