Rollup merge of #120999 - fmease:rustdoc-rm-instantiation-param, r=notriddle
rustdoc: replace `clean::InstantiationParam` with `clean::GenericArg` Probably better known as `SubstParam` (until #120958 which should've probably renamed it to `InstantiatedParam` but anyways). It doesn't make any sense to me why it should exist as a separate type. `GenericArg` is exactly what we want here anyways from a semantic perspective. Both have the same size btw. I also took the liberty of doing some drive-by cleanups.
This commit is contained in:
commit
2e98b27d94
3 changed files with 31 additions and 73 deletions
|
@ -254,16 +254,14 @@ fn clean_poly_trait_ref_with_bindings<'tcx>(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime {
|
fn clean_lifetime<'tcx>(lifetime: &hir::Lifetime, cx: &mut DocContext<'tcx>) -> Lifetime {
|
||||||
let def = cx.tcx.named_bound_var(lifetime.hir_id);
|
|
||||||
if let Some(
|
if let Some(
|
||||||
rbv::ResolvedArg::EarlyBound(node_id)
|
rbv::ResolvedArg::EarlyBound(did)
|
||||||
| rbv::ResolvedArg::LateBound(_, _, node_id)
|
| rbv::ResolvedArg::LateBound(_, _, did)
|
||||||
| rbv::ResolvedArg::Free(_, node_id),
|
| rbv::ResolvedArg::Free(_, did),
|
||||||
) = def
|
) = cx.tcx.named_bound_var(lifetime.hir_id)
|
||||||
|
&& let Some(lt) = cx.args.get(&did).and_then(|arg| arg.as_lt())
|
||||||
{
|
{
|
||||||
if let Some(lt) = cx.args.get(&node_id).and_then(|p| p.as_lt()).cloned() {
|
return lt.clone();
|
||||||
return lt;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Lifetime(lifetime.ident.name)
|
Lifetime(lifetime.ident.name)
|
||||||
}
|
}
|
||||||
|
@ -1791,12 +1789,12 @@ fn maybe_expand_private_type_alias<'tcx>(
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let Some(lt) = lifetime {
|
if let Some(lt) = lifetime {
|
||||||
let cleaned = if !lt.is_anonymous() {
|
let lt = if !lt.is_anonymous() {
|
||||||
clean_lifetime(lt, cx)
|
clean_lifetime(lt, cx)
|
||||||
} else {
|
} else {
|
||||||
Lifetime::elided()
|
Lifetime::elided()
|
||||||
};
|
};
|
||||||
args.insert(param.def_id.to_def_id(), InstantiationParam::Lifetime(cleaned));
|
args.insert(param.def_id.to_def_id(), GenericArg::Lifetime(lt));
|
||||||
}
|
}
|
||||||
indices.lifetimes += 1;
|
indices.lifetimes += 1;
|
||||||
}
|
}
|
||||||
|
@ -1805,44 +1803,20 @@ fn maybe_expand_private_type_alias<'tcx>(
|
||||||
let type_ = generic_args.args.iter().find_map(|arg| match arg {
|
let type_ = generic_args.args.iter().find_map(|arg| match arg {
|
||||||
hir::GenericArg::Type(ty) => {
|
hir::GenericArg::Type(ty) => {
|
||||||
if indices.types == j {
|
if indices.types == j {
|
||||||
return Some(ty);
|
return Some(*ty);
|
||||||
}
|
}
|
||||||
j += 1;
|
j += 1;
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
_ => None,
|
_ => None,
|
||||||
});
|
});
|
||||||
if let Some(ty) = type_ {
|
if let Some(ty) = type_.or(*default) {
|
||||||
args.insert(
|
args.insert(param.def_id.to_def_id(), GenericArg::Type(clean_ty(ty, cx)));
|
||||||
param.def_id.to_def_id(),
|
|
||||||
InstantiationParam::Type(clean_ty(ty, cx)),
|
|
||||||
);
|
|
||||||
} else if let Some(default) = *default {
|
|
||||||
args.insert(
|
|
||||||
param.def_id.to_def_id(),
|
|
||||||
InstantiationParam::Type(clean_ty(default, cx)),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
indices.types += 1;
|
indices.types += 1;
|
||||||
}
|
}
|
||||||
hir::GenericParamKind::Const { .. } => {
|
// FIXME(#82852): Instantiate const parameters.
|
||||||
let mut j = 0;
|
hir::GenericParamKind::Const { .. } => {}
|
||||||
let const_ = generic_args.args.iter().find_map(|arg| match arg {
|
|
||||||
hir::GenericArg::Const(ct) => {
|
|
||||||
if indices.consts == j {
|
|
||||||
return Some(ct);
|
|
||||||
}
|
|
||||||
j += 1;
|
|
||||||
None
|
|
||||||
}
|
|
||||||
_ => None,
|
|
||||||
});
|
|
||||||
if let Some(_) = const_ {
|
|
||||||
args.insert(param.def_id.to_def_id(), InstantiationParam::Constant);
|
|
||||||
}
|
|
||||||
// FIXME(const_generics_defaults)
|
|
||||||
indices.consts += 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2228,6 +2228,16 @@ pub(crate) enum GenericArg {
|
||||||
Infer,
|
Infer,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl GenericArg {
|
||||||
|
pub(crate) fn as_lt(&self) -> Option<&Lifetime> {
|
||||||
|
if let Self::Lifetime(lt) = self { Some(lt) } else { None }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn as_ty(&self) -> Option<&Type> {
|
||||||
|
if let Self::Type(ty) = self { Some(ty) } else { None }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
#[derive(Clone, PartialEq, Eq, Debug, Hash)]
|
||||||
pub(crate) enum GenericArgs {
|
pub(crate) enum GenericArgs {
|
||||||
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
|
AngleBracketed { args: Box<[GenericArg]>, bindings: ThinVec<TypeBinding> },
|
||||||
|
@ -2530,35 +2540,6 @@ pub(crate) enum TypeBindingKind {
|
||||||
Constraint { bounds: Vec<GenericBound> },
|
Constraint { bounds: Vec<GenericBound> },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The type, lifetime, or constant that a private type alias's parameter should be
|
|
||||||
/// replaced with when expanding a use of that type alias.
|
|
||||||
///
|
|
||||||
/// For example:
|
|
||||||
///
|
|
||||||
/// ```
|
|
||||||
/// type PrivAlias<T> = Vec<T>;
|
|
||||||
///
|
|
||||||
/// pub fn public_fn() -> PrivAlias<i32> { vec![] }
|
|
||||||
/// ```
|
|
||||||
///
|
|
||||||
/// `public_fn`'s docs will show it as returning `Vec<i32>`, since `PrivAlias` is private.
|
|
||||||
/// [`InstantiationParam`] is used to record that `T` should be mapped to `i32`.
|
|
||||||
pub(crate) enum InstantiationParam {
|
|
||||||
Type(Type),
|
|
||||||
Lifetime(Lifetime),
|
|
||||||
Constant,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl InstantiationParam {
|
|
||||||
pub(crate) fn as_ty(&self) -> Option<&Type> {
|
|
||||||
if let Self::Type(ty) = self { Some(ty) } else { None }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub(crate) fn as_lt(&self) -> Option<&Lifetime> {
|
|
||||||
if let Self::Lifetime(lt) = self { Some(lt) } else { None }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
|
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
|
||||||
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
|
||||||
mod size_asserts {
|
mod size_asserts {
|
||||||
|
|
|
@ -44,10 +44,13 @@ pub(crate) struct DocContext<'tcx> {
|
||||||
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
|
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
|
||||||
/// the same time.
|
/// the same time.
|
||||||
pub(crate) active_extern_traits: DefIdSet,
|
pub(crate) active_extern_traits: DefIdSet,
|
||||||
// The current set of parameter instantiations,
|
/// The current set of parameter instantiations for expanding type aliases at the HIR level.
|
||||||
// for expanding type aliases at the HIR level:
|
///
|
||||||
/// Table `DefId` of type, lifetime, or const parameter -> instantiated type, lifetime, or const
|
/// Maps from the `DefId` of a lifetime or type parameter to the
|
||||||
pub(crate) args: DefIdMap<clean::InstantiationParam>,
|
/// generic argument it's currently instantiated to in this context.
|
||||||
|
// FIXME(#82852): We don't record const params since we don't visit const exprs at all and
|
||||||
|
// therefore wouldn't use the corresp. generic arg anyway. Add support for them.
|
||||||
|
pub(crate) args: DefIdMap<clean::GenericArg>,
|
||||||
pub(crate) current_type_aliases: DefIdMap<usize>,
|
pub(crate) current_type_aliases: DefIdMap<usize>,
|
||||||
/// Table synthetic type parameter for `impl Trait` in argument position -> bounds
|
/// Table synthetic type parameter for `impl Trait` in argument position -> bounds
|
||||||
pub(crate) impl_trait_bounds: FxHashMap<ImplTraitParam, Vec<clean::GenericBound>>,
|
pub(crate) impl_trait_bounds: FxHashMap<ImplTraitParam, Vec<clean::GenericBound>>,
|
||||||
|
@ -87,7 +90,7 @@ impl<'tcx> DocContext<'tcx> {
|
||||||
/// the generic parameters for a type alias' RHS.
|
/// the generic parameters for a type alias' RHS.
|
||||||
pub(crate) fn enter_alias<F, R>(
|
pub(crate) fn enter_alias<F, R>(
|
||||||
&mut self,
|
&mut self,
|
||||||
args: DefIdMap<clean::InstantiationParam>,
|
args: DefIdMap<clean::GenericArg>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
f: F,
|
f: F,
|
||||||
) -> R
|
) -> R
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue