-
Notifications
You must be signed in to change notification settings - Fork 13k
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
const-stabilize HashMap/HashSet::with_hasher (+ required compiller changes) #118427
Closed
aDotInTheVoid
wants to merge
4
commits into
rust-lang:master
from
aDotInTheVoid:most-normal-stabilization
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ec12fea
const_eval: Allow std to stabley call const fns from deps.
aDotInTheVoid 9318d0a
const-stabilize HashMap/HashSet::with_hasher
aDotInTheVoid f4136eb
`any` -> `any_unmarked` for `rustc_allow_const_fn_unstable`
aDotInTheVoid ec8f6af
Add test for calling const-unstable function with `-Zforce-unstable-i…
aDotInTheVoid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![feature(staged_api)] | ||
#![stable(feature = "rust1", since = "1.0.0")] | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "const_identity", issue = "1")] | ||
pub const fn identity(x: i32) -> i32 { | ||
x | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// compile-flags: -Zforce-unstable-if-unmarked | ||
|
||
// This emulates a dep-of-std (eg hashbrown), that has const functions it | ||
// cannot mark as stable, and is build with force-unstable-if-unmarked. | ||
|
||
pub const fn do_something_else() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// aux-build:normal-const-fn.rs | ||
// check-pass | ||
#![crate_type = "lib"] | ||
#![feature(staged_api)] | ||
#![feature(rustc_attrs)] | ||
#![feature(rustc_private)] | ||
#![allow(internal_features)] | ||
#![feature(rustc_allow_const_fn_unstable)] | ||
#![stable(feature = "stable_feature", since = "1.0.0")] | ||
|
||
extern crate normal_const_fn; | ||
|
||
// This ensures std can call const functions in it's deps that don't have | ||
// access to rustc_const_stable annotations (and hense don't have a feature) | ||
// gate. | ||
|
||
#[rustc_const_stable(feature = "stable_feature", since = "1.0.0")] | ||
#[stable(feature = "stable_feature", since = "1.0.0")] | ||
#[rustc_allow_const_fn_unstable(any_unmarked)] | ||
pub const fn do_something() { | ||
normal_const_fn::do_something_else() | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/stability-attribute/const-unstable-from-unmarked.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// aux-build: const-unstable.rs | ||
// compile-flags: -Zforce-unstable-if-unmarked | ||
#![crate_type = "lib"] | ||
extern crate const_unstable; | ||
|
||
// Check that crates build with `-Zforce-unstable-if-unmarked` can't call | ||
// const-unstable functions, despite their functions sometimes being considerd | ||
// unstable. | ||
// | ||
// See https://github.com/rust-lang/rust/pull/118427#discussion_r1409914941 for | ||
// more context. | ||
|
||
pub const fn identity(x: i32) -> i32 { | ||
const_unstable::identity(x) | ||
//~^ ERROR `const_unstable::identity` is not yet stable as a const fn | ||
} |
10 changes: 10 additions & 0 deletions
10
tests/ui/stability-attribute/const-unstable-from-unmarked.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
error: `const_unstable::identity` is not yet stable as a const fn | ||
--> $DIR/const-unstable-from-unmarked.rs:14:5 | ||
| | ||
LL | const_unstable::identity(x) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: add `#![feature(const_identity)]` to the crate attributes to enable | ||
|
||
error: aborting due to 1 previous error | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
What I was asking is that this should error even if the crate has the feature flag enabled. So please add
feature(const_identity)
. I think then the error will disappear but we still want it to error (and requirerustc_allow_const_fn_unstable
to pass).That's how const-stable functions behave, and if we are going to allow calling unmarked functions from const-stable functions we should also apply this check to unmarked functions.
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.
Changing this breaks a load of stuff in
std
, as it has a load of these unmarked-unstable functions, and relies on them being able to call further const-unstable functions.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.
How bad would it be to mark those as
#[rustc_const_unstable("const_internals")]
or so?I'd really prefer us to guard against accidental stabilization of const features. It's way too easy to screw that up. I am not very concerned about specifically
HashMap::with_hasher
as that function does basically nothing, I am concerned about all the other const fn we will have in the future that call into hashbrown (or into other crates). We have to get this right.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.
It's 43 errors in core, can't see how many in std/alloc, so deffinatly doable if T-libs is fine with it.
I'll open a separate PR to do this (+ compiler changes), probably in a couple of weeks (exams).