From 506e7245ffef147b023d12c6f5fc210b4c73b609 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 11:54:04 +0200 Subject: [PATCH 1/9] We stopped using allow_internal_unstable a while ago --- src/stability.md | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/stability.md b/src/stability.md index cfb4efd89..4fce629cc 100644 --- a/src/stability.md +++ b/src/stability.md @@ -89,24 +89,28 @@ You can see an example of stabilizing a feature at [#75132](https://github.com/r ## allow_internal_unstable -Macros, compiler desugarings and `const fn`s expose their bodies to the call +Macros amd compiler desugarings expose their bodies to the call site. To work around not being able to use unstable things in the standard library's macros, there's the `#[allow_internal_unstable(feature1, feature2)]` -attribute that allows the given features to be used in stable macros or -`const fn`s. - -Note that `const fn`s are even more special in this regard. You can't just -allow any feature, the features need an implementation in -`qualify_min_const_fn.rs`. For example the `const_fn_union` feature gate allows -accessing fields of unions inside stable `const fn`s. The rules for when it's -ok to use such a feature gate are that behavior matches the runtime behavior of -the same code (see also [this blog post][blog]). This means that you may not -create a `const fn` that e.g. transmutes a memory address to an integer, +attribute that allows the given features to be used in stable macros. + +## rustc_allow_const_fn_unstable + +`const fn`, while not directly exposing their body to the world, are going to get +evaluated at compile time in stable crates. If their body does something const-unstable, +that could lock us into certain features indefinitely by accident. Thus no unstable const +features are allowed inside stable `const fn`. Sometimes we do know that a feature will get +stabilized, just not when or there is a stable (but e.g. runtime-slow) workaraound, so we +could always fall back to some stable version if we scrapped the unstable feature. + +You also need to take care to upload the `const fn` invariant that calling it at runtime and +compile-time needs to behave the same (see also [this blog post][blog]). This means that you +may not create a `const fn` that e.g. transmutes a memory address to an integer, because the addresses of things are nondeterministic and often unknown at compile-time. -Always ping @oli-obk, @RalfJung, and @Centril if you are adding more -`allow_internal_unstable` attributes to any `const fn` +Always ping @rust-lamg/const-eval if you are adding more +`rustc_allow_const_fn_unstable` attributes to any `const fn` ## staged_api From 34a6df6ea9f8a2184b9511d1b309c85a99e9c6b2 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 11:54:37 +0200 Subject: [PATCH 2/9] Update stability.md --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 4fce629cc..092a6020b 100644 --- a/src/stability.md +++ b/src/stability.md @@ -109,7 +109,7 @@ may not create a `const fn` that e.g. transmutes a memory address to an integer, because the addresses of things are nondeterministic and often unknown at compile-time. -Always ping @rust-lamg/const-eval if you are adding more +Always ping @rust-lamg/wg-const-eval if you are adding more `rustc_allow_const_fn_unstable` attributes to any `const fn` ## staged_api From e5ad3372b4b1f41cb655d1957d11adbb994ea423 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 12:01:08 +0200 Subject: [PATCH 3/9] Update stability.md --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 092a6020b..2c92dee67 100644 --- a/src/stability.md +++ b/src/stability.md @@ -89,7 +89,7 @@ You can see an example of stabilizing a feature at [#75132](https://github.com/r ## allow_internal_unstable -Macros amd compiler desugarings expose their bodies to the call +Macros and compiler desugarings expose their bodies to the call site. To work around not being able to use unstable things in the standard library's macros, there's the `#[allow_internal_unstable(feature1, feature2)]` attribute that allows the given features to be used in stable macros. From a16ae675e6c3236f8dc57a95443b349964556207 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 12:02:11 +0200 Subject: [PATCH 4/9] Update stability.md --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 2c92dee67..0b0e46106 100644 --- a/src/stability.md +++ b/src/stability.md @@ -103,7 +103,7 @@ features are allowed inside stable `const fn`. Sometimes we do know that a featu stabilized, just not when or there is a stable (but e.g. runtime-slow) workaraound, so we could always fall back to some stable version if we scrapped the unstable feature. -You also need to take care to upload the `const fn` invariant that calling it at runtime and +You also need to take care to uphold the `const fn` invariant that calling it at runtime and compile-time needs to behave the same (see also [this blog post][blog]). This means that you may not create a `const fn` that e.g. transmutes a memory address to an integer, because the addresses of things are nondeterministic and often unknown at From afa0f6d08e4fa95790ec2ff1dfa5aaace57b045c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 16:48:14 +0200 Subject: [PATCH 5/9] Update stability.md --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 0b0e46106..14a401fa0 100644 --- a/src/stability.md +++ b/src/stability.md @@ -109,7 +109,7 @@ may not create a `const fn` that e.g. transmutes a memory address to an integer, because the addresses of things are nondeterministic and often unknown at compile-time. -Always ping @rust-lamg/wg-const-eval if you are adding more +Always ping @rust-lang/wg-const-eval if you are adding more `rustc_allow_const_fn_unstable` attributes to any `const fn` ## staged_api From 50028a33854f234ef74e49d5ea1506193e833bed Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 16:59:09 +0200 Subject: [PATCH 6/9] Update src/stability.md Co-authored-by: Ralf Jung --- src/stability.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 14a401fa0..312339563 100644 --- a/src/stability.md +++ b/src/stability.md @@ -99,9 +99,13 @@ attribute that allows the given features to be used in stable macros. `const fn`, while not directly exposing their body to the world, are going to get evaluated at compile time in stable crates. If their body does something const-unstable, that could lock us into certain features indefinitely by accident. Thus no unstable const -features are allowed inside stable `const fn`. Sometimes we do know that a feature will get +features are allowed inside stable `const fn`. + +However, sometimes we do know that a feature will get stabilized, just not when or there is a stable (but e.g. runtime-slow) workaraound, so we could always fall back to some stable version if we scrapped the unstable feature. +In those cases, the rustc_allow_const_fn_unstable attribute can be used to allow some +unstable features in the body of a stable `const fn`. You also need to take care to uphold the `const fn` invariant that calling it at runtime and compile-time needs to behave the same (see also [this blog post][blog]). This means that you From 834bdcb6c472787d8f0f08e412d4023195502583 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 18:32:42 +0200 Subject: [PATCH 7/9] Update src/stability.md Co-authored-by: Yuki Okushi --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 312339563..ef256fccd 100644 --- a/src/stability.md +++ b/src/stability.md @@ -102,7 +102,7 @@ that could lock us into certain features indefinitely by accident. Thus no unsta features are allowed inside stable `const fn`. However, sometimes we do know that a feature will get -stabilized, just not when or there is a stable (but e.g. runtime-slow) workaraound, so we +stabilized, just not when or there is a stable (but e.g. runtime-slow) workaround, so we could always fall back to some stable version if we scrapped the unstable feature. In those cases, the rustc_allow_const_fn_unstable attribute can be used to allow some unstable features in the body of a stable `const fn`. From a9efa3b2c27ed6330c718c666b95e1d2d64e376c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 18:32:46 +0200 Subject: [PATCH 8/9] Update src/stability.md Co-authored-by: Yuki Okushi --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index ef256fccd..4dcc2903e 100644 --- a/src/stability.md +++ b/src/stability.md @@ -114,7 +114,7 @@ because the addresses of things are nondeterministic and often unknown at compile-time. Always ping @rust-lang/wg-const-eval if you are adding more -`rustc_allow_const_fn_unstable` attributes to any `const fn` +`rustc_allow_const_fn_unstable` attributes to any `const fn`. ## staged_api From 70db5089e9953ee8d86ed04cf1d65804499cf1cf Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Sat, 12 Jun 2021 23:16:27 +0200 Subject: [PATCH 9/9] Update src/stability.md Co-authored-by: Noah Lev --- src/stability.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/stability.md b/src/stability.md index 4dcc2903e..db5c57bba 100644 --- a/src/stability.md +++ b/src/stability.md @@ -102,7 +102,7 @@ that could lock us into certain features indefinitely by accident. Thus no unsta features are allowed inside stable `const fn`. However, sometimes we do know that a feature will get -stabilized, just not when or there is a stable (but e.g. runtime-slow) workaround, so we +stabilized, just not when, or there is a stable (but e.g. runtime-slow) workaround, so we could always fall back to some stable version if we scrapped the unstable feature. In those cases, the rustc_allow_const_fn_unstable attribute can be used to allow some unstable features in the body of a stable `const fn`.