-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Allow trait methods to be called on concrete types in a const context #68847
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
62ff11f
Add `is_const_impl_raw` query
ecstatic-morse 3e0b060
Const-check functions in a `const` impl
ecstatic-morse 5e422ef
Remove "not yet implemented" warning
ecstatic-morse 7a019b1
Check for trait methods on concrete types in const checking
ecstatic-morse 323ff19
Add tests for calling trait methods on concrete types
ecstatic-morse d6d6d25
Split const trait method test and impl `ops::Add`
ecstatic-morse 70f7879
Ensure const impl cannot coexist with non-const impl
ecstatic-morse 0a5abca
Use early return when forbidding unstable attrs
ecstatic-morse 8e7609b
Propagate `rustc_const_unstable` to children
ecstatic-morse 4992eb2
Test `rustc_const_unstable` on trait fns
ecstatic-morse c8f0abb
Add ignored test for associated types in const impl
ecstatic-morse 9a36824
Remove outdated FIXME
ecstatic-morse 160e630
Add passing test for `Add` on generic struct
ecstatic-morse cb81712
Make `fn_queries` helpers module-private
ecstatic-morse 5f06ce2
Prevent const trait methods from being marked stable
ecstatic-morse 19801b1
Update tests
ecstatic-morse 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
Test
rustc_const_unstable
on trait fns
- Loading branch information
commit 4992eb2c6fab0c7eb4a841385607723620a38cf6
There are no files selected for viewing
This file contains hidden or 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,33 @@ | ||
#![allow(incomplete_features)] | ||
#![feature(allow_internal_unstable)] | ||
#![feature(const_add)] | ||
#![feature(const_trait_impl)] | ||
#![feature(staged_api)] | ||
|
||
pub struct Int(i32); | ||
|
||
#[rustc_const_unstable(feature = "const_add", issue = "none")] | ||
impl const std::ops::Add for Int { | ||
type Output = Self; | ||
|
||
fn add(self, rhs: Self) -> Self { | ||
Int(self.0 + rhs.0) | ||
} | ||
} | ||
|
||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_stable(feature = "rust1", since = "1.0.0")] | ||
pub const fn foo() -> Int { | ||
Int(1i32) + Int(2i32) | ||
//~^ ERROR can only call other `const fn` within a `const fn` | ||
} | ||
|
||
// ok | ||
#[stable(feature = "rust1", since = "1.0.0")] | ||
#[rustc_const_unstable(feature = "bar", issue = "none")] | ||
pub const fn bar() -> Int { | ||
Int(1i32) + Int(2i32) | ||
} | ||
|
||
|
||
fn main() {} |
This file contains hidden or 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,12 @@ | ||
error[E0723]: can only call other `const fn` within a `const fn`, but `const <Int as std::ops::Add>::add` is not stable as `const fn` | ||
--> $DIR/stability.rs:21:5 | ||
| | ||
LL | Int(1i32) + Int(2i32) | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: for more information, see issue https://github.com/rust-lang/rust/issues/57563 | ||
= help: add `#![feature(const_fn)]` to the crate attributes to enable | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0723`. |
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.
Uh oh!
There was an error while loading. Please reload this page.