Skip to content

Commit 6ac8ada

Browse files
committedMay 25, 2022
Auto merge of #97365 - klensy:rustdoc-vs-clippy, r=notriddle
rustdoc: fix few clippy lints Fix few clippy lints: second commit - perf ones, first - other ones.
2 parents f80e454 + 2a326bc commit 6ac8ada

22 files changed

+104
-105
lines changed
 

‎src/librustdoc/clean/auto_trait.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
643643
/// both for visual consistency between 'rustdoc' runs, and to
644644
/// make writing tests much easier
645645
#[inline]
646-
fn sort_where_predicates(&self, mut predicates: &mut Vec<WherePredicate>) {
646+
fn sort_where_predicates(&self, predicates: &mut Vec<WherePredicate>) {
647647
// We should never have identical bounds - and if we do,
648648
// they're visually identical as well. Therefore, using
649649
// an unstable sort is fine.
650-
self.unstable_debug_sort(&mut predicates);
650+
self.unstable_debug_sort(predicates);
651651
}
652652

653653
/// Ensure that the bounds are in a consistent order. The precise
@@ -656,11 +656,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
656656
/// both for visual consistency between 'rustdoc' runs, and to
657657
/// make writing tests much easier
658658
#[inline]
659-
fn sort_where_bounds(&self, mut bounds: &mut Vec<GenericBound>) {
659+
fn sort_where_bounds(&self, bounds: &mut Vec<GenericBound>) {
660660
// We should never have identical bounds - and if we do,
661661
// they're visually identical as well. Therefore, using
662662
// an unstable sort is fine.
663-
self.unstable_debug_sort(&mut bounds);
663+
self.unstable_debug_sort(bounds);
664664
}
665665

666666
/// This might look horrendously hacky, but it's actually not that bad.

‎src/librustdoc/clean/mod.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
248248
hir::WherePredicate::BoundPredicate(ref wbp) => {
249249
let bound_params = wbp
250250
.bound_generic_params
251-
.into_iter()
251+
.iter()
252252
.map(|param| {
253253
// Higher-ranked params must be lifetimes.
254254
// Higher-ranked lifetimes can't have bounds.
@@ -525,7 +525,7 @@ fn clean_generic_param<'tcx>(
525525
},
526526
)
527527
}
528-
hir::GenericParamKind::Const { ref ty, default } => (
528+
hir::GenericParamKind::Const { ty, default } => (
529529
param.name.ident().name,
530530
GenericParamDefKind::Const {
531531
did: cx.tcx.hir().local_def_id(param.hir_id).to_def_id(),
@@ -947,7 +947,7 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
947947
// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
948948
// but shouldn't change any code meaning.
949949
let output = match sig.skip_binder().output().clean(cx) {
950-
Type::Tuple(inner) if inner.len() == 0 => DefaultReturn,
950+
Type::Tuple(inner) if inner.is_empty() => DefaultReturn,
951951
ty => Return(ty),
952952
};
953953

@@ -972,7 +972,7 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
972972
impl<'tcx> Clean<'tcx, FnRetTy> for hir::FnRetTy<'tcx> {
973973
fn clean(&self, cx: &mut DocContext<'tcx>) -> FnRetTy {
974974
match *self {
975-
Self::Return(ref typ) => Return(typ.clean(cx)),
975+
Self::Return(typ) => Return(typ.clean(cx)),
976976
Self::DefaultReturn(..) => DefaultReturn,
977977
}
978978
}
@@ -1013,13 +1013,13 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
10131013
let local_did = self.def_id.to_def_id();
10141014
cx.with_param_env(local_did, |cx| {
10151015
let inner = match self.kind {
1016-
hir::TraitItemKind::Const(ref ty, Some(default)) => AssocConstItem(
1016+
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
10171017
ty.clean(cx),
10181018
ConstantKind::Local { def_id: local_did, body: default },
10191019
),
1020-
hir::TraitItemKind::Const(ref ty, None) => TyAssocConstItem(ty.clean(cx)),
1020+
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(ty.clean(cx)),
10211021
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1022-
let m = clean_function(cx, sig, &self.generics, body);
1022+
let m = clean_function(cx, sig, self.generics, body);
10231023
MethodItem(m, None)
10241024
}
10251025
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
@@ -1060,16 +1060,16 @@ impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> {
10601060
let local_did = self.def_id.to_def_id();
10611061
cx.with_param_env(local_did, |cx| {
10621062
let inner = match self.kind {
1063-
hir::ImplItemKind::Const(ref ty, expr) => {
1063+
hir::ImplItemKind::Const(ty, expr) => {
10641064
let default = ConstantKind::Local { def_id: local_did, body: expr };
10651065
AssocConstItem(ty.clean(cx), default)
10661066
}
10671067
hir::ImplItemKind::Fn(ref sig, body) => {
1068-
let m = clean_function(cx, sig, &self.generics, body);
1068+
let m = clean_function(cx, sig, self.generics, body);
10691069
let defaultness = cx.tcx.associated_item(self.def_id).defaultness;
10701070
MethodItem(m, Some(defaultness))
10711071
}
1072-
hir::ImplItemKind::TyAlias(ref hir_ty) => {
1072+
hir::ImplItemKind::TyAlias(hir_ty) => {
10731073
let type_ = hir_ty.clean(cx);
10741074
let generics = self.generics.clean(cx);
10751075
let item_type = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
@@ -1292,7 +1292,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
12921292
let hir::TyKind::Path(qpath) = kind else { unreachable!() };
12931293

12941294
match qpath {
1295-
hir::QPath::Resolved(None, ref path) => {
1295+
hir::QPath::Resolved(None, path) => {
12961296
if let Res::Def(DefKind::TyParam, did) = path.res {
12971297
if let Some(new_ty) = cx.substs.get(&did).and_then(|p| p.as_ty()).cloned() {
12981298
return new_ty;
@@ -1309,7 +1309,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
13091309
resolve_type(cx, path)
13101310
}
13111311
}
1312-
hir::QPath::Resolved(Some(ref qself), p) => {
1312+
hir::QPath::Resolved(Some(qself), p) => {
13131313
// Try to normalize `<X as Y>::T` to a type
13141314
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
13151315
if let Some(normalized_value) = normalize(cx, ty) {
@@ -1333,7 +1333,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
13331333
trait_,
13341334
}
13351335
}
1336-
hir::QPath::TypeRelative(ref qself, segment) => {
1336+
hir::QPath::TypeRelative(qself, segment) => {
13371337
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
13381338
let res = match ty.kind() {
13391339
ty::Projection(proj) => Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id),
@@ -1463,8 +1463,8 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
14631463
let lifetime = if elided { None } else { Some(l.clean(cx)) };
14641464
BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) }
14651465
}
1466-
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
1467-
TyKind::Array(ref ty, ref length) => {
1466+
TyKind::Slice(ty) => Slice(box ty.clean(cx)),
1467+
TyKind::Array(ty, ref length) => {
14681468
let length = match length {
14691469
hir::ArrayLen::Infer(_, _) => "_".to_string(),
14701470
hir::ArrayLen::Body(anon_const) => {
@@ -1499,7 +1499,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
14991499
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
15001500
DynTrait(bounds, lifetime)
15011501
}
1502-
TyKind::BareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
1502+
TyKind::BareFn(barefn) => BareFunction(box barefn.clean(cx)),
15031503
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
15041504
TyKind::Infer | TyKind::Err => Infer,
15051505
TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind),
@@ -1908,7 +1908,7 @@ fn clean_maybe_renamed_item<'tcx>(
19081908
bounds: ty.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
19091909
generics: ty.generics.clean(cx),
19101910
}),
1911-
ItemKind::TyAlias(hir_ty, ref generics) => {
1911+
ItemKind::TyAlias(hir_ty, generics) => {
19121912
let rustdoc_ty = hir_ty.clean(cx);
19131913
let ty = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
19141914
TypedefItem(Typedef {
@@ -1917,26 +1917,26 @@ fn clean_maybe_renamed_item<'tcx>(
19171917
item_type: Some(ty),
19181918
})
19191919
}
1920-
ItemKind::Enum(ref def, ref generics) => EnumItem(Enum {
1920+
ItemKind::Enum(ref def, generics) => EnumItem(Enum {
19211921
variants: def.variants.iter().map(|v| v.clean(cx)).collect(),
19221922
generics: generics.clean(cx),
19231923
}),
1924-
ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias {
1924+
ItemKind::TraitAlias(generics, bounds) => TraitAliasItem(TraitAlias {
19251925
generics: generics.clean(cx),
19261926
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
19271927
}),
1928-
ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union {
1928+
ItemKind::Union(ref variant_data, generics) => UnionItem(Union {
19291929
generics: generics.clean(cx),
19301930
fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
19311931
}),
1932-
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
1932+
ItemKind::Struct(ref variant_data, generics) => StructItem(Struct {
19331933
struct_type: CtorKind::from_hir(variant_data),
19341934
generics: generics.clean(cx),
19351935
fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
19361936
}),
1937-
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx),
1937+
ItemKind::Impl(impl_) => return clean_impl(impl_, item.hir_id(), cx),
19381938
// proc macros can have a name set by attributes
1939-
ItemKind::Fn(ref sig, ref generics, body_id) => {
1939+
ItemKind::Fn(ref sig, generics, body_id) => {
19401940
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
19411941
}
19421942
ItemKind::Macro(ref macro_def, _) => {
@@ -1945,7 +1945,7 @@ fn clean_maybe_renamed_item<'tcx>(
19451945
source: display_macro_source(cx, name, macro_def, def_id, ty_vis),
19461946
})
19471947
}
1948-
ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => {
1948+
ItemKind::Trait(is_auto, unsafety, generics, bounds, item_ids) => {
19491949
let items =
19501950
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
19511951
TraitItem(Trait {
@@ -2192,7 +2192,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
21922192
let def_id = item.def_id.to_def_id();
21932193
cx.with_param_env(def_id, |cx| {
21942194
let kind = match item.kind {
2195-
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
2195+
hir::ForeignItemKind::Fn(decl, names, generics) => {
21962196
let (generics, decl) = enter_impl_trait(cx, |cx| {
21972197
// NOTE: generics must be cleaned before args
21982198
let generics = generics.clean(cx);
@@ -2202,7 +2202,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
22022202
});
22032203
ForeignFunctionItem(Function { decl, generics })
22042204
}
2205-
hir::ForeignItemKind::Static(ref ty, mutability) => {
2205+
hir::ForeignItemKind::Static(ty, mutability) => {
22062206
ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: None })
22072207
}
22082208
hir::ForeignItemKind::Type => ForeignTypeItem,
@@ -2232,7 +2232,7 @@ impl<'tcx> Clean<'tcx, TypeBindingKind> for hir::TypeBindingKind<'tcx> {
22322232
hir::TypeBindingKind::Equality { ref term } => {
22332233
TypeBindingKind::Equality { term: term.clean(cx) }
22342234
}
2235-
hir::TypeBindingKind::Constraint { ref bounds } => TypeBindingKind::Constraint {
2235+
hir::TypeBindingKind::Constraint { bounds } => TypeBindingKind::Constraint {
22362236
bounds: bounds.iter().filter_map(|b| b.clean(cx)).collect(),
22372237
},
22382238
}

‎src/librustdoc/clean/render_macro_matchers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn print_tts(printer: &mut Printer<'_>, tts: &TokenStream) {
171171
if state != Start && needs_space {
172172
printer.space();
173173
}
174-
print_tt(printer, &tt);
174+
print_tt(printer, tt);
175175
state = next_state;
176176
}
177177
}

‎src/librustdoc/clean/types.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,7 @@ impl AttributesExt for [ast::Attribute] {
880880
let mut doc_cfg = self
881881
.iter()
882882
.filter(|attr| attr.has_name(sym::doc))
883-
.flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new))
883+
.flat_map(|attr| attr.meta_item_list().unwrap_or_default())
884884
.filter(|attr| attr.has_name(sym::cfg))
885885
.peekable();
886886
if doc_cfg.peek().is_some() && doc_cfg_active {
@@ -1011,7 +1011,7 @@ pub(crate) enum DocFragmentKind {
10111011
fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
10121012
let s = frag.doc.as_str();
10131013
let mut iter = s.lines();
1014-
if s == "" {
1014+
if s.is_empty() {
10151015
out.push('\n');
10161016
return;
10171017
}
@@ -1594,17 +1594,17 @@ impl Type {
15941594
match (self, other) {
15951595
// Recursive cases.
15961596
(Type::Tuple(a), Type::Tuple(b)) => {
1597-
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| a.is_same(&b, cache))
1597+
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| a.is_same(b, cache))
15981598
}
1599-
(Type::Slice(a), Type::Slice(b)) => a.is_same(&b, cache),
1600-
(Type::Array(a, al), Type::Array(b, bl)) => al == bl && a.is_same(&b, cache),
1599+
(Type::Slice(a), Type::Slice(b)) => a.is_same(b, cache),
1600+
(Type::Array(a, al), Type::Array(b, bl)) => al == bl && a.is_same(b, cache),
16011601
(Type::RawPointer(mutability, type_), Type::RawPointer(b_mutability, b_type_)) => {
1602-
mutability == b_mutability && type_.is_same(&b_type_, cache)
1602+
mutability == b_mutability && type_.is_same(b_type_, cache)
16031603
}
16041604
(
16051605
Type::BorrowedRef { mutability, type_, .. },
16061606
Type::BorrowedRef { mutability: b_mutability, type_: b_type_, .. },
1607-
) => mutability == b_mutability && type_.is_same(&b_type_, cache),
1607+
) => mutability == b_mutability && type_.is_same(b_type_, cache),
16081608
// Placeholders and generics are equal to all other types.
16091609
(Type::Infer, _) | (_, Type::Infer) => true,
16101610
(Type::Generic(_), _) | (_, Type::Generic(_)) => true,
@@ -1667,7 +1667,7 @@ impl Type {
16671667

16681668
pub(crate) fn projection(&self) -> Option<(&Type, DefId, PathSegment)> {
16691669
if let QPath { self_type, trait_, assoc, .. } = self {
1670-
Some((&self_type, trait_.def_id(), *assoc.clone()))
1670+
Some((self_type, trait_.def_id(), *assoc.clone()))
16711671
} else {
16721672
None
16731673
}

‎src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn external_generic_args<'tcx>(
106106
bindings: Vec<TypeBinding>,
107107
substs: SubstsRef<'tcx>,
108108
) -> GenericArgs {
109-
let args = substs_to_args(cx, &substs, has_self);
109+
let args = substs_to_args(cx, substs, has_self);
110110

111111
if cx.tcx.fn_trait_kind_from_lang_item(did).is_some() {
112112
let inputs =

‎src/librustdoc/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ impl Options {
667667
return Err(1);
668668
}
669669

670-
let scrape_examples_options = ScrapeExamplesOptions::new(&matches, &diag)?;
670+
let scrape_examples_options = ScrapeExamplesOptions::new(matches, &diag)?;
671671
let with_examples = matches.opt_strs("with-examples");
672672
let call_locations = crate::scrape_examples::load_call_locations(with_examples, &diag)?;
673673

‎src/librustdoc/doctest.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ fn scrape_test_config(attrs: &[ast::Attribute]) -> GlobalTestOptions {
228228
let test_attrs: Vec<_> = attrs
229229
.iter()
230230
.filter(|a| a.has_name(sym::doc))
231-
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
231+
.flat_map(|a| a.meta_item_list().unwrap_or_default())
232232
.filter(|a| a.has_name(sym::test))
233233
.collect();
234234
let attrs = test_attrs.iter().flat_map(|a| a.meta_item_list().unwrap_or(&[]));
@@ -738,7 +738,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
738738
}
739739
};
740740
// If a parsing error happened, it's very likely that the attribute is incomplete.
741-
if !parser.parse_attribute(InnerAttrPolicy::Permitted).is_ok() {
741+
if parser.parse_attribute(InnerAttrPolicy::Permitted).is_err() {
742742
return false;
743743
}
744744
// We now check if there is an unclosed delimiter for the attribute. To do so, we look at

‎src/librustdoc/formats/cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
456456
let ty::Adt(adt, _) = self.tcx.type_of(path.def_id()).kind() &&
457457
adt.is_fundamental() {
458458
for ty in generics {
459-
if let Some(did) = ty.def_id(&self.cache) {
459+
if let Some(did) = ty.def_id(self.cache) {
460460
dids.insert(did);
461461
}
462462
}

0 commit comments

Comments
 (0)
Please sign in to comment.