From 94a09232ff8f598d0e38aaa26f8abb89779665bd Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 11 Jul 2022 00:25:25 +0200 Subject: [PATCH 1/7] Remove box syntax from Box construction The function pointer should be extremely small, close to pointer size. --- src/librustdoc/core.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 51b245e36ba3b..636ace01ea89d 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -285,7 +285,7 @@ pub(crate) fn create_config( diagnostic_output: DiagnosticOutput::Default, lint_caps, 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| { // Most lints will require typechecking, so just don't run them. providers.lint_mod = |_, _| {}; From cb5e94bb62308735612c9102e8ca6ee38678db12 Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 11 Jul 2022 00:05:19 +0200 Subject: [PATCH 2/7] Remove box syntax from doctest.rs Doctests are fairly cold code, so even if there is a regression, which i doubt, it won't matter. --- src/librustdoc/doctest.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 509c4253f0f76..6b25fbebdef42 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -103,7 +103,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> { diagnostic_output: DiagnosticOutput::Default, lint_caps, parse_sess_created: None, - register_lints: Some(box crate::lint::register_lints), + register_lints: Some(Box::new(crate::lint::register_lints)), override_queries: None, make_codegen_backend: None, registry: rustc_driver::diagnostics_registry(), @@ -556,7 +556,7 @@ pub(crate) fn make_test( .supports_color(); let emitter = EmitterWriter::new( - box io::sink(), + Box::new(io::sink()), None, None, fallback_bundle, @@ -568,7 +568,7 @@ pub(crate) fn make_test( ); // 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 mut found_main = false; @@ -1005,7 +1005,7 @@ impl Tester for Collector { if let Err(err) = std::fs::create_dir_all(&path) { eprintln!("Couldn't create directory for doctest executables: {}", err); - panic::resume_unwind(box ()); + panic::resume_unwind(Box::new(())); } DirState::Perm(path) @@ -1034,7 +1034,7 @@ impl Tester for Collector { no_run, test_type: test::TestType::DocTest, }, - testfn: test::DynTestFn(box move || { + testfn: test::DynTestFn(Box::new(move || { let report_unused_externs = |uext| { unused_externs.lock().unwrap().push(uext); }; @@ -1105,9 +1105,9 @@ impl Tester for Collector { } } - panic::resume_unwind(box ()); + panic::resume_unwind(Box::new(())); } - }), + })), }); } From 1ac17fcddb80187a76a461982e2028a5df48de3d Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 11 Jul 2022 00:16:01 +0200 Subject: [PATCH 3/7] Remove box syntax from Box construction The iterators created should be pretty light weight. --- src/librustdoc/html/format.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 0982c4b3acec8..1c22fb3601135 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -737,21 +737,23 @@ pub(crate) fn href_relative_parts<'fqp>( if f != r { let dissimilar_part_count = relative_to_fqp.len() - i; let fqp_module = &fqp[i..fqp.len()]; - return box iter::repeat(sym::dotdot) - .take(dissimilar_part_count) - .chain(fqp_module.iter().copied()); + return Box::new( + iter::repeat(sym::dotdot) + .take(dissimilar_part_count) + .chain(fqp_module.iter().copied()), + ); } } // e.g. linking to std::sync::atomic from std::sync 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 } else if fqp.len() < relative_to_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 } else { - box iter::empty() + Box::new(iter::empty()) } } From ccf1bdbca6962329fdf5fdc57a7abf36eb8ddafe Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 10 Jul 2022 23:49:33 +0200 Subject: [PATCH 4/7] Remove box syntax for Box construction Attributes only has 48 bytes according to compiler internal rustdoc. --- src/librustdoc/clean/inline.rs | 14 ++++++++++---- src/librustdoc/clean/mod.rs | 2 +- src/librustdoc/clean/types.rs | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index d4c38f34b5b11..23af7d2ef1e24 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -124,8 +124,14 @@ pub(crate) fn try_inline( let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone); cx.inlined.insert(did.into()); - let mut item = - clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, box attrs, cx, cfg); + let mut item = clean::Item::from_def_id_and_attrs_and_parts( + did, + Some(name), + kind, + Box::new(attrs), + cx, + cfg, + ); 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. item.visibility = cx.tcx.visibility(import_def_id).clean(cx); @@ -506,7 +512,7 @@ pub(crate) fn build_impl( ImplKind::Normal }, }), - box merged_attrs, + Box::new(merged_attrs), cx, cfg, )); @@ -535,7 +541,7 @@ fn build_module( let prim_ty = clean::PrimitiveType::from(p); items.push(clean::Item { name: None, - attrs: box clean::Attributes::default(), + attrs: Box::new(clean::Attributes::default()), item_id: ItemId::Primitive(prim_ty, did.krate), visibility: clean::Public, kind: box clean::ImportItem(clean::Import::new_simple( diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 6ee725edcfc1d..8c15ce42ba415 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2062,7 +2062,7 @@ fn clean_extern_crate<'tcx>( // FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason vec![Item { name: Some(name), - attrs: box attrs.clean(cx), + attrs: Box::new(attrs.clean(cx)), item_id: crate_def_id.into(), visibility: ty_vis.clean(cx), kind: box ExternCrateItem { src: orig_name }, diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 81aa8c6cf8e19..d29ba2dedaf71 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -477,7 +477,7 @@ impl Item { def_id, name, kind, - box ast_attrs.clean(cx), + Box::new(ast_attrs.clean(cx)), cx, ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg), ) From 88d72a97fc11097d971568c8b291274be7710ba2 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 10 Jul 2022 23:42:47 +0200 Subject: [PATCH 5/7] Remove box syntax for Box construction ImplItem only has 80 bytes according to compiler internal rustdoc. --- src/librustdoc/clean/auto_trait.rs | 4 ++-- src/librustdoc/clean/blanket_impl.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index fb178cbd95e7b..e6f006135e29a 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -117,7 +117,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { attrs: Default::default(), visibility: Inherited, 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, generics: new_generics, trait_: Some(trait_ref.clean(self.cx)), @@ -125,7 +125,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { items: Vec::new(), polarity, kind: ImplKind::Auto, - }), + })), cfg: None, }) } diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index c591c59133111..12137667e7bf8 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -106,7 +106,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { attrs: Default::default(), visibility: Inherited, 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, generics: clean_ty_generics( cx, @@ -123,8 +123,8 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> { .map(|x| x.clean(cx)) .collect::>(), 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, }); } From 3fa637dacb78dd1a07c36df00fed2cd3e0f19d74 Mon Sep 17 00:00:00 2001 From: est31 Date: Sun, 10 Jul 2022 23:59:33 +0200 Subject: [PATCH 6/7] Remove box syntax for Box construction The type has 80 bytes according to compiler internal rustdoc. --- src/librustdoc/clean/mod.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 8c15ce42ba415..cd028bc4b4611 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -403,7 +403,7 @@ fn clean_projection<'tcx>( Type::QPath { assoc: Box::new(projection_to_path_segment(ty, cx)), should_show_cast, - self_type: box self_type, + self_type: Box::new(self_type), trait_, } } @@ -1320,7 +1320,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type Type::QPath { assoc: Box::new(p.segments.last().expect("segments were empty").clean(cx)), should_show_cast, - self_type: box self_type, + self_type: Box::new(self_type), trait_, } } @@ -1340,7 +1340,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type Type::QPath { assoc: Box::new(segment.clean(cx)), should_show_cast, - self_type: box self_type, + self_type: Box::new(self_type), trait_, } } @@ -1440,7 +1440,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> { match self.kind { 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) => { // 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`. @@ -1452,9 +1452,9 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> { let elided = l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh)); 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) => { let length = match length { hir::ArrayLen::Infer(_, _) => "_".to_string(), @@ -1473,7 +1473,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::OpaqueDef(item_id, _) => { @@ -1540,16 +1540,16 @@ fn clean_ty<'tcx>(this: Ty<'tcx>, cx: &mut DocContext<'tcx>, def_id: Option Primitive(uint_ty.into()), ty::Float(float_ty) => Primitive(float_ty.into()), 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) => { let mut n = cx.tcx.lift(n).expect("array lift failed"); n = n.eval(cx.tcx, ty::ParamEnv::reveal_all()); 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) => { - 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(_) => { let ty = cx.tcx.lift(this).expect("FnPtr lift failed"); From 3d2494dbf22c3f2d5c53d8d8b13a2ae4c15d785a Mon Sep 17 00:00:00 2001 From: est31 Date: Mon, 11 Jul 2022 00:13:21 +0200 Subject: [PATCH 7/7] Remove box syntax from Box construction The type has 144 bytes according to compiler internal rustdoc. --- src/librustdoc/clean/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index cd028bc4b4611..cfcedc0e4c08d 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1490,7 +1490,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> { let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None }; 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. TyKind::Infer | TyKind::Err => Infer, TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind), @@ -1555,12 +1555,12 @@ fn clean_ty<'tcx>(this: Ty<'tcx>, cx: &mut DocContext<'tcx>, def_id: Option { let did = def.did();