1
Fork 0

Auto merge of #99066 - est31:remove_box_librustdoc, r=jsha

Remove most box syntax from librustdoc

This is the second attempt after the librustdoc specific changes have been reverted from #87781 in #89134, due to a minor, but exant regression caused by the changes. ~~There have been some changes to librustdoc in the past and maybe thanks to them there is no regression any more. If there is still a regression, one can investigate further and maybe find ways to fix the regressions. Thus, i request a perf run.~~ Edit: turns out there is still a regression, but it's caused only by a subset of the changes. So I've changed this PR to only contains the changes that don't cause any performance regressions, keeping the regression causing changes for a later PR.
This commit is contained in:
bors 2022-07-13 08:29:57 +00:00
commit a639f89d04
8 changed files with 47 additions and 39 deletions

View file

@ -117,7 +117,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
attrs: Default::default(), attrs: Default::default(),
visibility: Inherited, visibility: Inherited,
item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id }, item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
kind: box ImplItem(Impl { kind: Box::new(ImplItem(Impl {
unsafety: hir::Unsafety::Normal, unsafety: hir::Unsafety::Normal,
generics: new_generics, generics: new_generics,
trait_: Some(trait_ref.clean(self.cx)), trait_: Some(trait_ref.clean(self.cx)),
@ -125,7 +125,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
items: Vec::new(), items: Vec::new(),
polarity, polarity,
kind: ImplKind::Auto, kind: ImplKind::Auto,
}), })),
cfg: None, cfg: None,
}) })
} }

View file

@ -106,7 +106,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
attrs: Default::default(), attrs: Default::default(),
visibility: Inherited, visibility: Inherited,
item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id }, item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
kind: box ImplItem(Impl { kind: Box::new(ImplItem(Impl {
unsafety: hir::Unsafety::Normal, unsafety: hir::Unsafety::Normal,
generics: clean_ty_generics( generics: clean_ty_generics(
cx, cx,
@ -123,8 +123,8 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
.map(|x| x.clean(cx)) .map(|x| x.clean(cx))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
polarity: ty::ImplPolarity::Positive, polarity: ty::ImplPolarity::Positive,
kind: ImplKind::Blanket(box trait_ref.0.self_ty().clean(cx)), kind: ImplKind::Blanket(Box::new(trait_ref.0.self_ty().clean(cx))),
}), })),
cfg: None, cfg: None,
}); });
} }

View file

