-
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
allow concrete self types in consts #76195
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
error: generic parameters must not be used inside of non trivial constant values | ||
error: generic `Self` types are currently not permitted in anonymous constants | ||
--> $DIR/issue-62504.rs:19:25 | ||
| | ||
LL | ArrayHolder([0; Self::SIZE]) | ||
| ^^^^^^^^^^ non-trivial anonymous constants must not depend on the parameter `Self` | ||
| ^^^^^^^^^^ | ||
| | ||
= help: it is currently only allowed to use either `Self` or `{ Self }` as generic constants | ||
note: not a concrete type | ||
--> $DIR/issue-62504.rs:17:22 | ||
| | ||
LL | impl<const X: usize> ArrayHolder<X> { | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
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
27 changes: 27 additions & 0 deletions
27
src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.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,27 @@ | ||
#![feature(min_const_generics)] | ||
|
||
trait Foo { | ||
fn t1() -> [u8; std::mem::size_of::<Self>()]; //~ERROR generic parameters | ||
} | ||
|
||
struct Bar<T>(T); | ||
|
||
impl Bar<u8> { | ||
fn t2() -> [u8; std::mem::size_of::<Self>()] { todo!() } // ok | ||
} | ||
|
||
impl<T> Bar<T> { | ||
fn t3() -> [u8; std::mem::size_of::<Self>()] {} //~ERROR generic `Self` | ||
} | ||
|
||
trait Baz { | ||
fn hey(); | ||
} | ||
|
||
impl Baz for u16 { | ||
fn hey() { | ||
let _: [u8; std::mem::size_of::<Self>()]; // ok | ||
} | ||
} | ||
|
||
fn main() {} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/const-generics/min_const_generics/self-ty-in-const-1.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,22 @@ | ||
error: generic parameters must not be used inside of non trivial constant values | ||
--> $DIR/self-ty-in-const-1.rs:4:41 | ||
| | ||
LL | fn t1() -> [u8; std::mem::size_of::<Self>()]; | ||
| ^^^^ non-trivial anonymous constants must not depend on the parameter `Self` | ||
| | ||
= help: it is currently only allowed to use either `Self` or `{ Self }` as generic constants | ||
|
||
error: generic `Self` types are currently not permitted in anonymous constants | ||
--> $DIR/self-ty-in-const-1.rs:14:41 | ||
| | ||
LL | fn t3() -> [u8; std::mem::size_of::<Self>()] {} | ||
| ^^^^ | ||
| | ||
note: not a concrete type | ||
--> $DIR/self-ty-in-const-1.rs:13:9 | ||
| | ||
LL | impl<T> Bar<T> { | ||
| ^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
21 changes: 21 additions & 0 deletions
21
src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.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,21 @@ | ||
#![feature(min_const_generics)] | ||
|
||
struct Bar<T>(T); | ||
|
||
trait Baz { | ||
fn hey(); | ||
} | ||
|
||
impl Baz for u16 { | ||
fn hey() { | ||
let _: [u8; std::mem::size_of::<Self>()]; // ok | ||
} | ||
} | ||
|
||
impl<T> Baz for Bar<T> { | ||
fn hey() { | ||
let _: [u8; std::mem::size_of::<Self>()]; //~ERROR generic `Self` | ||
} | ||
} | ||
|
||
fn main() {} |
14 changes: 14 additions & 0 deletions
14
src/test/ui/const-generics/min_const_generics/self-ty-in-const-2.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,14 @@ | ||
error: generic `Self` types are currently not permitted in anonymous constants | ||
--> $DIR/self-ty-in-const-2.rs:17:41 | ||
| | ||
LL | let _: [u8; std::mem::size_of::<Self>()]; | ||
| ^^^^ | ||
| | ||
note: not a concrete type | ||
--> $DIR/self-ty-in-const-2.rs:15:17 | ||
| | ||
LL | impl<T> Baz for Bar<T> { | ||
| ^^^^^^ | ||
|
||
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.
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.
Ideally this would be a new
enum
, but it is great you added docs to it.