Skip to content

Commit 37c8feb

Browse files
committed
rustdoc: properly elide cross-crate host effect args
1 parent ffb7ed9 commit 37c8feb

File tree

8 files changed

+53
-21
lines changed

8 files changed

+53
-21
lines changed

src/librustdoc/clean/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2534,7 +2534,8 @@ fn clean_generic_args<'tcx>(
25342534
}
25352535
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
25362536
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
2537-
// FIXME(effects): This will still emit `<true>` for non-const impls of const traits
2537+
// Checking for `#[rustc_host]` on the `AnonConst` not only accounts for the case
2538+
// where the argument is `host` but for all possible cases (e.g., `true`, `false`).
25382539
hir::GenericArg::Const(ct)
25392540
if cx.tcx.has_attr(ct.value.def_id, sym::rustc_host) =>
25402541
{

src/librustdoc/clean/utils.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ pub(crate) fn ty_args_to_args<'tcx>(
124124
)))
125125
}
126126
GenericArgKind::Const(ct) => {
127-
// FIXME(effects): this relies on the host effect being called `host`, which users could also name
128-
// their const generics.
129-
// FIXME(effects): this causes `host = true` and `host = false` generics to also be emitted.
130-
if let ty::ConstKind::Param(p) = ct.kind()
131-
&& p.name == sym::host
127+
if let ty::GenericParamDefKind::Const { is_host_effect: true, .. } = params[index].kind
132128
{
133129
return None;
134130
}

tests/rustdoc/const-effect-param.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Check that we don't render host effect parameters & arguments.
2+
13
#![crate_name = "foo"]
24
#![feature(effects, const_trait_impl)]
35

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(effects, const_trait_impl)]
2+
3+
#[const_trait]
4+
pub trait Resource {}
5+
6+
impl Resource for () {}
7+
8+
pub const fn load<R: ~const Resource>() -> i32 {
9+
0
10+
}
11+
12+
pub const fn lock<R: Resource>() {}
13+
14+
#[allow(non_upper_case_globals)]
15+
pub trait Clash<const host: u64> {}
16+
17+
#[allow(non_upper_case_globals)]
18+
pub const fn clash<T: Clash<host>, const host: u64>() {}

tests/rustdoc/inline_cross/auxiliary/const-fn.rs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub use const_effect_param::*;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Regression test for issue #116629.
2+
// Check that we don't render host effect parameters & arguments.
3+
4+
// aux-crate:const_effect_param=const-effect-param.rs
5+
// edition: 2021
6+
#![crate_name = "user"]
7+
8+
// Don't render the host param on `load` and the host arg `host` passed to `Resource`.
9+
// @has user/fn.load.html
10+
// @has - '//pre[@class="rust item-decl"]' "pub const fn load<R>() -> i32\
11+
// where \
12+
// R: Resource"
13+
pub use const_effect_param::load;
14+
15+
// Don't render the host arg `true` passed to `Resource`.
16+
// @has user/fn.lock.html
17+
// @has - '//pre[@class="rust item-decl"]' "pub const fn lock<R>()\
18+
// where \
19+
// R: Resource"
20+
pub use const_effect_param::lock;
21+
22+
// Regression test for an issue introduced in PR #116670.
23+
// Don't hide the const param `host` since it actually isn't the host effect param.
24+
// @has user/fn.clash.html
25+
// @has - '//pre[@class="rust item-decl"]' \
26+
// "pub const fn clash<T, const host: u64>()\
27+
// where \
28+
// T: Clash<host>"
29+
pub use const_effect_param::clash;

tests/rustdoc/inline_cross/const-fn.rs

-10
This file was deleted.

0 commit comments

Comments
 (0)