Skip to content

Commit

Permalink
Fix clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Aug 29, 2024
1 parent a60a9e5 commit 8683439
Show file tree
Hide file tree
Showing 16 changed files with 94 additions and 105 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/auto_trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ fn clean_region_outlives_constraints<'tcx>(
.map(|&region| {
let lifetime = early_bound_region_name(region)
.inspect(|name| assert!(region_params.contains(name)))
.map(|name| Lifetime(name))
.map(Lifetime)
.unwrap_or(Lifetime::statik());
clean::GenericBound::Outlives(lifetime)
})
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) fn synthesize_blanket_impls(
let mut blanket_impls = Vec::new();
for trait_def_id in tcx.all_traits() {
if !cx.cache.effective_visibilities.is_reachable(tcx, trait_def_id)
|| cx.generated_synthetics.get(&(ty.skip_binder(), trait_def_id)).is_some()
|| cx.generated_synthetics.contains(&(ty.skip_binder(), trait_def_id))
{
continue;
}
Expand Down
28 changes: 12 additions & 16 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub(crate) fn try_inline(
debug!("attrs={attrs:?}");

let attrs_without_docs = attrs.map(|(attrs, def_id)| {
(attrs.into_iter().filter(|a| a.doc_str().is_none()).cloned().collect::<Vec<_>>(), def_id)
(attrs.iter().filter(|a| a.doc_str().is_none()).cloned().collect::<Vec<_>>(), def_id)
});
let attrs_without_docs =
attrs_without_docs.as_ref().map(|(attrs, def_id)| (&attrs[..], *def_id));
Expand Down Expand Up @@ -288,10 +288,7 @@ pub(crate) fn build_external_trait(cx: &mut DocContext<'_>, did: DefId) -> clean
clean::Trait { def_id: did, generics, items: trait_items, bounds: supertrait_bounds }
}

pub(crate) fn build_function<'tcx>(
cx: &mut DocContext<'tcx>,
def_id: DefId,
) -> Box<clean::Function> {
pub(crate) fn build_function(cx: &mut DocContext<'_>, def_id: DefId) -> Box<clean::Function> {
let sig = cx.tcx.fn_sig(def_id).instantiate_identity();
// The generics need to be cleaned before the signature.
let mut generics =
Expand Down Expand Up @@ -425,7 +422,7 @@ pub(crate) fn merge_attrs(
both.cfg(cx.tcx, &cx.cache.hidden_cfg),
)
} else {
(Attributes::from_ast(&old_attrs), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg))
(Attributes::from_ast(old_attrs), old_attrs.cfg(cx.tcx, &cx.cache.hidden_cfg))
}
}

Expand Down Expand Up @@ -791,16 +788,15 @@ fn build_macro(
/// implementation for `AssociatedType`
fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean::Generics {
for pred in &mut g.where_predicates {
match *pred {
clean::WherePredicate::BoundPredicate { ty: clean::SelfTy, ref mut bounds, .. } => {
bounds.retain(|bound| match bound {
clean::GenericBound::TraitBound(clean::PolyTrait { trait_, .. }, _) => {
trait_.def_id() != trait_did
}
_ => true,
});
}
_ => {}
if let clean::WherePredicate::BoundPredicate { ty: clean::SelfTy, ref mut bounds, .. } =
*pred
{
bounds.retain(|bound| match bound {
clean::GenericBound::TraitBound(clean::PolyTrait { trait_, .. }, _) => {
trait_.def_id() != trait_did
}
_ => true,
});
}
}

Expand Down
55 changes: 25 additions & 30 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ fn clean_poly_trait_ref_with_constraints<'tcx>(
)
}

fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime {
fn clean_lifetime(lifetime: &hir::Lifetime, cx: &mut DocContext<'_>) -> Lifetime {
if let Some(
rbv::ResolvedArg::EarlyBound(did)
| rbv::ResolvedArg::LateBound(_, _, did)
| rbv::ResolvedArg::Free(_, did),
) = cx.tcx.named_bound_var(lifetime.hir_id)
&& let Some(lt) = cx.args.get(&did.to_def_id()).and_then(|arg| arg.as_lt())
{
return lt.clone();
return *lt;
}
Lifetime(lifetime.ident.name)
}
Expand All @@ -285,7 +285,7 @@ pub(crate) fn clean_const<'tcx>(
) -> ConstantKind {
match &constant.kind {
hir::ConstArgKind::Path(qpath) => {
ConstantKind::Path { path: qpath_to_string(&qpath).into() }
ConstantKind::Path { path: qpath_to_string(qpath).into() }
}
hir::ConstArgKind::Anon(anon) => ConstantKind::Anonymous { body: anon.body },
}
Expand All @@ -299,7 +299,7 @@ pub(crate) fn clean_middle_const<'tcx>(
ConstantKind::TyConst { expr: constant.skip_binder().to_string().into() }
}

pub(crate) fn clean_middle_region<'tcx>(region: ty::Region<'tcx>) -> Option<Lifetime> {
pub(crate) fn clean_middle_region(region: ty::Region<'_>) -> Option<Lifetime> {
match *region {
ty::ReStatic => Some(Lifetime::statik()),
_ if !region.has_name() => None,
Expand Down Expand Up @@ -389,8 +389,8 @@ fn clean_poly_trait_predicate<'tcx>(
})
}

fn clean_region_outlives_predicate<'tcx>(
pred: ty::RegionOutlivesPredicate<'tcx>,
fn clean_region_outlives_predicate(
pred: ty::RegionOutlivesPredicate<'_>,
) -> Option<WherePredicate> {
let ty::OutlivesPredicate(a, b) = pred;

Expand Down Expand Up @@ -513,10 +513,10 @@ fn projection_to_path_segment<'tcx>(
}
}

