Skip to content

Commit 29b1248

Browse files
committed
Auto merge of #89430 - GuillaumeGomez:rustdoc-clippy-lints, r=jyn514,camelid,notriddle
Fix clippy lints in librustdoc I ran clippy on librustdoc and simply fixed the lints. :) r? `@notriddle`
2 parents 84c2a85 + 4614ca4 commit 29b1248

27 files changed

+194
-221
lines changed

src/librustdoc/clean/auto_trait.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
136136
let f = auto_trait::AutoTraitFinder::new(tcx);
137137

138138
debug!("get_auto_trait_impls({:?})", ty);
139-
let auto_traits: Vec<_> = self.cx.auto_traits.iter().cloned().collect();
139+
let auto_traits: Vec<_> = self.cx.auto_traits.iter().copied().collect();
140140
let mut auto_traits: Vec<Item> = auto_traits
141141
.into_iter()
142142
.filter_map(|trait_def_id| {
@@ -193,8 +193,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
193193
// to its smaller and larger regions. Note that 'larger' regions correspond
194194
// to sub-regions in Rust code (e.g., in 'a: 'b, 'a is the larger region).
195195
for constraint in regions.constraints.keys() {
196-
match constraint {
197-
&Constraint::VarSubVar(r1, r2) => {
196+
match *constraint {
197+
Constraint::VarSubVar(r1, r2) => {
198198
{
199199
let deps1 = vid_map.entry(RegionTarget::RegionVid(r1)).or_default();
200200
deps1.larger.insert(RegionTarget::RegionVid(r2));
@@ -203,15 +203,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
203203
let deps2 = vid_map.entry(RegionTarget::RegionVid(r2)).or_default();
204204
deps2.smaller.insert(RegionTarget::RegionVid(r1));
205205
}
206-
&Constraint::RegSubVar(region, vid) => {
206+
Constraint::RegSubVar(region, vid) => {
207207
let deps = vid_map.entry(RegionTarget::RegionVid(vid)).or_default();
208208
deps.smaller.insert(RegionTarget::Region(region));
209209
}
210-
&Constraint::VarSubReg(vid, region) => {
210+
Constraint::VarSubReg(vid, region) => {
211211
let deps = vid_map.entry(RegionTarget::RegionVid(vid)).or_default();
212212
deps.larger.insert(RegionTarget::Region(region));
213213
}
214-
&Constraint::RegSubReg(r1, r2) => {
214+
Constraint::RegSubReg(r1, r2) => {
215215
// The constraint is already in the form that we want, so we're done with it
216216
// Desired order is 'larger, smaller', so flip then
217217
if region_name(r1) != region_name(r2) {
@@ -513,8 +513,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
513513
// as we want to combine them with any 'Output' qpaths
514514
// later
515515

516-
let is_fn = match &mut b {
517-
&mut GenericBound::TraitBound(ref mut p, _) => {
516+
let is_fn = match b {
517+
GenericBound::TraitBound(ref mut p, _) => {
518518
// Insert regions into the for_generics hash map first, to ensure
519519
// that we don't end up with duplicate bounds (e.g., for<'b, 'b>)
520520
for_generics.extend(p.generic_params.clone());
@@ -699,8 +699,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
699699
}
700700

701701
fn region_name(region: Region<'_>) -> Option<Symbol> {
702-
match region {
703-
&ty::ReEarlyBound(r) => Some(r.name),
702+
match *region {
703+
ty::ReEarlyBound(r) => Some(r.name),
704704
_ => None,
705705
}
706706
}
@@ -717,8 +717,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx> {
717717
}
718718

719719
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
720-
(match r {
721-
&ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
720+
(match *r {
721+
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
722722
_ => None,
723723
})
724724
.unwrap_or_else(|| r.super_fold_with(self))

src/librustdoc/clean/mod.rs

+23-27
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,15 @@ impl<'tcx> Clean<GenericBound> for ty::PolyTraitRef<'tcx> {
216216
impl Clean<Lifetime> for hir::Lifetime {
217217
fn clean(&self, cx: &mut DocContext<'_>) -> Lifetime {
218218
let def = cx.tcx.named_region(self.hir_id);
219-
match def {
220-
Some(
221-
rl::Region::EarlyBound(_, node_id, _)
222-
| rl::Region::LateBound(_, _, node_id, _)
223-
| rl::Region::Free(_, node_id),
224-
) => {
225-
if let Some(lt) = cx.lt_substs.get(&node_id).cloned() {
226-
return lt;
227-
}
219+
if let Some(
220+
rl::Region::EarlyBound(_, node_id, _)
221+
| rl::Region::LateBound(_, _, node_id, _)
222+
| rl::Region::Free(_, node_id),
223+
) = def
224+
{
225+
if let Some(lt) = cx.lt_substs.get(&node_id).cloned() {
226+
return lt;
228227
}
229-
_ => {}
230228
}
231229
Lifetime(self.name.ident().name)
232230
}
@@ -828,7 +826,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
828826
.iter()
829827
.enumerate()
830828
.map(|(i, ty)| Argument {
831-
name: name_from_pat(&body.params[i].pat),
829+
name: name_from_pat(body.params[i].pat),
832830
type_: ty.clean(cx),
833831
})
834832
.collect(),
@@ -924,7 +922,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
924922
}
925923
MethodItem(m, None)
926924
}
927-
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
925+
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
928926
let (generics, decl) = enter_impl_trait(cx, |cx| {
929927
(self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx))
930928
});
@@ -936,7 +934,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
936934
}
937935
TyMethodItem(t)
938936
}
939-
hir::TraitItemKind::Type(ref bounds, ref default) => {
937+
hir::TraitItemKind::Type(bounds, ref default) => {
940938
AssocTypeItem(bounds.clean(cx), default.clean(cx))
941939
}
942940
};
@@ -1260,7 +1258,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12601258
let path = path.clean(cx);
12611259
resolve_type(cx, path)
12621260
}
1263-
hir::QPath::Resolved(Some(ref qself), ref p) => {
1261+
hir::QPath::Resolved(Some(ref qself), p) => {
12641262
// Try to normalize `<X as Y>::T` to a type
12651263
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
12661264
if let Some(normalized_value) = normalize(cx, ty) {
@@ -1281,7 +1279,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
12811279
trait_,
12821280
}
12831281
}
1284-
hir::QPath::TypeRelative(ref qself, ref segment) => {
1282+
hir::QPath::TypeRelative(ref qself, segment) => {
12851283
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
12861284
let res = match ty.kind() {
12871285
ty::Projection(proj) => Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id),
@@ -1337,7 +1335,7 @@ impl Clean<Type> for hir::Ty<'_> {
13371335
let length = print_const(cx, ct.eval(cx.tcx, param_env));
13381336
Array(box ty.clean(cx), length)
13391337
}
1340-
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
1338+
TyKind::Tup(tys) => Tuple(tys.clean(cx)),
13411339
TyKind::OpaqueDef(item_id, _) => {
13421340
let item = cx.tcx.hir().item(item_id);
13431341
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
@@ -1346,8 +1344,8 @@ impl Clean<Type> for hir::Ty<'_> {
13461344
unreachable!()
13471345
}
13481346
}
1349-
TyKind::Path(_) => clean_qpath(&self, cx),
1350-
TyKind::TraitObject(ref bounds, ref lifetime, _) => {
1347+
TyKind::Path(_) => clean_qpath(self, cx),
1348+
TyKind::TraitObject(bounds, ref lifetime, _) => {
13511349
let bounds = bounds.iter().map(|bound| bound.clean(cx)).collect();
13521350
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
13531351
DynTrait(bounds, lifetime)
@@ -1441,7 +1439,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14411439
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
14421440
ResolvedPath { path, did }
14431441
}
1444-
ty::Dynamic(ref obj, ref reg) => {
1442+
ty::Dynamic(obj, ref reg) => {
14451443
// HACK: pick the first `did` as the `did` of the trait object. Someone
14461444
// might want to implement "native" support for marker-trait-only
14471445
// trait objects.
@@ -1481,9 +1479,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
14811479

14821480
DynTrait(bounds, lifetime)
14831481
}
1484-
ty::Tuple(ref t) => {
1485-
Tuple(t.iter().map(|t| t.expect_ty()).collect::<Vec<_>>().clean(cx))
1486-
}
1482+
ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty()).collect::<Vec<_>>().clean(cx)),
14871483

14881484
ty::Projection(ref data) => data.clean(cx),
14891485

@@ -1821,9 +1817,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
18211817
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
18221818
}
18231819
ItemKind::Macro(ref macro_def) => MacroItem(Macro {
1824-
source: display_macro_source(cx, name, &macro_def, def_id, &item.vis),
1820+
source: display_macro_source(cx, name, macro_def, def_id, &item.vis),
18251821
}),
1826-
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
1822+
ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => {
18271823
let items = item_ids
18281824
.iter()
18291825
.map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx))
@@ -2065,10 +2061,10 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
20652061
let def_id = item.def_id.to_def_id();
20662062
cx.with_param_env(def_id, |cx| {
20672063
let kind = match item.kind {
2068-
hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
2064+
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
20692065
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id());
20702066
let (generics, decl) = enter_impl_trait(cx, |cx| {
2071-
(generics.clean(cx), (&**decl, &names[..]).clean(cx))
2067+
(generics.clean(cx), (&*decl, &names[..]).clean(cx))
20722068
});
20732069
ForeignFunctionItem(Function {
20742070
decl,
@@ -2113,7 +2109,7 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
21132109
hir::TypeBindingKind::Equality { ref ty } => {
21142110
TypeBindingKind::Equality { ty: ty.clean(cx) }
21152111
}
2116-
hir::TypeBindingKind::Constraint { ref bounds } => {
2112+
hir::TypeBindingKind::Constraint { bounds } => {
21172113
TypeBindingKind::Constraint { bounds: bounds.iter().map(|b| b.clean(cx)).collect() }
21182114
}
21192115
}

src/librustdoc/clean/types.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl ExternalCrate {
204204
.filter_map(|a| a.value_str())
205205
.map(to_remote)
206206
.next()
207-
.or(extern_url.map(to_remote)) // NOTE: only matters if `extern_url_takes_precedence` is false
207+
.or_else(|| extern_url.map(to_remote)) // NOTE: only matters if `extern_url_takes_precedence` is false
208208
.unwrap_or(Unknown) // Well, at least we tried.
209209
}
210210

@@ -238,7 +238,7 @@ impl ExternalCrate {
238238
hir::ItemKind::Mod(_) => {
239239
as_keyword(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
240240
}
241-
hir::ItemKind::Use(ref path, hir::UseKind::Single)
241+
hir::ItemKind::Use(path, hir::UseKind::Single)
242242
if item.vis.node.is_pub() =>
243243
{
244244
as_keyword(path.res.expect_non_local())
@@ -304,7 +304,7 @@ impl ExternalCrate {
304304
hir::ItemKind::Mod(_) => {
305305
as_primitive(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
306306
}
307-
hir::ItemKind::Use(ref path, hir::UseKind::Single)
307+
hir::ItemKind::Use(path, hir::UseKind::Single)
308308
if item.vis.node.is_pub() =>
309309
{
310310
as_primitive(path.res.expect_non_local()).map(|(_, prim)| {
@@ -381,7 +381,7 @@ impl Item {
381381
{
382382
*span
383383
} else {
384-
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(|| Span::dummy())
384+
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
385385
}
386386
}
387387

@@ -562,7 +562,7 @@ impl Item {
562562
}
563563

564564
crate fn stability_class(&self, tcx: TyCtxt<'_>) -> Option<String> {
565-
self.stability(tcx).as_ref().and_then(|ref s| {
565+
self.stability(tcx).as_ref().and_then(|s| {
566566
let mut classes = Vec::with_capacity(2);
567567

568568
if s.level.is_unstable() {
@@ -820,9 +820,9 @@ impl AttributesExt for [ast::Attribute] {
820820
// #[doc(cfg(...))]
821821
if let Some(cfg_mi) = item
822822
.meta_item()
823-
.and_then(|item| rustc_expand::config::parse_cfg(&item, sess))
823+
.and_then(|item| rustc_expand::config::parse_cfg(item, sess))
824824
{
825-
match Cfg::parse(&cfg_mi) {
825+
match Cfg::parse(cfg_mi) {
826826
Ok(new_cfg) => cfg &= new_cfg,
827827
Err(e) => sess.span_err(e.span, e.msg),
828828
}
@@ -934,7 +934,7 @@ impl<'a> FromIterator<&'a DocFragment> for String {
934934
T: IntoIterator<Item = &'a DocFragment>,
935935
{
936936
iter.into_iter().fold(String::new(), |mut acc, frag| {
937-
add_doc_fragment(&mut acc, &frag);
937+
add_doc_fragment(&mut acc, frag);
938938
acc
939939
})
940940
}
@@ -1061,12 +1061,12 @@ impl Attributes {
10611061

10621062
let ori = iter.next()?;
10631063
let mut out = String::new();
1064-
add_doc_fragment(&mut out, &ori);
1065-
while let Some(new_frag) = iter.next() {
1064+
add_doc_fragment(&mut out, ori);
1065+
for new_frag in iter {
10661066
if new_frag.kind != ori.kind || new_frag.parent_module != ori.parent_module {
10671067
break;
10681068
}
1069-
add_doc_fragment(&mut out, &new_frag);
1069+
add_doc_fragment(&mut out, new_frag);
10701070
}
10711071
if out.is_empty() { None } else { Some(out) }
10721072
}
@@ -1079,7 +1079,7 @@ impl Attributes {
10791079

10801080
for new_frag in self.doc_strings.iter() {
10811081
let out = ret.entry(new_frag.parent_module).or_default();
1082-
add_doc_fragment(out, &new_frag);
1082+
add_doc_fragment(out, new_frag);
10831083
}
10841084
ret
10851085
}

src/librustdoc/clean/utils.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ crate fn strip_path_generics(path: Path) -> Path {
171171

172172
crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {
173173
let segments = match *p {
174-
hir::QPath::Resolved(_, ref path) => &path.segments,
175-
hir::QPath::TypeRelative(_, ref segment) => return segment.ident.to_string(),
174+
hir::QPath::Resolved(_, path) => &path.segments,
175+
hir::QPath::TypeRelative(_, segment) => return segment.ident.to_string(),
176176
hir::QPath::LangItem(lang_item, ..) => return lang_item.name().to_string(),
177177
};
178178

@@ -217,23 +217,23 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
217217
PatKind::Wild | PatKind::Struct(..) => return kw::Underscore,
218218
PatKind::Binding(_, _, ident, _) => return ident.name,
219219
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
220-
PatKind::Or(ref pats) => {
220+
PatKind::Or(pats) => {
221221
pats.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(" | ")
222222
}
223-
PatKind::Tuple(ref elts, _) => format!(
223+
PatKind::Tuple(elts, _) => format!(
224224
"({})",
225225
elts.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(", ")
226226
),
227-
PatKind::Box(ref p) => return name_from_pat(&**p),
228-
PatKind::Ref(ref p, _) => return name_from_pat(&**p),
227+
PatKind::Box(p) => return name_from_pat(&*p),
228+
PatKind::Ref(p, _) => return name_from_pat(&*p),
229229
PatKind::Lit(..) => {
230230
warn!(
231231
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
232232
);
233233
return Symbol::intern("()");
234234
}
235235
PatKind::Range(..) => return kw::Underscore,
236-
PatKind::Slice(ref begin, ref mid, ref end) => {
236+
PatKind::Slice(begin, ref mid, end) => {
237237
let begin = begin.iter().map(|p| name_from_pat(p).to_string());
238238
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();
239239
let end = end.iter().map(|p| name_from_pat(p).to_string());
@@ -507,7 +507,7 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
507507
/// so that the channel is consistent.
508508
///
509509
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
510-
crate const DOC_RUST_LANG_ORG_CHANNEL: &'static str = env!("DOC_RUST_LANG_ORG_CHANNEL");
510+
crate const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");
511511

512512
/// Render a sequence of macro arms in a format suitable for displaying to the user
513513
/// as part of an item declaration.

0 commit comments

Comments
 (0)