Skip to content

Commit 29c1bc9

Browse files
authored
Rollup merge of #80546 - matthiaskrgr:rustdoclippy, r=LingMan
clippy fixes for librustdoc fixes clippy warnings of type: match_like_matches_macro or_fun_call op_ref needless_return let_and_return single_char_add_str useless_format unnecessary_sort_by match_ref_pats redundant_field_names
2 parents 5986dd8 + a5807ac commit 29c1bc9

15 files changed

+58
-88
lines changed

src/librustdoc/clean/auto_trait.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -738,11 +738,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
738738
}
739739

740740
fn is_fn_ty(&self, tcx: TyCtxt<'_>, ty: &Type) -> bool {
741-
match &ty {
742-
&&Type::ResolvedPath { ref did, .. } => {
743-
*did == tcx.require_lang_item(LangItem::Fn, None)
744-
|| *did == tcx.require_lang_item(LangItem::FnMut, None)
745-
|| *did == tcx.require_lang_item(LangItem::FnOnce, None)
741+
match ty {
742+
&Type::ResolvedPath { did, .. } => {
743+
did == tcx.require_lang_item(LangItem::Fn, None)
744+
|| did == tcx.require_lang_item(LangItem::FnMut, None)
745+
|| did == tcx.require_lang_item(LangItem::FnOnce, None)
746746
}
747747
_ => false,
748748
}

src/librustdoc/clean/cfg.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,21 @@ impl Cfg {
177177
Cfg::Any(ref sub_cfgs) | Cfg::All(ref sub_cfgs) => {
178178
sub_cfgs.first().map(Cfg::should_capitalize_first_letter).unwrap_or(false)
179179
}
180-
Cfg::Cfg(name, _) => match name {
181-
sym::debug_assertions | sym::target_endian => true,
182-
_ => false,
183-
},
180+
Cfg::Cfg(name, _) => name == sym::debug_assertions || name == sym::target_endian,
184181
}
185182
}
186183

187184
fn should_append_only_to_description(&self) -> bool {
188185
match *self {
189186
Cfg::False | Cfg::True => false,
190187
Cfg::Any(..) | Cfg::All(..) | Cfg::Cfg(..) => true,
191-
Cfg::Not(ref child) => match **child {
192-
Cfg::Cfg(..) => true,
193-
_ => false,
194-
},
188+
Cfg::Not(box Cfg::Cfg(..)) => true,
189+
Cfg::Not(..) => false,
195190
}
196191
}
197192

198193
fn should_use_with_in_description(&self) -> bool {
199-
match *self {
200-
Cfg::Cfg(name, _) if name == sym::target_feature => true,
201-
_ => false,
202-
}
194+
matches!(self, Cfg::Cfg(sym::target_feature, _))
203195
}
204196

205197
/// Attempt to simplify this cfg by assuming that `assume` is already known to be true, will

src/librustdoc/clean/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -640,10 +640,10 @@ impl Clean<Generics> for hir::Generics<'_> {
640640
///
641641
/// [`lifetime_to_generic_param`]: rustc_ast_lowering::LoweringContext::lifetime_to_generic_param
642642
fn is_elided_lifetime(param: &hir::GenericParam<'_>) -> bool {
643-
match param.kind {
644-
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided } => true,
645-
_ => false,
646-
}
643+
matches!(
644+
param.kind,
645+
hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Elided }
646+
)
647647
}
648648

