-
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
Various fixes for const_trait_impl #89359
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// check-pass | ||
|
||
#![feature(const_trait_impl)] | ||
#![feature(const_fn_trait_bound)] | ||
#![feature(const_precise_live_drops)] | ||
|
||
const fn foo<T, E>(res: Result<T, E>) -> Option<T> where E: ~const Drop { | ||
match res { | ||
Ok(t) => Some(t), | ||
Err(_e) => None, | ||
} | ||
} | ||
|
||
pub struct Foo<T>(T); | ||
|
||
const fn baz<T: ~const Drop, E: ~const Drop>(res: Result<Foo<T>, Foo<E>>) -> Option<Foo<T>> { | ||
foo(res) | ||
} | ||
|
||
fn main() {} |
51 changes: 51 additions & 0 deletions
51
src/test/ui/rfc-2632-const-trait-impl/trait-default-body-stability.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,51 @@ | ||
// check-pass | ||
|
||
#![feature(staged_api)] | ||
#![feature(const_trait_impl)] | ||
#![feature(const_fn_trait_bound)] | ||
#![feature(const_t_try)] | ||
#![feature(const_try)] | ||
#![feature(try_trait_v2)] | ||
|
||
#![stable(feature = "foo", since = "1.0")] | ||
|
||
use std::ops::{ControlFlow, FromResidual, Try}; | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
pub struct T; | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
#[rustc_const_unstable(feature = "const_t_try", issue = "none")] | ||
impl const Try for T { | ||
type Output = T; | ||
type Residual = T; | ||
|
||
fn from_output(t: T) -> T { | ||
t | ||
} | ||
|
||
fn branch(self) -> ControlFlow<T, T> { | ||
ControlFlow::Continue(self) | ||
} | ||
} | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
#[rustc_const_unstable(feature = "const_t_try", issue = "none")] | ||
impl const FromResidual for T { | ||
fn from_residual(t: T) -> T { | ||
t | ||
} | ||
} | ||
|
||
#[stable(feature = "foo", since = "1.0")] | ||
pub trait Tr { | ||
#[default_method_body_is_const] | ||
#[stable(feature = "foo", since = "1.0")] | ||
fn bar() -> T { | ||
T? | ||
// Should be allowed. | ||
// Must enable unstable features to call this trait fn in const contexts. | ||
} | ||
} | ||
|
||
fn main() {} |
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.
So
~const Drop
bounds already are unlikeDrop
bounds in that the type does not have to actually implement theDrop
trait. Is this noted anywhere?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.
See https://internals.rust-lang.org/t/pre-rfc-revamped-const-trait-impl-aka-rfc-2632/15192#drop-5
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.
Ok. That makes sense now, seeing as there isn't really any other way to easily do it.