Skip to content

Commit 193e8a1

Browse files
committed
Auto merge of rust-lang#116670 - oli-obk:host_docs, r=fmease
Hide host effect params from docs addresses (only on nightly, needs backport) rust-lang#116629 r? `@compiler-errors` cc `@GuillaumeGomez` `@fee1-dead`
2 parents 34bc571 + 16f8396 commit 193e8a1

File tree

10 files changed

+84
-21
lines changed

10 files changed

+84
-21
lines changed

src/librustdoc/clean/mod.rs

+19-9
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ fn clean_generic_param_def<'tcx>(
521521
},
522522
)
523523
}
524-
ty::GenericParamDefKind::Const { has_default, .. } => (
524+
ty::GenericParamDefKind::Const { has_default, is_host_effect } => (
525525
def.name,
526526
GenericParamDefKind::Const {
527527
ty: Box::new(clean_middle_ty(
@@ -541,6 +541,7 @@ fn clean_generic_param_def<'tcx>(
541541
)),
542542
false => None,
543543
},
544+
is_host_effect,
544545
},
545546
),
546547
};
@@ -597,6 +598,7 @@ fn clean_generic_param<'tcx>(
597598
ty: Box::new(clean_ty(ty, cx)),
598599
default: default
599600
.map(|ct| Box::new(ty::Const::from_anon_const(cx.tcx, ct.def_id).to_string())),
601+
is_host_effect: cx.tcx.has_attr(param.def_id, sym::rustc_host),
600602
},
601603
),
602604
};
@@ -2508,14 +2510,22 @@ fn clean_generic_args<'tcx>(
25082510
let args = generic_args
25092511
.args
25102512
.iter()
2511-
.map(|arg| match arg {
2512-
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
2513-
GenericArg::Lifetime(clean_lifetime(*lt, cx))
2514-
}
2515-
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
2516-
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
2517-
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
2518-
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
2513+
.filter_map(|arg| {
2514+
Some(match arg {
2515+
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => {
2516+
GenericArg::Lifetime(clean_lifetime(*lt, cx))
2517+
}
2518+
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()),
2519+
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)),
2520+
// FIXME(effects): This will still emit `<true>` for non-const impls of const traits
2521+
hir::GenericArg::Const(ct)
2522+
if cx.tcx.has_attr(ct.value.def_id, sym::rustc_host) =>
2523+
{
2524+
return None;
2525+
}
2526+
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))),
2527+
hir::GenericArg::Infer(_inf) => GenericArg::Infer,
2528+
})
25192529
})
25202530
.collect::<Vec<_>>()
25212531
.into();

src/librustdoc/clean/types.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ impl WherePredicate {
13061306
pub(crate) enum GenericParamDefKind {
13071307
Lifetime { outlives: Vec<Lifetime> },
13081308
Type { did: DefId, bounds: Vec<GenericBound>, default: Option<Box<Type>>, synthetic: bool },
1309-
Const { ty: Box<Type>, default: Option<Box<String>> },
1309+
Const { ty: Box<Type>, default: Option<Box<String>>, is_host_effect: bool },
13101310
}
13111311

13121312
impl GenericParamDefKind {
@@ -1326,9 +1326,10 @@ impl GenericParamDef {
13261326
Self { name, kind: GenericParamDefKind::Lifetime { outlives: Vec::new() } }
13271327
}
13281328

1329-
pub(crate) fn is_synthetic_type_param(&self) -> bool {
1329+
pub(crate) fn is_synthetic_param(&self) -> bool {
13301330
match self.kind {
1331-
GenericParamDefKind::Lifetime { .. } | GenericParamDefKind::Const { .. } => false,
1331+
GenericParamDefKind::Lifetime { .. } => false,
1332+
GenericParamDefKind::Const { is_host_effect, .. } => is_host_effect,
13321333
GenericParamDefKind::Type { synthetic, .. } => synthetic,
13331334
}
13341335
}

src/librustdoc/clean/utils.rs

+4
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ pub(crate) fn ty_args_to_args<'tcx>(
104104
arg: index,
105105
}),
106106
))),
107+
// FIXME(effects): this relies on the host effect being called `host`, which users could also name
108+
// their const generics.
109+
// FIXME(effects): this causes `host = true` and `host = false` generics to also be emitted.
110+
GenericArgKind::Const(ct) if let ty::ConstKind::Param(p) = ct.kind() && p.name == sym::host => None,
107111
GenericArgKind::Const(ct) => {
108112
Some(GenericArg::Const(Box::new(clean_middle_const(kind.rebind(ct), cx))))
109113
}

