diff options
Diffstat (limited to 'src/librustdoc/clean')
| -rw-r--r-- | src/librustdoc/clean/auto_trait.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/blanket_impl.rs | 2 | ||||
| -rw-r--r-- | src/librustdoc/clean/inline.rs | 28 | ||||
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 55 | ||||
| -rw-r--r-- | src/librustdoc/clean/simplify.rs | 16 | ||||
| -rw-r--r-- | src/librustdoc/clean/types.rs | 31 | ||||
| -rw-r--r-- | src/librustdoc/clean/utils.rs | 12 |
7 files changed, 62 insertions, 84 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs index 467f349ef9a..65490108027 100644 --- a/src/librustdoc/clean/auto_trait.rs +++ b/src/librustdoc/clean/auto_trait.rs @@ -342,7 +342,7 @@ fn clean_region_outlives_constraints<'tcx>( .map(|®ion| { 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) }) diff --git a/src/librustdoc/clean/blanket_impl.rs b/src/librustdoc/clean/blanket_impl.rs index 0729a2af875..1f5f6602b9f 100644 --- a/src/librustdoc/clean/blanket_impl.rs +++ b/src/librustdoc/clean/blanket_impl.rs @@ -25,7 +25,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; } diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 4e4a45b6cfb..d22c4cc4b76 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -55,7 +55,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)); @@ -289,10 +289,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 = @@ -426,7 +423,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)) } } @@ -792,16 +789,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, + }); } } diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 58ef900127e..710bd4a5fdf 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -267,7 +267,7 @@ 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) @@ -275,7 +275,7 @@ fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> ) = 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) } @@ -286,7 +286,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 }, } @@ -300,7 +300,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, @@ -390,8 +390,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; @@ -514,10 +514,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 => { @@ -1304,10 +1304,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 => { @@ -1460,7 +1457,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, @@ -1662,7 +1659,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) @@ -1797,7 +1794,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)) })) } @@ -1807,8 +1804,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))), @@ -1844,17 +1841,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))), @@ -2356,7 +2353,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, @@ -2379,7 +2376,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, @@ -2527,7 +2524,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)), @@ -2580,11 +2577,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()) @@ -2804,7 +2801,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 @@ -3135,9 +3132,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 { diff --git a/src/librustdoc/clean/simplify.rs b/src/librustdoc/clean/simplify.rs index 1d81ae3eb8b..b8db82e540c 100644 --- a/src/librustdoc/clean/simplify.rs +++ b/src/librustdoc/clean/simplify.rs @@ -14,7 +14,6 @@ use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::unord::UnordSet; use rustc_hir::def_id::DefId; -use rustc_middle::ty; use thin_vec::ThinVec; use crate::clean; @@ -70,7 +69,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, @@ -113,18 +112,9 @@ fn trait_is_same_or_supertrait(cx: &DocContext<'_>, child: DefId, trait_: DefId) return true; } let predicates = cx.tcx.explicit_super_predicates_of(child); - debug_assert!(cx.tcx.generics_of(child).has_self); - let self_ty = cx.tcx.types.self_param; predicates - .predicates - .iter() - .filter_map(|(pred, _)| { - if let ty::ClauseKind::Trait(pred) = pred.kind().skip_binder() { - if pred.trait_ref.self_ty() == self_ty { Some(pred.def_id()) } else { None } - } else { - None - } - }) + .iter_identity_copied() + .filter_map(|(pred, _)| Some(pred.as_trait_clause()?.def_id())) .any(|did| trait_is_same_or_supertrait(cx, did, trait_)) } diff --git a/src/librustdoc/clean/types.rs b/src/librustdoc/clean/types.rs index 4b5d3c802e6..58fcfc4ed8d 100644 --- a/src/librustdoc/clean/types.rs +++ b/src/librustdoc/clean/types.rs @@ -369,11 +369,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)) } @@ -946,9 +946,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; @@ -1044,15 +1044,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() } } @@ -1062,15 +1062,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, }) @@ -1390,7 +1390,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()) } } @@ -1503,7 +1503,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 } @@ -1632,10 +1632,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> { @@ -1674,7 +1671,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), diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index caa448cd4b3..5686307d83d 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -322,9 +322,9 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { "({})", elts.iter().map(|p| name_from_pat(p).to_string()).collect::<Vec<String>>().join(", ") ), - PatKind::Box(p) => return name_from_pat(&*p), - PatKind::Deref(p) => format!("deref!({})", name_from_pat(&*p)), - PatKind::Ref(p, _) => return name_from_pat(&*p), + PatKind::Box(p) => return name_from_pat(p), + PatKind::Deref(p) => format!("deref!({})", 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" @@ -334,7 +334,7 @@ pub(crate) fn name_from_pat(p: &hir::Pat<'_>) -> Symbol { PatKind::Range(..) => return kw::Underscore, 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 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()); format!("[{}]", begin.chain(mid).chain(end).collect::<Vec<_>>().join(", ")) } @@ -345,7 +345,7 @@ pub(crate) fn print_const(cx: &DocContext<'_>, n: ty::Const<'_>) -> String { match n.kind() { ty::ConstKind::Unevaluated(ty::UnevaluatedConst { def, args: _ }) => { let s = if let Some(def) = def.as_local() { - rendered_const(cx.tcx, &cx.tcx.hir().body_owned_by(def), def) + rendered_const(cx.tcx, cx.tcx.hir().body_owned_by(def), def) } else { inline::print_inlined_const(cx.tcx, def) }; @@ -384,7 +384,7 @@ pub(crate) fn print_evaluated_const( fn format_integer_with_underscore_sep(num: &str) -> String { let num_chars: Vec<_> = num.chars().collect(); - let mut num_start_index = if num_chars.get(0) == Some(&'-') { 1 } else { 0 }; + let mut num_start_index = if num_chars.first() == Some(&'-') { 1 } else { 0 }; let chunk_size = match num[num_start_index..].as_bytes() { [b'0', b'b' | b'x', ..] => { num_start_index += 2; |
