Skip to content

Commit 74eac92

Browse files
committed
Test diagnostic output of type mismatches for types that have const
generics arguments.
1 parent 5880ce3 commit 74eac92

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(const_generics)]
2+
//~^ WARN the feature `const_generics` is incomplete and may cause the compiler to crash
3+
4+
// tests the diagnostic output of type mismatches for types that have const generics arguments.
5+
6+
use std::marker::PhantomData;
7+
8+
struct A<'a, T, const X: u32, const Y: u32> {
9+
data: PhantomData<&'a T>
10+
}
11+
12+
fn a<'a, 'b>() {
13+
let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData };
14+
//~^ ERROR mismatched types
15+
let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData };
16+
//~^ ERROR mismatched types
17+
}
18+
19+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
warning: the feature `const_generics` is incomplete and may cause the compiler to crash
2+
--> $DIR/types-mismatch-const-args.rs:1:12
3+
|
4+
LL | #![feature(const_generics)]
5+
| ^^^^^^^^^^^^^^
6+
|
7+
= note: `#[warn(incomplete_features)]` on by default
8+
9+
error[E0308]: mismatched types
10+
--> $DIR/types-mismatch-const-args.rs:13:41
11+
|
12+
LL | let _: A<'a, u32, {2u32}, {3u32}> = A::<'a, u32, {4u32}, {3u32}> { data: PhantomData };
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2u32`, found `4u32`
14+
|
15+
= note: expected type `A<'_, _, 2u32, _>`
16+
found type `A<'_, _, 4u32, _>`
17+
18+
error[E0308]: mismatched types
19+
--> $DIR/types-mismatch-const-args.rs:15:41
20+
|
21+
LL | let _: A<'a, u16, {2u32}, {3u32}> = A::<'b, u32, {2u32}, {3u32}> { data: PhantomData };
22+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected u16, found u32
23+
|
24+
= note: expected type `A<'a, u16, _, _>`
25+
found type `A<'b, u32, _, _>`
26+
27+
error: aborting due to 2 previous errors
28+
29+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)