fn clean_generic_param_def<'tcx>(
fn clean_generic_param_def(
def: &ty::GenericParamDef,
defaults: ParamDefaults,
cx: &mut DocContext<'tcx>,
cx: &mut DocContext<'_>,
) -> GenericParamDef {
let (name, kind) = match def.kind {
ty::GenericParamDefKind::Lifetime => {
Expand Down Expand Up @@ -1303,10 +1303,7 @@ pub(crate) fn clean_impl_item<'tcx>(
})
}

pub(crate) fn clean_middle_assoc_item<'tcx>(
assoc_item: &ty::AssocItem,
cx: &mut DocContext<'tcx>,
) -> Item {
pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocContext<'_>) -> Item {
let tcx = cx.tcx;
let kind = match assoc_item.kind {
ty::AssocKind::Const => {
Expand Down Expand Up @@ -1459,7 +1456,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
// which only has one associated type, which is not a GAT, so whatever.
}
}
bounds.extend(mem::replace(pred_bounds, Vec::new()));
bounds.extend(mem::take(pred_bounds));
false
}
_ => true,
Expand Down Expand Up @@ -1661,7 +1658,7 @@ fn clean_qpath<'tcx>(hir_ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> Type
expanded
} else {
// First we check if it's a private re-export.
let path = if let Some(path) = first_non_private(cx, hir_id, &path) {
let path = if let Some(path) = first_non_private(cx, hir_id, path) {
path
} else {
clean_path(path, cx)
Expand Down Expand Up @@ -1796,7 +1793,7 @@ fn maybe_expand_private_type_alias<'tcx>(
}

Some(cx.enter_alias(args, def_id.to_def_id(), |cx| {
cx.with_param_env(def_id.to_def_id(), |cx| clean_ty(&ty, cx))
cx.with_param_env(def_id.to_def_id(), |cx| clean_ty(ty, cx))
}))
}

Expand All @@ -1806,8 +1803,8 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
match ty.kind {
TyKind::Never => Primitive(PrimitiveType::Never),
TyKind::Ptr(ref m) => RawPointer(m.mutbl, Box::new(clean_ty(m.ty, cx))),
TyKind::Ref(ref l, ref m) => {
let lifetime = if l.is_anonymous() { None } else { Some(clean_lifetime(*l, cx)) };
TyKind::Ref(l, ref m) => {
let lifetime = if l.is_anonymous() { None } else { Some(clean_lifetime(l, cx)) };
BorrowedRef { lifetime, mutability: m.mutbl, type_: Box::new(clean_ty(m.ty, cx)) }
}
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
Expand Down Expand Up @@ -1843,17 +1840,17 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
TyKind::Tup(tys) => Tuple(tys.iter().map(|ty| clean_ty(ty, cx)).collect()),
TyKind::OpaqueDef(item_id, _, _) => {
let item = cx.tcx.hir().item(item_id);
if let hir::ItemKind::OpaqueTy(ref ty) = item.kind {
if let hir::ItemKind::OpaqueTy(ty) = item.kind {
ImplTrait(ty.bounds.iter().filter_map(|x| clean_generic_bound(x, cx)).collect())
} else {
unreachable!()
}
}
TyKind::Path(_) => clean_qpath(ty, cx),
TyKind::TraitObject(bounds, ref lifetime, _) => {
TyKind::TraitObject(bounds, lifetime, _) => {
let bounds = bounds.iter().map(|(bound, _)| clean_poly_trait_ref(bound, cx)).collect();
let lifetime =
if !lifetime.is_elided() { Some(clean_lifetime(*lifetime, cx)) } else { None };
if !lifetime.is_elided() { Some(clean_lifetime(lifetime, cx)) } else { None };
DynTrait(bounds, lifetime)
}
TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))),
Expand Down Expand Up @@ -2355,7 +2352,7 @@ pub(crate) fn clean_field<'tcx>(field: &hir::FieldDef<'tcx>, cx: &mut DocContext
clean_field_with_def_id(field.def_id.to_def_id(), field.ident.name, clean_ty(field.ty, cx), cx)
}

pub(crate) fn clean_middle_field<'tcx>(field: &ty::FieldDef, cx: &mut DocContext<'tcx>) -> Item {
pub(crate) fn clean_middle_field(field: &ty::FieldDef, cx: &mut DocContext<'_>) -> Item {
clean_field_with_def_id(
field.did,
field.name,
Expand All @@ -2378,7 +2375,7 @@ pub(crate) fn clean_field_with_def_id(
Item::from_def_id_and_parts(def_id, Some(name), StructFieldItem(ty), cx)
}

pub(crate) fn clean_variant_def<'tcx>(variant: &ty::VariantDef, cx: &mut DocContext<'tcx>) -> Item {
pub(crate) fn clean_variant_def(variant: &ty::VariantDef, cx: &mut DocContext<'_>) -> Item {
let discriminant = match variant.discr {
ty::VariantDiscr::Explicit(def_id) => Some(Discriminant { expr: None, value: def_id }),
ty::VariantDiscr::Relative(_) => None,
Expand Down Expand Up @@ -2526,7 +2523,7 @@ fn clean_generic_args<'tcx>(
.filter_map(|arg| {
Some(match arg {
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
GenericArg::Lifetime(clean_lifetime(*lt, cx))
GenericArg::Lifetime(clean_lifetime(lt, cx))
}
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
Expand Down Expand Up @@ -2579,11 +2576,11 @@ fn clean_bare_fn_ty<'tcx>(
BareFunctionDecl { safety: bare_fn.safety, abi: bare_fn.abi, decl, generic_params }
}

pub(crate) fn reexport_chain<'tcx>(
tcx: TyCtxt<'tcx>,
pub(crate) fn reexport_chain(
tcx: TyCtxt<'_>,
import_def_id: LocalDefId,
target_def_id: DefId,
) -> &'tcx [Reexport] {
) -> &[Reexport] {
for child in tcx.module_children_local(tcx.local_parent(import_def_id)) {
if child.res.opt_def_id() == Some(target_def_id)
&& child.reexport_chain.first().and_then(|r| r.id()) == Some(import_def_id.to_def_id())
Expand Down Expand Up @@ -2803,7 +2800,7 @@ fn clean_maybe_renamed_item<'tcx>(
fields: variant_data.fields().iter().map(|x| clean_field(x, cx)).collect(),
}),
ItemKind::Impl(impl_) => return clean_impl(impl_, item.owner_id.def_id, cx),
ItemKind::Macro(ref macro_def, MacroKind::Bang) => {
ItemKind::Macro(macro_def, MacroKind::Bang) => {
let ty_vis = cx.tcx.visibility(def_id);
MacroItem(Macro {
// FIXME this shouldn't be false
Expand Down Expand Up @@ -3134,9 +3131,7 @@ fn clean_assoc_item_constraint<'tcx>(
}
}

fn clean_bound_vars<'tcx>(
bound_vars: &'tcx ty::List<ty::BoundVariableKind>,
) -> Vec<GenericParamDef> {
fn clean_bound_vars(bound_vars: &ty::List<ty::BoundVariableKind>) -> Vec<GenericParamDef> {
bound_vars
.into_iter()
.filter_map(|var| match var {
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/clean/simplify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub(crate) fn where_clauses(cx: &DocContext<'_>, clauses: ThinVec<WP>) -> ThinVe

pub(crate) fn merge_bounds(
cx: &clean::DocContext<'_>,
bounds: &mut Vec<clean::GenericBound>,
bounds: &mut [clean::GenericBound],
trait_did: DefId,
assoc: clean::PathSegment,
rhs: &clean::Term,
Expand Down
31 changes: 14 additions & 17 deletions src/librustdoc/clean/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ fn is_field_vis_inherited(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
}

impl Item {
pub(crate) fn stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<Stability> {
pub(crate) fn stability(&self, tcx: TyCtxt<'_>) -> Option<Stability> {
self.def_id().and_then(|did| tcx.lookup_stability(did))
}

pub(crate) fn const_stability<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Option<ConstStability> {
pub(crate) fn const_stability(&self, tcx: TyCtxt<'_>) -> Option<ConstStability> {
self.def_id().and_then(|did| tcx.lookup_const_stability(did))
}

Expand Down Expand Up @@ -945,9 +945,9 @@ pub(crate) trait AttributesExt {
where
Self: 'a;

fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a>;
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_>;

fn iter<'a>(&'a self) -> Self::Attributes<'a>;
fn iter(&self) -> Self::Attributes<'_>;

fn cfg(&self, tcx: TyCtxt<'_>, hidden_cfg: &FxHashSet<Cfg>) -> Option<Arc<Cfg>> {
let sess = tcx.sess;
Expand Down Expand Up @@ -1043,15 +1043,15 @@ impl AttributesExt for [ast::Attribute] {
type AttributeIterator<'a> = impl Iterator<Item = ast::NestedMetaItem> + 'a;
type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a;

fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a> {
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
self.iter()
.filter(move |attr| attr.has_name(name))
.filter_map(ast::Attribute::meta_item_list)
.flatten()
}

fn iter<'a>(&'a self) -> Self::Attributes<'a> {
self.into_iter()
fn iter(&self) -> Self::Attributes<'_> {
self.iter()
}
}

Expand All @@ -1061,15 +1061,15 @@ impl AttributesExt for [(Cow<'_, ast::Attribute>, Option<DefId>)] {
type Attributes<'a> = impl Iterator<Item = &'a ast::Attribute> + 'a
where Self: 'a;

fn lists<'a>(&'a self, name: Symbol) -> Self::AttributeIterator<'a> {
fn lists(&self, name: Symbol) -> Self::AttributeIterator<'_> {
AttributesExt::iter(self)
.filter(move |attr| attr.has_name(name))
.filter_map(ast::Attribute::meta_item_list)
.flatten()
}

fn iter<'a>(&'a self) -> Self::Attributes<'a> {
self.into_iter().map(move |(attr, _)| match attr {
fn iter(&self) -> Self::Attributes<'_> {
self.iter().map(move |(attr, _)| match attr {
Cow::Borrowed(attr) => *attr,
Cow::Owned(attr) => attr,
})
Expand Down Expand Up @@ -1389,7 +1389,7 @@ pub(crate) struct FnDecl {

impl FnDecl {
pub(crate) fn receiver_type(&self) -> Option<&Type> {
self.inputs.values.get(0).and_then(|v| v.to_receiver())
self.inputs.values.first().and_then(|v| v.to_receiver())
}
}

Expand Down Expand Up @@ -1502,7 +1502,7 @@ impl Type {
pub(crate) fn without_borrowed_ref(&self) -> &Type {
let mut result = self;
while let Type::BorrowedRef { type_, .. } = result {
result = &*type_;
result = type_;
}
result
}
Expand Down Expand Up @@ -1631,10 +1631,7 @@ impl Type {
}

pub(crate) fn is_self_type(&self) -> bool {
match *self {
SelfTy => true,
_ => false,
}
matches!(*self, Type::SelfTy)
}

pub(crate) fn generic_args(&self) -> Option<&GenericArgs> {
Expand Down Expand Up @@ -1673,7 +1670,7 @@ impl Type {
pub(crate) fn def_id(&self, cache: &Cache) -> Option<DefId> {
let t: PrimitiveType = match *self {
Type::Path { ref path } => return Some(path.def_id()),
DynTrait(ref bounds, _) => return bounds.get(0).map(|b| b.trait_.def_id()),
DynTrait(ref bounds, _) => return bounds.first().map(|b| b.trait_.def_id()),
Primitive(p) => return cache.primitive_locations.get(&p).cloned(),
BorrowedRef { type_: box Generic(..), .. } => PrimitiveType::Reference,
BorrowedRef { ref type_, .. } => return type_.def_id(cache),
Expand Down
Loading

0 comments on commit 8683439

Please sign in to comment.