-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Allow impl ~const Trait
opaque types
#105725
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
bors
merged 2 commits into
rust-lang:master
from
fee1-dead-contrib:allow-impl-const-trait
Dec 16, 2022
Merged
Changes from all commits
Commits
Show all changes
2 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 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
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,55 @@ | ||
// check-pass | ||
#![allow(incomplete_features)] | ||
#![feature( | ||
associated_type_bounds, | ||
const_trait_impl, | ||
const_cmp, | ||
return_position_impl_trait_in_trait, | ||
)] | ||
|
||
use std::marker::Destruct; | ||
|
||
const fn cmp(a: &impl ~const PartialEq) -> bool { | ||
a == a | ||
} | ||
|
||
const fn wrap(x: impl ~const PartialEq + ~const Destruct) | ||
-> impl ~const PartialEq + ~const Destruct | ||
{ | ||
x | ||
} | ||
|
||
#[const_trait] | ||
trait Foo { | ||
fn huh() -> impl ~const PartialEq + ~const Destruct + Copy; | ||
} | ||
|
||
impl const Foo for () { | ||
fn huh() -> impl ~const PartialEq + ~const Destruct + Copy { | ||
123 | ||
} | ||
} | ||
|
||
const _: () = { | ||
assert!(cmp(&0xDEADBEEFu32)); | ||
assert!(cmp(&())); | ||
assert!(wrap(123) == wrap(123)); | ||
assert!(wrap(123) != wrap(456)); | ||
let x = <() as Foo>::huh(); | ||
assert!(x == x); | ||
}; | ||
|
||
#[const_trait] | ||
trait T {} | ||
struct S; | ||
impl const T for S {} | ||
|
||
const fn rpit() -> impl ~const T { S } | ||
|
||
const fn apit(_: impl ~const T + ~const Destruct) {} | ||
|
||
const fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } | ||
|
||
const fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T> + ~const Destruct) {} | ||
|
||
fn main() {} |
17 changes: 0 additions & 17 deletions
17
src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.rs
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
36 changes: 2 additions & 34 deletions
36
src/test/ui/rfc-2632-const-trait-impl/tilde-const-invalid-places.stderr
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 |
---|---|---|
@@ -1,40 +1,8 @@ | ||
error: `~const` is not allowed here | ||
--> $DIR/tilde-const-invalid-places.rs:9:19 | ||
| | ||
LL | fn rpit() -> impl ~const T { S } | ||
| ^^^^^^^^ | ||
| | ||
= note: `impl Trait`s cannot have `~const` trait bounds | ||
|
||
error: `~const` is not allowed here | ||
--> $DIR/tilde-const-invalid-places.rs:12:17 | ||
| | ||
LL | fn apit(_: impl ~const T) {} | ||
| ^^^^^^^^ | ||
| | ||
= note: `impl Trait`s cannot have `~const` trait bounds | ||
|
||
error: `~const` is not allowed here | ||
--> $DIR/tilde-const-invalid-places.rs:15:50 | ||
| | ||
LL | fn rpit_assoc_bound() -> impl IntoIterator<Item: ~const T> { Some(S) } | ||
| ^^^^^^^^ | ||
| | ||
= note: `impl Trait`s cannot have `~const` trait bounds | ||
|
||
error: `~const` is not allowed here | ||
--> $DIR/tilde-const-invalid-places.rs:18:48 | ||
| | ||
LL | fn apit_assoc_bound(_: impl IntoIterator<Item: ~const T>) {} | ||
| ^^^^^^^^ | ||
| | ||
= note: `impl Trait`s cannot have `~const` trait bounds | ||
|
||
error: `~const` and `?` are mutually exclusive | ||
--> $DIR/tilde-const-invalid-places.rs:21:25 | ||
--> $DIR/tilde-const-invalid-places.rs:4:25 | ||
| | ||
LL | struct TildeQuestion<T: ~const ?Sized>(std::marker::PhantomData<T>); | ||
| ^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 5 previous errors | ||
error: aborting due to previous error | ||
|
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.