forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#64858 - skinny121:str-const-generics, r=varkor
Add support for relating slices in `super_relate_consts` This allows passing strings as generic arguments. Fixes rust-lang#63773 Fixes rust-lang#60813 r? @varkor
- Loading branch information
Showing
8 changed files
with
116 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
struct ConstString<const T: &'static str>; | ||
struct ConstBytes<const T: &'static [u8]>; | ||
|
||
pub fn main() { | ||
let _: ConstString<"Hello"> = ConstString::<"Hello">; | ||
let _: ConstString<"Hello"> = ConstString::<"World">; //~ ERROR mismatched types | ||
let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↦">; | ||
let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; //~ ERROR mismatched types | ||
let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>; | ||
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types | ||
} |
38 changes: 38 additions & 0 deletions
38
src/test/ui/const-generics/slice-const-param-mismatch.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,38 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/slice-const-param-mismatch.rs:1:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/slice-const-param-mismatch.rs:9:35 | ||
| | ||
LL | let _: ConstString<"Hello"> = ConstString::<"World">; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` | ||
| | ||
= note: expected type `ConstString<>` | ||
found type `ConstString<>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/slice-const-param-mismatch.rs:11:33 | ||
| | ||
LL | let _: ConstString<"ℇ㇈↦"> = ConstString::<"ℇ㇈↥">; | ||
| ^^^^^^^^^^^^^^^^^^^^^ expected `"ℇ㇈↦"`, found `"ℇ㇈↥"` | ||
| | ||
= note: expected type `ConstString<>` | ||
found type `ConstString<>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/slice-const-param-mismatch.rs:13:33 | ||
| | ||
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; | ||
| ^^^^^^^^^^^^^^^^^^^^ expected `b"AAA"`, found `b"BBB"` | ||
| | ||
= note: expected type `ConstBytes<>` | ||
found type `ConstBytes<>` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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,19 @@ | ||
// run-pass | ||
|
||
#![feature(const_generics)] | ||
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash | ||
|
||
pub fn function_with_str<const STRING: &'static str>() -> &'static str { | ||
STRING | ||
} | ||
|
||
pub fn function_with_bytes<const BYTES: &'static [u8]>() -> &'static [u8] { | ||
BYTES | ||
} | ||
|
||
pub fn main() { | ||
assert_eq!(function_with_str::<"Rust">(), "Rust"); | ||
assert_eq!(function_with_str::<"ℇ㇈↦">(), "ℇ㇈↦"); | ||
assert_eq!(function_with_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]); | ||
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA"); | ||
} |
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,8 @@ | ||
warning: the feature `const_generics` is incomplete and may cause the compiler to crash | ||
--> $DIR/slice-const-param.rs:3:12 | ||
| | ||
LL | #![feature(const_generics)] | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(incomplete_features)]` on by default | ||
|