Remove Type::ResolvedPath.is_generic
It can be computed on-demand.
This commit is contained in:
parent
c7dbe7a830
commit
07d6454a0f
7 changed files with 52 additions and 77 deletions
|
@ -354,7 +354,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
let (poly_trait, output) =
|
let (poly_trait, output) =
|
||||||
(data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new));
|
(data.0.as_ref().unwrap().clone(), data.1.as_ref().cloned().map(Box::new));
|
||||||
let new_ty = match poly_trait.trait_ {
|
let new_ty = match poly_trait.trait_ {
|
||||||
Type::ResolvedPath { ref path, ref did, ref is_generic } => {
|
Type::ResolvedPath { ref path, ref did } => {
|
||||||
let mut new_path = path.clone();
|
let mut new_path = path.clone();
|
||||||
let last_segment =
|
let last_segment =
|
||||||
new_path.segments.pop().expect("segments were empty");
|
new_path.segments.pop().expect("segments were empty");
|
||||||
|
@ -389,11 +389,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
.segments
|
.segments
|
||||||
.push(PathSegment { name: last_segment.name, args: new_params });
|
.push(PathSegment { name: last_segment.name, args: new_params });
|
||||||
|
|
||||||
Type::ResolvedPath {
|
Type::ResolvedPath { path: new_path, did: *did }
|
||||||
path: new_path,
|
|
||||||
did: *did,
|
|
||||||
is_generic: *is_generic,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => panic!("Unexpected data: {:?}, {:?}", ty, data),
|
_ => panic!("Unexpected data: {:?}, {:?}", ty, data),
|
||||||
};
|
};
|
||||||
|
@ -563,11 +559,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
Type::QPath { name: left_name, ref self_type, ref trait_, .. } => {
|
Type::QPath { name: left_name, ref self_type, ref trait_, .. } => {
|
||||||
let ty = &*self_type;
|
let ty = &*self_type;
|
||||||
match **trait_ {
|
match **trait_ {
|
||||||
Type::ResolvedPath {
|
Type::ResolvedPath { path: ref trait_path, ref did } => {
|
||||||
path: ref trait_path,
|
|
||||||
ref did,
|
|
||||||
ref is_generic,
|
|
||||||
} => {
|
|
||||||
let mut new_trait_path = trait_path.clone();
|
let mut new_trait_path = trait_path.clone();
|
||||||
|
|
||||||
if self.is_fn_ty(trait_) && left_name == sym::Output {
|
if self.is_fn_ty(trait_) && left_name == sym::Output {
|
||||||
|
@ -612,7 +604,6 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> {
|
||||||
trait_: Type::ResolvedPath {
|
trait_: Type::ResolvedPath {
|
||||||
path: new_trait_path,
|
path: new_trait_path,
|
||||||
did: *did,
|
did: *did,
|
||||||
is_generic: *is_generic,
|
|
||||||
},
|
},
|
||||||
generic_params: Vec::new(),
|
generic_params: Vec::new(),
|
||||||
},
|
},
|
||||||
|
|
|
@ -168,7 +168,7 @@ impl Clean<Type> for (ty::TraitRef<'_>, &[TypeBinding]) {
|
||||||
|
|
||||||
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
|
debug!("ty::TraitRef\n subst: {:?}\n", trait_ref.substs);
|
||||||
|
|
||||||
ResolvedPath { path, did: trait_ref.def_id, is_generic: false }
|
ResolvedPath { path, did: trait_ref.def_id }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1442,12 +1442,12 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||||
};
|
};
|
||||||
inline::record_extern_fqn(cx, did, kind);
|
inline::record_extern_fqn(cx, did, kind);
|
||||||
let path = external_path(cx, did, false, vec![], substs);
|
let path = external_path(cx, did, false, vec![], substs);
|
||||||
ResolvedPath { path, did, is_generic: false }
|
ResolvedPath { path, did }
|
||||||
}
|
}
|
||||||
ty::Foreign(did) => {
|
ty::Foreign(did) => {
|
||||||
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
|
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
|
||||||
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
|
let path = external_path(cx, did, false, vec![], InternalSubsts::empty());
|
||||||
ResolvedPath { path, did, is_generic: false }
|
ResolvedPath { path, did }
|
||||||
}
|
}
|
||||||
ty::Dynamic(ref obj, ref reg) => {
|
ty::Dynamic(ref obj, ref reg) => {
|
||||||
// HACK: pick the first `did` as the `did` of the trait object. Someone
|
// HACK: pick the first `did` as the `did` of the trait object. Someone
|
||||||
|
@ -1473,7 +1473,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||||
let path = external_path(cx, did, false, vec![], empty);
|
let path = external_path(cx, did, false, vec![], empty);
|
||||||
inline::record_extern_fqn(cx, did, ItemType::Trait);
|
inline::record_extern_fqn(cx, did, ItemType::Trait);
|
||||||
let bound = PolyTrait {
|
let bound = PolyTrait {
|
||||||
trait_: ResolvedPath { path, did, is_generic: false },
|
trait_: ResolvedPath { path, did },
|
||||||
generic_params: Vec::new(),
|
generic_params: Vec::new(),
|
||||||
};
|
};
|
||||||
bounds.push(bound);
|
bounds.push(bound);
|
||||||
|
@ -1490,10 +1490,7 @@ impl<'tcx> Clean<Type> for Ty<'tcx> {
|
||||||
let path = external_path(cx, did, false, bindings, substs);
|
let path = external_path(cx, did, false, bindings, substs);
|
||||||
bounds.insert(
|
bounds.insert(
|
||||||
0,
|
0,
|
||||||
PolyTrait {
|
PolyTrait { trait_: ResolvedPath { path, did }, generic_params: Vec::new() },
|
||||||
trait_: ResolvedPath { path, did, is_generic: false },
|
|
||||||
generic_params: Vec::new(),
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
|
|
||||||
DynTrait(bounds, lifetime)
|
DynTrait(bounds, lifetime)
|
||||||
|
|
|
@ -1114,10 +1114,7 @@ impl GenericBound {
|
||||||
let path = external_path(cx, did, false, vec![], empty);
|
let path = external_path(cx, did, false, vec![], empty);
|
||||||
inline::record_extern_fqn(cx, did, ItemType::Trait);
|
inline::record_extern_fqn(cx, did, ItemType::Trait);
|
||||||
GenericBound::TraitBound(
|
GenericBound::TraitBound(
|
||||||
PolyTrait {
|
PolyTrait { trait_: ResolvedPath { path, did }, generic_params: Vec::new() },
|
||||||
trait_: ResolvedPath { path, did, is_generic: false },
|
|
||||||
generic_params: Vec::new(),
|
|
||||||
},
|
|
||||||
hir::TraitBoundModifier::Maybe,
|
hir::TraitBoundModifier::Maybe,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1384,8 +1381,6 @@ crate enum Type {
|
||||||
ResolvedPath {
|
ResolvedPath {
|
||||||
path: Path,
|
path: Path,
|
||||||
did: DefId,
|
did: DefId,
|
||||||
/// `true` if is a `T::Name` path for associated types.
|
|
||||||
is_generic: bool,
|
|
||||||
},
|
},
|
||||||
/// `dyn for<'a> Trait<'a> + Send + 'static`
|
/// `dyn for<'a> Trait<'a> + Send + 'static`
|
||||||
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
|
DynTrait(Vec<PolyTrait>, Option<Lifetime>),
|
||||||
|
@ -1504,8 +1499,8 @@ impl Type {
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn is_generic(&self) -> bool {
|
crate fn is_generic(&self) -> bool {
|
||||||
match *self {
|
match self {
|
||||||
ResolvedPath { is_generic, .. } => is_generic,
|
ResolvedPath { path, .. } => path.is_generic(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1994,6 +1989,15 @@ impl Path {
|
||||||
String::from(if self.global { "::" } else { "" })
|
String::from(if self.global { "::" } else { "" })
|
||||||
+ &self.segments.iter().map(|s| s.name.to_string()).collect::<Vec<_>>().join("::")
|
+ &self.segments.iter().map(|s| s.name.to_string()).collect::<Vec<_>>().join("::")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
crate fn is_generic(&self) -> bool {
|
||||||
|
match self.res {
|
||||||
|
Res::SelfTy(..) if self.segments.len() != 1 => true,
|
||||||
|
Res::Def(DefKind::TyParam, _) if self.segments.len() != 1 => true,
|
||||||
|
Res::Def(DefKind::AssocTy, _) => true,
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
|
|
|
@ -159,9 +159,7 @@ pub(super) fn external_path(
|
||||||
|
|
||||||
crate fn strip_type(ty: Type) -> Type {
|
crate fn strip_type(ty: Type) -> Type {
|
||||||
match ty {
|
match ty {
|
||||||
Type::ResolvedPath { path, did, is_generic } => {
|
Type::ResolvedPath { path, did } => Type::ResolvedPath { path: strip_path(&path), did },
|
||||||
Type::ResolvedPath { path: strip_path(&path), did, is_generic }
|
|
||||||
}
|
|
||||||
Type::DynTrait(mut bounds, lt) => {
|
Type::DynTrait(mut bounds, lt) => {
|
||||||
let first = bounds.remove(0);
|
let first = bounds.remove(0);
|
||||||
let stripped_trait = strip_type(first.trait_);
|
let stripped_trait = strip_type(first.trait_);
|
||||||
|
@ -404,19 +402,15 @@ crate fn print_const_expr(tcx: TyCtxt<'_>, body: hir::BodyId) -> String {
|
||||||
crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
|
crate fn resolve_type(cx: &mut DocContext<'_>, path: Path) -> Type {
|
||||||
debug!("resolve_type({:?})", path);
|
debug!("resolve_type({:?})", path);
|
||||||
|
|
||||||
let is_generic = match path.res {
|
match path.res {
|
||||||
Res::PrimTy(p) => return Primitive(PrimitiveType::from(p)),
|
Res::PrimTy(p) => Primitive(PrimitiveType::from(p)),
|
||||||
Res::SelfTy(..) if path.segments.len() == 1 => {
|
Res::SelfTy(..) if path.segments.len() == 1 => Generic(kw::SelfUpper),
|
||||||
return Generic(kw::SelfUpper);
|
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => Generic(path.segments[0].name),
|
||||||
|
_ => {
|
||||||
|
let did = register_res(cx, path.res);
|
||||||
|
ResolvedPath { path, did }
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) if path.segments.len() == 1 => {
|
}
|
||||||
return Generic(path.segments[0].name);
|
|
||||||
}
|
|
||||||
Res::SelfTy(..) | Res::Def(DefKind::TyParam | DefKind::AssocTy, _) => true,
|
|
||||||
_ => false,
|
|
||||||
};
|
|
||||||
let did = register_res(cx, path.res);
|
|
||||||
ResolvedPath { path, did, is_generic }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crate fn get_auto_trait_and_blanket_impls(
|
crate fn get_auto_trait_and_blanket_impls(
|
||||||
|
|
|
@ -752,9 +752,9 @@ fn fmt_type<'cx>(
|
||||||
|
|
||||||
match *t {
|
match *t {
|
||||||
clean::Generic(name) => write!(f, "{}", name),
|
clean::Generic(name) => write!(f, "{}", name),
|
||||||
clean::ResolvedPath { did, ref path, is_generic } => {
|
clean::ResolvedPath { did, ref path } => {
|
||||||
// Paths like `T::Output` and `Self::Output` should be rendered with all segments.
|
// Paths like `T::Output` and `Self::Output` should be rendered with all segments.
|
||||||
resolved_path(f, did, path, is_generic, use_absolute, cx)
|
resolved_path(f, did, path, path.is_generic(), use_absolute, cx)
|
||||||
}
|
}
|
||||||
clean::DynTrait(ref bounds, ref lt) => {
|
clean::DynTrait(ref bounds, ref lt) => {
|
||||||
f.write_str("dyn ")?;
|
f.write_str("dyn ")?;
|
||||||
|
@ -825,28 +825,17 @@ fn fmt_type<'cx>(
|
||||||
hir::Mutability::Mut => "mut",
|
hir::Mutability::Mut => "mut",
|
||||||
hir::Mutability::Not => "const",
|
hir::Mutability::Not => "const",
|
||||||
};
|
};
|
||||||
match **t {
|
|
||||||
clean::Generic(_) | clean::ResolvedPath { is_generic: true, .. } => {
|
if matches!(**t, clean::Generic(_)) || t.is_generic() {
|
||||||
if f.alternate() {
|
let text = if f.alternate() {
|
||||||
primitive_link(
|
format!("*{} {:#}", m, t.print(cx))
|
||||||
f,
|
} else {
|
||||||
clean::PrimitiveType::RawPointer,
|
format!("*{} {}", m, t.print(cx))
|
||||||
&format!("*{} {:#}", m, t.print(cx)),
|
};
|
||||||
cx,
|
primitive_link(f, clean::PrimitiveType::RawPointer, &text, cx)
|
||||||
)
|
} else {
|
||||||
} else {
|
primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{} ", m), cx)?;
|
||||||
primitive_link(
|
fmt::Display::fmt(&t.print(cx), f)
|
||||||
f,
|
|
||||||
clean::PrimitiveType::RawPointer,
|
|
||||||
&format!("*{} {}", m, t.print(cx)),
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
primitive_link(f, clean::PrimitiveType::RawPointer, &format!("*{} ", m), cx)?;
|
|
||||||
fmt::Display::fmt(&t.print(cx), f)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clean::BorrowedRef { lifetime: ref l, mutability, type_: ref ty } => {
|
clean::BorrowedRef { lifetime: ref l, mutability, type_: ref ty } => {
|
||||||
|
|
|
@ -712,11 +712,10 @@ fn item_trait(w: &mut Buffer, cx: &Context<'_>, it: &clean::Item, t: &clean::Tra
|
||||||
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
|
let mut implementor_dups: FxHashMap<Symbol, (DefId, bool)> = FxHashMap::default();
|
||||||
for implementor in implementors {
|
for implementor in implementors {
|
||||||
match implementor.inner_impl().for_ {
|
match implementor.inner_impl().for_ {
|
||||||
clean::ResolvedPath { ref path, did, is_generic: false, .. }
|
clean::ResolvedPath { ref path, did, .. }
|
||||||
| clean::BorrowedRef {
|
| clean::BorrowedRef {
|
||||||
type_: box clean::ResolvedPath { ref path, did, is_generic: false, .. },
|
type_: box clean::ResolvedPath { ref path, did, .. }, ..
|
||||||
..
|
} if !path.is_generic() => {
|
||||||
} => {
|
|
||||||
let &mut (prev_did, ref mut has_duplicates) =
|
let &mut (prev_did, ref mut has_duplicates) =
|
||||||
implementor_dups.entry(path.last()).or_insert((did, false));
|
implementor_dups.entry(path.last()).or_insert((did, false));
|
||||||
if prev_did != did {
|
if prev_did != did {
|
||||||
|
@ -1410,11 +1409,12 @@ fn render_implementor(
|
||||||
// If there's already another implementor that has the same abridged name, use the
|
// If there's already another implementor that has the same abridged name, use the
|
||||||
// full path, for example in `std::iter::ExactSizeIterator`
|
// full path, for example in `std::iter::ExactSizeIterator`
|
||||||
let use_absolute = match implementor.inner_impl().for_ {
|
let use_absolute = match implementor.inner_impl().for_ {
|
||||||
clean::ResolvedPath { ref path, is_generic: false, .. }
|
clean::ResolvedPath { ref path, .. }
|
||||||
| clean::BorrowedRef {
|
| clean::BorrowedRef { type_: box clean::ResolvedPath { ref path, .. }, .. }
|
||||||
type_: box clean::ResolvedPath { ref path, is_generic: false, .. },
|
if !path.is_generic() =>
|
||||||
..
|
{
|
||||||
} => implementor_dups[&path.last()].1,
|
implementor_dups[&path.last()].1
|
||||||
|
}
|
||||||
_ => false,
|
_ => false,
|
||||||
};
|
};
|
||||||
render_impl(
|
render_impl(
|
||||||
|
|
|
@ -387,7 +387,7 @@ impl FromWithTcx<clean::Type> for Type {
|
||||||
fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
|
fn from_tcx(ty: clean::Type, tcx: TyCtxt<'_>) -> Self {
|
||||||
use clean::Type::*;
|
use clean::Type::*;
|
||||||
match ty {
|
match ty {
|
||||||
ResolvedPath { path, did, is_generic: _ } => Type::ResolvedPath {
|
ResolvedPath { path, did } => Type::ResolvedPath {
|
||||||
name: path.whole_name(),
|
name: path.whole_name(),
|
||||||
id: from_item_id(did.into()),
|
id: from_item_id(did.into()),
|
||||||
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
|
args: path.segments.last().map(|args| Box::new(args.clone().args.into_tcx(tcx))),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue