-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add support for relating slices in super_relate_consts
#64858
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
Changes from 4 commits
22b87a5
875fa72
c94fea0
5cb0039
54bad93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![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::<"World">; //~ ERROR mismatched types | ||
let _: ConstBytes<b"AAA"> = ConstBytes::<{&[0x41, 0x41, 0x41]}>; | ||
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">; //~ ERROR mismatched types | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
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:8:35 | ||
| | ||
LL | let _: ConstString<"Hello"> = ConstString::<"World">; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ expected `"Hello"`, found `"World"` | ||
| | ||
= note: expected type `ConstString<>` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. btw @varkor, this is a rather unfortunate diagnostic... do we have an issue for that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a case for it: #61395. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah excellent, thanks! |
||
found type `ConstString<>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/slice-const-param-mismatch.rs:10: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 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// 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_bytes::<b"AAAA">(), &[0x41, 0x41, 0x41, 0x41]); | ||
assert_eq!(function_with_bytes::<{&[0x41, 0x41, 0x41, 0x41]}>(), b"AAAA"); | ||
} |
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 | ||
|
Uh oh!
There was an error while loading. Please reload this page.