Skip to content

Commit 9c7ae1d

Browse files
Rollup merge of rust-lang#129743 - GuillaumeGomez:fix-rustdoc-clippy, r=notriddle
Fix rustdoc clippy lints Ran clippy on rustdoc and fixed the errors. r? `@notriddle`
2 parents 7e23a44 + 8683439 commit 9c7ae1d

16 files changed

+94
-105
lines changed

src/librustdoc/clean/auto_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn clean_region_outlives_constraints<'tcx>(
341341
.map(|&region| {
342342
let lifetime = early_bound_region_name(region)
343343
.inspect(|name| assert!(region_params.contains(name)))
344-
.map(|name| Lifetime(name))
344+
.map(Lifetime)
345345
.unwrap_or(Lifetime::statik());
346346
clean::GenericBound::Outlives(lifetime)
347347
})

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub(crate) fn synthesize_blanket_impls(
2424
let mut blanket_impls = Vec::new();
2525
for trait_def_id in tcx.all_traits() {
2626
if !cx.cache.effective_visibilities.is_reachable(tcx, trait_def_id)
27-
|| cx.generated_synthetics.get(&(ty.skip_binder(), trait_def_id)).is_some()
27+
|| cx.generated_synthetics.contains(&(ty.skip_binder(), trait_def_id))
2828
{
2929
continue;
3030
}

src/librustdoc/clean/inline.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub(crate) fn try_inline(
5454
debug!("attrs={attrs:?}");
5555

5656
let attrs_without_docs = attrs.map(|(attrs, def_id)| {
57-
(attrs.into_iter().filter(|a| a.doc_str().is_none()).cloned().collect::<Vec<_>>(), def_id)
57+
(attrs.iter().filter(|a| a.doc_str().is_none()).cloned().collect::<Vec<_>>(), def_id)
5858
});
5959
let attrs_without_docs =
6060
attrs_without_docs.as_ref().map(|(attrs, def_id)| (&attrs[..], *def_id));
@@ -288,10 +288,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
288288
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
289289
}
290290

291-
pub(crate) fn build_function<'tcx>(
292-
cx: &mut DocContext<'tcx>,
293-
def_id: DefId,
294-
) -> Box<clean::Function> {
291+
pub(crate) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clean::Function> {
295292
let sig = cx.tcx.fn_sig(def_id).instantiate_identity();
296293
// The generics need to be cleaned before the signature.
297294
let mut generics =
@@ -425,7 +422,7 @@ pub(crate) fn merge_attrs(
425422
both.cfg(cx.tcx, &cx.cache.hidden_cfg),
426423
)
427424
} else {
428-
(Attributes::from_ast(&old_attrs), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg))
425+
(Attributes::from_ast(old_attrs), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg))
429426
}
430427
}
431428

@@ -791,16 +788,15 @@ fn build_macro(
791788
/// implementation for `AssociatedType`
792789
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean::Generics {
793790
for pred in &mut g.where_predicates {
794-
match *pred {
795-
clean::WherePredicate::BoundPredicate { ty: clean::SelfTy, ref mut bounds, .. } => {
796-
bounds.retain(|bound| match bound {
797-
clean::GenericBound::TraitBound(clean::PolyTrait { trait_, .. }, _) => {
798-
trait_.def_id() != trait_did
799-
}
800-
_ => true,
801-
});
802-
}
803-
_ => {}
791+
if let clean::WherePredicate::BoundPredicate { ty: clean::SelfTy, ref mut bounds, .. } =
792+
*pred
793+
{
794+
bounds.retain(|bound| match bound {
795+
clean::GenericBound::TraitBound(clean::PolyTrait { trait_, .. }, _) => {
796+
trait_.def_id() != trait_did
797+
}
798+
_ => true,
799+
});
804800
}
805801
}
806802

src/librustdoc/clean/mod.rs

+25-30
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,15 @@ fn clean_poly_trait_ref_with_constraints<'tcx>(
266266
)
267267
}
268268

269-
fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime {
269+
fn clean_lifetime(lifetime: &hir::Lifetime, cx: &mut DocContext<'_>) -> Lifetime {
270270
if let Some(
271271
rbv::ResolvedArg::EarlyBound(did)
272272
| rbv::ResolvedArg::LateBound(_, _, did)
273273
| rbv::ResolvedArg::Free(_, did),
274274
) = cx.tcx.named_bound_var(lifetime.hir_id)
275275
&& let Some(lt) = cx.args.get(&did.to_def_id()).and_then(|arg| arg.as_lt())
276276
{
277-
return lt.clone();
277+
return *lt;
278278
}
279279
Lifetime(lifetime.ident.name)
280280
}
@@ -285,7 +285,7 @@ pub(crate) fn clean_const<'tcx>(
285285
) -> ConstantKind {
286286
match &constant.kind {
287287
hir::ConstArgKind::Path(qpath) => {
288-
ConstantKind::Path { path: qpath_to_string(&qpath).into() }
288+
ConstantKind::Path { path: qpath_to_string(qpath).into() }
289289
}
290290
hir::ConstArgKind::Anon(anon) => ConstantKind::Anonymous { body: anon.body },
291291
}
@@ -299,7 +299,7 @@ pub(crate) fn clean_middle_const<'tcx>(
299299
ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() }
300300
}
301301

