Skip to content

Commit a639f89

Browse files
committed
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.
2 parents 95e8b86 + 3d2494d commit a639f89

File tree

8 files changed

+47
-39
lines changed

8 files changed

+47
-39
lines changed

src/librustdoc/clean/auto_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
117117
attrs: Default::default(),
118118
visibility: Inherited,
119119
item_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
120-
kind: box ImplItem(Impl {
120+
kind: Box::new(ImplItem(Impl {
121121
unsafety: hir::Unsafety::Normal,
122122
generics: new_generics,
123123
trait_: Some(trait_ref.clean(self.cx)),
124124
for_: ty.clean(self.cx),
125125
items: Vec::new(),
126126
polarity,
127127
kind: ImplKind::Auto,
128-
}),
128+
})),
129129
cfg: None,
130130
})
131131
}

src/librustdoc/clean/blanket_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
106106
attrs: Default::default(),
107107
visibility: Inherited,
108108
item_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
109-
kind: box ImplItem(Impl {
109+
kind: Box::new(ImplItem(Impl {
110110
unsafety: hir::Unsafety::Normal,
111111
generics: clean_ty_generics(
112112
cx,
@@ -123,8 +123,8 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
123123
.map(|x| x.clean(cx))
124124
.collect::<Vec<_>>(),
125125
polarity: ty::ImplPolarity::Positive,
126-
kind: ImplKind::Blanket(box trait_ref.0.self_ty().clean(cx)),
127-
}),
126+
kind: ImplKind::Blanket(Box::new(trait_ref.0.self_ty().clean(cx))),
127+
})),
128128
cfg: None,
129129
});
130130
}

src/librustdoc/clean/inline.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,14 @@ pub(crate) fn try_inline(
124124

125125
let (attrs, cfg) = merge_attrs(cx, Some(parent_module), load_attrs(cx, did), attrs_clone);
126126
cx.inlined.insert(did.into());
127-
let mut item =
128-
clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, box attrs, cx, cfg);
127+
let mut item = clean::Item::from_def_id_and_attrs_and_parts(
128+
did,
129+
Some(name),
130+
kind,
131+
Box::new(attrs),
132+
cx,
133+
cfg,
134+
);
129135
if let Some(import_def_id) = import_def_id {
130136
// The visibility needs to reflect the one from the reexport and not from the "source" DefId.
131137
item.visibility = cx.tcx.visibility(import_def_id).clean(cx);
@@ -506,7 +512,7 @@ pub(crate) fn build_impl(
506512
ImplKind::Normal
507513
},
508514
}),
509-
box merged_attrs,
515+
Box::new(merged_attrs),
510516
cx,
511517
cfg,
512518
));
@@ -535,7 +541,7 @@ fn build_module(
535541
let prim_ty = clean::PrimitiveType::from(p);
536542
items.push(clean::Item {
537543
name: None,
538-
attrs: box clean::Attributes::default(),
544+
attrs: Box::new(clean::Attributes::default()),
539545
item_id: ItemId::Primitive(prim_ty, did.krate),
540546
visibility: clean::Public,
541547
kind: box clean::ImportItem(clean::Import::new_simple(

src/librustdoc/clean/mod.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ fn clean_projection<'tcx>(
403403
Type::QPath {
404404
assoc: Box::new(projection_to_path_segment(ty, cx)),
405405
should_show_cast,
406-
self_type: box self_type,
406+
self_type: Box::new(self_type),
407407
trait_,
408408
}
409409
}
@@ -1321,7 +1321,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
13211321
Type::QPath {
13221322
assoc: Box::new(p.segments.last().expect("segments were empty").clean(cx)),
13231323
should_show_cast,
1324-
self_type: box self_type,
1324+
self_type: Box::new(self_type),
13251325
trait_,
13261326
}
13271327
}
@@ -1341,7 +1341,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
13411341
Type::QPath {
13421342
assoc: Box::new(segment.clean(cx)),
13431343
should_show_cast,
1344-
self_type: box self_type,
1344+
self_type: Box::new(self_type),
13451345
trait_,
13461346
}
13471347
}
@@ -1441,7 +1441,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
14411441

14421442
match self.kind {
14431443
TyKind::Never => Primitive(PrimitiveType::Never),
1444-
TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)),
1444+
TyKind::Ptr(ref m) => RawPointer(m.mutbl, Box::new(m.ty.clean(cx))),
14451445
TyKind::Rptr(ref l, ref m) => {
14461446
// There are two times a `Fresh` lifetime can be created:
14471447
// 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> {
14531453
let elided =
14541454
l.is_elided() || matches!(l.name, LifetimeName::Param(_, ParamName::Fresh));
14551455
let lifetime = if elided { None } else { Some(l.clean(cx)) };
1456-
BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) }
1456+
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(m.ty.clean(cx)) }
14571457
}
1458-
TyKind::Slice(ty) => Slice(box ty.clean(cx)),
1458+
TyKind::Slice(ty) => Slice(Box::new(ty.clean(cx))),
14591459
TyKind::Array(ty, ref length) => {
14601460
let length = match length {
14611461
hir::ArrayLen::Infer(_, _) => "_".to_string(),
@@ -1474,7 +1474,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
14741474
}
14751475
};
14761476

