Skip to content

Commit cfff31b

Browse files
committed
Auto merge of rust-lang#89134 - est31:revert_rustdoc_box_syntax, r=GuillaumeGomez
Revert the rustdoc box syntax removal Reverts the rustdoc box syntax removal from rust-lang#87781. It turned out to cause (minor) perf regressions. Requested in rust-lang#87781 (comment)
2 parents ce45663 + f809ed6 commit cfff31b

10 files changed

+47
-54
lines changed

src/librustdoc/clean/auto_trait.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
114114
attrs: Default::default(),
115115
visibility: Inherited,
116116
def_id: ItemId::Auto { trait_: trait_def_id, for_: item_def_id },
117-
kind: Box::new(ImplItem(Impl {
117+
kind: box ImplItem(Impl {
118118
span: Span::dummy(),
119119
unsafety: hir::Unsafety::Normal,
120120
generics: new_generics,
@@ -124,7 +124,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
124124
negative_polarity,
125125
synthetic: true,
126126
blanket_impl: None,
127-
})),
127+
}),
128128
cfg: None,
129129
})
130130
}

src/librustdoc/clean/blanket_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
100100
attrs: Default::default(),
101101
visibility: Inherited,
102102
def_id: ItemId::Blanket { impl_id: impl_def_id, for_: item_def_id },
103-
kind: Box::new(ImplItem(Impl {
103+
kind: box ImplItem(Impl {
104104
span: Span::new(self.cx.tcx.def_span(impl_def_id)),
105105
unsafety: hir::Unsafety::Normal,
106106
generics: (
@@ -121,8 +121,8 @@ impl<'a, 'tcx> BlanketImplFinder<'a, 'tcx> {
121121
.clean(self.cx),
122122
negative_polarity: false,
123123
synthetic: false,
124-
blanket_impl: Some(Box::new(trait_ref.self_ty().clean(self.cx))),
125-
})),
124+
blanket_impl: Some(box trait_ref.self_ty().clean(self.cx)),
125+
}),
126126
cfg: None,
127127
});
128128
}

