@@ -207,8 +207,13 @@ pub(crate) fn clean_trait_ref_with_bindings<'tcx>(
207
207
span_bug!(cx.tcx.def_span(trait_ref.def_id()), "`TraitRef` had unexpected kind {kind:?}");
208
208
}
209
209
inline::record_extern_fqn(cx, trait_ref.def_id(), kind);
210
- let path =
211
- external_path(cx, trait_ref.def_id(), true, bindings, trait_ref.map_bound(|tr| tr.args));
210
+ let path = clean_middle_path(
211
+ cx,
212
+ trait_ref.def_id(),
213
+ true,
214
+ bindings,
215
+ trait_ref.map_bound(|tr| tr.args),
216
+ );
212
217
213
218
debug!(?trait_ref);
214
219
@@ -467,7 +472,7 @@ fn projection_to_path_segment<'tcx>(
467
472
PathSegment {
468
473
name: item.name,
469
474
args: GenericArgs::AngleBracketed {
470
- args: ty_args_to_args (
475
+ args: clean_middle_generic_args (
471
476
cx,
472
477
ty.map_bound(|ty| &ty.args[generics.parent_count..]),
473
478
false,
@@ -1903,7 +1908,7 @@ fn normalize<'tcx>(
1903
1908
1904
1909
fn clean_trait_object_lifetime_bound<'tcx>(
1905
1910
region: ty::Region<'tcx>,
1906
- container: Option<ContainerTy<'tcx>>,
1911
+ container: Option<ContainerTy<'_, ' tcx>>,
1907
1912
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
1908
1913
tcx: TyCtxt<'tcx>,
1909
1914
) -> Option<Lifetime> {
@@ -1932,7 +1937,7 @@ fn clean_trait_object_lifetime_bound<'tcx>(
1932
1937
1933
1938
fn can_elide_trait_object_lifetime_bound<'tcx>(
1934
1939
region: ty::Region<'tcx>,
1935
- container: Option<ContainerTy<'tcx>>,
1940
+ container: Option<ContainerTy<'_, ' tcx>>,
1936
1941
preds: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
1937
1942
tcx: TyCtxt<'tcx>,
1938
1943
) -> bool {
@@ -1979,21 +1984,22 @@ fn can_elide_trait_object_lifetime_bound<'tcx>(
1979
1984
}
1980
1985
1981
1986
#[derive(Debug)]
1982
- pub(crate) enum ContainerTy<'tcx> {
1987
+ pub(crate) enum ContainerTy<'a, ' tcx> {
1983
1988
Ref(ty::Region<'tcx>),
1984
1989
Regular {
1985
1990
ty: DefId,
1986
- args: ty::Binder<'tcx, &'tcx [ty::GenericArg<'tcx>]>,
1987
- has_self: bool,
1991
+ /// The arguments *have* to contain an arg for the self type if the corresponding generics
1992
+ /// contain a self type.
1993
+ args: ty::Binder<'tcx, &'a [ty::GenericArg<'tcx>]>,
1988
1994
arg: usize,
1989
1995
},
1990
1996
}
1991
1997
1992
- impl<'tcx> ContainerTy<'tcx> {
1998
+ impl<'tcx> ContainerTy<'_, ' tcx> {
1993
1999
fn object_lifetime_default(self, tcx: TyCtxt<'tcx>) -> ObjectLifetimeDefault<'tcx> {
1994
2000
match self {
1995
2001
Self::Ref(region) => ObjectLifetimeDefault::Arg(region),
1996
- Self::Regular { ty: container, args, has_self, arg: index } => {
2002
+ Self::Regular { ty: container, args, arg: index } => {
1997
2003
let (DefKind::Struct
1998
2004
| DefKind::Union
1999
2005
| DefKind::Enum
@@ -2006,14 +2012,7 @@ impl<'tcx> ContainerTy<'tcx> {
2006
2012
let generics = tcx.generics_of(container);
2007
2013
debug_assert_eq!(generics.parent_count, 0);
2008
2014
2009
- // If the container is a trait object type, the arguments won't contain the self type but the
2010
- // generics of the corresponding trait will. In such a case, offset the index by one.
2011
- // For comparison, if the container is a trait inside a bound, the arguments do contain the
2012
- // self type.
2013
- let offset =
2014
- if !has_self && generics.parent.is_none() && generics.has_self { 1 } else { 0 };
2015
- let param = generics.params[index + offset].def_id;
2016
-
2015
+ let param = generics.params[index].def_id;
2017
2016
let default = tcx.object_lifetime_default(param);
2018
2017
match default {
2019
2018
rbv::ObjectLifetimeDefault::Param(lifetime) => {
@@ -2045,7 +2044,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
2045
2044
bound_ty: ty::Binder<'tcx, Ty<'tcx>>,
2046
2045
cx: &mut DocContext<'tcx>,
2047
2046
parent_def_id: Option<DefId>,
2048
- container: Option<ContainerTy<'tcx>>,
2047
+ container: Option<ContainerTy<'_, ' tcx>>,
2049
2048
) -> Type {
2050
2049
let bound_ty = normalize(cx, bound_ty).unwrap_or(bound_ty);
2051
2050
match *bound_ty.skip_binder().kind() {
@@ -2096,12 +2095,12 @@ pub(crate) fn clean_middle_ty<'tcx>(
2096
2095
AdtKind::Enum => ItemType::Enum,
2097
2096
};
2098
2097
inline::record_extern_fqn(cx, did, kind);
2099
- let path = external_path (cx, did, false, ThinVec::new(), bound_ty.rebind(args));
2098
+ let path = clean_middle_path (cx, did, false, ThinVec::new(), bound_ty.rebind(args));
2100
2099
Type::Path { path }
2101
2100
}
2102
2101
ty::Foreign(did) => {
2103
2102
inline::record_extern_fqn(cx, did, ItemType::ForeignType);
2104
- let path = external_path (
2103
+ let path = clean_middle_path (
2105
2104
cx,
2106
2105
did,
2107
2106
false,
@@ -2132,7 +2131,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
2132
2131
let mut bounds = dids
2133
2132
.map(|did| {
2134
2133
let empty = ty::Binder::dummy(ty::GenericArgs::empty());
2135
- let path = external_path (cx, did, false, ThinVec::new(), empty);
2134
+ let path = clean_middle_path (cx, did, false, ThinVec::new(), empty);
2136
2135
inline::record_extern_fqn(cx, did, ItemType::Trait);
2137
2136
PolyTrait { trait_: path, generic_params: Vec::new() }
2138
2137
})
@@ -2171,7 +2170,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
2171
2170
.collect();
2172
2171
let late_bound_regions = late_bound_regions.into_iter().collect();
2173
2172
2174
- let path = external_path (cx, did, false, bindings, args);
2173
+ let path = clean_middle_path (cx, did, false, bindings, args);
2175
2174
bounds.insert(0, PolyTrait { trait_: path, generic_params: late_bound_regions });
2176
2175
2177
2176
DynTrait(bounds, lifetime)
@@ -2193,7 +2192,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
2193
2192
assoc: PathSegment {
2194
2193
name: cx.tcx.associated_item(def_id).name,
2195
2194
args: GenericArgs::AngleBracketed {
2196
- args: ty_args_to_args (
2195
+ args: clean_middle_generic_args (
2197
2196
cx,
2198
2197
alias_ty.map_bound(|ty| ty.args.as_slice()),
2199
2198
true,
@@ -2213,7 +2212,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
2213
2212
if cx.tcx.features().lazy_type_alias {
2214
2213
// Weak type alias `data` represents the `type X` in `type X = Y`. If we need `Y`,
2215
2214
// we need to use `type_of`.
2216
- let path = external_path (
2215
+ let path = clean_middle_path (
2217
2216
cx,
2218
2217
data.def_id,
2219
2218
false,
@@ -2243,7 +2242,8 @@ pub(crate) fn clean_middle_ty<'tcx>(
2243
2242
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => {
2244
2243
// If it's already in the same alias, don't get an infinite loop.
2245
2244
if cx.current_type_aliases.contains_key(&def_id) {
2246
- let path = external_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
2245
+ let path =
2246
+ clean_middle_path(cx, def_id, false, ThinVec::new(), bound_ty.rebind(args));
2247
2247
Type::Path { path }
2248
2248
} else {
2249
2249
*cx.current_type_aliases.entry(def_id).or_insert(0) += 1;
0 commit comments