1477-
Array(box ty.clean(cx), length)
1477+
Array(Box::new(ty.clean(cx)), length)
14781478
}
14791479
TyKind::Tup(tys) => Tuple(tys.iter().map(|x| x.clean(cx)).collect()),
14801480
TyKind::OpaqueDef(item_id, _) => {
@@ -1491,7 +1491,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
14911491
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
14921492
DynTrait(bounds, lifetime)
14931493
}
1494-
TyKind::BareFn(barefn) => BareFunction(box barefn.clean(cx)),
1494+
TyKind::BareFn(barefn) => BareFunction(Box::new(barefn.clean(cx))),
14951495
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
14961496
TyKind::Infer | TyKind::Err => Infer,
14971497
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
15411541
ty::Uint(uint_ty) => Primitive(uint_ty.into()),
15421542
ty::Float(float_ty) => Primitive(float_ty.into()),
15431543
ty::Str => Primitive(PrimitiveType::Str),
1544-
ty::Slice(ty) => Slice(box ty.clean(cx)),
1544+
ty::Slice(ty) => Slice(Box::new(ty.clean(cx))),
15451545
ty::Array(ty, n) => {
15461546
let mut n = cx.tcx.lift(n).expect("array lift failed");
15471547
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
15481548
let n = print_const(cx, n);
1549-
Array(box ty.clean(cx), n)
1549+
Array(Box::new(ty.clean(cx)), n)
15501550
}
1551-
ty::RawPtr(mt) => RawPointer(mt.mutbl, box mt.ty.clean(cx)),
1551+
ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(mt.ty.clean(cx))),
15521552
ty::Ref(r, ty, mutbl) => {
1553-
BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: box ty.clean(cx) }
1553+
BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: Box::new(ty.clean(cx)) }
15541554
}
15551555
ty::FnDef(..) | ty::FnPtr(_) => {
15561556
let ty = cx.tcx.lift(this).expect("FnPtr lift failed");
15571557
let sig = ty.fn_sig(cx.tcx);
15581558
let decl = clean_fn_decl_from_did_and_sig(cx, None, sig);
1559-
BareFunction(box BareFunctionDecl {
1559+
BareFunction(Box::new(BareFunctionDecl {
15601560
unsafety: sig.unsafety(),
15611561
generic_params: Vec::new(),
15621562
decl,
15631563
abi: sig.abi(),
1564-
})
1564+
}))
15651565
}
15661566
ty::Adt(def, substs) => {
15671567
let did = def.did();
@@ -2062,7 +2062,7 @@ fn clean_extern_crate<'tcx>(
20622062
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
20632063
vec![Item {
20642064
name: Some(name),
2065-
attrs: box attrs.clean(cx),
2065+
attrs: Box::new(attrs.clean(cx)),
20662066
item_id: crate_def_id.into(),
20672067
visibility: ty_vis.clean(cx),
20682068
kind: box ExternCrateItem { src: orig_name },

src/librustdoc/clean/types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ impl Item {
477477
def_id,
478478
name,
479479
kind,
480-
box ast_attrs.clean(cx),
480+
Box::new(ast_attrs.clean(cx)),
481481
cx,
482482
ast_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg),
483483
)

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ pub(crate) fn create_config(
288288
diagnostic_output: DiagnosticOutput::Default,
289289
lint_caps,
290290
parse_sess_created: None,
291-
register_lints: Some(box crate::lint::register_lints),
291+
register_lints: Some(Box::new(crate::lint::register_lints)),
292292
override_queries: Some(|_sess, providers, _external_providers| {
293293
// Most lints will require typechecking, so just don't run them.
294294
providers.lint_mod = |_, _| {};

src/librustdoc/doctest.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub(crate) fn run(options: RustdocOptions) -> Result<(), ErrorGuaranteed> {
103103
diagnostic_output: DiagnosticOutput::Default,
104104
lint_caps,
105105
parse_sess_created: None,
106-
register_lints: Some(box crate::lint::register_lints),
106+
register_lints: Some(Box::new(crate::lint::register_lints)),
107107
override_queries: None,
108108
make_codegen_backend: None,
109109
registry: rustc_driver::diagnostics_registry(),
@@ -556,7 +556,7 @@ pub(crate) fn make_test(
556556
.supports_color();
557557

558558
let emitter = EmitterWriter::new(
559-
box io::sink(),
559+
Box::new(io::sink()),
560560
None,
561561
None,
562562
fallback_bundle,
@@ -568,7 +568,7 @@ pub(crate) fn make_test(
568568
);
569569

570570
// FIXME(misdreavus): pass `-Z treat-err-as-bug` to the doctest parser
571-
let handler = Handler::with_emitter(false, None, box emitter);
571+
let handler = Handler::with_emitter(false, None, Box::new(emitter));
572572
let sess = ParseSess::with_span_handler(handler, sm);
573573

574574
let mut found_main = false;
@@ -1032,7 +1032,7 @@ impl Tester for Collector {
10321032

10331033
if let Err(err) = std::fs::create_dir_all(&path) {
10341034
eprintln!("Couldn't create directory for doctest executables: {}", err);
1035-
panic::resume_unwind(box ());
1035+
panic::resume_unwind(Box::new(()));
10361036
}
10371037

10381038
DirState::Perm(path)
@@ -1061,7 +1061,7 @@ impl Tester for Collector {
10611061
no_run,
10621062
test_type: test::TestType::DocTest,
10631063
},
1064-
testfn: test::DynTestFn(box move || {
1064+
testfn: test::DynTestFn(Box::new(move || {
10651065
let report_unused_externs = |uext| {
10661066
unused_externs.lock().unwrap().push(uext);
10671067
};
@@ -1132,9 +1132,9 @@ impl Tester for Collector {
11321132
}
11331133
}
11341134

1135-
panic::resume_unwind(box ());
1135+
panic::resume_unwind(Box::new(()));
11361136
}
1137-
}),
1137+
})),
11381138
});
11391139
}
11401140

src/librustdoc/html/format.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -743,21 +743,23 @@ pub(crate) fn href_relative_parts<'fqp>(
743743
if f != r {
744744
let dissimilar_part_count = relative_to_fqp.len() - i;
745745
let fqp_module = &fqp[i..fqp.len()];
746-
return box iter::repeat(sym::dotdot)
747-
.take(dissimilar_part_count)
748-
.chain(fqp_module.iter().copied());
746+
return Box::new(
747+
iter::repeat(sym::dotdot)
748+
.take(dissimilar_part_count)
749+
.chain(fqp_module.iter().copied()),
750+
);
749751
}
750752
}
751753
// e.g. linking to std::sync::atomic from std::sync
752754
if relative_to_fqp.len() < fqp.len() {
753-
box fqp[relative_to_fqp.len()..fqp.len()].iter().copied()
755+
Box::new(fqp[relative_to_fqp.len()..fqp.len()].iter().copied())
754756
// e.g. linking to std::sync from std::sync::atomic
755757
} else if fqp.len() < relative_to_fqp.len() {
756758
let dissimilar_part_count = relative_to_fqp.len() - fqp.len();
757-
box iter::repeat(sym::dotdot).take(dissimilar_part_count)
759+
Box::new(iter::repeat(sym::dotdot).take(dissimilar_part_count))
758760
// linking to the same module
759761
} else {
760-
box iter::empty()
762+
Box::new(iter::empty())
761763
}
762764
}
763765

0 commit comments

Comments
 (0)