src/librustdoc/clean/inline.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,8 @@ 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 = 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-
);
127+
let mut item =
128+
clean::Item::from_def_id_and_attrs_and_parts(did, Some(name), kind, box attrs, cx, cfg);
135129
if let Some(import_def_id) = import_def_id {
136130
// The visibility needs to reflect the one from the reexport and not from the "source" DefId.
137131
item.visibility = cx.tcx.visibility(import_def_id).clean(cx);
@@ -464,7 +458,7 @@ crate fn build_impl(
464458
synthetic: false,
465459
blanket_impl: None,
466460
}),
467-
Box::new(merged_attrs),
461+
box merged_attrs,
468462
cx,
469463
cfg,
470464
));
@@ -493,10 +487,10 @@ fn build_module(
493487
let prim_ty = clean::PrimitiveType::from(p);
494488
items.push(clean::Item {
495489
name: None,
496-
attrs: Box::new(clean::Attributes::default()),
490+
attrs: box clean::Attributes::default(),
497491
def_id: ItemId::Primitive(prim_ty, did.krate),
498492
visibility: clean::Public,
499-
kind: Box::new(clean::ImportItem(clean::Import::new_simple(
493+
kind: box clean::ImportItem(clean::Import::new_simple(
500494
item.ident.name,
501495
clean::ImportSource {
502496
path: clean::Path {
@@ -513,7 +507,7 @@ fn build_module(
513507
did: None,
514508
},
515509
true,
516-
))),
510+
)),
517511
cfg: None,
518512
});
519513
} else if let Some(i) = try_inline(cx, did, None, res, item.ident.name, None, visited) {

src/librustdoc/clean/mod.rs

+21-23
Original file line numberDiff line numberDiff line change
@@ -392,8 +392,8 @@ impl<'tcx> Clean<Type> for ty::ProjectionTy<'tcx> {
392392
Type::QPath {
393393
name: cx.tcx.associated_item(self.item_def_id).ident.name,
394394
self_def_id: self_type.def_id(),
395-
self_type: Box::new(self_type),
396-
trait_: Box::new(trait_),
395+
self_type: box self_type,
396+
trait_: box trait_,
397397
}
398398
}
399399
}
@@ -1284,8 +1284,8 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12841284
Type::QPath {
12851285
name: p.segments.last().expect("segments were empty").ident.name,
12861286
self_def_id: Some(DefId::local(qself.hir_id.owner.local_def_index)),
1287-
self_type: Box::new(qself.clean(cx)),
1288-
trait_: Box::new(resolve_type(cx, trait_path)),
1287+
self_type: box qself.clean(cx),
1288+
trait_: box resolve_type(cx, trait_path),
12891289
}
12901290
}
12911291
hir::QPath::TypeRelative(ref qself, ref segment) => {
@@ -1300,8 +1300,8 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
13001300
Type::QPath {
13011301
name: segment.ident.name,
13021302
self_def_id: res.opt_def_id(),
1303-
self_type: Box::new(qself.clean(cx)),
1304-
trait_: Box::new(resolve_type(cx, trait_path)),
1303+
self_type: box qself.clean(cx),
1304+
trait_: box resolve_type(cx, trait_path),
13051305
}
13061306
}
13071307
hir::QPath::LangItem(..) => bug!("clean: requiring documentation of lang item"),
@@ -1314,7 +1314,7 @@ impl Clean<Type> for hir::Ty<'_> {
13141314

13151315
match self.kind {
13161316
TyKind::Never => Never,
1317-
TyKind::Ptr(ref m) => RawPointer(m.mutbl, Box::new(m.ty.clean(cx))),
1317+
TyKind::Ptr(ref m) => RawPointer(m.mutbl, box m.ty.clean(cx)),
13181318
TyKind::Rptr(ref l, ref m) => {
13191319
// There are two times a `Fresh` lifetime can be created:
13201320
// 1. For `&'_ x`, written by the user. This corresponds to `lower_lifetime` in `rustc_ast_lowering`.
@@ -1326,9 +1326,9 @@ impl Clean<Type> for hir::Ty<'_> {
13261326
let elided =
13271327
l.is_elided() || matches!(l.name, LifetimeName::Param(ParamName::Fresh(_)));
13281328
let lifetime = if elided { None } else { Some(l.clean(cx)) };
1329-
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(m.ty.clean(cx)) }
1329+
BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) }
13301330
}
1331-
TyKind::Slice(ref ty) => Slice(Box::new(ty.clean(cx))),
1331+
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
13321332
TyKind::Array(ref ty, ref length) => {
13331333
let def_id = cx.tcx.hir().local_def_id(length.hir_id);
13341334
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
@@ -1341,7 +1341,7 @@ impl Clean<Type> for hir::Ty<'_> {
13411341
let ct = ty::Const::from_anon_const(cx.tcx, def_id);
13421342
let param_env = cx.tcx.param_env(def_id);
13431343
let length = print_const(cx, ct.eval(cx.tcx, param_env));
1344-
Array(Box::new(ty.clean(cx)), length)
1344+
Array(box ty.clean(cx), length)
13451345
}
13461346
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
13471347
TyKind::OpaqueDef(item_id, _) => {
@@ -1358,7 +1358,7 @@ impl Clean<Type> for hir::Ty<'_> {
13581358
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
13591359
DynTrait(bounds, lifetime)
13601360
}
1361-
TyKind::BareFn(ref barefn) => BareFunction(Box::new(barefn.clean(cx))),
1361+
TyKind::BareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
13621362
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
13631363
TyKind::Infer | TyKind::Err => Infer,
13641364
TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind),
@@ -1409,29 +1409,27 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14091409
ty::Uint(uint_ty) => Primitive(uint_ty.into()),
14101410
ty::Float(float_ty) => Primitive(float_ty.into()),
14111411
ty::Str => Primitive(PrimitiveType::Str),
1412-
ty::Slice(ty) => Slice(Box::new(ty.clean(cx))),
1412+
ty::Slice(ty) => Slice(box ty.clean(cx)),
14131413
ty::Array(ty, n) => {
14141414
let mut n = cx.tcx.lift(n).expect("array lift failed");
14151415
n = n.eval(cx.tcx, ty::ParamEnv::reveal_all());
14161416
let n = print_const(cx, n);
1417-
Array(Box::new(ty.clean(cx)), n)
1417+
Array(box ty.clean(cx), n)
1418+
}
1419+
ty::RawPtr(mt) => RawPointer(mt.mutbl, box mt.ty.clean(cx)),
1420+
ty::Ref(r, ty, mutbl) => {
1421+
BorrowedRef { lifetime: r.clean(cx), mutability: mutbl, type_: box ty.clean(cx) }
14181422
}
1419-
ty::RawPtr(mt) => RawPointer(mt.mutbl, Box::new(mt.ty.clean(cx))),
1420-
ty::Ref(r, ty, mutbl) => BorrowedRef {
1421-
lifetime: r.clean(cx),
1422-
mutability: mutbl,
1423-
type_: Box::new(ty.clean(cx)),
1424-
},
14251423
ty::FnDef(..) | ty::FnPtr(_) => {
14261424
let ty = cx.tcx.lift(*self).expect("FnPtr lift failed");
14271425
let sig = ty.fn_sig(cx.tcx);
14281426
let def_id = DefId::local(CRATE_DEF_INDEX);
1429-
BareFunction(Box::new(BareFunctionDecl {
1427+
BareFunction(box BareFunctionDecl {
14301428
unsafety: sig.unsafety(),
14311429
generic_params: Vec::new(),
14321430
decl: (def_id, sig).clean(cx),
14331431
abi: sig.abi(),
1434-
}))
1432+
})
14351433
}
14361434
ty::Adt(def, substs) => {
14371435
let did = def.did;
@@ -1974,10 +1972,10 @@ fn clean_extern_crate(
19741972
// FIXME: using `from_def_id_and_kind` breaks `rustdoc/masked` for some reason
19751973
vec![Item {
19761974
name: Some(name),
1977-
attrs: Box::new(attrs.clean(cx)),
1975+
attrs: box attrs.clean(cx),
19781976
def_id: crate_def_id.into(),
19791977
visibility: krate.vis.clean(cx),
1980-
kind: Box::new(ExternCrateItem { src: orig_name }),
1978+
kind: box ExternCrateItem { src: orig_name },
19811979
cfg: attrs.cfg(cx.sess()),
19821980
}]
19831981
}

src/librustdoc/clean/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ impl Item {
421421
def_id,
422422
name,
423423
kind,
424-
Box::new(ast_attrs.clean(cx)),
424+
box ast_attrs.clean(cx),
425425
cx,
426426
ast_attrs.cfg(cx.sess()),
427427
)
@@ -439,7 +439,7 @@ impl Item {
439439

440440
Item {
441441
def_id: def_id.into(),
442-
kind: Box::new(kind),
442+
kind: box kind,
443443
name,
444444
attrs,
445445
visibility: cx.tcx.visibility(def_id).clean(cx),

src/librustdoc/core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ crate fn create_config(
263263
stderr: None,
264264
lint_caps,
265265
parse_sess_created: None,
266-
register_lints: Some(Box::new(crate::lint::register_lints)),
266+
register_lints: Some(box crate::lint::register_lints),
267267
override_queries: Some(|_sess, providers, _external_providers| {
268268
// Most lints will require typechecking, so just don't run them.
269269
providers.lint_mod = |_, _| {};

src/librustdoc/doctest.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ crate fn run(options: Options) -> Result<(), ErrorReported> {
9999
stderr: None,
100100
lint_caps,
101101
parse_sess_created: None,
102-
register_lints: Some(Box::new(crate::lint::register_lints)),
102+
register_lints: Some(box crate::lint::register_lints),
103103
override_queries: None,
104104
make_codegen_backend: None,
105105
registry: rustc_driver::diagnostics_registry(),
@@ -550,10 +550,10 @@ crate fn make_test(
550550
.supports_color();
551551

552552
let emitter =
553-
EmitterWriter::new(Box::new(io::sink()), None, false, false, false, None, false);
553+
EmitterWriter::new(box io::sink(), None, false, false, false, None, false);
554554

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

559559
let mut found_main = false;
@@ -963,7 +963,7 @@ impl Tester for Collector {
963963
no_run,
964964
test_type: test::TestType::DocTest,
965965
},
966-
testfn: test::DynTestFn(Box::new(move || {
966+
testfn: test::DynTestFn(box move || {
967967
let report_unused_externs = |uext| {
968968
unused_externs.lock().unwrap().push(uext);
969969
};
@@ -1043,9 +1043,9 @@ impl Tester for Collector {
10431043
}
10441044
}
10451045

1046-
panic::resume_unwind(Box::new(()));
1046+
panic::resume_unwind(box ());
10471047
}
1048-
})),
1048+
}),
10491049
});
10501050
}
10511051

src/librustdoc/fold.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::clean::*;
22

33
crate fn strip_item(mut item: Item) -> Item {
44
if !matches!(*item.kind, StrippedItem(..)) {
5-
item.kind = Box::new(StrippedItem(item.kind));
5+
item.kind = box StrippedItem(item.kind);
66
}
77
item
88
}
@@ -69,10 +69,10 @@ crate trait DocFolder: Sized {
6969

7070
/// don't override!
7171
fn fold_item_recur(&mut self, mut item: Item) -> Item {
72-
item.kind = Box::new(match *item.kind {
73-
StrippedItem(box i) => StrippedItem(Box::new(self.fold_inner_recur(i))),
72+
item.kind = box match *item.kind {
73+
StrippedItem(box i) => StrippedItem(box self.fold_inner_recur(i)),
7474
_ => self.fold_inner_recur(*item.kind),
75-
});
75+
};
7676
item
7777
}
7878

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#![feature(assert_matches)]
88
#![feature(box_patterns)]
99
#![feature(control_flow_enum)]
10+
#![feature(box_syntax)]
1011
#![feature(in_band_lifetimes)]
1112
#![feature(nll)]
1213
#![feature(test)]

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ enum ErrorKind<'a> {
6464

6565
impl<'a> From<ResolutionFailure<'a>> for ErrorKind<'a> {
6666
fn from(err: ResolutionFailure<'a>) -> Self {
67-
ErrorKind::Resolve(Box::new(err))
67+
ErrorKind::Resolve(box err)
6868
}
6969
}
7070

0 commit comments

Comments
 (0)