302-
pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Lifetime> {
302+
pub(crate) fn clean_middle_region(region: ty::Region<'_>) -> Option<Lifetime> {
303303
match *region {
304304
ty::ReStatic => Some(Lifetime::statik()),
305305
_ if !region.has_name() => None,
@@ -389,8 +389,8 @@ fn clean_poly_trait_predicate<'tcx>(
389389
})
390390
}
391391

392-
fn clean_region_outlives_predicate<'tcx>(
393-
pred: ty::RegionOutlivesPredicate<'tcx>,
392+
fn clean_region_outlives_predicate(
393+
pred: ty::RegionOutlivesPredicate<'_>,
394394
) -> Option<WherePredicate> {
395395
let ty::OutlivesPredicate(a, b) = pred;
396396

@@ -513,10 +513,10 @@ fn projection_to_path_segment<'tcx>(
513513
}
514514
}
515515

516-
fn clean_generic_param_def<'tcx>(
516+
fn clean_generic_param_def(
517517
def: &ty::GenericParamDef,
518518
defaults: ParamDefaults,
519-
cx: &mut DocContext<'tcx>,
519+
cx: &mut DocContext<'_>,
520520
) -> GenericParamDef {
521521
let (name, kind) = match def.kind {
522522
ty::GenericParamDefKind::Lifetime => {
@@ -1303,10 +1303,7 @@ pub(crate) fn clean_impl_item<'tcx>(
13031303
})
13041304
}
13051305

1306-
pub(crate) fn clean_middle_assoc_item<'tcx>(
1307-
assoc_item: &ty::AssocItem,
1308-
cx: &mut DocContext<'tcx>,
1309-
) -> Item {
1306+
pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocContext<'_>) -> Item {
13101307
let tcx = cx.tcx;
13111308
let kind = match assoc_item.kind {
13121309
ty::AssocKind::Const => {
@@ -1459,7 +1456,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
14591456
// which only has one associated type, which is not a GAT, so whatever.
14601457
}
14611458
}
1462-
bounds.extend(mem::replace(pred_bounds, Vec::new()));
1459+
bounds.extend(mem::take(pred_bounds));
14631460
false
14641461
}
14651462
_ => true,
@@ -1661,7 +1658,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
16611658
expanded
16621659
} else {
16631660
// First we check if it's a private re-export.
1664-
let path = if let Some(path) = first_non_private(cx, hir_id, &path) {
1661+
let path = if let Some(path) = first_non_private(cx, hir_id, path) {
16651662
path
16661663
} else {
16671664
clean_path(path, cx)
@@ -1796,7 +1793,7 @@ fn maybe_expand_private_type_alias<'tcx>(
17961793
}
17971794

17981795
Some(cx.enter_alias(args, def_id.to_def_id(), |cx| {
1799-
cx.with_param_env(def_id.to_def_id(), |cx| clean_ty(&ty, cx))
1796+
cx.with_param_env(def_id.to_def_id(), |cx| clean_ty(ty, cx))
18001797
}))
18011798
}
18021799

@@ -1806,8 +1803,8 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18061803
match ty.kind {
18071804
TyKind::Never => Primitive(PrimitiveType::Never),
18081805
TyKind::Ptr(ref m) => RawPointer(m.mutbl, Box::new(clean_ty(m.ty, cx))),
1809-
TyKind::Ref(ref l, ref m) => {
1810-
let lifetime = if l.is_anonymous() { None } else { Some(clean_lifetime(*l, cx)) };
1806+
TyKind::Ref(l, ref m) => {
1807+
let lifetime = if l.is_anonymous() { None } else { Some(clean_lifetime(l, cx)) };
18111808
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
18121809
}
18131810
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
@@ -1843,17 +1840,17 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
18431840
TyKind::Tup(tys) => Tuple(tys.iter().map(|ty| clean_ty(ty, cx)).collect()),
18441841
TyKind::OpaqueDef(item_id, _, _) => {
18451842
let item = cx.tcx.hir().item(item_id);
1846-
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
1843+
if let hir::ItemKind::OpaqueTy(ty) = item.kind {
18471844
ImplTrait(ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect())
18481845
} else {
18491846
unreachable!()
18501847
}
18511848
}
18521849
TyKind::Path(_) => clean_qpath(ty, cx),
1853-
TyKind::TraitObject(bounds, ref lifetime, _) => {
1850+
TyKind::TraitObject(bounds, lifetime, _) => {
18541851
let bounds = bounds.iter().map(|(bound, _)| clean_poly_trait_ref(bound, cx)).collect();
18551852
let lifetime =
1856-
if !lifetime.is_elided() { Some(clean_lifetime(*lifetime, cx)) } else { None };
1853+
if !lifetime.is_elided() { Some(clean_lifetime(lifetime, cx)) } else { None };
18571854
DynTrait(bounds, lifetime)
18581855
}
18591856
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
@@ -2355,7 +2352,7 @@ pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext
23552352
clean_field_with_def_id(field.def_id.to_def_id(), field.ident.name, clean_ty(field.ty, cx), cx)
23562353
}
23572354

2358-
pub(crate) fn clean_middle_field<'tcx>(field: &ty::FieldDef, cx: &mut DocContext<'tcx>) -> Item {
2355+
pub(crate) fn clean_middle_field(field: &ty::FieldDef, cx: &mut DocContext<'_>) -> Item {
23592356
clean_field_with_def_id(
23602357
field.did,
23612358
field.name,
@@ -2378,7 +2375,7 @@ pub(crate) fn clean_field_with_def_id(
23782375
Item::from_def_id_and_parts(def_id, Some(name), StructFieldItem(ty), cx)
23792376
}
23802377

2381-
pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item {
2378+
pub(crate) fn clean_variant_def(variant: &ty::VariantDef, cx: &mut DocContext<'_>) -> Item {
23822379
let discriminant = match variant.discr {
23832380
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
23842381
ty::VariantDiscr::Relative(_) => None,
@@ -2526,7 +2523,7 @@ fn clean_generic_args<'tcx>(
25262523
.filter_map(|arg| {
25272524
Some(match arg {
25282525
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
2529-
GenericArg::Lifetime(clean_lifetime(*lt, cx))
2526+
GenericArg::Lifetime(clean_lifetime(lt, cx))
25302527
}
25312528
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
25322529
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
@@ -2579,11 +2576,11 @@ fn clean_bare_fn_ty<'tcx>(
25792576
BareFunctionDecl { safety: bare_fn.safety, abi: bare_fn.abi, decl, generic_params }
25802577
}
25812578

2582-
pub(crate) fn reexport_chain<'tcx>(
2583-
tcx: TyCtxt<'tcx>,
2579+
pub(crate) fn reexport_chain(
2580+
tcx: TyCtxt<'_>,
25842581
import_def_id: LocalDefId,
25852582
target_def_id: DefId,
2586-
) -> &'tcx [Reexport] {
2583+
) -> &[Reexport] {
25872584
for child in tcx.module_children_local(tcx.local_parent(import_def_id)) {
25882585
if child.res.opt_def_id() == Some(target_def_id)
25892586
&& child.reexport_chain.first().and_then(|r| r.id()) == Some(import_def_id.to_def_id())
@@ -2803,7 +2800,7 @@ fn clean_maybe_renamed_item<'tcx>(
28032800
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
28042801
}),
28052802
ItemKind::Impl(impl_) => return clean_impl(impl_, item.owner_id.def_id, cx),
2806-
ItemKind::Macro(ref macro_def, MacroKind::Bang) => {
2803+
ItemKind::Macro(macro_def, MacroKind::Bang) => {
28072804
let ty_vis = cx.tcx.visibility(def_id);
28082805
MacroItem(Macro {
28092806
// FIXME this shouldn't be false
@@ -3134,9 +3131,7 @@ fn clean_assoc_item_constraint<'tcx>(
31343131
}
31353132
}
31363133

3137-
fn clean_bound_vars<'tcx>(
3138-
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
3139-
) -> Vec<GenericParamDef> {
3134+
fn clean_bound_vars(bound_vars: &ty::List<ty::BoundVariableKind>) -> Vec<GenericParamDef> {
31403135
bound_vars
31413136
.into_iter()
31423137
.filter_map(|var| match var {

src/librustdoc/clean/simplify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: ThinVec<WP>) -> ThinVe
7070

7171
pub(crate) fn merge_bounds(
7272
cx: &clean::DocContext<'_>,
73-
bounds: &mut Vec<clean::GenericBound>,
73+
bounds: &mut [clean::GenericBound],
7474
trait_did: DefId,
7575
assoc: clean::PathSegment,
7676
rhs: &clean::Term,

src/librustdoc/clean/types.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ fn is_field_vis_inherited(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
368368
}
369369

370370
impl Item {
371-
pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
371+
pub(crate) fn stability(&self, tcx: TyCtxt<'_>) -> Option<Stability> {
372372
self.def_id().and_then(|did| tcx.lookup_stability(did))
373373
}
374374

375-
pub(crate) fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
375+
pub(crate) fn const_stability(&self, tcx: TyCtxt<'_>) -> Option<ConstStability> {
376376
self.def_id().and_then(|did| tcx.lookup_const_stability(did))
377377
}
378378

@@ -945,9 +945,9 @@ pub(crate) trait AttributesExt {
945945
where
946946
Self: 'a;
947947

948-
fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a>;
948+
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_>;
949949

950-
fn iter<'a>(&'a self) -> Self::Attributes<'a>;
950+
fn iter(&self) -> Self::Attributes<'_>;
951951

952952
fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
953953
let sess = tcx.sess;
@@ -1043,15 +1043,15 @@ impl AttributesExt for [ast::Attribute] {
10431043
type AttributeIterator<'a> = impl Iterator<Item = ast::NestedMetaItem> + 'a;
10441044
type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a;
10451045

1046-
fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a> {
1046+
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
10471047
self.iter()
10481048
.filter(move |attr| attr.has_name(name))
10491049
.filter_map(ast::Attribute::meta_item_list)
10501050
.flatten()
10511051
}
10521052

1053-
fn iter<'a>(&'a self) -> Self::Attributes<'a> {
1054-
self.into_iter()
1053+
fn iter(&self) -> Self::Attributes<'_> {
1054+
self.iter()
10551055
}
10561056
}
10571057

@@ -1061,15 +1061,15 @@ impl AttributesExt for [(Cow<'_, ast::Attribute>, Option<DefId>)] {
10611061
type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a
10621062
where Self: 'a;
10631063

1064-
fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a> {
1064+
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
10651065
AttributesExt::iter(self)
10661066
.filter(move |attr| attr.has_name(name))
10671067
.filter_map(ast::Attribute::meta_item_list)
10681068
.flatten()
10691069
}
10701070

1071-
fn iter<'a>(&'a self) -> Self::Attributes<'a> {
1072-
self.into_iter().map(move |(attr, _)| match attr {
1071+
fn iter(&self) -> Self::Attributes<'_> {
1072+
self.iter().map(move |(attr, _)| match attr {
10731073
Cow::Borrowed(attr) => *attr,
10741074
Cow::Owned(attr) => attr,
10751075
})
@@ -1389,7 +1389,7 @@ pub(crate) struct FnDecl {
13891389

13901390
impl FnDecl {
13911391
pub(crate) fn receiver_type(&self) -> Option<&Type> {
1392-
self.inputs.values.get(0).and_then(|v| v.to_receiver())
1392+
self.inputs.values.first().and_then(|v| v.to_receiver())
13931393
}
13941394
}
13951395

@@ -1502,7 +1502,7 @@ impl Type {
15021502
pub(crate) fn without_borrowed_ref(&self) -> &Type {
15031503
let mut result = self;
15041504
while let Type::BorrowedRef { type_, .. } = result {
1505-
result = &*type_;
1505+
result = type_;
15061506
}
15071507
result
15081508
}
@@ -1631,10 +1631,7 @@ impl Type {
16311631
}
16321632

16331633
pub(crate) fn is_self_type(&self) -> bool {
1634-
match *self {
1635-
SelfTy => true,
1636-
_ => false,
1637-
}
1634+
matches!(*self, Type::SelfTy)
16381635
}
16391636

16401637
pub(crate) fn generic_args(&self) -> Option<&GenericArgs> {
@@ -1673,7 +1670,7 @@ impl Type {
16731670
pub(crate) fn def_id(&self, cache: &Cache) -> Option<DefId> {
16741671
let t: PrimitiveType = match *self {
16751672
Type::Path { ref path } => return Some(path.def_id()),
1676-
DynTrait(ref bounds, _) => return bounds.get(0).map(|b| b.trait_.def_id()),
1673+
DynTrait(ref bounds, _) => return bounds.first().map(|b| b.trait_.def_id()),
16771674
Primitive(p) => return cache.primitive_locations.get(&p).cloned(),
16781675
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
16791676
BorrowedRef { ref type_, .. } => return type_.def_id(cache),

0 commit comments

Comments
 (0)