Skip to content

Commit 6e99c68

Browse files
committed
use deref_patterns in rustdoc
1 parent c8c4c83 commit 6e99c68

16 files changed

Lines changed: 108 additions & 103 deletions

File tree

src/librustdoc/clean/cfg.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Cfg {
149149
| CfgEntry::All(..)
150150
| CfgEntry::NameValue { .. }
151151
| CfgEntry::Version(..)
152-
| CfgEntry::Not(box CfgEntry::NameValue { .. }, _) => true,
152+
| CfgEntry::Not(CfgEntry::NameValue { .. }, _) => true,
153153
CfgEntry::Not(..) | CfgEntry::Bool(..) => false,
154154
}
155155
}
@@ -386,7 +386,7 @@ impl Display<'_> {
386386
impl fmt::Display for Display<'_> {
387387
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
388388
match &self.0 {
389-
CfgEntry::Not(box CfgEntry::Any(sub_cfgs, _), _) => {
389+
CfgEntry::Not(CfgEntry::Any(sub_cfgs, _), _) => {
390390
let separator = if sub_cfgs.iter().all(is_simple_cfg) { " nor " } else { ", nor " };
391391
fmt.write_str("neither ")?;
392392

@@ -399,10 +399,10 @@ impl fmt::Display for Display<'_> {
399399
})
400400
.joined(separator, fmt)
401401
}
402-
CfgEntry::Not(box simple @ CfgEntry::NameValue { .. }, _) => {
402+
CfgEntry::Not(simple @ CfgEntry::NameValue { .. }, _) => {
403403
write!(fmt, "non-{}", Display(simple, self.1))
404404
}
405-
CfgEntry::Not(box c, _) => write!(fmt, "not ({})", Display(c, self.1)),
405+
CfgEntry::Not(c, _) => write!(fmt, "not ({})", Display(c, self.1)),
406406

407407
CfgEntry::Any(sub_cfgs, _) => {
408408
let separator = if sub_cfgs.iter().all(is_simple_cfg) { " or " } else { ", or " };

src/librustdoc/clean/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,11 +1472,8 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
14721472
generics.where_predicates.retain_mut(|pred| match *pred {
14731473
WherePredicate::BoundPredicate {
14741474
ty:
1475-
QPath(box QPathData {
1476-
ref assoc,
1477-
ref self_type,
1478-
trait_: Some(ref trait_),
1479-
..
1475+
QPath(QPathData {
1476+
ref assoc, ref self_type, trait_: Some(ref trait_), ..
14801477
}),
14811478
bounds: ref mut pred_bounds,
14821479
..
@@ -2786,7 +2783,7 @@ fn add_without_unwanted_attributes<'hir>(
27862783
hir::Attribute::Parsed(AttributeKind::DocComment { .. }) => {
27872784
attrs.push((Cow::Borrowed(attr), import_parent));
27882785
}
2789-
hir::Attribute::Parsed(AttributeKind::Doc(box d)) => {
2786+
hir::Attribute::Parsed(AttributeKind::Doc(d)) => {
27902787
// Remove attributes from `normal` that should not be inherited by `use` re-export.
27912788
let DocAttribute {
27922789
first_span: _,

src/librustdoc/clean/types.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ impl Item {
491491

492492
/// Returns true if item is an associated function with a `self` parameter.
493493
pub(crate) fn has_self_param(&self) -> bool {
494-
if let ItemKind::MethodItem(box Function { decl, .. }, _) = &self.inner.kind {
494+
if let ItemKind::MethodItem(Function { decl, .. }, _) = &self.inner.kind {
495495
decl.receiver_type().is_some()
496496
} else {
497497
false
@@ -505,8 +505,8 @@ impl Item {
505505
};
506506
match kind {
507507
ItemKind::ModuleItem(Module { span, .. }) => Some(*span),
508-
ItemKind::ImplItem(box Impl { kind: ImplKind::Auto, .. }) => None,
509-
ItemKind::ImplItem(box Impl { kind: ImplKind::Blanket(_), .. }) => {
508+
ItemKind::ImplItem(Impl { kind: ImplKind::Auto, .. }) => None,
509+
ItemKind::ImplItem(Impl { kind: ImplKind::Blanket(_), .. }) => {
510510
if let ItemId::Blanket { impl_id, .. } = self.item_id {
511511
Some(rustc_span(impl_id, tcx))
512512
} else {
@@ -667,16 +667,21 @@ impl Item {
667667
self.type_() == ItemType::Variant
668668
}
669669
pub(crate) fn is_associated_type(&self) -> bool {
670-
matches!(self.kind, AssocTypeItem(..) | StrippedItem(box AssocTypeItem(..)))
670+
matches!(self.kind, AssocTypeItem(..) | StrippedItem(AssocTypeItem(..)))
671671
}
672672
pub(crate) fn is_required_associated_type(&self) -> bool {
673-
matches!(self.kind, RequiredAssocTypeItem(..) | StrippedItem(box RequiredAssocTypeItem(..)))
673+
matches!(self.kind, RequiredAssocTypeItem(..) | StrippedItem(RequiredAssocTypeItem(..)))
674674
}
675675
pub(crate) fn is_associated_const(&self) -> bool {
676-
matches!(self.kind, ProvidedAssocConstItem(..) | ImplAssocConstItem(..) | StrippedItem(box (ProvidedAssocConstItem(..) | ImplAssocConstItem(..))))
676+
matches!(
677+
self.kind,
678+
ProvidedAssocConstItem(..)
679+
| ImplAssocConstItem(..)
680+
| StrippedItem(ProvidedAssocConstItem(..) | ImplAssocConstItem(..))
681+
)
677682
}
678683
pub(crate) fn is_required_associated_const(&self) -> bool {
679-
matches!(self.kind, RequiredAssocConstItem(..) | StrippedItem(box RequiredAssocConstItem(..)))
684+
matches!(self.kind, RequiredAssocConstItem(..) | StrippedItem(RequiredAssocConstItem(..)))
680685
}
681686
pub(crate) fn is_method(&self) -> bool {
682687
self.type_() == ItemType::Method
@@ -1508,9 +1513,9 @@ impl Type {
15081513

15091514
pub(crate) fn primitive_type(&self) -> Option<PrimitiveType> {
15101515
match *self {
1511-
Primitive(p) | BorrowedRef { type_: box Primitive(p), .. } => Some(p),
1512-
Slice(..) | BorrowedRef { type_: box Slice(..), .. } => Some(PrimitiveType::Slice),
1513-
Array(..) | BorrowedRef { type_: box Array(..), .. } => Some(PrimitiveType::Array),
1516+
Primitive(p) | BorrowedRef { type_: Primitive(p), .. } => Some(p),
1517+
Slice(..) | BorrowedRef { type_: Slice(..), .. } => Some(PrimitiveType::Slice),
1518+
Array(..) | BorrowedRef { type_: Array(..), .. } => Some(PrimitiveType::Array),
15141519
Tuple(ref tys) => {
15151520
if tys.is_empty() {
15161521
Some(PrimitiveType::Unit)
@@ -1590,7 +1595,7 @@ impl Type {
15901595
Type::Path { path } => return Some(path.def_id()),
15911596
DynTrait(bounds, _) => return bounds.first().map(|b| b.trait_.def_id()),
15921597
Primitive(p) => return cache.primitive_locations.get(p).cloned(),
1593-
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
1598+
BorrowedRef { type_: Generic(..), .. } => PrimitiveType::Reference,
15941599
BorrowedRef { type_, .. } => return type_.def_id(cache),
15951600
Tuple(tys) => {
15961601
if tys.is_empty() {
@@ -1605,7 +1610,7 @@ impl Type {
16051610
Type::Pat(..) => PrimitiveType::Pat,
16061611
Type::FieldOf(..) => PrimitiveType::FieldOf,
16071612
RawPointer(..) => PrimitiveType::RawPointer,
1608-
QPath(box QPathData { self_type, .. }) => return self_type.def_id(cache),
1613+
QPath(QPathData { self_type, .. }) => return self_type.def_id(cache),
16091614
Generic(_) | SelfTy | Infer | ImplTrait(_) | UnsafeBinder(_) => return None,
16101615
};
16111616
Primitive(t).def_id(cache)

src/librustdoc/fold.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ pub(crate) trait DocFolder: Sized {
105105
/// don't override!
106106
fn fold_item_recur(&mut self, mut item: Item) -> Item {
107107
item.inner.kind = match item.inner.kind {
108-
StrippedItem(box i) => StrippedItem(Box::new(self.fold_inner_recur(i))),
108+
StrippedItem(i) => StrippedItem(Box::new(self.fold_inner_recur(*i))),
109109
_ => self.fold_inner_recur(item.inner.kind),
110110
};
111111
item

src/librustdoc/formats/cache.rs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl DocFolder for CacheBuilder<'_, '_> {
248248
// If this is a stripped module,
249249
// we don't want it or its children in the search index.
250250
let orig_stripped_mod = match item.kind {
251-
clean::StrippedItem(box clean::ModuleItem(..)) => {
251+
clean::StrippedItem(clean::ModuleItem(..)) => {
252252
mem::replace(&mut self.cache.stripped_mod, true)
253253
}
254254
_ => self.cache.stripped_mod,
@@ -409,69 +409,69 @@ impl DocFolder for CacheBuilder<'_, '_> {
409409

410410
// Once we've recursively found all the generics, hoard off all the
411411
// implementations elsewhere.
412-
let ret = if let clean::Item {
413-
inner: box clean::ItemInner { kind: clean::ImplItem(ref i), .. },
414-
} = item
415-
{
416-
// Figure out the id of this impl. This may map to a
417-
// primitive rather than always to a struct/enum.
418-
// Note: matching twice to restrict the lifetime of the `i` borrow.
419-
let mut dids = FxIndexSet::default();
420-
match i.for_ {
421-
clean::Type::Path { ref path }
422-
| clean::BorrowedRef { type_: box clean::Type::Path { ref path }, .. } => {
423-
dids.insert(path.def_id());
424-
if let Some(generics) = path.generics()
425-
&& let ty::Adt(adt, _) = self
426-
.tcx
427-
.type_of(path.def_id())
428-
.instantiate_identity()
429-
.skip_norm_wip()
430-
.kind()
431-
&& adt.is_fundamental()
432-
{
433-
for ty in generics {
434-
dids.extend(ty.def_id(self.cache));
412+
let ret =
413+
if let clean::Item { inner: clean::ItemInner { kind: clean::ImplItem(ref i), .. } } =
414+
item
415+
{
416+
// Figure out the id of this impl. This may map to a
417+
// primitive rather than always to a struct/enum.
418+
// Note: matching twice to restrict the lifetime of the `i` borrow.
419+
let mut dids = FxIndexSet::default();
420+
match i.for_ {
421+
clean::Type::Path { ref path }
422+
| clean::BorrowedRef { type_: clean::Type::Path { ref path }, .. } => {
423+
dids.insert(path.def_id());
424+
if let Some(generics) = path.generics()
425+
&& let ty::Adt(adt, _) = self
426+
.tcx
427+
.type_of(path.def_id())
428+
.instantiate_identity()
429+
.skip_norm_wip()
430+
.kind()
431+
&& adt.is_fundamental()
432+
{
433+
for ty in generics {
434+
dids.extend(ty.def_id(self.cache));
435+
}
435436
}
436437
}
437-
}
438-
clean::DynTrait(ref bounds, _)
439-
| clean::BorrowedRef { type_: box clean::DynTrait(ref bounds, _), .. } => {
440-
dids.insert(bounds[0].trait_.def_id());
441-
}
442-
ref t => {
443-
let did = t
444-
.primitive_type()
445-
.and_then(|t| self.cache.primitive_locations.get(&t).cloned());
438+
clean::DynTrait(ref bounds, _)
439+
| clean::BorrowedRef { type_: clean::DynTrait(ref bounds, _), .. } => {
440+
dids.insert(bounds[0].trait_.def_id());
441+
}
442+
ref t => {
443+
let did = t
444+
.primitive_type()
445+
.and_then(|t| self.cache.primitive_locations.get(&t).cloned());
446446

447-
dids.extend(did);
447+
dids.extend(did);
448+
}
448449
}
449-
}
450450

451-
if let Some(trait_) = &i.trait_
452-
&& let Some(generics) = trait_.generics()
453-
{
454-
for bound in generics {
455-
dids.extend(bound.def_id(self.cache));
451+
if let Some(trait_) = &i.trait_
452+
&& let Some(generics) = trait_.generics()
453+
{
454+
for bound in generics {
455+
dids.extend(bound.def_id(self.cache));
456+
}
456457
}
457-
}
458-
let impl_item = Impl { impl_item: item };
459-
let impl_did = impl_item.def_id();
460-
let trait_did = impl_item.trait_did();
461-
if trait_did.is_none_or(|d| self.cache.traits.contains_key(&d)) {
462-
for did in dids {
463-
if self.impl_ids.entry(did).or_default().insert(impl_did) {
464-
self.cache.impls.entry(did).or_default().push(impl_item.clone());
458+
let impl_item = Impl { impl_item: item };
459+
let impl_did = impl_item.def_id();
460+
let trait_did = impl_item.trait_did();
461+
if trait_did.is_none_or(|d| self.cache.traits.contains_key(&d)) {
462+
for did in dids {
463+
if self.impl_ids.entry(did).or_default().insert(impl_did) {
464+
self.cache.impls.entry(did).or_default().push(impl_item.clone());
465+
}
465466
}
467+
} else {
468+
let trait_did = trait_did.expect("no trait did");
469+
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
466470
}
471+
None
467472
} else {
468-
let trait_did = trait_did.expect("no trait did");
469-
self.cache.orphan_trait_impls.push((trait_did, dids, impl_item));
470-
}
471-
None
472-
} else {
473-
Some(item)
474-
};
473+
Some(item)
474+
};
475475

476476
if pushed {
477477
self.cache.stack.pop().expect("stack already empty");
@@ -655,7 +655,7 @@ enum ParentStackItem {
655655
impl ParentStackItem {
656656
fn new(item: &clean::Item) -> Self {
657657
match &item.kind {
658-
clean::ItemKind::ImplItem(box clean::Impl { for_, trait_, generics, kind, .. }) => {
658+
clean::ItemKind::ImplItem(clean::Impl { for_, trait_, generics, kind, .. }) => {
659659
ParentStackItem::Impl {
660660
for_: for_.clone(),
661661
trait_: trait_.clone(),

src/librustdoc/formats/item_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ item_type! {
106106
impl<'a> From<&'a clean::Item> for ItemType {
107107
fn from(item: &'a clean::Item) -> ItemType {
108108
let kind = match &item.kind {
109-
clean::StrippedItem(box item) => item,
109+
clean::StrippedItem(item) => item,
110110
kind => kind,
111111
};
112112

src/librustdoc/formats/renderer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ fn run_format_inner<'tcx, T: FormatRenderer<'tcx>>(
7575
prof.generic_activity_with_arg("render_mod_item", item.name.unwrap().to_string());
7676

7777
cx.mod_item_in(item)?;
78-
let (clean::StrippedItem(box clean::ModuleItem(ref module))
79-
| clean::ModuleItem(ref module)) = item.inner.kind
78+
let (clean::StrippedItem(clean::ModuleItem(ref module)) | clean::ModuleItem(ref module)) =
79+
item.inner.kind
8080
else {
8181
unreachable!()
8282
};

src/librustdoc/html/format.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,7 @@ fn fmt_type(
961961
}
962962
}
963963
},
964-
clean::Slice(box clean::Generic(name)) => {
964+
clean::Slice(clean::Generic(name)) => {
965965
primitive_link(f, PrimitiveType::Slice, format_args!("[{name}]"), cx)
966966
}
967967
clean::Slice(t) => Wrapped::with_square_brackets().wrap(print_type(t, cx)).fmt(f),
@@ -974,7 +974,7 @@ fn fmt_type(
974974
fmt::Display::fmt(&print_type(t, cx), f)?;
975975
write!(f, ", {field})")
976976
}
977-
clean::Array(box clean::Generic(name), n) if !f.alternate() => primitive_link(
977+
clean::Array(clean::Generic(name), n) if !f.alternate() => primitive_link(
978978
f,
979979
PrimitiveType::Array,
980980
format_args!("[{name}; {n}]", n = Escape(n)),
@@ -1280,7 +1280,7 @@ fn print_parameter(parameter: &clean::Parameter, cx: &Context<'_>) -> impl fmt::
12801280
if let Some(self_ty) = parameter.to_receiver() {
12811281
match self_ty {
12821282
clean::SelfTy => f.write_str("self"),
1283-
clean::BorrowedRef { lifetime, mutability, type_: box clean::SelfTy } => {
1283+
clean::BorrowedRef { lifetime, mutability, type_: clean::SelfTy } => {
12841284
f.write_str(if f.alternate() { "&" } else { "&amp;" })?;
12851285
if let Some(lt) = lifetime {
12861286
write!(f, "{lt} ", lt = print_lifetime(lt))?;

src/librustdoc/html/render/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,7 @@ impl<'tcx> FormatRenderer<'tcx> for Context<'tcx> {
832832

833833
// Render sidebar-items.js used throughout this module.
834834
if !self.info.render_redirect_pages {
835-
let (clean::StrippedItem(box clean::ModuleItem(ref module))
835+
let (clean::StrippedItem(clean::ModuleItem(ref module))
836836
| clean::ModuleItem(ref module)) = item.kind
837837
else {
838838
unreachable!()

src/librustdoc/html/render/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,8 @@ fn document_full_inner(
809809
}
810810

811811
let kind = match &item.kind {
812-
clean::ItemKind::StrippedItem(box kind) | kind => kind,
812+
clean::ItemKind::StrippedItem(kind) => kind,
813+
kind => kind,
813814
};
814815

815816
if let clean::ItemKind::FunctionItem(..) | clean::ItemKind::MethodItem(..) = kind {
@@ -1582,7 +1583,7 @@ fn render_deref_methods(
15821583
.items
15831584
.iter()
15841585
.find_map(|item| match item.kind {
1585-
clean::AssocTypeItem(box ref t, _) => Some(match *t {
1586+
clean::AssocTypeItem(ref t, _) => Some(match *t {
15861587
clean::TypeAlias { item_type: Some(ref type_), .. } => (type_, &t.type_),
15871588
_ => (&t.type_, &t.type_),
15881589
}),
@@ -2709,7 +2710,7 @@ fn collect_paths_for_type(first_ty: &clean::Type, cache: &Cache) -> Vec<String>
27092710
clean::Type::BorrowedRef { type_, .. } => {
27102711
work.push_back(type_);
27112712
}
2712-
clean::Type::QPath(box clean::QPathData { self_type, trait_, .. }) => {
2713+
clean::Type::QPath(clean::QPathData { self_type, trait_, .. }) => {
27132714
work.push_back(self_type);
27142715
if let Some(trait_) = trait_ {
27152716
process_path(trait_.def_id());

0 commit comments

Comments
 (0)