@ -124,8 +124,14 @@ pub(crate) fn try_inline(
let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone); let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone);
cx.inlined.insert(did.into()); cx.inlined.insert(did.into());
let mut item = let mut item = clean::Item::from_def_id_and_attrs_and_parts(
clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, box attrs, cx, cfg); did,
Some(name),
kind,
Box::new(attrs),
cx,
cfg,
);
if let Some(import_def_id) = import_def_id { if let Some(import_def_id) = import_def_id {
// The visibility needs to reflect the one from the reexport and not from the "source" DefId. // The visibility needs to reflect the one from the reexport and not from the "source" DefId.
item.visibility = cx.tcx.visibility(import_def_id).clean(cx); item.visibility = cx.tcx.visibility(import_def_id).clean(cx);
@ -506,7 +512,7 @@ pub(crate) fn build_impl(
ImplKind::Normal ImplKind::Normal
}, },
}), }),
box merged_attrs, Box::new(merged_attrs),
cx, cx,
cfg, cfg,
)); ));
@ -535,7 +541,7 @@ fn build_module(
let prim_ty = clean::PrimitiveType::from(p); let prim_ty = clean::PrimitiveType::from(p);
items.push(clean::Item { items.push(clean::Item {
name: None, name: None,
attrs: box clean::Attributes::default(), attrs: Box::new(clean::Attributes::default()),
item_id: ItemId::Primitive(prim_ty, did.krate), item_id: ItemId::Primitive(prim_ty, did.krate),
visibility: clean::Public, visibility: clean::Public,
kind: box clean::ImportItem(clean::Import::new_simple( kind: box clean::ImportItem(clean::Import::new_simple(

View file

@ -403,7 +403,7 @@ fn clean_projection<'tcx>(
Type::QPath { Type::QPath {
assoc: Box::new(projection_to_path_segment(ty, cx)), assoc: Box::new(projection_to_path_segment(ty, cx)),
should_show_cast, should_show_cast,
self_type: box self_type, self_type: Box::new(self_type),
trait_, trait_,
} }
} }
@ -1321,7 +1321,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
Type::QPath { Type::QPath {
assoc: Box::new(p.segments.last().expect("segments were empty").clean(cx)), assoc: Box::new(p.segments.last().expect("segments were empty").clean(cx)),
should_show_cast, should_show_cast,
self_type: box self_type, self_type: Box::new(self_type),
trait_, trait_,
} }
} }
@ -1341,7 +1341,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
Type::QPath { Type::QPath {
assoc: Box::new(segment.clean(cx)), assoc: Box::new(segment.clean(cx)),
should_show_cast, should_show_cast,
self_type: box self_type, self_type: Box::new(self_type),
trait_, trait_,
} }
} }
@ -1441,7 +1441,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
match self.kind { match self.kind {
TyKind::Never => Primitive(PrimitiveType::Never), TyKind::Never => Primitive(PrimitiveType::Never),
TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)), TyKind::Ptr(ref m) => RawPointer(m.mutbl, Box::new(m.ty.clean(cx))),
TyKind::Rptr(ref l, ref m) => { TyKind::Rptr(ref l, ref m) => {
// There are two times a `Fresh` lifetime can be created: // There are two times a `Fresh` lifetime can be created:
// 1. For `&'_ x`, written by the user. This corresponds to `lower_lifetime` in `rustc_ast_lowering`. // 1. For `&'_ x`, written by the user. This corresponds to `lower_lifetime` in `rustc_ast_lowering`.
@ -1453,9 +1453,9 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
let elided = let elided =
l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh)); l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh));
let lifetime = if elided { None } else { Some(l.clean(cx)) }; let lifetime = if elided { None } else { Some(l.clean(cx)) };
BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) } BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(m.ty.clean(cx)) }
} }
TyKind::Slice(ty) => Slice(box ty.clean(cx)), TyKind::Slice(ty) => Slice(Box::new(ty.clean(cx))),
TyKind::Array(ty, ref length) => { TyKind::Array(ty, ref length) => {
let length = match length { let length = match length {
hir::ArrayLen::Infer(_, _) => "_".to_string(), hir::ArrayLen::Infer(_, _) => "_".to_string(),
@ -1474,7 +1474,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
} }
}; };
Array(box ty.clean(cx), length) Array(Box::new(ty.clean(cx)), length)
} }
TyKind::Tup(tys) => Tuple(tys.iter().map(|x| x.clean(cx)).collect()), TyKind::Tup(tys) => Tuple(tys.iter().map(|x| x.clean(cx)).collect()),
TyKind::OpaqueDef(item_id, _) => { TyKind::OpaqueDef(item_id, _) => {
@ -1491,7 +1491,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None }; let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
DynTrait(bounds, lifetime) DynTrait(bounds, lifetime)
} }
TyKind::BareFn(barefn) => BareFunction(box barefn.clean(cx)), TyKind::BareFn(barefn) => BareFunction(Box::new(barefn.clean(cx))),
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s. // Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
TyKind::Infer | TyKind::Err => Infer, TyKind::Infer | TyKind::Err => Infer,
TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind), TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind),
@ -1541,27 +1541,27 @@ fn clean_ty<'tcx>(this: Ty<'tcx>, cx: &mut DocContext<'tcx>, def_id: Option<DefI
ty::Uint(uint_ty) => Primitive(uint_ty.into()), ty::Uint(uint_ty) => Primitive(uint_ty.into()),
ty::Float(float_ty) => Primitive(float_ty.into()), ty::Float(float_ty) => Primitive(float_ty.into()),
ty::Str => Primitive(PrimitiveType::Str), ty::Str => Primitive(PrimitiveType::Str),
ty::Slice(ty) => Slice(box ty.clean(cx)), ty::Slice(ty) => Slice(Box::new(ty.clean(cx))),
ty::Array(ty, n) => { ty::Array(ty, n) => {
let mut n = cx.tcx.lift(n).expect("array lift failed"); let mut n = cx.tcx.lift(n).expect("array lift failed");
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all()); n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
let n = print_const(cx, n); let n = print_const(cx, n);
Array(box ty.clean(cx), n) Array(Box::new(ty.clean(cx)), n)
} }
ty::RawPtr(mt) => RawPointer(mt.mutbl, box mt.ty.clean(cx)), ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(mt.ty.clean(cx))),
ty::Ref(r, ty, mutbl) => { ty::Ref(r, ty, mutbl) => {
BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: box ty.clean(cx) } BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: Box::new(ty.clean(cx)) }
} }
ty::FnDef(..) | ty::FnPtr(_) => { ty::FnDef(..) | ty::FnPtr(_) => {
let ty = cx.tcx.lift(this).expect("FnPtr lift failed"); let ty = cx.tcx.lift(this).expect("FnPtr lift failed");
let sig = ty.fn_sig(cx.tcx); let sig = ty.fn_sig(cx.tcx);
let decl = clean_fn_decl_from_did_and_sig(cx, None, sig); let decl = clean_fn_decl_from_did_and_sig(cx, None, sig);
BareFunction(box BareFunctionDecl { BareFunction(Box::new(BareFunctionDecl {
unsafety: sig.unsafety(), unsafety: sig.unsafety(),
generic_params: Vec::new(), generic_params: Vec::new(),
decl, decl,
abi: sig.abi(), abi: sig.abi(),
}) }))
} }
ty::Adt(def, substs) => { ty::Adt(def, substs) => {
let did = def.did(); let did = def.did();
@ -2062,7 +2062,7 @@ fn clean_extern_crate<'tcx>(
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason // FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
vec![Item { vec![Item {
name: Some(name), name: Some(name),
attrs: box attrs.clean(cx), attrs: Box::new(attrs.clean(cx)),
item_id: crate_def_id.into(), item_id: crate_def_id.into(),
visibility: ty_vis.clean(cx), visibility: ty_vis.clean(cx),
kind: box ExternCrateItem { src: orig_name }, kind: box ExternCrateItem { src: orig_name },

View file

@ -477,7 +477,7 @@ impl Item {
def_id, def_id,
name, name,
kind, kind,
box ast_attrs.clean(cx), Box::new(ast_attrs.clean(cx)),
cx, cx,
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg), ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
) )

View file

@ -288,7 +288,7 @@ pub(crate) fn create_config(
diagnostic_output: DiagnosticOutput::Default, diagnostic_output: DiagnosticOutput::Default,
lint_caps, lint_caps,
parse_sess_created: None, parse_sess_created: None,
register_lints: Some(box crate::lint::register_lints), register_lints: Some(Box::new(crate::lint::register_lints)),
override_queries: Some(|_sess, providers, _external_providers| { override_queries: Some(|_sess, providers, _external_providers| {
// Most lints will require typechecking, so just don't run them. // Most lints will require typechecking, so just don't run them.
providers.lint_mod = |_, _| {}; providers.lint_mod = |_, _| {};

View file

@ -103,7 +103,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
diagnostic_output: DiagnosticOutput::Default, diagnostic_output: DiagnosticOutput::Default,
lint_caps, lint_caps,
parse_sess_created: None, parse_sess_created: None,
register_lints: Some(box crate::lint::register_lints), register_lints: Some(Box::new(crate::lint::register_lints)),
override_queries: None, override_queries: None,
make_codegen_backend: None, make_codegen_backend: None,
registry: rustc_driver::diagnostics_registry(), registry: rustc_driver::diagnostics_registry(),
@ -556,7 +556,7 @@ pub(crate) fn make_test(
.supports_color(); .supports_color();
let emitter = EmitterWriter::new( let emitter = EmitterWriter::new(
box io::sink(), Box::new(io::sink()),
None, None,
None, None,
fallback_bundle, fallback_bundle,
@ -568,7 +568,7 @@ pub(crate) fn make_test(
); );
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser // FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
let handler = Handler::with_emitter(false, None, box emitter); let handler = Handler::with_emitter(false, None, Box::new(emitter));
let sess = ParseSess::with_span_handler(handler, sm); let sess = ParseSess::with_span_handler(handler, sm);
let mut found_main = false; let mut found_main = false;
@ -1032,7 +1032,7 @@ impl Tester for Collector {
if let Err(err) = std::fs::create_dir_all(&path) { if let Err(err) = std::fs::create_dir_all(&path) {
eprintln!("Couldn't create directory for doctest executables: {}", err); eprintln!("Couldn't create directory for doctest executables: {}", err);
panic::resume_unwind(box ()); panic::resume_unwind(Box::new(()));
} }
DirState::Perm(path) DirState::Perm(path)
@ -1061,7 +1061,7 @@ impl Tester for Collector {
no_run, no_run,
test_type: test::TestType::DocTest, test_type: test::TestType::DocTest,
}, },
testfn: test::DynTestFn(box move || { testfn: test::DynTestFn(Box::new(move || {
let report_unused_externs = |uext| { let report_unused_externs = |uext| {
unused_externs.lock().unwrap().push(uext); unused_externs.lock().unwrap().push(uext);
}; };
@ -1132,9 +1132,9 @@ impl Tester for Collector {
} }
} }
panic::resume_unwind(box ()); panic::resume_unwind(Box::new(()));
} }
}), })),
}); });
} }

