Skip to content

Commit

Permalink
Auto merge of rust-lang#97365 - klensy:rustdoc-vs-clippy, r=notriddle
Browse files Browse the repository at this point in the history
rustdoc: fix few clippy lints

Fix few clippy lints: second commit - perf ones, first - other ones.
  • Loading branch information
bors committed May 25, 2022
2 parents f80e454 + 2a326bc commit 6ac8ada
Show file tree
Hide file tree
Showing 22 changed files with 104 additions and 105 deletions.
8 changes: 4 additions & 4 deletions src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,11 +643,11 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
/// both for visual consistency between 'rustdoc' runs, and to
/// make writing tests much easier
#[inline]
fn sort_where_predicates(&self, mut predicates: &mut Vec<WherePredicate>) {
fn sort_where_predicates(&self, predicates: &mut Vec<WherePredicate>) {
// We should never have identical bounds - and if we do,
// they're visually identical as well. Therefore, using
// an unstable sort is fine.
self.unstable_debug_sort(&mut predicates);
self.unstable_debug_sort(predicates);
}

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

/// This might look horrendously hacky, but it's actually not that bad.
Expand Down
54 changes: 27 additions & 27 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ impl<'tcx> Clean<'tcx, Option<WherePredicate>> for hir::WherePredicate<'tcx> {
hir::WherePredicate::BoundPredicate(ref wbp) => {
let bound_params = wbp
.bound_generic_params
.into_iter()
.iter()
.map(|param| {
// Higher-ranked params must be lifetimes.
// Higher-ranked lifetimes can't have bounds.
Expand Down Expand Up @@ -525,7 +525,7 @@ fn clean_generic_param<'tcx>(
},
)
}
hir::GenericParamKind::Const { ref ty, default } => (
hir::GenericParamKind::Const { ty, default } => (
param.name.ident().name,
GenericParamDefKind::Const {
did: cx.tcx.hir().local_def_id(param.hir_id).to_def_id(),
Expand Down Expand Up @@ -947,7 +947,7 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
// We assume all empty tuples are default return type. This theoretically can discard `-> ()`,
// but shouldn't change any code meaning.
let output = match sig.skip_binder().output().clean(cx) {
Type::Tuple(inner) if inner.len() == 0 => DefaultReturn,
Type::Tuple(inner) if inner.is_empty() => DefaultReturn,
ty => Return(ty),
};

Expand All @@ -972,7 +972,7 @@ fn clean_fn_decl_from_did_and_sig<'tcx>(
impl<'tcx> Clean<'tcx, FnRetTy> for hir::FnRetTy<'tcx> {
fn clean(&self, cx: &mut DocContext<'tcx>) -> FnRetTy {
match *self {
Self::Return(ref typ) => Return(typ.clean(cx)),
Self::Return(typ) => Return(typ.clean(cx)),
Self::DefaultReturn(..) => DefaultReturn,
}
}
Expand Down Expand Up @@ -1013,13 +1013,13 @@ impl<'tcx> Clean<'tcx, Item> for hir::TraitItem<'tcx> {
let local_did = self.def_id.to_def_id();
cx.with_param_env(local_did, |cx| {
let inner = match self.kind {
hir::TraitItemKind::Const(ref ty, Some(default)) => AssocConstItem(
hir::TraitItemKind::Const(ty, Some(default)) => AssocConstItem(
ty.clean(cx),
ConstantKind::Local { def_id: local_did, body: default },
),
hir::TraitItemKind::Const(ref ty, None) => TyAssocConstItem(ty.clean(cx)),
hir::TraitItemKind::Const(ty, None) => TyAssocConstItem(ty.clean(cx)),
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Provided(body)) => {
let m = clean_function(cx, sig, &self.generics, body);
let m = clean_function(cx, sig, self.generics, body);
MethodItem(m, None)
}
hir::TraitItemKind::Fn(ref sig, hir::TraitFn::Required(names)) => {
Expand Down Expand Up @@ -1060,16 +1060,16 @@ impl<'tcx> Clean<'tcx, Item> for hir::ImplItem<'tcx> {
let local_did = self.def_id.to_def_id();
cx.with_param_env(local_did, |cx| {
let inner = match self.kind {
hir::ImplItemKind::Const(ref ty, expr) => {
hir::ImplItemKind::Const(ty, expr) => {
let default = ConstantKind::Local { def_id: local_did, body: expr };
AssocConstItem(ty.clean(cx), default)
}
hir::ImplItemKind::Fn(ref sig, body) => {
let m = clean_function(cx, sig, &self.generics, body);
let m = clean_function(cx, sig, self.generics, body);
let defaultness = cx.tcx.associated_item(self.def_id).defaultness;
MethodItem(m, Some(defaultness))
}
hir::ImplItemKind::TyAlias(ref hir_ty) => {
hir::ImplItemKind::TyAlias(hir_ty) => {
let type_ = hir_ty.clean(cx);
let generics = self.generics.clean(cx);
let item_type = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
Expand Down Expand Up @@ -1292,7 +1292,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
let hir::TyKind::Path(qpath) = kind else { unreachable!() };

match qpath {
hir::QPath::Resolved(None, ref path) => {
hir::QPath::Resolved(None, path) => {
if let Res::Def(DefKind::TyParam, did) = path.res {
if let Some(new_ty) = cx.substs.get(&did).and_then(|p| p.as_ty()).cloned() {
return new_ty;
Expand All @@ -1309,7 +1309,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
resolve_type(cx, path)
}
}
hir::QPath::Resolved(Some(ref qself), p) => {
hir::QPath::Resolved(Some(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 @@ -1333,7 +1333,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
trait_,
}
}
hir::QPath::TypeRelative(ref qself, segment) => {
hir::QPath::TypeRelative(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 @@ -1463,8 +1463,8 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
let lifetime = if elided { None } else { Some(l.clean(cx)) };
BorrowedRef { lifetime, mutability: m.mutbl, type_: box m.ty.clean(cx) }
}
TyKind::Slice(ref ty) => Slice(box ty.clean(cx)),
TyKind::Array(ref ty, ref length) => {
TyKind::Slice(ty) => Slice(box ty.clean(cx)),
TyKind::Array(ty, ref length) => {
let length = match length {
hir::ArrayLen::Infer(_, _) => "_".to_string(),
hir::ArrayLen::Body(anon_const) => {
Expand Down Expand Up @@ -1499,7 +1499,7 @@ impl<'tcx> Clean<'tcx, Type> for hir::Ty<'tcx> {
let lifetime = if !lifetime.is_elided() { Some(lifetime.clean(cx)) } else { None };
DynTrait(bounds, lifetime)
}
TyKind::BareFn(ref barefn) => BareFunction(box barefn.clean(cx)),
TyKind::BareFn(barefn) => BareFunction(box barefn.clean(cx)),
// Rustdoc handles `TyKind::Err`s by turning them into `Type::Infer`s.
TyKind::Infer | TyKind::Err => Infer,
TyKind::Typeof(..) => panic!("unimplemented type {:?}", self.kind),
Expand Down Expand Up @@ -1908,7 +1908,7 @@ fn clean_maybe_renamed_item<'tcx>(
bounds: ty.bounds.iter().filter_map(|x| x.clean(cx)).collect(),
generics: ty.generics.clean(cx),
}),
ItemKind::TyAlias(hir_ty, ref generics) => {
ItemKind::TyAlias(hir_ty, generics) => {
let rustdoc_ty = hir_ty.clean(cx);
let ty = hir_ty_to_ty(cx.tcx, hir_ty).clean(cx);
TypedefItem(Typedef {
Expand All @@ -1917,26 +1917,26 @@ fn clean_maybe_renamed_item<'tcx>(
item_type: Some(ty),
})
}
ItemKind::Enum(ref def, ref generics) => EnumItem(Enum {
ItemKind::Enum(ref def, generics) => EnumItem(Enum {
variants: def.variants.iter().map(|v| v.clean(cx)).collect(),
generics: generics.clean(cx),
}),
ItemKind::TraitAlias(ref generics, bounds) => TraitAliasItem(TraitAlias {
ItemKind::TraitAlias(generics, bounds) => TraitAliasItem(TraitAlias {
generics: generics.clean(cx),
bounds: bounds.iter().filter_map(|x| x.clean(cx)).collect(),
}),
ItemKind::Union(ref variant_data, ref generics) => UnionItem(Union {
ItemKind::Union(ref variant_data, generics) => UnionItem(Union {
generics: generics.clean(cx),
fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
}),
ItemKind::Struct(ref variant_data, ref generics) => StructItem(Struct {
ItemKind::Struct(ref variant_data, generics) => StructItem(Struct {
struct_type: CtorKind::from_hir(variant_data),
generics: generics.clean(cx),
fields: variant_data.fields().iter().map(|x| x.clean(cx)).collect(),
}),
ItemKind::Impl(ref impl_) => return clean_impl(impl_, item.hir_id(), cx),
ItemKind::Impl(impl_) => return clean_impl(impl_, item.hir_id(), cx),
// proc macros can have a name set by attributes
ItemKind::Fn(ref sig, ref generics, body_id) => {
ItemKind::Fn(ref sig, generics, body_id) => {
clean_fn_or_proc_macro(item, sig, generics, body_id, &mut name, cx)
}
ItemKind::Macro(ref macro_def, _) => {
Expand All @@ -1945,7 +1945,7 @@ fn clean_maybe_renamed_item<'tcx>(
source: display_macro_source(cx, name, macro_def, def_id, ty_vis),
})
}
ItemKind::Trait(is_auto, unsafety, ref generics, bounds, item_ids) => {
ItemKind::Trait(is_auto, unsafety, generics, bounds, item_ids) => {
let items =
item_ids.iter().map(|ti| cx.tcx.hir().trait_item(ti.id).clean(cx)).collect();
TraitItem(Trait {
Expand Down Expand Up @@ -2192,7 +2192,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
let def_id = item.def_id.to_def_id();
cx.with_param_env(def_id, |cx| {
let kind = match item.kind {
hir::ForeignItemKind::Fn(decl, names, ref generics) => {
hir::ForeignItemKind::Fn(decl, names, generics) => {
let (generics, decl) = enter_impl_trait(cx, |cx| {
// NOTE: generics must be cleaned before args
let generics = generics.clean(cx);
Expand All @@ -2202,7 +2202,7 @@ fn clean_maybe_renamed_foreign_item<'tcx>(
});
ForeignFunctionItem(Function { decl, generics })
}
hir::ForeignItemKind::Static(ref ty, mutability) => {
hir::ForeignItemKind::Static(ty, mutability) => {
ForeignStaticItem(Static { type_: ty.clean(cx), mutability, expr: None })
}
hir::ForeignItemKind::Type => ForeignTypeItem,
Expand Down Expand Up @@ -2232,7 +2232,7 @@ impl<'tcx> Clean<'tcx, TypeBindingKind> for hir::TypeBindingKind<'tcx> {
hir::TypeBindingKind::Equality { ref term } => {
TypeBindingKind::Equality { term: term.clean(cx) }
}
hir::TypeBindingKind::Constraint { ref bounds } => TypeBindingKind::Constraint {
hir::TypeBindingKind::Constraint { bounds } => TypeBindingKind::Constraint {
bounds: bounds.iter().filter_map(|b| b.clean(cx)).collect(),
},
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/render_macro_matchers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn print_tts(printer: &mut Printer<'_>, tts: &TokenStream) {
if state != Start && needs_space {
printer.space();
}
print_tt(printer, &tt);
print_tt(printer, tt);
state = next_state;
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ impl AttributesExt for [ast::Attribute] {
let mut doc_cfg = self
.iter()
.filter(|attr| attr.has_name(sym::doc))
.flat_map(|attr| attr.meta_item_list().unwrap_or_else(Vec::new))
.flat_map(|attr| attr.meta_item_list().unwrap_or_default())
.filter(|attr| attr.has_name(sym::cfg))
.peekable();
if doc_cfg.peek().is_some() && doc_cfg_active {
Expand Down Expand Up @@ -1011,7 +1011,7 @@ pub(crate) enum DocFragmentKind {
fn add_doc_fragment(out: &mut String, frag: &DocFragment) {
let s = frag.doc.as_str();
let mut iter = s.lines();
if s == "" {
if s.is_empty() {
out.push('\n');
return;
}
Expand Down Expand Up @@ -1594,17 +1594,17 @@ impl Type {
match (self, other) {
// Recursive cases.
(Type::Tuple(a), Type::Tuple(b)) => {
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| a.is_same(&b, cache))
a.len() == b.len() && a.iter().zip(b).all(|(a, b)| a.is_same(b, cache))
}
(Type::Slice(a), Type::Slice(b)) => a.is_same(&b, cache),
(Type::Array(a, al), Type::Array(b, bl)) => al == bl && a.is_same(&b, cache),
(Type::Slice(a), Type::Slice(b)) => a.is_same(b, cache),
(Type::Array(a, al), Type::Array(b, bl)) => al == bl && a.is_same(b, cache),
(Type::RawPointer(mutability, type_), Type::RawPointer(b_mutability, b_type_)) => {
mutability == b_mutability && type_.is_same(&b_type_, cache)
mutability == b_mutability && type_.is_same(b_type_, cache)
}
(
Type::BorrowedRef { mutability, type_, .. },
Type::BorrowedRef { mutability: b_mutability, type_: b_type_, .. },
) => mutability == b_mutability && type_.is_same(&b_type_, cache),
) => mutability == b_mutability && type_.is_same(b_type_, cache),
// Placeholders and generics are equal to all other types.
(Type::Infer, _) | (_, Type::Infer) => true,
(Type::Generic(_), _) | (_, Type::Generic(_)) => true,
Expand Down Expand Up @@ -1667,7 +1667,7 @@ impl Type {

pub(crate) fn projection(&self) -> Option<(&Type, DefId, PathSegment)> {
if let QPath { self_type, trait_, assoc, .. } = self {
Some((&self_type, trait_.def_id(), *assoc.clone()))
Some((self_type, trait_.def_id(), *assoc.clone()))
} else {
None
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn external_generic_args<'tcx>(
bindings: Vec<TypeBinding>,
substs: SubstsRef<'tcx>,
) -> GenericArgs {
let args = substs_to_args(cx, &substs, has_self);
let args = substs_to_args(cx, substs, has_self);

if cx.tcx.fn_trait_kind_from_lang_item(did).is_some() {
let inputs =
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ impl Options {
return Err(1);
}

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

Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/doctest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ fn scrape_test_config(attrs: &[ast::Attribute]) -> GlobalTestOptions {
let test_attrs: Vec<_> = attrs
.iter()
.filter(|a| a.has_name(sym::doc))
.flat_map(|a| a.meta_item_list().unwrap_or_else(Vec::new))
.flat_map(|a| a.meta_item_list().unwrap_or_default())
.filter(|a| a.has_name(sym::test))
.collect();
let attrs = test_attrs.iter().flat_map(|a| a.meta_item_list().unwrap_or(&[]));
Expand Down Expand Up @@ -738,7 +738,7 @@ fn check_if_attr_is_complete(source: &str, edition: Edition) -> bool {
}
};
// If a parsing error happened, it's very likely that the attribute is incomplete.
if !parser.parse_attribute(InnerAttrPolicy::Permitted).is_ok() {
if parser.parse_attribute(InnerAttrPolicy::Permitted).is_err() {
return false;
}
// We now check if there is an unclosed delimiter for the attribute. To do so, we look at
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/formats/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ impl<'a, 'tcx> DocFolder for CacheBuilder<'a, 'tcx> {
let ty::Adt(adt, _) = self.tcx.type_of(path.def_id()).kind() &&
adt.is_fundamental() {
for ty in generics {
if let Some(did) = ty.def_id(&self.cache) {
if let Some(did) = ty.def_id(self.cache) {
dids.insert(did);
}
}
Expand Down
Loading

0 comments on commit 6ac8ada

Please sign in to comment.