src/librustdoc/html/format.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ impl clean::Generics {
250250
cx: &'a Context<'tcx>,
251251
) -> impl fmt::Display + 'a + Captures<'tcx> {
252252
display_fn(move |f| {
253-
let mut real_params =
254-
self.params.iter().filter(|p| !p.is_synthetic_type_param()).peekable();
253+
let mut real_params = self.params.iter().filter(|p| !p.is_synthetic_param()).peekable();
255254
if real_params.peek().is_none() {
256255
return Ok(());
257256
}

src/librustdoc/json/conversions.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ impl FromWithTcx<clean::GenericParamDefKind> for GenericParamDefKind {
453453
default: default.map(|x| (*x).into_tcx(tcx)),
454454
synthetic,
455455
},
456-
Const { ty, default } => GenericParamDefKind::Const {
456+
Const { ty, default, is_host_effect: _ } => GenericParamDefKind::Const {
457457
type_: (*ty).into_tcx(tcx),
458458
default: default.map(|x| *x),
459459
},
@@ -491,12 +491,14 @@ impl FromWithTcx<clean::WherePredicate> for WherePredicate {
491491
default: default.map(|ty| (*ty).into_tcx(tcx)),
492492
synthetic,
493493
},
494-
clean::GenericParamDefKind::Const { ty, default } => {
495-
GenericParamDefKind::Const {
496-
type_: (*ty).into_tcx(tcx),
497-
default: default.map(|d| *d),
498-
}
499-
}
494+
clean::GenericParamDefKind::Const {
495+
ty,
496+
default,
497+
is_host_effect: _,
498+
} => GenericParamDefKind::Const {
499+
type_: (*ty).into_tcx(tcx),
500+
default: default.map(|d| *d),
501+
},
500502
};
501503
GenericParamDef { name, kind }
502504
})

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#![feature(array_methods)]
77
#![feature(assert_matches)]
88
#![feature(box_patterns)]
9+
#![feature(if_let_guard)]
910
#![feature(impl_trait_in_assoc_type)]
1011
#![feature(iter_intersperse)]
1112
#![feature(lazy_cell)]

tests/rustdoc/const-effect-param.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#![crate_name = "foo"]
2+
#![feature(effects, const_trait_impl)]
3+
4+
#[const_trait]
5+
pub trait Tr {
6+
fn f();
7+
}
8+
9+
// @has foo/fn.g.html
10+
// @has - '//pre[@class="rust item-decl"]' 'pub const fn g<T: Tr>()'
11+
/// foo
12+
pub const fn g<T: ~const Tr>() {}

tests/rustdoc/const-fn-effects.rs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![crate_name = "foo"]
2+
#![feature(effects)]
3+
4+
// @has foo/fn.bar.html
5+
// @has - '//pre[@class="rust item-decl"]' 'pub const fn bar() -> '
6+
/// foo
7+
pub const fn bar() -> usize {
8+
2
9+
}
10+
11+
// @has foo/struct.Foo.html
12+
// @has - '//*[@class="method"]' 'const fn new()'
13+
pub struct Foo(usize);
14+
15+
impl Foo {
16+
pub const fn new() -> Foo {
17+
Foo(0)
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#![feature(effects)]
2+
3+
pub const fn load() -> i32 {
4+
0
5+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Regression test for issue #116629.
2+
// Check that we render the correct generic params of const fn
3+
4+
// aux-crate:const_fn=const-fn.rs
5+
// edition: 2021
6+
#![crate_name = "user"]
7+
8+
// @has user/fn.load.html
9+
// @has - '//pre[@class="rust item-decl"]' "pub const fn load() -> i32"
10+
pub use const_fn::load;

0 commit comments

Comments
 (0)