-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include const generic arguments in metadata.
- Loading branch information
Showing
5 changed files
with
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![feature(const_generics)] | ||
|
||
pub struct Struct<const N: usize>(pub [u8; N]); | ||
|
||
pub type Alias = Struct<2>; | ||
|
||
pub fn function(value: Struct<3>) -> u8 { | ||
value.0[0] | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/ui/const-generics/const-argument-cross-crate-mismatch.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,10 @@ | ||
// aux-build:const_generic_lib.rs | ||
|
||
extern crate const_generic_lib; | ||
|
||
fn main() { | ||
let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8])); | ||
//~^ ERROR mismatched types | ||
let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]); | ||
//~^ ERROR mismatched types | ||
} |
21 changes: 21 additions & 0 deletions
21
src/test/ui/const-generics/const-argument-cross-crate-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,21 @@ | ||
error[E0308]: mismatched types | ||
--> $DIR/const-argument-cross-crate-mismatch.rs:6:41 | ||
| | ||
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8])); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3usize`, found `2usize` | ||
| | ||
= note: expected type `const_generic_lib::Struct<3usize>` | ||
found type `const_generic_lib::Struct<_: usize>` | ||
|
||
error[E0308]: mismatched types | ||
--> $DIR/const-argument-cross-crate-mismatch.rs:8:39 | ||
| | ||
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2usize`, found `3usize` | ||
| | ||
= note: expected type `const_generic_lib::Struct<2usize>` | ||
found type `const_generic_lib::Struct<_: usize>` | ||
|
||
error: aborting due to 2 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,12 @@ | ||
// run-pass | ||
// aux-build:const_generic_lib.rs | ||
|
||
extern crate const_generic_lib; | ||
|
||
struct Container(const_generic_lib::Alias); | ||
|
||
fn main() { | ||
let res = const_generic_lib::function(const_generic_lib::Struct([14u8, 1u8, 2u8])); | ||
assert_eq!(res, 14u8); | ||
let _ = Container(const_generic_lib::Struct([0u8, 1u8])); | ||
} |