Auto merge of #80091 - GuillaumeGomez:str-to-symbol, r=jyn514

Replace String with Symbol where possible

The same as #80047 but on different types. Might be interesting to run some perf comparison.

r? `@jyn514`
This commit is contained in:
bors 2020-12-17 06:00:12 +00:00
commit bdd0a78582
11 changed files with 109 additions and 106 deletions

View File

@ -333,10 +333,9 @@ fn extract_for_generics(
match br {
// We only care about named late bound regions, as we need to add them
// to the 'for<>' section
ty::BrNamed(_, name) => Some(GenericParamDef {
name: name.to_string(),
kind: GenericParamDefKind::Lifetime,
}),
ty::BrNamed(_, name) => {
Some(GenericParamDef { name, kind: GenericParamDefKind::Lifetime })
}
_ => None,
}
})
@ -569,7 +568,7 @@ fn param_env_to_generics(
}
WherePredicate::EqPredicate { lhs, rhs } => {
match lhs {
Type::QPath { name: ref left_name, ref self_type, ref trait_ } => {
Type::QPath { name: left_name, ref self_type, ref trait_ } => {
let ty = &*self_type;
match **trait_ {
Type::ResolvedPath {
@ -580,7 +579,7 @@ fn param_env_to_generics(
} => {
let mut new_trait_path = trait_path.clone();
if self.is_fn_ty(tcx, trait_) && left_name == FN_OUTPUT_NAME {
if self.is_fn_ty(tcx, trait_) && left_name == sym::Output {
ty_to_fn
.entry(*ty.clone())
.and_modify(|e| *e = (e.0.clone(), Some(rhs.clone())))

View File

@ -12,7 +12,7 @@
use rustc_middle::ty;
use rustc_mir::const_eval::is_min_const_fn;
use rustc_span::hygiene::MacroKind;
use rustc_span::symbol::{sym, Symbol};
use rustc_span::symbol::{kw, sym, Symbol};
use rustc_span::Span;
use crate::clean::{self, Attributes, GetDefId, ToSource, TypeKind};
@ -583,7 +583,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
for pred in &mut g.where_predicates {
match *pred {
clean::WherePredicate::BoundPredicate { ty: clean::Generic(ref s), ref mut bounds }
if *s == "Self" =>
if *s == kw::SelfUpper =>
{
bounds.retain(|bound| match *bound {
clean::GenericBound::TraitBound(
@ -606,7 +606,7 @@ fn filter_non_trait_generics(trait_did: DefId, mut g: clean::Generics) -> clean:
name: ref _name,
},
ref bounds,
} => !(bounds.is_empty() || *s == "Self" && did == trait_did),
} => !(bounds.is_empty() || *s == kw::SelfUpper && did == trait_did),
_ => true,
});
g
@ -621,7 +621,7 @@ fn separate_supertrait_bounds(
let mut ty_bounds = Vec::new();
g.where_predicates.retain(|pred| match *pred {
clean::WherePredicate::BoundPredicate { ty: clean::Generic(ref s), ref bounds }
if *s == "Self" =>
if *s == kw::SelfUpper =>
{
ty_bounds.extend(bounds.iter().cloned());
false

View File

@ -48,8 +48,6 @@
crate use self::types::Visibility::{Inherited, Public};
crate use self::types::*;
const FN_OUTPUT_NAME: &str = "Output";
crate trait Clean<T> {
fn clean(&self, cx: &DocContext<'_>) -> T;
}
@ -329,10 +327,9 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericBound {
.collect_referenced_late_bound_regions(&poly_trait_ref)
.into_iter()
.filter_map(|br| match br {
ty::BrNamed(_, name) => Some(GenericParamDef {
name: name.to_string(),
kind: GenericParamDefKind::Lifetime,
}),
ty::BrNamed(_, name) => {
Some(GenericParamDef { name, kind: GenericParamDefKind::Lifetime })
}
_ => None,
})
.collect();
@ -546,7 +543,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
GenericBound::Outlives(_) => panic!("cleaning a trait got a lifetime"),
};
Type::QPath {
name: cx.tcx.associated_item(self.item_def_id).ident.name.clean(cx),
name: cx.tcx.associated_item(self.item_def_id).ident.name,
self_type: box self.self_ty().clean(cx),
trait_: box trait_,
}
@ -556,14 +553,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
impl Clean<GenericParamDef> for ty::GenericParamDef {
fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
let (name, kind) = match self.kind {
ty::GenericParamDefKind::Lifetime => {
(self.name.to_string(), GenericParamDefKind::Lifetime)
}
ty::GenericParamDefKind::Lifetime => (self.name, GenericParamDefKind::Lifetime),
ty::GenericParamDefKind::Type { has_default, synthetic, .. } => {
let default =
if has_default { Some(cx.tcx.type_of(self.def_id).clean(cx)) } else { None };
(
self.name.clean(cx),
self.name,
GenericParamDefKind::Type {
did: self.def_id,
bounds: vec![], // These are filled in from the where-clauses.
@ -573,7 +568,7 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
)
}
ty::GenericParamDefKind::Const { .. } => (
self.name.clean(cx),
self.name,
GenericParamDefKind::Const {
did: self.def_id,
ty: cx.tcx.type_of(self.def_id).clean(cx),
@ -599,14 +594,14 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
for bound in bounds {
s.push_str(&format!(" + {}", bound.name.ident()));
}
s
Symbol::intern(&s)
} else {
self.name.ident().to_string()
self.name.ident().name
};
(name, GenericParamDefKind::Lifetime)
}
hir::GenericParamKind::Type { ref default, synthetic } => (
self.name.ident().name.clean(cx),
self.name.ident().name,
GenericParamDefKind::Type {
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
bounds: self.bounds.clean(cx),
@ -615,7 +610,7 @@ fn clean(&self, cx: &DocContext<'_>) -> GenericParamDef {
},
),
hir::GenericParamKind::Const { ref ty } => (
self.name.ident().name.clean(cx),
self.name.ident().name,
GenericParamDefKind::Const {
did: cx.tcx.hir().local_def_id(self.hir_id).to_def_id(),
ty: ty.clean(cx),
@ -730,7 +725,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
.collect::<Vec<GenericParamDef>>();
// param index -> [(DefId of trait, associated type name, type)]
let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, String, Ty<'tcx>)>>::default();
let mut impl_trait_proj = FxHashMap::<u32, Vec<(DefId, Symbol, Ty<'tcx>)>>::default();
let where_predicates = preds
.predicates
@ -778,11 +773,10 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
if let Some(((_, trait_did, name), rhs)) =
proj.as_ref().and_then(|(lhs, rhs)| Some((lhs.projection()?, rhs)))
{
impl_trait_proj.entry(param_idx).or_default().push((
trait_did,
name.to_string(),
rhs,
));
impl_trait_proj
.entry(param_idx)
.or_default()
.push((trait_did, name, rhs));
}
return None;
@ -800,7 +794,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Generics {
if let crate::core::ImplTraitParam::ParamIndex(idx) = param {
if let Some(proj) = impl_trait_proj.remove(&idx) {
for (trait_did, name, rhs) in proj {
simplify::merge_bounds(cx, &mut bounds, trait_did, &name, &rhs.clean(cx));
simplify::merge_bounds(cx, &mut bounds, trait_did, name, &rhs.clean(cx));
}
}
} else {
@ -936,9 +930,9 @@ fn clean(&self, cx: &DocContext<'_>) -> Arguments {
.iter()
.enumerate()
.map(|(i, ty)| {
let mut name = self.1.get(i).map(|ident| ident.to_string()).unwrap_or_default();
let mut name = self.1.get(i).map(|ident| ident.name).unwrap_or(kw::Invalid);
if name.is_empty() {
name = "_".to_string();
name = kw::Underscore;
}
Argument { name, type_: ty.clean(cx) }
})
@ -995,7 +989,7 @@ fn clean(&self, cx: &DocContext<'_>) -> FnDecl {
.iter()
.map(|t| Argument {
type_: t.clean(cx),
name: names.next().map_or_else(|| String::new(), |name| name.to_string()),
name: names.next().map(|i| i.name).unwrap_or(kw::Invalid),
})
.collect(),
},
@ -1150,12 +1144,12 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
};
let self_arg_ty = sig.input(0).skip_binder();
if self_arg_ty == self_ty {
decl.inputs.values[0].type_ = Generic(String::from("Self"));
decl.inputs.values[0].type_ = Generic(kw::SelfUpper);
} else if let ty::Ref(_, ty, _) = *self_arg_ty.kind() {
if ty == self_ty {
match decl.inputs.values[0].type_ {
BorrowedRef { ref mut type_, .. } => {
**type_ = Generic(String::from("Self"))
**type_ = Generic(kw::SelfUpper)
}
_ => unreachable!(),
}
@ -1210,7 +1204,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
}
}
ty::AssocKind::Type => {
let my_name = self.ident.name.clean(cx);
let my_name = self.ident.name;
if let ty::TraitContainer(_) = self.container {
let bounds = cx.tcx.explicit_item_bounds(self.def_id);
@ -1235,7 +1229,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
_ => return None,
}
match **self_type {
Generic(ref s) if *s == "Self" => {}
Generic(ref s) if *s == kw::SelfUpper => {}
_ => return None,
}
Some(bounds)
@ -1408,7 +1402,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &DocContext<'_>) -> Type {
segments: trait_segments.clean(cx),
};
Type::QPath {
name: p.segments.last().expect("segments were empty").ident.name.clean(cx),
name: p.segments.last().expect("segments were empty").ident.name,
self_type: box qself.clean(cx),
trait_: box resolve_type(cx, trait_path, hir_id),
}
@ -1422,7 +1416,7 @@ fn clean_qpath(hir_ty: &hir::Ty<'_>, cx: &DocContext<'_>) -> Type {
};
let trait_path = hir::Path { span, res, segments: &[] };
Type::QPath {
name: segment.ident.name.clean(cx),
name: segment.ident.name,
self_type: box qself.clean(cx),
trait_: box resolve_type(cx, trait_path.clean(cx), hir_id),
}
@ -1625,7 +1619,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
let mut bindings = vec![];
for pb in obj.projection_bounds() {
bindings.push(TypeBinding {
name: cx.tcx.associated_item(pb.item_def_id()).ident.name.clean(cx),
name: cx.tcx.associated_item(pb.item_def_id()).ident.name,
kind: TypeBindingKind::Equality { ty: pb.skip_binder().ty.clean(cx) },
});
}
@ -1644,7 +1638,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
if let Some(bounds) = cx.impl_trait_bounds.borrow_mut().remove(&p.index.into()) {
ImplTrait(bounds)
} else {
Generic(p.name.to_string())
Generic(p.name)
}
}
@ -1702,8 +1696,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Type {
.tcx
.associated_item(proj.projection_ty.item_def_id)
.ident
.name
.clean(cx),
.name,
kind: TypeBindingKind::Equality {
ty: proj.ty.clean(cx),
},
@ -2339,7 +2332,7 @@ fn clean(&self, cx: &DocContext<'_>) -> Item {
impl Clean<TypeBinding> for hir::TypeBinding<'_> {
fn clean(&self, cx: &DocContext<'_>) -> TypeBinding {
TypeBinding { name: self.ident.name.clean(cx), kind: self.kind.clean(cx) }
TypeBinding { name: self.ident.name, kind: self.kind.clean(cx) }
}
}

View File

@ -15,6 +15,7 @@
use rustc_hir::def_id::DefId;
use rustc_middle::ty;
use rustc_span::Symbol;
use crate::clean;
use crate::clean::GenericArgs as PP;
@ -78,7 +79,7 @@
cx: &clean::DocContext<'_>,
bounds: &mut Vec<clean::GenericBound>,
trait_did: DefId,
name: &str,
name: Symbol,
rhs: &clean::Type,
) -> bool {
!bounds.iter_mut().any(|b| {
@ -100,7 +101,7 @@
match last.args {
PP::AngleBracketed { ref mut bindings, .. } => {
bindings.push(clean::TypeBinding {
name: name.to_string(),
name,
kind: clean::TypeBindingKind::Equality { ty: rhs.clone() },
});
}

View File

@ -949,7 +949,7 @@ impl GenericParamDefKind {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct GenericParamDef {
crate name: String,
crate name: Symbol,
crate kind: GenericParamDefKind,
}
@ -1037,7 +1037,7 @@ impl FnDecl {
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct Argument {
crate type_: Type,
crate name: String,
crate name: Symbol,
}
#[derive(Clone, PartialEq, Debug)]
@ -1049,7 +1049,7 @@ impl FnDecl {
impl Argument {
crate fn to_self(&self) -> Option<SelfTy> {
if self.name != "self" {
if self.name != kw::SelfLower {
return None;
}
if self.type_.is_self_type() {
@ -1117,7 +1117,7 @@ fn def_id(&self) -> Option<DefId> {
},
/// For parameterized types, so the consumer of the JSON don't go
/// looking for types which don't exist anywhere.
Generic(String),
Generic(Symbol),
/// Primitives are the fixed-size numeric types (plus int/usize/float), char,
/// arrays, slices, and tuples.
Primitive(PrimitiveType),
@ -1136,7 +1136,7 @@ fn def_id(&self) -> Option<DefId> {
// `<Type as Trait>::Name`
QPath {
name: String,
name: Symbol,
self_type: Box<Type>,
trait_: Box<Type>,
},
@ -1237,7 +1237,7 @@ impl Type {
crate fn is_self_type(&self) -> bool {
match *self {
Generic(ref name) => name == "Self",
Generic(name) => name == kw::SelfUpper,
_ => false,
}
}
@ -1282,16 +1282,16 @@ impl Type {
}
}
crate fn projection(&self) -> Option<(&Type, DefId, &str)> {
crate fn projection(&self) -> Option<(&Type, DefId, Symbol)> {
let (self_, trait_, name) = match self {
QPath { ref self_type, ref trait_, ref name } => (self_type, trait_, name),
QPath { ref self_type, ref trait_, name } => (self_type, trait_, name),
_ => return None,
};
let trait_did = match **trait_ {
ResolvedPath { did, .. } => did,
_ => return None,
};
Some((&self_, trait_did, name))
Some((&self_, trait_did, *name))
}
}
@ -1816,7 +1816,7 @@ impl Import {
/// `A: Send + Sync` in `Foo<A: Send + Sync>`).
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
crate struct TypeBinding {
crate name: String,
crate name: Symbol,
crate kind: TypeBindingKind,
}

View File

@ -170,13 +170,13 @@ pub(super) fn external_path(
cx: &DocContext<'_>,
recurse: i32,
) -> FxHashSet<(Type, TypeKind)> {
let arg_s = arg.print().to_string();
let mut res = FxHashSet::default();
if recurse >= 10 {
// FIXME: remove this whole recurse thing when the recursion bug is fixed
return res;
}
if arg.is_full_generic() {
let arg_s = Symbol::intern(&arg.print().to_string());
if let Some(where_pred) = generics.where_predicates.iter().find(|g| match g {
&WherePredicate::BoundPredicate { ref ty, .. } => ty.def_id() == arg.def_id(),
_ => false,
@ -375,13 +375,13 @@ fn to_src(&self, cx: &DocContext<'_>) -> String {
}
}
crate fn name_from_pat(p: &hir::Pat<'_>) -> String {
crate fn name_from_pat(p: &hir::Pat<'_>) -> Symbol {
use rustc_hir::*;
debug!("trying to get a name from pattern: {:?}", p);
match p.kind {
PatKind::Wild => "_".to_string(),
PatKind::Binding(_, _, ident, _) => ident.to_string(),
Symbol::intern(&match p.kind {
PatKind::Wild => return kw::Underscore,
PatKind::Binding(_, _, ident, _) => return ident.name,
PatKind::TupleStruct(ref p, ..) | PatKind::Path(ref p) => qpath_to_string(p),
PatKind::Struct(ref name, ref fields, etc) => format!(
"{} {{ {}{} }}",
@ -393,32 +393,37 @@ fn to_src(&self, cx: &DocContext<'_>) -> String {
.join(", "),
if etc { ", .." } else { "" }
),
PatKind::Or(ref pats) => {
pats.iter().map(|p| name_from_pat(&**p)).collect::<Vec<String>>().join(" | ")
}
PatKind::Or(ref pats) => pats
.iter()
.map(|p| name_from_pat(&**p).to_string())
.collect::<Vec<String>>()
.join(" | "),
PatKind::Tuple(ref elts, _) => format!(
"({})",
elts.iter().map(|p| name_from_pat(&**p)).collect::<Vec<String>>().join(", ")
elts.iter()
.map(|p| name_from_pat(&**p).to_string())
.collect::<Vec<String>>()
.join(", ")
),
PatKind::Box(ref p) => name_from_pat(&**p),
PatKind::Ref(ref p, _) => name_from_pat(&**p),
PatKind::Box(ref p) => return name_from_pat(&**p),
PatKind::Ref(ref p, _) => return name_from_pat(&**p),
PatKind::Lit(..) => {
warn!(
"tried to get argument name from PatKind::Lit, which is silly in function arguments"
);
"()".to_string()
return Symbol::intern("()");
}
PatKind::Range(..) => panic!(
"tried to get argument name from PatKind::Range, \
which is not allowed in function arguments"
),
PatKind::Slice(ref begin, ref mid, ref end) => {
let begin = begin.iter().map(|p| name_from_pat(&**p));
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));
let end = end.iter().map(|p| name_from_pat(&**p).to_string());
format!("[{}]", begin.chain(mid).chain(end).collect::<Vec<_>>().join(", "))
}
}
})
}
crate fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String {
@ -534,10 +539,10 @@ fn print_const_with_custom_print_scalar(cx: &DocContext<'_>, ct: &'tcx ty::Const
let is_generic = match path.res {
Res::PrimTy(p) => return Primitive(PrimitiveType::from(p)),
Res::SelfTy(..) if path.segments.len() == 1 => {
return Generic(kw::SelfUpper.to_string());
return Generic(kw::SelfUpper);
}
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
return Generic(format!("{:#}", path.print()));
return Generic(Symbol::intern(&format!("{:#}", path.print())));
}
Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true,
_ => false,

View File

@ -172,7 +172,7 @@ impl clean::GenericParamDef {
display_fn(move |f| match self.kind {
clean::GenericParamDefKind::Lifetime => write!(f, "{}", self.name),
clean::GenericParamDefKind::Type { ref bounds, ref default, .. } => {
f.write_str(&self.name)?;
f.write_str(&*self.name.as_str())?;
if !bounds.is_empty() {
if f.alternate() {
@ -193,13 +193,10 @@ impl clean::GenericParamDef {
Ok(())
}
clean::GenericParamDefKind::Const { ref ty, .. } => {
f.write_str("const ")?;
f.write_str(&self.name)?;
if f.alternate() {
write!(f, ": {:#}", ty.print())
write!(f, "const {}: {:#}", self.name, ty.print())
} else {
write!(f, ":&nbsp;{}", ty.print())
write!(f, "const {}:&nbsp;{}", self.name, ty.print())
}
}
})
@ -638,7 +635,7 @@ fn tybounds(param_names: &Option<Vec<clean::GenericBound>>) -> impl fmt::Display
fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) -> fmt::Result {
match *t {
clean::Generic(ref name) => f.write_str(name),
clean::Generic(name) => write!(f, "{}", name),
clean::ResolvedPath { did, ref param_names, ref path, is_generic } => {
if param_names.is_some() {
f.write_str("dyn ")?;
@ -1203,7 +1200,7 @@ impl clean::ImportSource {
impl clean::TypeBinding {
crate fn print(&self) -> impl fmt::Display + '_ {
display_fn(move |f| {
f.write_str(&self.name)?;
f.write_str(&*self.name.as_str())?;
match self.kind {
clean::TypeBindingKind::Equality { ref ty } => {
if f.alternate() {

View File

@ -208,7 +208,7 @@ fn get_index_type_name(clean_type: &clean::Type, accept_generic: bool) -> Option
});
Some(path_segment.name.clone())
}
clean::Generic(ref s) if accept_generic => Some(s.clone()),
clean::Generic(s) if accept_generic => Some(s.to_string()),
clean::Primitive(ref p) => Some(format!("{:?}", p)),
clean::BorrowedRef { ref type_, .. } => get_index_type_name(type_, accept_generic),
// FIXME: add all from clean::Type.

View File

@ -136,7 +136,7 @@ fn from(constant: clean::Constant) -> Self {
impl From<clean::TypeBinding> for TypeBinding {
fn from(binding: clean::TypeBinding) -> Self {
TypeBinding { name: binding.name, binding: binding.kind.into() }
TypeBinding { name: binding.name.to_string(), binding: binding.kind.into() }
}
}
@ -275,7 +275,7 @@ fn from(generics: clean::Generics) -> Self {
impl From<clean::GenericParamDef> for GenericParamDef {
fn from(generic_param: clean::GenericParamDef) -> Self {
GenericParamDef { name: generic_param.name, kind: generic_param.kind.into() }
GenericParamDef { name: generic_param.name.to_string(), kind: generic_param.kind.into() }
}
}
@ -351,7 +351,7 @@ fn from(ty: clean::Type) -> Self {
.map(|v| v.into_iter().map(Into::into).collect())
.unwrap_or_default(),
},
Generic(s) => Type::Generic(s),
Generic(s) => Type::Generic(s.to_string()),
Primitive(p) => Type::Primitive(p.as_str().to_string()),
BareFunction(f) => Type::FunctionPointer(Box::new((*f).into())),
Tuple(t) => Type::Tuple(t.into_iter().map(Into::into).collect()),
@ -370,7 +370,7 @@ fn from(ty: clean::Type) -> Self {
type_: Box::new((*type_).into()),
},
QPath { name, self_type, trait_ } => Type::QualifiedPath {
name,
name: name.to_string(),
self_type: Box::new((*self_type).into()),
trait_: Box::new((*trait_).into()),
},
@ -394,7 +394,11 @@ impl From<clean::FnDecl> for FnDecl {
fn from(decl: clean::FnDecl) -> Self {
let clean::FnDecl { inputs, output, c_variadic, attrs: _ } = decl;
FnDecl {
inputs: inputs.values.into_iter().map(|arg| (arg.name, arg.type_.into())).collect(),
inputs: inputs
.values
.into_iter()
.map(|arg| (arg.name.to_string(), arg.type_.into()))
.collect(),
output: match output {
clean::FnRetTy::Return(t) => Some(t.into()),
clean::FnRetTy::DefaultReturn => None,

View File

@ -753,11 +753,14 @@ fn traits_implemented_by(cx: &DocContext<'_>, type_: DefId, module: DefId) -> Fx
///
/// These are common and we should just resolve to the trait in that case.
fn is_derive_trait_collision<T>(ns: &PerNS<Result<(Res, T), ResolutionFailure<'_>>>) -> bool {
matches!(*ns, PerNS {
type_ns: Ok((Res::Def(DefKind::Trait, _), _)),
macro_ns: Ok((Res::Def(DefKind::Macro(MacroKind::Derive), _), _)),
..
})
matches!(
*ns,
PerNS {
type_ns: Ok((Res::Def(DefKind::Trait, _), _)),
macro_ns: Ok((Res::Def(DefKind::Macro(MacroKind::Derive), _), _)),
..
}
)
}
impl<'a, 'tcx> DocFolder for LinkCollector<'a, 'tcx> {

View File

@ -58,18 +58,19 @@ fn add_test(&mut self, _: String, config: LangString, _: usize) {
}
crate fn should_have_doc_example(cx: &DocContext<'_>, item: &clean::Item) -> bool {
if matches!(item.kind,
if matches!(
item.kind,
clean::StructFieldItem(_)
| clean::VariantItem(_)
| clean::AssocConstItem(_, _)
| clean::AssocTypeItem(_, _)
| clean::TypedefItem(_, _)
| clean::StaticItem(_)
| clean::ConstantItem(_)
| clean::ExternCrateItem(_, _)
| clean::ImportItem(_)
| clean::PrimitiveItem(_)
| clean::KeywordItem(_)
| clean::VariantItem(_)
| clean::AssocConstItem(_, _)
| clean::AssocTypeItem(_, _)
| clean::TypedefItem(_, _)
| clean::StaticItem(_)
| clean::ConstantItem(_)
| clean::ExternCrateItem(_, _)
| clean::ImportItem(_)
| clean::PrimitiveItem(_)
| clean::KeywordItem(_)
) {
return false;
}