View file

@ -743,21 +743,23 @@ pub(crate) fn href_relative_parts<'fqp>(
if f != r { if f != r {
let dissimilar_part_count = relative_to_fqp.len() - i; let dissimilar_part_count = relative_to_fqp.len() - i;
let fqp_module = &fqp[i..fqp.len()]; let fqp_module = &fqp[i..fqp.len()];
return box iter::repeat(sym::dotdot) return Box::new(
.take(dissimilar_part_count) iter::repeat(sym::dotdot)
.chain(fqp_module.iter().copied()); .take(dissimilar_part_count)
.chain(fqp_module.iter().copied()),
);
} }
} }
// e.g. linking to std::sync::atomic from std::sync // e.g. linking to std::sync::atomic from std::sync
if relative_to_fqp.len() < fqp.len() { if relative_to_fqp.len() < fqp.len() {
box fqp[relative_to_fqp.len()..fqp.len()].iter().copied() Box::new(fqp[relative_to_fqp.len()..fqp.len()].iter().copied())
// e.g. linking to std::sync from std::sync::atomic // e.g. linking to std::sync from std::sync::atomic
} else if fqp.len() < relative_to_fqp.len() { } else if fqp.len() < relative_to_fqp.len() {
let dissimilar_part_count = relative_to_fqp.len() - fqp.len(); let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
box iter::repeat(sym::dotdot).take(dissimilar_part_count) Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
// linking to the same module // linking to the same module
} else { } else {
box iter::empty() Box::new(iter::empty())
} }
} }