Skip to content

Commit b138631

Browse files
authored
Unrolled build for #160295
Rollup merge of #160295 - Colepng:main, r=GuillaumeGomez Fix rustdoc ICE when checking if a generic arg can be elided Fixes #133637 The `param_at` call expects a index into the full generics list, while index is generated only from the children. I also noticed a call to `skip_norm_wip` so I replaced that with `skip_normalization` I have one question about adding the regression test, should it live under rustdoc-ui or rustdoc-ui/issue. I will add it later today. @fmease
2 parents c9ff496 + 569e0bc commit b138631

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

src/librustdoc/clean/utils.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,18 +117,22 @@ pub(crate) fn clean_middle_generic_args<'tcx>(
117117
};
118118

119119
let mut elision_has_failed_once_before = false;
120+
121+
// Calculates where the parent trait's generic parameters end
122+
let index_offset = generics.count() - args.len();
120123
let clean_arg = |(index, &arg): (usize, &ty::GenericArg<'tcx>)| {
121124
// Elide the self type.
122125
if has_self && index == 0 {
123126
return None;
124127
}
125128

126-
let param = generics.param_at(index, cx.tcx);
129+
// Skips over the parent trait's generic parameters
130+
let param = generics.param_at(index + index_offset, cx.tcx);
127131
let arg = ty::Binder::bind_with_vars(arg, bound_vars);
128132

129133
// Elide arguments that coincide with their default.
130134
if !elision_has_failed_once_before && let Some(default) = param.default_value(cx.tcx) {
131-
let default = default.instantiate(cx.tcx, args.as_ref()).skip_norm_wip();
135+
let default = default.instantiate(cx.tcx, args.as_ref()).skip_normalization();
132136
if can_elide_generic_arg(arg, arg.rebind(default)) {
133137
return None;
134138
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
// https://github.com/rust-lang/rust/issues/133637
3+
#![crate_name="foo"]
4+
5+
// Regression test for issue #133637. Previously we would index into the flattened generics list
6+
// with the children generic indexes. This resulted in an ICE when debug assertions were on.
7+
8+
trait Trait<Default = ()> {
9+
type Type<'a, 'b>;
10+
}
11+
12+
type Type<T> = <T as Trait>::Type<'static, 'static>;

0 commit comments

Comments
 (0)