-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hide host effect params from docs #116670
Changes from all commits
20363f4
c4e61fa
8f2af7e
cfb6afa
6724f99
16f8396
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -521,7 +521,7 @@ fn clean_generic_param_def<'tcx>( | |
}, | ||
) | ||
} | ||
ty::GenericParamDefKind::Const { has_default, .. } => ( | ||
ty::GenericParamDefKind::Const { has_default, is_host_effect } => ( | ||
def.name, | ||
GenericParamDefKind::Const { | ||
ty: Box::new(clean_middle_ty( | ||
|
@@ -541,6 +541,7 @@ fn clean_generic_param_def<'tcx>( | |
)), | ||
false => None, | ||
}, | ||
is_host_effect, | ||
}, | ||
), | ||
}; | ||
|
@@ -597,6 +598,7 @@ fn clean_generic_param<'tcx>( | |
ty: Box::new(clean_ty(ty, cx)), | ||
default: default | ||
.map(|ct| Box::new(ty::Const::from_anon_const(cx.tcx, ct.def_id).to_string())), | ||
is_host_effect: cx.tcx.has_attr(param.def_id, sym::rustc_host), | ||
}, | ||
), | ||
}; | ||
|
@@ -2508,14 +2510,22 @@ fn clean_generic_args<'tcx>( | |
let args = generic_args | ||
.args | ||
.iter() | ||
.map(|arg| match arg { | ||
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => { | ||
GenericArg::Lifetime(clean_lifetime(*lt, cx)) | ||
} | ||
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), | ||
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)), | ||
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))), | ||
hir::GenericArg::Infer(_inf) => GenericArg::Infer, | ||
.filter_map(|arg| { | ||
Some(match arg { | ||
hir::GenericArg::Lifetime(lt) if !lt.is_anonymous() => { | ||
GenericArg::Lifetime(clean_lifetime(*lt, cx)) | ||
} | ||
hir::GenericArg::Lifetime(_) => GenericArg::Lifetime(Lifetime::elided()), | ||
hir::GenericArg::Type(ty) => GenericArg::Type(clean_ty(ty, cx)), | ||
// FIXME(effects): This will still emit `<true>` for non-const impls of const traits | ||
hir::GenericArg::Const(ct) | ||
if cx.tcx.has_attr(ct.value.def_id, sym::rustc_host) => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't hide host args like #[const_trait] pub trait Tr {}
impl Tr for () {} It gets rendered as |
||
{ | ||
return None; | ||
} | ||
hir::GenericArg::Const(ct) => GenericArg::Const(Box::new(clean_const(ct, cx))), | ||
hir::GenericArg::Infer(_inf) => GenericArg::Infer, | ||
}) | ||
}) | ||
.collect::<Vec<_>>() | ||
.into(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,6 +104,10 @@ pub(crate) fn ty_args_to_args<'tcx>( | |
arg: index, | ||
}), | ||
))), | ||
// FIXME(effects): this relies on the host effect being called `host`, which users could also name | ||
// their const generics. | ||
// FIXME(effects): this causes `host = true` and `host = false` generics to also be emitted. | ||
GenericArgKind::Const(ct) if let ty::ConstKind::Param(p) = ct.kind() && p.name == sym::host => None, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contrary to the HIR code path which filters out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're just looking for I only know of one case where this currently surfaces (without using (This would also surface with always-const bounds if they were introduced like |
||
GenericArgKind::Const(ct) => { | ||
Some(GenericArg::Const(Box::new(clean_middle_const(kind.rebind(ct), cx)))) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#![crate_name = "foo"] | ||
#![feature(effects, const_trait_impl)] | ||
|
||
#[const_trait] | ||
pub trait Tr { | ||
fn f(); | ||
} | ||
|
||
// @has foo/fn.g.html | ||
// @has - '//pre[@class="rust item-decl"]' 'pub const fn g<T: Tr>()' | ||
/// foo | ||
pub const fn g<T: ~const Tr>() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#![crate_name = "foo"] | ||
#![feature(effects)] | ||
|
||
// @has foo/fn.bar.html | ||
// @has - '//pre[@class="rust item-decl"]' 'pub const fn bar() -> ' | ||
/// foo | ||
pub const fn bar() -> usize { | ||
2 | ||
} | ||
|
||
// @has foo/struct.Foo.html | ||
// @has - '//*[@class="method"]' 'const fn new()' | ||
pub struct Foo(usize); | ||
|
||
impl Foo { | ||
pub const fn new() -> Foo { | ||
Foo(0) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![feature(effects)] | ||
|
||
pub const fn load() -> i32 { | ||
0 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Regression test for issue #116629. | ||
// Check that we render the correct generic params of const fn | ||
|
||
// aux-crate:const_fn=const-fn.rs | ||
// edition: 2021 | ||
#![crate_name = "user"] | ||
|
||
// @has user/fn.load.html | ||
// @has - '//pre[@class="rust item-decl"]' "pub const fn load() -> i32" | ||
pub use const_fn::load; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we re-encoding this here? Why not just call has_attr when needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this works if it comes from the HIR, but that's not always true, there is also a code path where the
is_host_effect
comes from aty::GenericParamDef
due to coming from a different crate. I don't have tests for this, but that's the reason why we encode this field inty::GenericParamDef
instead of just loading the information lazily.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can call tcx.has_attr on a foreign param, though, and we should be encoding attrs for foreign params too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought we were filtering out most of them.
@fee1-dead do you remember why we put the
is_host_effect
field onGenericParamDef
? did I ask for it just to callhas_attr
less?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[rustc_host]
used to be encoded in an earlier version of #115727 (84a4907) but since #115727 (comment) it no longer is.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We currently don't encode attributes on const generics params, and IIRC I added the field for that purpose