Skip to content

Commit ab7d207

Browse files
Use correct param env when building and cleaning items in librustdoc
1 parent 623bd58 commit ab7d207

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed

src/librustdoc/clean/inline.rs

+38-18
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,49 @@ pub(crate) fn try_inline(
6565
let kind = match res {
6666
Res::Def(DefKind::Trait, did) => {
6767
record_extern_fqn(cx, did, ItemType::Trait);
68-
build_impls(cx, did, attrs_without_docs, &mut ret);
69-
clean::TraitItem(Box::new(build_external_trait(cx, did)))
68+
cx.with_param_env(did, |cx| {
69+
build_impls(cx, did, attrs_without_docs, &mut ret);
70+
clean::TraitItem(Box::new(build_external_trait(cx, did)))
71+
})
7072
}
7173
Res::Def(DefKind::Fn, did) => {
7274
record_extern_fqn(cx, did, ItemType::Function);
73-
clean::FunctionItem(build_external_function(cx, did))
75+
cx.with_param_env(did, |cx| clean::FunctionItem(build_external_function(cx, did)))
7476
}
7577
Res::Def(DefKind::Struct, did) => {
7678
record_extern_fqn(cx, did, ItemType::Struct);
77-
build_impls(cx, did, attrs_without_docs, &mut ret);
78-
clean::StructItem(build_struct(cx, did))
79+
cx.with_param_env(did, |cx| {
80+
build_impls(cx, did, attrs_without_docs, &mut ret);
81+
clean::StructItem(build_struct(cx, did))
82+
})
7983
}
8084
Res::Def(DefKind::Union, did) => {
8185
record_extern_fqn(cx, did, ItemType::Union);
82-
build_impls(cx, did, attrs_without_docs, &mut ret);
83-
clean::UnionItem(build_union(cx, did))
86+
cx.with_param_env(did, |cx| {
87+
build_impls(cx, did, attrs_without_docs, &mut ret);
88+
clean::UnionItem(build_union(cx, did))
89+
})
8490
}
8591
Res::Def(DefKind::TyAlias, did) => {
8692
record_extern_fqn(cx, did, ItemType::TypeAlias);
87-
build_impls(cx, did, attrs_without_docs, &mut ret);
88-
clean::TypeAliasItem(build_type_alias(cx, did, &mut ret))
93+
cx.with_param_env(did, |cx| {
94+
build_impls(cx, did, attrs_without_docs, &mut ret);
95+
clean::TypeAliasItem(build_type_alias(cx, did, &mut ret))
96+
})
8997
}
9098
Res::Def(DefKind::Enum, did) => {
9199
record_extern_fqn(cx, did, ItemType::Enum);
92-
build_impls(cx, did, attrs_without_docs, &mut ret);
93-
clean::EnumItem(build_enum(cx, did))
100+
cx.with_param_env(did, |cx| {
101+
build_impls(cx, did, attrs_without_docs, &mut ret);
102+
clean::EnumItem(build_enum(cx, did))
103+
})
94104
}
95105
Res::Def(DefKind::ForeignTy, did) => {
96106
record_extern_fqn(cx, did, ItemType::ForeignType);
97-
build_impls(cx, did, attrs_without_docs, &mut ret);
98-
clean::ForeignTypeItem
107+
cx.with_param_env(did, |cx| {
108+
build_impls(cx, did, attrs_without_docs, &mut ret);
109+
clean::ForeignTypeItem
110+
})
99111
}
100112
// Never inline enum variants but leave them shown as re-exports.
101113
Res::Def(DefKind::Variant, _) => return None,
@@ -108,11 +120,13 @@ pub(crate) fn try_inline(
108120
}
109121
Res::Def(DefKind::Static(_), did) => {
110122
record_extern_fqn(cx, did, ItemType::Static);
111-
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
123+
cx.with_param_env(did, |cx| {
124+
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
125+
})
112126
}
113127
Res::Def(DefKind::Const, did) => {
114128
record_extern_fqn(cx, did, ItemType::Constant);
115-
clean::ConstantItem(build_const(cx, did))
129+
cx.with_param_env(did, |cx| clean::ConstantItem(build_const(cx, did)))
116130
}
117131
Res::Def(DefKind::Macro(kind), did) => {
118132
let mac = build_macro(cx, did, name, import_def_id, kind);
@@ -313,7 +327,9 @@ pub(crate) fn build_impls(
313327

314328
// for each implementation of an item represented by `did`, build the clean::Item for that impl
315329
for &did in tcx.inherent_impls(did).into_iter().flatten() {
316-
build_impl(cx, did, attrs, ret);
330+
cx.with_param_env(did, |cx| {
331+
build_impl(cx, did, attrs, ret);
332+
});
317333
}
318334

319335
// This pretty much exists expressly for `dyn Error` traits that exist in the `alloc` crate.
@@ -326,7 +342,9 @@ pub(crate) fn build_impls(
326342
let type_ =
327343
if tcx.is_trait(did) { SimplifiedType::Trait(did) } else { SimplifiedType::Adt(did) };
328344
for &did in tcx.incoherent_impls(type_).into_iter().flatten() {
329-
build_impl(cx, did, attrs, ret);
345+
cx.with_param_env(did, |cx| {
346+
build_impl(cx, did, attrs, ret);
347+
});
330348
}
331349
}
332350
}
@@ -528,7 +546,9 @@ pub(crate) fn build_impl(
528546
}
529547

530548
if let Some(did) = trait_.as_ref().map(|t| t.def_id()) {
531-
record_extern_trait(cx, did);
549+
cx.with_param_env(did, |cx| {
550+
record_extern_trait(cx, did);
551+
});
532552
}
533553

534554
let (merged_attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs);

src/librustdoc/clean/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -947,7 +947,9 @@ fn clean_ty_alias_inner_type<'tcx>(
947947
};
948948

949949
if !adt_def.did().is_local() {
950-
inline::build_impls(cx, adt_def.did(), None, ret);
950+
cx.with_param_env(adt_def.did(), |cx| {
951+
inline::build_impls(cx, adt_def.did(), None, ret);
952+
});
951953
}
952954

953955
Some(if adt_def.is_enum() {

src/librustdoc/clean/utils.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,16 @@ pub(crate) fn build_deref_target_impls(
295295
if let Some(prim) = target.primitive_type() {
296296
let _prof_timer = tcx.sess.prof.generic_activity("build_primitive_inherent_impls");
297297
for did in prim.impls(tcx).filter(|did| !did.is_local()) {
298-
inline::build_impl(cx, did, None, ret);
298+
cx.with_param_env(did, |cx| {
299+
inline::build_impl(cx, did, None, ret);
300+
});
299301
}
300302
} else if let Type::Path { path } = target {
301303
let did = path.def_id();
302304
if !did.is_local() {
303-
inline::build_impls(cx, did, None, ret);
305+
cx.with_param_env(did, |cx| {
306+
inline::build_impls(cx, did, None, ret);
307+
});
304308
}
305309
}
306310
}

src/librustdoc/passes/collect_trait_impls.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
4949
let _prof_timer = tcx.sess.prof.generic_activity("build_extern_trait_impls");
5050
for &cnum in tcx.crates(()) {
5151
for &impl_def_id in tcx.trait_impls_in_crate(cnum) {
52-
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);
52+
cx.with_param_env(impl_def_id, |cx| {
53+
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);
54+
});
5355
}
5456
}
5557
}
@@ -74,7 +76,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
7476
);
7577
parent = tcx.opt_parent(did);
7678
}
77-
inline::build_impl(cx, impl_def_id, Some((&attr_buf, None)), &mut new_items_local);
79+
cx.with_param_env(impl_def_id, |cx| {
80+
inline::build_impl(cx, impl_def_id, Some((&attr_buf, None)), &mut new_items_local);
81+
});
7882
attr_buf.clear();
7983
}
8084
}
@@ -83,7 +87,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
8387
for def_id in PrimitiveType::all_impls(tcx) {
8488
// Try to inline primitive impls from other crates.
8589
if !def_id.is_local() {
86-
inline::build_impl(cx, def_id, None, &mut new_items_external);
90+
cx.with_param_env(def_id, |cx| {
91+
inline::build_impl(cx, def_id, None, &mut new_items_external);
92+
});
8793
}
8894
}
8995
for (prim, did) in PrimitiveType::primitive_locations(tcx) {

0 commit comments

Comments
 (0)