649649
let impl_trait_params = self
@@ -801,7 +801,7 @@ impl<'a, 'tcx> Clean<Generics> for (&'a ty::Generics, ty::GenericPredicates<'tcx
801801

802802
for (param, mut bounds) in impl_trait {
803803
// Move trait bounds to the front.
804-
bounds.sort_by_key(|b| if let GenericBound::TraitBound(..) = b { false } else { true });
804+
bounds.sort_by_key(|b| !matches!(b, GenericBound::TraitBound(..)));
805805

806806
if let crate::core::ImplTraitParam::ParamIndex(idx) = param {
807807
if let Some(proj) = impl_trait_proj.remove(&idx) {

src/librustdoc/clean/types.rs

+8-19
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,9 @@ impl Item {
175175
}
176176

177177
crate fn is_crate(&self) -> bool {
178-
match *self.kind {
178+
matches!(*self.kind,
179179
StrippedItem(box ModuleItem(Module { is_crate: true, .. }))
180-
| ModuleItem(Module { is_crate: true, .. }) => true,
181-
_ => false,
182-
}
180+
| ModuleItem(Module { is_crate: true, .. }))
183181
}
184182
crate fn is_mod(&self) -> bool {
185183
self.type_() == ItemType::Module
@@ -378,10 +376,7 @@ impl ItemKind {
378376
}
379377

380378
crate fn is_type_alias(&self) -> bool {
381-
match *self {
382-
ItemKind::TypedefItem(_, _) | ItemKind::AssocTypeItem(_, _) => true,
383-
_ => false,
384-
}
379+
matches!(self, ItemKind::TypedefItem(..) | ItemKind::AssocTypeItem(..))
385380
}
386381
}
387382

@@ -674,7 +669,7 @@ impl Attributes {
674669
span: attr.span,
675670
doc: contents,
676671
kind: DocFragmentKind::Include { filename },
677-
parent_module: parent_module,
672+
parent_module,
678673
});
679674
}
680675
}
@@ -750,7 +745,7 @@ impl Attributes {
750745
Some(did) => {
751746
if let Some((mut href, ..)) = href(did) {
752747
if let Some(ref fragment) = *fragment {
753-
href.push_str("#");
748+
href.push('#');
754749
href.push_str(fragment);
755750
}
756751
Some(RenderedLink {
@@ -945,10 +940,7 @@ crate enum GenericParamDefKind {
945940

946941
impl GenericParamDefKind {
947942
crate fn is_type(&self) -> bool {
948-
match *self {
949-
GenericParamDefKind::Type { .. } => true,
950-
_ => false,
951-
}
943+
matches!(self, GenericParamDefKind::Type { .. })
952944
}
953945

954946
// FIXME(eddyb) this either returns the default of a type parameter, or the
@@ -1292,15 +1284,12 @@ impl Type {
12921284
}
12931285

12941286
crate fn is_full_generic(&self) -> bool {
1295-
match *self {
1296-
Type::Generic(_) => true,
1297-
_ => false,
1298-
}
1287+
matches!(self, Type::Generic(_))
12991288
}
13001289

13011290
crate fn projection(&self) -> Option<(&Type, DefId, Symbol)> {
13021291
let (self_, trait_, name) = match self {
1303-
QPath { ref self_type, ref trait_, name } => (self_type, trait_, name),
1292+
QPath { self_type, trait_, name } => (self_type, trait_, name),
13041293
_ => return None,
13051294
};
13061295
let trait_did = match **trait_ {

src/librustdoc/config.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ crate enum OutputFormat {
3737

3838
impl OutputFormat {
3939
crate fn is_json(&self) -> bool {
40-
match self {
41-
OutputFormat::Json => true,
42-
_ => false,
43-
}
40+
matches!(self, OutputFormat::Json)
4441
}
4542
}
4643

src/librustdoc/doctest.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -636,15 +636,15 @@ fn partition_source(s: &str) -> (String, String, String) {
636636
match state {
637637
PartitionState::Attrs => {
638638
before.push_str(line);
639-
before.push_str("\n");
639+
before.push('\n');
640640
}
641641
PartitionState::Crates => {
642642
crates.push_str(line);
643-
crates.push_str("\n");
643+
crates.push('\n');
644644
}
645645
PartitionState::Other => {
646646
after.push_str(line);
647-
after.push_str("\n");
647+
after.push('\n');
648648
}
649649
}
650650
}

src/librustdoc/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ crate trait DocFolder: Sized {
6161
j.fields = j.fields.into_iter().filter_map(|x| self.fold_item(x)).collect();
6262
j.fields_stripped |= num_fields != j.fields.len()
6363
|| j.fields.iter().any(|f| f.is_stripped());
64-
VariantItem(Variant { kind: VariantKind::Struct(j), ..i2 })
64+
VariantItem(Variant { kind: VariantKind::Struct(j) })
6565
}
6666
_ => VariantItem(i2),
6767
}

src/librustdoc/html/format.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ impl<'a> fmt::Display for WhereClause<'a> {
245245
}
246246

247247
match pred {
248-
&clean::WherePredicate::BoundPredicate { ref ty, ref bounds } => {
248+
clean::WherePredicate::BoundPredicate { ty, bounds } => {
249249
let bounds = bounds;
250250
if f.alternate() {
251251
clause.push_str(&format!(
@@ -261,7 +261,7 @@ impl<'a> fmt::Display for WhereClause<'a> {
261261
));
262262
}
263263
}
264-
&clean::WherePredicate::RegionPredicate { ref lifetime, ref bounds } => {
264+
clean::WherePredicate::RegionPredicate { lifetime, bounds } => {
265265
clause.push_str(&format!(
266266
"{}: {}",
267267
lifetime.print(),
@@ -272,7 +272,7 @@ impl<'a> fmt::Display for WhereClause<'a> {
272272
.join(" + ")
273273
));
274274
}
275-
&clean::WherePredicate::EqPredicate { ref lhs, ref rhs } => {
275+
clean::WherePredicate::EqPredicate { lhs, rhs } => {
276276
if f.alternate() {
277277
clause.push_str(&format!("{:#} == {:#}", lhs.print(), rhs.print()));
278278
} else {
@@ -376,8 +376,8 @@ impl clean::GenericBound {
376376
impl clean::GenericArgs {
377377
fn print(&self) -> impl fmt::Display + '_ {
378378
display_fn(move |f| {
379-
match *self {
380-
clean::GenericArgs::AngleBracketed { ref args, ref bindings } => {
379+
match self {
380+
clean::GenericArgs::AngleBracketed { args, bindings } => {
381381
if !args.is_empty() || !bindings.is_empty() {
382382
if f.alternate() {
383383
f.write_str("<")?;
@@ -414,7 +414,7 @@ impl clean::GenericArgs {
414414
}
415415
}
416416
}
417-
clean::GenericArgs::Parenthesized { ref inputs, ref output } => {
417+
clean::GenericArgs::Parenthesized { inputs, output } => {
418418
f.write_str("(")?;
419419
let mut comma = false;
420420
for ty in inputs {
@@ -501,7 +501,7 @@ crate fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
501501
};
502502
for component in &fqp[..fqp.len() - 1] {
503503
url.push_str(component);
504-
url.push_str("/");
504+
url.push('/');
505505
}
506506
match shortty {
507507
ItemType::Module => {
@@ -510,7 +510,7 @@ crate fn href(did: DefId) -> Option<(String, ItemType, Vec<String>)> {
510510
}
511511
_ => {
512512
url.push_str(shortty.as_str());
513-
url.push_str(".");
513+
url.push('.');
514514
url.push_str(fqp.last().unwrap());
515515
url.push_str(".html");
516516
}
@@ -1021,7 +1021,7 @@ impl Function<'_> {
10211021
} else {
10221022
if i > 0 {
10231023
args.push_str(" <br>");
1024-
args_plain.push_str(" ");
1024+
args_plain.push(' ');
10251025
}
10261026
if !input.name.is_empty() {
10271027
args.push_str(&format!("{}: ", input.name));

src/librustdoc/html/markdown.rs

+4-9
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,10 @@ impl<'a, I: Iterator<Item = Event<'a>>> SummaryLine<'a, I> {
489489
}
490490

491491
fn check_if_allowed_tag(t: &Tag<'_>) -> bool {
492-
match *t {
493-
Tag::Paragraph
494-
| Tag::Item
495-
| Tag::Emphasis
496-
| Tag::Strong
497-
| Tag::Link(..)
498-
| Tag::BlockQuote => true,
499-
_ => false,
500-
}
492+
matches!(
493+
t,
494+
Tag::Paragraph | Tag::Item | Tag::Emphasis | Tag::Strong | Tag::Link(..) | Tag::BlockQuote
495+
)
501496
}
502497

503498
impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {

src/librustdoc/html/render/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ themePicker.onblur = handleThemeButtonsBlur;
979979
.iter()
980980
.map(|s| format!("\"{}\"", s.to_str().expect("invalid osstring conversion")))
981981
.collect::<Vec<_>>();
982-
files.sort_unstable_by(|a, b| a.cmp(b));
982+
files.sort_unstable();
983983
let subs = subs.iter().map(|s| s.to_json_string()).collect::<Vec<_>>().join(",");
984984
let dirs =
985985
if subs.is_empty() { String::new() } else { format!(",\"dirs\":[{}]", subs) };
@@ -1428,7 +1428,7 @@ impl Setting {
14281428
.map(|opt| format!(
14291429
"<option value=\"{}\" {}>{}</option>",
14301430
opt.0,
1431-
if &opt.0 == default_value { "selected" } else { "" },
1431+
if opt.0 == default_value { "selected" } else { "" },
14321432
opt.1,
14331433
))
14341434
.collect::<String>(),
@@ -1595,7 +1595,7 @@ impl Context<'_> {
15951595
if let Some(&(ref names, ty)) = cache.paths.get(&it.def_id) {
15961596
for name in &names[..names.len() - 1] {
15971597
url.push_str(name);
1598-
url.push_str("/");
1598+
url.push('/');
15991599
}
16001600
url.push_str(&item_path(ty, names.last().unwrap()));
16011601
layout::redirect(&url)
@@ -2308,7 +2308,7 @@ fn short_item_info(
23082308
let since = &since.as_str();
23092309
if !stability::deprecation_in_effect(is_since_rustc_version, Some(since)) {
23102310
if *since == "TBD" {
2311-
format!("Deprecating in a future Rust version")
2311+
String::from("Deprecating in a future Rust version")
23122312
} else {
23132313
format!("Deprecating in {}", Escape(since))
23142314
}
@@ -4323,9 +4323,11 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
43234323
.any(|i| i.inner_impl().trait_.def_id() == c.deref_mut_trait_did);
43244324
let inner_impl = target
43254325
.def_id()
4326-
.or(target
4327-
.primitive_type()
4328-
.and_then(|prim| c.primitive_locations.get(&prim).cloned()))
4326+
.or_else(|| {
4327+
target
4328+
.primitive_type()
4329+
.and_then(|prim| c.primitive_locations.get(&prim).cloned())
4330+
})
43294331
.and_then(|did| c.impls.get(&did));
43304332
if let Some(impls) = inner_impl {
43314333
out.push_str("<a class=\"sidebar-title\" href=\"#deref-methods\">");

src/librustdoc/html/toc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ impl TocBuilder {
132132
}
133133
Some(entry) => {
134134
sec_number = entry.sec_number.clone();
135-
sec_number.push_str(".");
135+
sec_number.push('.');
136136
(entry.level, &entry.children)
137137
}
138138
};

src/librustdoc/passes/collect_intra_doc_links.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ impl LinkCollector<'_, '_> {
12761276
// This could just be a normal link or a broken link
12771277
// we could potentially check if something is
12781278
// "intra-doc-link-like" and warn in that case.
1279-
return None;
1279+
None
12801280
}
12811281
Err(ErrorKind::AnchorFailure(msg)) => {
12821282
anchor_failure(
@@ -1287,7 +1287,7 @@ impl LinkCollector<'_, '_> {
12871287
diag.link_range,
12881288
msg,
12891289
);
1290-
return None;
1290+
None
12911291
}
12921292
}
12931293
}
@@ -1383,7 +1383,7 @@ impl LinkCollector<'_, '_> {
13831383
diag.link_range,
13841384
candidates.present_items().collect(),
13851385
);
1386-
return None;
1386+
None
13871387
}
13881388
}
13891389
Some(MacroNS) => {
@@ -1408,7 +1408,7 @@ impl LinkCollector<'_, '_> {
14081408
diag.link_range,
14091409
smallvec![kind],
14101410
);
1411-
return None;
1411+
None
14121412
}
14131413
}
14141414
}

src/librustdoc/passes/html_tags.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ fn drop_tag(
5959
continue;
6060
}
6161
let last_tag_name_low = last_tag_name.to_lowercase();
62-
if ALLOWED_UNCLOSED.iter().any(|&at| at == &last_tag_name_low) {
62+
if ALLOWED_UNCLOSED.iter().any(|&at| at == last_tag_name_low) {
6363
continue;
6464
}
6565
// `tags` is used as a queue, meaning that everything after `pos` is included inside it.

src/librustdoc/passes/strip_hidden.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ crate fn strip_hidden(krate: clean::Crate, _: &DocContext<'_>) -> clean::Crate {
2626

2727
// strip all impls referencing stripped items
2828
let mut stripper = ImplStripper { retained: &retained };
29-
let krate = stripper.fold_crate(krate);
30-
31-
krate
29+
stripper.fold_crate(krate)
3230
}
3331

3432
struct Stripper<'a> {

0 commit comments

Comments
 (0)