Skip to content

Commit 678059f

Browse files
committed
fix simple clippy lints
1 parent b2eba05 commit 678059f

21 files changed

+81
-90
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 Clean<Option<WherePredicate>> for hir::WherePredicate<'_> {
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.
@@ -520,7 +520,7 @@ fn clean_generic_param(
520520
},
521521
)
522522
}
523-
hir::GenericParamKind::Const { ref ty, default } => (
523+
hir::GenericParamKind::Const { ty, default } => (
524524
param.name.ident().name,
525525
GenericParamDefKind::Const {
526526
did: cx.tcx.hir().local_def_id(param.hir_id).to_def_id(),
@@ -942,7 +942,7 @@ fn clean_fn_decl_from_did_and_sig(
942942
// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
943943
// but shouldn't change any code meaning.
944944
let output = match sig.skip_binder().output().clean(cx) {
945-
Type::Tuple(inner) if inner.len() == 0 => DefaultReturn,
945+
Type::Tuple(inner) if inner.is_empty() => DefaultReturn,
946946
ty => Return(ty),
947947
};
948948

@@ -967,7 +967,7 @@ fn clean_fn_decl_from_did_and_sig(
967967
impl Clean<FnRetTy> for hir::FnRetTy<'_> {
968968
fn clean(&self, cx: &mut DocContext<'_>) -> FnRetTy {
969969
match *self {
970-
Self::Return(ref typ) => Return(typ.clean(cx)),
970+
Self::Return(typ) => Return(typ.clean(cx)),
971971
Self::DefaultReturn(..) => DefaultReturn,
972972
}
973973
}
@@ -1008,13 +1008,13 @@ impl Clean<Item> for hir::TraitItem<'_> {
10081008
let local_did = self.def_id.to_def_id();
10091009
cx.with_param_env(local_did, |cx| {
10101010
let inner = match self.kind {
1011-
hir::TraitItemKind::Const(ref ty, Some(default)) => AssocConstItem(
1011+
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
10121012
ty.clean(cx),
10131013
ConstantKind::Local { def_id: local_did, body: default },
10141014
),
1015-
hir::TraitItemKind::Const(ref ty, None) => TyAssocConstItem(ty.clean(cx)),
1015+
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(ty.clean(cx)),
10161016
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
1017-
let m = clean_function(cx, sig, &self.generics, body);
1017+
let m = clean_function(cx, sig, self.generics, body);
10181018
MethodItem(m, None)
10191019
}
10201020
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
@@ -1055,16 +1055,16 @@ impl Clean<Item> for hir::ImplItem<'_> {
10551055
let local_did = self.def_id.to_def_id();
10561056
cx.with_param_env(local_did, |cx| {
10571057
let inner = match self.kind {
1058-
hir::ImplItemKind::Const(ref ty, expr) => {
1058+
hir::ImplItemKind::Const(ty, expr) => {
10591059
let default = ConstantKind::Local { def_id: local_did, body: expr };
10601060
AssocConstItem(ty.clean(cx), default)
10611061
}
10621062
hir::ImplItemKind::Fn(ref sig, body) => {
1063-
let m = clean_function(cx, sig, &self.generics, body);
1063+
let m = clean_function(cx, sig, self.generics, body);
10641064
let defaultness = cx.tcx.associated_item(self.def_id).defaultness;
10651065
MethodItem(m, Some(defaultness))
10661066
}
1067-
hir::ImplItemKind::TyAlias(ref hir_ty) => {
1067+
hir::ImplItemKind::TyAlias(hir_ty) => {
10681068
let type_ = hir_ty.clean(cx);
10691069
let generics = self.generics.clean(cx);
10701070
let item_type = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
@@ -1287,7 +1287,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12871287
let hir::TyKind::Path(qpath) = kind else { unreachable!() };
12881288

12891289
match qpath {
1290-
hir::QPath::Resolved(None, ref path) => {
1290+
hir::QPath::Resolved(None, path) => {
12911291
if let Res::Def(DefKind::TyParam, did) = path.res {
12921292
if let Some(new_ty) = cx.substs.get(&did).and_then(|p| p.as_ty()).cloned() {
12931293
return new_ty;
@@ -1304,7 +1304,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
13041304
resolve_type(cx, path)
13051305
}
13061306
}
1307-
hir::QPath::Resolved(Some(ref qself), p) => {
1307+
hir::QPath::Resolved(Some(qself), p) => {
13081308
// Try to normalize `<X as Y>::T` to a type
13091309
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
13101310
if let Some(normalized_value) = normalize(cx, ty) {
@@ -1328,7 +1328,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
13281328
trait_,
13291329
}
13301330
}
1331-
hir::QPath::TypeRelative(ref qself, segment) => {
1331+
hir::QPath::TypeRelative(qself, segment) => {
13321332
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
13331333
let res = match ty.kind() {
13341334
ty::Projection(proj) => Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id),
@@ -1455,8 +1455,8 @@ impl Clean<Type> for hir::Ty<'_> {
14551455
let lifetime = if elided { None } else { Some(l.clean(cx)) };
14561456
BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) }
14571457
}
1458-
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
1459-
TyKind::Array(ref ty, ref length) => {
1458+
TyKind::Slice(ty) => Slice(box ty.clean(cx)),
1459+
TyKind::Array(ty, ref length) => {
14601460
let length = match length {
14611461
hir::ArrayLen::Infer(_, _) => "_".to_string(),
14621462
hir::ArrayLen::Body(anon_const) => {
@@ -1491,7 +1491,7 @@ impl Clean<Type> for hir::Ty<'_> {
14911491
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
14921492
DynTrait(bounds, lifetime)
14931493
}
1494-
TyKind::BareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
1494+
TyKind::BareFn(barefn) => BareFunction(box 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),
@@ -1900,7 +1900,7 @@ fn clean_maybe_renamed_item(
19001900
bounds: ty.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
19011901
generics: ty.generics.clean(cx),
19021902
}),
1903-
ItemKind::TyAlias(hir_ty, ref generics) => {
1903+
ItemKind::TyAlias(hir_ty, generics) => {
19041904
let rustdoc_ty = hir_ty.clean(cx);
19051905
let ty = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
19061906
TypedefItem(Typedef {
@@ -1909,26 +1909,26 @@ fn clean_maybe_renamed_item(
19091909
item_type: Some(ty),
19101910
})
19111911
}
1912-
ItemKind::Enum(ref def, ref generics) => EnumItem(Enum {
1912+
ItemKind::Enum(ref def, generics) => EnumItem(Enum {
19131913
variants: def.variants.iter().map(|v| v.clean(cx)).collect(),
19141914
generics: generics.clean(cx),
19151915
}),
1916-
ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias {
1916+
ItemKind::TraitAlias(generics, bounds) => TraitAliasItem(TraitAlias {
19171917
generics: generics.clean(cx),
19181918
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
19191919
}),
1920-
ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union {
1920+
ItemKind::Union(ref variant_data, generics) => UnionItem(Union {
19211921
generics: generics.clean(cx),
19221922
fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
19231923
}),
1924-
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
1924+
ItemKind::Struct(ref variant_data, generics) => StructItem(Struct {
19251925
struct_type: CtorKind::from_hir(variant_data),
19261926
generics: generics.clean(cx),
19271927
fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
19281928
}),
1929-
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx),
1929+
ItemKind::Impl(impl_) => return clean_impl(impl_, item.hir_id(), cx),
19301930
// proc macros can have a name set by attributes
1931-
ItemKind::Fn(ref sig, ref generics, body_id) => {
1931+
ItemKind::Fn(ref sig, generics, body_id) => {
19321932
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
19331933
}
19341934
ItemKind::Macro(ref macro_def, _) => {
@@ -1937,7 +1937,7 @@ fn clean_maybe_renamed_item(
19371937
source: display_macro_source(cx, name, macro_def, def_id, ty_vis),
19381938
})
19391939
}
1940-
ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => {
1940+
ItemKind::Trait(is_auto, unsafety, generics, bounds, item_ids) => {
19411941
let items =
19421942
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
19431943
TraitItem(Trait {
@@ -2180,7 +2180,7 @@ fn clean_maybe_renamed_foreign_item(
21802180
let def_id = item.def_id.to_def_id();
21812181
cx.with_param_env(def_id, |cx| {
21822182
let kind = match item.kind {
2183-
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
2183+
hir::ForeignItemKind::Fn(decl, names, generics) => {
21842184
let (generics, decl) = enter_impl_trait(cx, |cx| {
21852185
// NOTE: generics must be cleaned before args
21862186
let generics = generics.clean(cx);
@@ -2190,7 +2190,7 @@ fn clean_maybe_renamed_foreign_item(
21902190
});
21912191
ForeignFunctionItem(Function { decl, generics })
21922192
}
2193-
hir::ForeignItemKind::Static(ref ty, mutability) => {
2193+
hir::ForeignItemKind::Static(ty, mutability) => {
21942194
ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: None })
21952195
}
21962196
hir::ForeignItemKind::Type => ForeignTypeItem,
@@ -2220,7 +2220,7 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
22202220
hir::TypeBindingKind::Equality { ref term } => {
22212221
TypeBindingKind::Equality { term: term.clean(cx) }
22222222
}
2223-
hir::TypeBindingKind::Constraint { ref bounds } => TypeBindingKind::Constraint {
2223+
hir::TypeBindingKind::Constraint { bounds } => TypeBindingKind::Constraint {
22242224
bounds: bounds.iter().filter_map(|b| b.clean(cx)).collect(),
22252225
},
22262226
}

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(
106106
bindings: Vec<TypeBinding>,
107107
substs: SubstsRef<'_>,
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
}

src/librustdoc/html/format.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,10 @@ pub(crate) enum HrefError {
545545
// Panics if `syms` is empty.
546546
pub(crate) fn join_with_double_colon(syms: &[Symbol]) -> String {
547547
let mut s = String::with_capacity(estimate_item_path_byte_length(syms.len()));
548-
s.push_str(&syms[0].as_str());
548+
s.push_str(syms[0].as_str());
549549
for sym in &syms[1..] {
550550
s.push_str("::");
551-
s.push_str(&sym.as_str());
551+
s.push_str(sym.as_str());
552552
}
553553
s
554554
}
@@ -1069,7 +1069,7 @@ impl clean::Impl {
10691069
write!(f, " for ")?;
10701070
}
10711071

1072-
if let Some(ref ty) = self.kind.as_blanket_ty() {
1072+
if let Some(ty) = self.kind.as_blanket_ty() {
10731073
fmt_type(ty, f, use_absolute, cx)?;
10741074
} else {
10751075
fmt_type(&self.for_, f, use_absolute, cx)?;
@@ -1311,8 +1311,7 @@ impl clean::Visibility {
13111311
// is the same as no visibility modifier
13121312
String::new()
13131313
} else if parent_module
1314-
.map(|parent| find_nearest_parent_module(cx.tcx(), parent))
1315-
.flatten()
1314+
.and_then(|parent| find_nearest_parent_module(cx.tcx(), parent))
13161315
== Some(vis_did)
13171316
{
13181317
"pub(super) ".to_owned()
@@ -1358,9 +1357,7 @@ impl clean::Visibility {
13581357
// `pub(in foo)` where `foo` is the parent module
13591358
// is the same as no visibility modifier
13601359
String::new()
1361-
} else if parent_module
1362-
.map(|parent| find_nearest_parent_module(tcx, parent))
1363-
.flatten()
1360+
} else if parent_module.and_then(|parent| find_nearest_parent_module(tcx, parent))
13641361
== Some(vis_did)
13651362
{
13661363
"pub(super) ".to_owned()

0 commit comments

Comments
 (0)