Skip to content

Commit

Permalink
Auto merge of #89430 - GuillaumeGomez:rustdoc-clippy-lints, r=jyn514,…
Browse files Browse the repository at this point in the history
…camelid,notriddle

Fix clippy lints in librustdoc

I ran clippy on librustdoc and simply fixed the lints. :)

r? `@notriddle`
  • Loading branch information
bors committed Oct 25, 2021
2 parents 84c2a85 + 4614ca4 commit 29b1248
Show file tree
Hide file tree
Showing 27 changed files with 194 additions and 221 deletions.
24 changes: 12 additions & 12 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
let f = auto_trait::AutoTraitFinder::new(tcx);

debug!("get_auto_trait_impls({:?})", ty);
let auto_traits: Vec<_> = self.cx.auto_traits.iter().cloned().collect();
let auto_traits: Vec<_> = self.cx.auto_traits.iter().copied().collect();
let mut auto_traits: Vec<Item> = auto_traits
.into_iter()
.filter_map(|trait_def_id| {
Expand Down Expand Up @@ -193,8 +193,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// to its smaller and larger regions. Note that 'larger' regions correspond
// to sub-regions in Rust code (e.g., in 'a: 'b, 'a is the larger region).
for constraint in regions.constraints.keys() {
match constraint {
&Constraint::VarSubVar(r1, r2) => {
match *constraint {
Constraint::VarSubVar(r1, r2) => {
{
let deps1 = vid_map.entry(RegionTarget::RegionVid(r1)).or_default();
deps1.larger.insert(RegionTarget::RegionVid(r2));
Expand All @@ -203,15 +203,15 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
let deps2 = vid_map.entry(RegionTarget::RegionVid(r2)).or_default();
deps2.smaller.insert(RegionTarget::RegionVid(r1));
}
&Constraint::RegSubVar(region, vid) => {
Constraint::RegSubVar(region, vid) => {
let deps = vid_map.entry(RegionTarget::RegionVid(vid)).or_default();
deps.smaller.insert(RegionTarget::Region(region));
}
&Constraint::VarSubReg(vid, region) => {
Constraint::VarSubReg(vid, region) => {
let deps = vid_map.entry(RegionTarget::RegionVid(vid)).or_default();
deps.larger.insert(RegionTarget::Region(region));
}
&Constraint::RegSubReg(r1, r2) => {
Constraint::RegSubReg(r1, r2) => {
// The constraint is already in the form that we want, so we're done with it
// Desired order is 'larger, smaller', so flip then
if region_name(r1) != region_name(r2) {
Expand Down Expand Up @@ -513,8 +513,8 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
// as we want to combine them with any 'Output' qpaths
// later

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

fn region_name(region: Region<'_>) -> Option<Symbol> {
match region {
&ty::ReEarlyBound(r) => Some(r.name),
match *region {
ty::ReEarlyBound(r) => Some(r.name),
_ => None,
}
}
Expand All @@ -717,8 +717,8 @@ impl<'a, 'tcx> TypeFolder<'tcx> for RegionReplacer<'a, 'tcx> {
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
(match r {
&ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
(match *r {
ty::ReVar(vid) => self.vid_to_region.get(&vid).cloned(),
_ => None,
})
.unwrap_or_else(|| r.super_fold_with(self))
Expand Down
50 changes: 23 additions & 27 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,17 +216,15 @@ impl<'tcx> Clean<GenericBound> for ty::PolyTraitRef<'tcx> {
impl Clean<Lifetime> for hir::Lifetime {
fn clean(&self, cx: &mut DocContext<'_>) -> Lifetime {
let def = cx.tcx.named_region(self.hir_id);
match def {
Some(
rl::Region::EarlyBound(_, node_id, _)
| rl::Region::LateBound(_, _, node_id, _)
| rl::Region::Free(_, node_id),
) => {
if let Some(lt) = cx.lt_substs.get(&node_id).cloned() {
return lt;
}
if let Some(
rl::Region::EarlyBound(_, node_id, _)
| rl::Region::LateBound(_, _, node_id, _)
| rl::Region::Free(_, node_id),
) = def
{
if let Some(lt) = cx.lt_substs.get(&node_id).cloned() {
return lt;
}
_ => {}
}
Lifetime(self.name.ident().name)
}
Expand Down Expand Up @@ -828,7 +826,7 @@ impl<'a> Clean<Arguments> for (&'a [hir::Ty<'a>], hir::BodyId) {
.iter()
.enumerate()
.map(|(i, ty)| Argument {
name: name_from_pat(&body.params[i].pat),
name: name_from_pat(body.params[i].pat),
type_: ty.clean(cx),
})
.collect(),
Expand Down Expand Up @@ -924,7 +922,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
}
MethodItem(m, None)
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(ref names)) => {
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
let (generics, decl) = enter_impl_trait(cx, |cx| {
(self.generics.clean(cx), (&*sig.decl, &names[..]).clean(cx))
});
Expand All @@ -936,7 +934,7 @@ impl Clean<Item> for hir::TraitItem<'_> {
}
TyMethodItem(t)
}
hir::TraitItemKind::Type(ref bounds, ref default) => {
hir::TraitItemKind::Type(bounds, ref default) => {
AssocTypeItem(bounds.clean(cx), default.clean(cx))
}
};
Expand Down Expand Up @@ -1260,7 +1258,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
let path = path.clean(cx);
resolve_type(cx, path)
}
hir::QPath::Resolved(Some(ref qself), ref p) => {
hir::QPath::Resolved(Some(ref qself), p) => {
// Try to normalize `<X as Y>::T` to a type
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
if let Some(normalized_value) = normalize(cx, ty) {
Expand All @@ -1281,7 +1279,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &mut DocContext<'_>) -> Type {
trait_,
}
}
hir::QPath::TypeRelative(ref qself, ref segment) => {
hir::QPath::TypeRelative(ref qself, segment) => {
let ty = hir_ty_to_ty(cx.tcx, hir_ty);
let res = match ty.kind() {
ty::Projection(proj) => Res::Def(DefKind::Trait, proj.trait_ref(cx.tcx).def_id),
Expand Down Expand Up @@ -1337,7 +1335,7 @@ impl Clean<Type> for hir::Ty<'_> {
let length = print_const(cx, ct.eval(cx.tcx, param_env));
Array(box ty.clean(cx), length)
}
TyKind::Tup(ref tys) => Tuple(tys.clean(cx)),
TyKind::Tup(tys) => Tuple(tys.clean(cx)),
TyKind::OpaqueDef(item_id, _) => {
let item = cx.tcx.hir().item(item_id);
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
Expand All @@ -1346,8 +1344,8 @@ impl Clean<Type> for hir::Ty<'_> {
unreachable!()
}
}
TyKind::Path(_) => clean_qpath(&self, cx),
TyKind::TraitObject(ref bounds, ref lifetime, _) => {
TyKind::Path(_) => clean_qpath(self, cx),
TyKind::TraitObject(bounds, ref lifetime, _) => {
let bounds = bounds.iter().map(|bound| bound.clean(cx)).collect();
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
DynTrait(bounds, lifetime)
Expand Down Expand Up @@ -1441,7 +1439,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
ResolvedPath { path, did }
}
ty::Dynamic(ref obj, ref reg) => {
ty::Dynamic(obj, ref reg) => {
// HACK: pick the first `did` as the `did` of the trait object. Someone
// might want to implement "native" support for marker-trait-only
// trait objects.
Expand Down Expand Up @@ -1481,9 +1479,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {

DynTrait(bounds, lifetime)
}
ty::Tuple(ref t) => {
Tuple(t.iter().map(|t| t.expect_ty()).collect::<Vec<_>>().clean(cx))
}
ty::Tuple(t) => Tuple(t.iter().map(|t| t.expect_ty()).collect::<Vec<_>>().clean(cx)),

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

Expand Down Expand Up @@ -1821,9 +1817,9 @@ impl Clean<Vec<Item>> for (&hir::Item<'_>, Option<Symbol>) {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
}
ItemKind::Macro(ref macro_def) => MacroItem(Macro {
source: display_macro_source(cx, name, &macro_def, def_id, &item.vis),
source: display_macro_source(cx, name, macro_def, def_id, &item.vis),
}),
ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => {
ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => {
let items = item_ids
.iter()
.map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx))
Expand Down Expand Up @@ -2065,10 +2061,10 @@ impl Clean<Item> for (&hir::ForeignItem<'_>, Option<Symbol>) {
let def_id = item.def_id.to_def_id();
cx.with_param_env(def_id, |cx| {
let kind = match item.kind {
hir::ForeignItemKind::Fn(ref decl, ref names, ref generics) => {
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
let abi = cx.tcx.hir().get_foreign_abi(item.hir_id());
let (generics, decl) = enter_impl_trait(cx, |cx| {
(generics.clean(cx), (&**decl, &names[..]).clean(cx))
(generics.clean(cx), (&*decl, &names[..]).clean(cx))
});
ForeignFunctionItem(Function {
decl,
Expand Down Expand Up @@ -2113,7 +2109,7 @@ impl Clean<TypeBindingKind> for hir::TypeBindingKind<'_> {
hir::TypeBindingKind::Equality { ref ty } => {
TypeBindingKind::Equality { ty: ty.clean(cx) }
}
hir::TypeBindingKind::Constraint { ref bounds } => {
hir::TypeBindingKind::Constraint { bounds } => {
TypeBindingKind::Constraint { bounds: bounds.iter().map(|b| b.clean(cx)).collect() }
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl ExternalCrate {
.filter_map(|a| a.value_str())
.map(to_remote)
.next()
.or(extern_url.map(to_remote)) // NOTE: only matters if `extern_url_takes_precedence` is false
.or_else(|| extern_url.map(to_remote)) // NOTE: only matters if `extern_url_takes_precedence` is false
.unwrap_or(Unknown) // Well, at least we tried.
}

Expand Down Expand Up @@ -238,7 +238,7 @@ impl ExternalCrate {
hir::ItemKind::Mod(_) => {
as_keyword(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
}
hir::ItemKind::Use(ref path, hir::UseKind::Single)
hir::ItemKind::Use(path, hir::UseKind::Single)
if item.vis.node.is_pub() =>
{
as_keyword(path.res.expect_non_local())
Expand Down Expand Up @@ -304,7 +304,7 @@ impl ExternalCrate {
hir::ItemKind::Mod(_) => {
as_primitive(Res::Def(DefKind::Mod, id.def_id.to_def_id()))
}
hir::ItemKind::Use(ref path, hir::UseKind::Single)
hir::ItemKind::Use(path, hir::UseKind::Single)
if item.vis.node.is_pub() =>
{
as_primitive(path.res.expect_non_local()).map(|(_, prim)| {
Expand Down Expand Up @@ -381,7 +381,7 @@ impl Item {
{
*span
} else {
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(|| Span::dummy())
self.def_id.as_def_id().map(|did| rustc_span(did, tcx)).unwrap_or_else(Span::dummy)
}
}

Expand Down Expand Up @@ -562,7 +562,7 @@ impl Item {
}

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

if s.level.is_unstable() {
Expand Down Expand Up @@ -820,9 +820,9 @@ impl AttributesExt for [ast::Attribute] {
// #[doc(cfg(...))]
if let Some(cfg_mi) = item
.meta_item()
.and_then(|item| rustc_expand::config::parse_cfg(&item, sess))
.and_then(|item| rustc_expand::config::parse_cfg(item, sess))
{
match Cfg::parse(&cfg_mi) {
match Cfg::parse(cfg_mi) {
Ok(new_cfg) => cfg &= new_cfg,
Err(e) => sess.span_err(e.span, e.msg),
}
Expand Down Expand Up @@ -934,7 +934,7 @@ impl<'a> FromIterator<&'a DocFragment> for String {
T: IntoIterator<Item = &'a DocFragment>,
{
iter.into_iter().fold(String::new(), |mut acc, frag| {
add_doc_fragment(&mut acc, &frag);
add_doc_fragment(&mut acc, frag);
acc
})
}
Expand Down Expand Up @@ -1061,12 +1061,12 @@ impl Attributes {

let ori = iter.next()?;
let mut out = String::new();
add_doc_fragment(&mut out, &ori);
while let Some(new_frag) = iter.next() {
add_doc_fragment(&mut out, ori);
for new_frag in iter {
if new_frag.kind != ori.kind || new_frag.parent_module != ori.parent_module {
break;
}
add_doc_fragment(&mut out, &new_frag);
add_doc_fragment(&mut out, new_frag);
}
if out.is_empty() { None } else { Some(out) }
}
Expand All @@ -1079,7 +1079,7 @@ impl Attributes {

for new_frag in self.doc_strings.iter() {
let out = ret.entry(new_frag.parent_module).or_default();
add_doc_fragment(out, &new_frag);
add_doc_fragment(out, new_frag);
}
ret
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ crate fn strip_path_generics(path: Path) -> Path {

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

Expand Down Expand Up @@ -217,23 +217,23 @@ crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
PatKind::Wild | PatKind::Struct(..) => return kw::Underscore,
PatKind::Binding(_, _, ident, _) => return ident.name,
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
PatKind::Or(ref pats) => {
PatKind::Or(pats) => {
pats.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(" | ")
}
PatKind::Tuple(ref elts, _) => format!(
PatKind::Tuple(elts, _) => format!(
"({})",
elts.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(", ")
),
PatKind::Box(ref p) => return name_from_pat(&**p),
PatKind::Ref(ref p, _) => return name_from_pat(&**p),
PatKind::Box(p) => return name_from_pat(&*p),
PatKind::Ref(p, _) => return name_from_pat(&*p),
PatKind::Lit(..) => {
warn!(
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
);
return Symbol::intern("()");
}
PatKind::Range(..) => return kw::Underscore,
PatKind::Slice(ref begin, ref mid, ref end) => {
PatKind::Slice(begin, ref mid, end) => {
let begin = begin.iter().map(|p| name_from_pat(p).to_string());
let mid = mid.as_ref().map(|p| format!("..{}", name_from_pat(&**p))).into_iter();
let end = end.iter().map(|p| name_from_pat(p).to_string());
Expand Down Expand Up @@ -507,7 +507,7 @@ crate fn has_doc_flag(attrs: ty::Attributes<'_>, flag: Symbol) -> bool {
/// so that the channel is consistent.
///
/// Set by `bootstrap::Builder::doc_rust_lang_org_channel` in order to keep tests passing on beta/stable.
crate const DOC_RUST_LANG_ORG_CHANNEL: &'static str = env!("DOC_RUST_LANG_ORG_CHANNEL");
crate const DOC_RUST_LANG_ORG_CHANNEL: &str = env!("DOC_RUST_LANG_ORG_CHANNEL");

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

0 comments on commit 29b1248

Please sign in to comment.