Skip to content

Commit 6c587fd

Browse files
committed
Auto merge of #165699 - lapla-cogito:issue_165186, r=fmease
rustdoc: Clean inlined assoc items in their own param-env When inlining associated items from another crate, `clean_middle_assoc_item` cleaned them in the param-env of their parent impl or trait. That param-env doesn't contain the item's own generic parameters, so normalizing a signature that mentions them could fail. In particular, normalizing a generic const item such as `[u8; P::<N>]`, where `N` is a const parameter of the associated item itself, made the new solver ICE because it couldn't find the type of `N` in the param-env. Fixes #165186
2 parents ac7bce9 + c290cf4 commit 6c587fd

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

‎src/librustdoc/clean/mod.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,7 +1385,7 @@ pub(crate) fn clean_impl_item<'tcx>(
13851385

13861386
pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocContext<'_>) -> Item {
13871387
let tcx = cx.tcx;
1388-
let kind = match assoc_item.kind {
1388+
let kind = cx.with_param_env(assoc_item.def_id, |cx| match assoc_item.kind {
13891389
ty::AssocKind::Const { .. } => {
13901390
let type_ = clean_middle_ty(
13911391
ty::Binder::dummy(
@@ -1573,7 +1573,7 @@ pub(crate) fn clean_middle_assoc_item(assoc_item: &ty::AssocItem, cx: &mut DocCo
15731573
type_: type_.map(|type_| AliasedType { type_, middle_type: None }),
15741574
}))
15751575
}
1576-
};
1576+
});
15771577

15781578
Item::from_def_id_and_parts(assoc_item.def_id, Some(assoc_item.name()), kind, tcx)
15791579
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//@ compile-flags: -Znext-solver=globally
2+
3+
#![feature(generic_const_items, gca_const_items, gca_macroless_args, gca_min_const_items)]
4+
5+
pub const P<const N: usize>: usize = N;
6+
7+
pub struct S;
8+
9+
impl S {
10+
pub fn f<const N: usize>(_: [u8; P::<N>]) {}
11+
12+
pub const C<const N: usize>: [u8; P::<N>] = [0; P::<N>];
13+
}
14+
15+
pub trait Tr {
16+
type T<const N: usize>;
17+
}
18+
19+
impl Tr for S {
20+
type T<const N: usize> = [u8; P::<N>];
21+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/165186
2+
3+
//@ aux-crate:gca_assoc_item_sig=gca-assoc-item-sig.rs
4+
//@ compile-flags: -Znext-solver=globally
5+
//@ edition:2021
6+
7+
#![crate_name = "user"]
8+
9+
//@ has 'user/struct.S.html'
10+
//@ has - '//*[@id="method.f"]' 'pub fn f<const N: usize>(_: [u8; gca_assoc_item_sig::P::<N>])'
11+
//@ has - '//*[@id="associatedconstant.C"]' \
12+
// 'pub const C<const N: usize>: [u8; gca_assoc_item_sig::P::<N>]'
13+
//@ has - '//*[@id="associatedtype.T"]' 'type T<const N: usize> = [u8; gca_assoc_item_sig::P::<N>]'
14+
pub use gca_assoc_item_sig::S;

0 commit comments

Comments
 (0)