-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #76195 - lcnr:const-Self, r=varkor
allow concrete self types in consts This is quite a bad hack to fix #75486. There might be a better way to check if the self type depends on generic parameters, but I wasn't able to come up with one. r? `@varkor` cc `@petrochenkov`
- Loading branch information
Showing
13 changed files
with
146 additions
and
20 deletions.
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 | ||
|