Skip to content

Commit

Permalink
Use correct param env when building and cleaning items in librustdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Feb 5, 2024
1 parent 6c9a64f commit c80c836
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 24 deletions.
56 changes: 38 additions & 18 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,37 +65,49 @@ pub(crate) fn try_inline(
let kind = match res {
Res::Def(DefKind::Trait, did) => {
record_extern_fqn(cx, did, ItemType::Trait);
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TraitItem(Box::new(build_external_trait(cx, did)))
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TraitItem(Box::new(build_external_trait(cx, did)))
})
}
Res::Def(DefKind::Fn, did) => {
record_extern_fqn(cx, did, ItemType::Function);
clean::FunctionItem(build_external_function(cx, did))
cx.with_param_env(did, |cx| clean::FunctionItem(build_external_function(cx, did)))
}
Res::Def(DefKind::Struct, did) => {
record_extern_fqn(cx, did, ItemType::Struct);
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::StructItem(build_struct(cx, did))
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::StructItem(build_struct(cx, did))
})
}
Res::Def(DefKind::Union, did) => {
record_extern_fqn(cx, did, ItemType::Union);
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::UnionItem(build_union(cx, did))
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::UnionItem(build_union(cx, did))
})
}
Res::Def(DefKind::TyAlias, did) => {
record_extern_fqn(cx, did, ItemType::TypeAlias);
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TypeAliasItem(build_type_alias(cx, did, &mut ret))
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::TypeAliasItem(build_type_alias(cx, did, &mut ret))
})
}
Res::Def(DefKind::Enum, did) => {
record_extern_fqn(cx, did, ItemType::Enum);
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::EnumItem(build_enum(cx, did))
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::EnumItem(build_enum(cx, did))
})
}
Res::Def(DefKind::ForeignTy, did) => {
record_extern_fqn(cx, did, ItemType::ForeignType);
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::ForeignTypeItem
cx.with_param_env(did, |cx| {
build_impls(cx, did, attrs_without_docs, &mut ret);
clean::ForeignTypeItem
})
}
// Never inline enum variants but leave them shown as re-exports.
Res::Def(DefKind::Variant, _) => return None,
Expand All @@ -108,11 +120,13 @@ pub(crate) fn try_inline(
}
Res::Def(DefKind::Static(_), did) => {
record_extern_fqn(cx, did, ItemType::Static);
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
cx.with_param_env(did, |cx| {
clean::StaticItem(build_static(cx, did, cx.tcx.is_mutable_static(did)))
})
}
Res::Def(DefKind::Const, did) => {
record_extern_fqn(cx, did, ItemType::Constant);
clean::ConstantItem(build_const(cx, did))
cx.with_param_env(did, |cx| clean::ConstantItem(build_const(cx, did)))
}
Res::Def(DefKind::Macro(kind), did) => {
let mac = build_macro(cx, did, name, import_def_id, kind);
Expand Down Expand Up @@ -313,7 +327,9 @@ pub(crate) fn build_impls(

// for each implementation of an item represented by `did`, build the clean::Item for that impl
for &did in tcx.inherent_impls(did).into_iter().flatten() {
build_impl(cx, did, attrs, ret);
cx.with_param_env(did, |cx| {
build_impl(cx, did, attrs, ret);
});
}

// This pretty much exists expressly for `dyn Error` traits that exist in the `alloc` crate.
Expand All @@ -326,7 +342,9 @@ pub(crate) fn build_impls(
let type_ =
if tcx.is_trait(did) { SimplifiedType::Trait(did) } else { SimplifiedType::Adt(did) };
for &did in tcx.incoherent_impls(type_).into_iter().flatten() {
build_impl(cx, did, attrs, ret);
cx.with_param_env(did, |cx| {
build_impl(cx, did, attrs, ret);
});
}
}
}
Expand Down Expand Up @@ -528,7 +546,9 @@ pub(crate) fn build_impl(
}

if let Some(did) = trait_.as_ref().map(|t| t.def_id()) {
record_extern_trait(cx, did);
cx.with_param_env(did, |cx| {
record_extern_trait(cx, did);
});
}

let (merged_attrs, cfg) = merge_attrs(cx, load_attrs(cx, did), attrs);
Expand Down
4 changes: 3 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,9 @@ fn clean_ty_alias_inner_type<'tcx>(
};

if !adt_def.did().is_local() {
inline::build_impls(cx, adt_def.did(), None, ret);
cx.with_param_env(adt_def.did(), |cx| {
inline::build_impls(cx, adt_def.did(), None, ret);
});
}

Some(if adt_def.is_enum() {
Expand Down
8 changes: 6 additions & 2 deletions src/librustdoc/clean/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,16 @@ pub(crate) fn build_deref_target_impls(
if let Some(prim) = target.primitive_type() {
let _prof_timer = tcx.sess.prof.generic_activity("build_primitive_inherent_impls");
for did in prim.impls(tcx).filter(|did| !did.is_local()) {
inline::build_impl(cx, did, None, ret);
cx.with_param_env(did, |cx| {
inline::build_impl(cx, did, None, ret);
});
}
} else if let Type::Path { path } = target {
let did = path.def_id();
if !did.is_local() {
inline::build_impls(cx, did, None, ret);
cx.with_param_env(did, |cx| {
inline::build_impls(cx, did, None, ret);
});
}
}
}
Expand Down
12 changes: 9 additions & 3 deletions src/librustdoc/passes/collect_trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
let _prof_timer = tcx.sess.prof.generic_activity("build_extern_trait_impls");
for &cnum in tcx.crates(()) {
for &impl_def_id in tcx.trait_impls_in_crate(cnum) {
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);
cx.with_param_env(impl_def_id, |cx| {
inline::build_impl(cx, impl_def_id, None, &mut new_items_external);
});
}
}
}
Expand All @@ -74,7 +76,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
);
parent = tcx.opt_parent(did);
}
inline::build_impl(cx, impl_def_id, Some((&attr_buf, None)), &mut new_items_local);
cx.with_param_env(impl_def_id, |cx| {
inline::build_impl(cx, impl_def_id, Some((&attr_buf, None)), &mut new_items_local);
});
attr_buf.clear();
}
}
Expand All @@ -83,7 +87,9 @@ pub(crate) fn collect_trait_impls(mut krate: Crate, cx: &mut DocContext<'_>) ->
for def_id in PrimitiveType::all_impls(tcx) {
// Try to inline primitive impls from other crates.
if !def_id.is_local() {
inline::build_impl(cx, def_id, None, &mut new_items_external);
cx.with_param_env(def_id, |cx| {
inline::build_impl(cx, def_id, None, &mut new_items_external);
});
}
}
for (prim, did) in PrimitiveType::primitive_locations(tcx) {
Expand Down

0 comments on commit c80c836

Please sign in to comment.