Skip to content

Commit 7e7b4c8

Browse files
committed
modify error comment and bless test
1 parent 62ddebf commit 7e7b4c8

30 files changed

Lines changed: 364 additions & 125 deletions

tests/crashes/133966.rs

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/ui/const-generics/adt_const_params/byte-string-u8-validation.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@
66

77
#[rustc_dump_predicates]
88
struct ConstBytes<const T: &'static [*mut u8; 3]>
9-
//~^ ERROR rustc_dump_predicates
9+
//~^ ERROR `&'static [*mut u8; 3]` can't be used as a const parameter type
10+
//~| NOTE required by a const generic parameter in `ConstBytes`
11+
//~| NOTE required by this const generic parameter in `ConstBytes`
12+
//~| ERROR rustc_dump_predicates
13+
//~| NOTE `*mut u8` must implement `ConstParamTy_`, but it does not
14+
//~| NOTE `[*mut u8; 3]` must implement `ConstParamTy_`, but it does not
1015
//~| NOTE Binder { value: ConstArgHasType(T/#0, &'static [*mut u8; 3_usize]), bound_vars: [] }
11-
//~| NOTE Binder { value: TraitPredicate(<ConstBytes<b"AAA"> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
16+
//~| NOTE Binder { value: TraitPredicate(<ConstBytes<*b"AAA"> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
17+
1218
where
1319
ConstBytes<b"AAA">: Sized;
14-
//~^ ERROR mismatched types
20+
//~^ ERROR the constant `*b"AAA"` is not of type `&'static [*mut u8; 3]`
21+
//~| NOTE expected `&'static [*mut u8; 3]`, found `[u8; 3]`
22+
//~| ERROR mismatched types
1523
//~| NOTE expected `&[*mut u8; 3]`, found `&[u8; 3]`
1624
//~| NOTE expected reference `&'static [*mut u8; 3]`
1725

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
error[E0308]: mismatched types
2-
--> $DIR/byte-string-u8-validation.rs:13:16
1+
error: the constant `*b"AAA"` is not of type `&'static [*mut u8; 3]`
2+
--> $DIR/byte-string-u8-validation.rs:19:25
33
|
44
LL | ConstBytes<b"AAA">: Sized;
5-
| ^^^^^^ expected `&[*mut u8; 3]`, found `&[u8; 3]`
5+
| ^^^^^ expected `&'static [*mut u8; 3]`, found `[u8; 3]`
66
|
7-
= note: expected reference `&'static [*mut u8; 3]`
8-
found reference `&'static [u8; 3]`
7+
note: required by a const generic parameter in `ConstBytes`
8+
--> $DIR/byte-string-u8-validation.rs:8:19
9+
|
10+
LL | struct ConstBytes<const T: &'static [*mut u8; 3]>
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `ConstBytes`
12+
13+
error[E0741]: `&'static [*mut u8; 3]` can't be used as a const parameter type
14+
--> $DIR/byte-string-u8-validation.rs:8:28
15+
|
16+
LL | struct ConstBytes<const T: &'static [*mut u8; 3]>
17+
| ^^^^^^^^^^^^^^^^^^^^^
18+
|
19+
= note: `*mut u8` must implement `ConstParamTy_`, but it does not
20+
= note: `[*mut u8; 3]` must implement `ConstParamTy_`, but it does not
921

1022
error: rustc_dump_predicates
1123
--> $DIR/byte-string-u8-validation.rs:8:1
@@ -14,8 +26,18 @@ LL | struct ConstBytes<const T: &'static [*mut u8; 3]>
1426
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1527
|
1628
= note: Binder { value: ConstArgHasType(T/#0, &'static [*mut u8; 3_usize]), bound_vars: [] }
17-
= note: Binder { value: TraitPredicate(<ConstBytes<b"AAA"> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
29+
= note: Binder { value: TraitPredicate(<ConstBytes<*b"AAA"> as std::marker::Sized>, polarity:Positive), bound_vars: [] }
30+
31+
error[E0308]: mismatched types
32+
--> $DIR/byte-string-u8-validation.rs:19:16
33+
|
34+
LL | ConstBytes<b"AAA">: Sized;
35+
| ^^^^^^ expected `&[*mut u8; 3]`, found `&[u8; 3]`
36+
|
37+
= note: expected reference `&'static [*mut u8; 3]`
38+
found reference `&'static [u8; 3]`
1839

19-
error: aborting due to 2 previous errors
40+
error: aborting due to 4 previous errors
2041

21-
For more information about this error, try `rustc --explain E0308`.
42+
Some errors have detailed explanations: E0308, E0741.
43+
For more information about an error, try `rustc --explain E0308`.

tests/ui/const-generics/adt_const_params/mismatch-raw-ptr-in-adt.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ struct ConstBytes<const T: &'static [*mut u8; 3]>;
88
pub fn main() {
99
let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
1010
//~^ ERROR mismatched types
11+
//~| ERROR the constant `*b"BBB"` is not of type `&'static [*mut u8; 3]`
12+
//~| ERROR the constant `*b"AAA"` is not of type `&'static [*mut u8; 3]`
13+
//~| ERROR mismatched types
1114
//~| ERROR mismatched types
1215
}

tests/ui/const-generics/adt_const_params/mismatch-raw-ptr-in-adt.stderr

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,39 @@ LL | struct ConstBytes<const T: &'static [*mut u8; 3]>;
88
= note: `[*mut u8; 3]` must implement `ConstParamTy_`, but it does not
99

1010
error[E0308]: mismatched types
11-
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:23
11+
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:33
1212
|
1313
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
14-
| ^^^^^^ expected `&[*mut u8; 3]`, found `&[u8; 3]`
14+
| ------------------ ^^^^^^^^^^^^^^^^^^^^ expected `*b"AAA"`, found `*b"BBB"`
15+
| |
16+
| expected due to this
1517
|
16-
= note: expected reference `&'static [*mut u8; 3]`
17-
found reference `&'static [u8; 3]`
18+
= note: expected struct `ConstBytes<*b"AAA">`
19+
found struct `ConstBytes<*b"BBB">`
20+
21+
error: the constant `*b"BBB"` is not of type `&'static [*mut u8; 3]`
22+
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:33
23+
|
24+
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
25+
| ^^^^^^^^^^^^^^^^^^^^ expected `&'static [*mut u8; 3]`, found `[u8; 3]`
26+
|
27+
note: required by a const generic parameter in `ConstBytes`
28+
--> $DIR/mismatch-raw-ptr-in-adt.rs:5:19
29+
|
30+
LL | struct ConstBytes<const T: &'static [*mut u8; 3]>;
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `ConstBytes`
32+
33+
error: the constant `*b"AAA"` is not of type `&'static [*mut u8; 3]`
34+
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:12
35+
|
36+
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
37+
| ^^^^^^^^^^^^^^^^^^ expected `&'static [*mut u8; 3]`, found `[u8; 3]`
38+
|
39+
note: required by a const generic parameter in `ConstBytes`
40+
--> $DIR/mismatch-raw-ptr-in-adt.rs:5:19
41+
|
42+
LL | struct ConstBytes<const T: &'static [*mut u8; 3]>;
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `ConstBytes`
1844

1945
error[E0308]: mismatched types
2046
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:46
@@ -25,7 +51,16 @@ LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
2551
= note: expected reference `&'static [*mut u8; 3]`
2652
found reference `&'static [u8; 3]`
2753

28-
error: aborting due to 3 previous errors
54+
error[E0308]: mismatched types
55+
--> $DIR/mismatch-raw-ptr-in-adt.rs:9:23
56+
|
57+
LL | let _: ConstBytes<b"AAA"> = ConstBytes::<b"BBB">;
58+
| ^^^^^^ expected `&[*mut u8; 3]`, found `&[u8; 3]`
59+
|
60+
= note: expected reference `&'static [*mut u8; 3]`
61+
found reference `&'static [u8; 3]`
62+
63+
error: aborting due to 6 previous errors
2964

3065
Some errors have detailed explanations: E0308, E0741.
3166
For more information about an error, try `rustc --explain E0308`.

tests/ui/const-generics/generic_const_exprs/issue-105257.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
#![expect(incomplete_features)]
33

44
trait Trait<T> {
5-
fn fnc<const N: usize = "">(&self) {} //~ERROR defaults for generic parameters are not allowed here
6-
//~^ ERROR: mismatched types
7-
fn foo<const N: usize = { std::mem::size_of::<T>() }>(&self) {} //~ERROR defaults for generic parameters are not allowed here
5+
fn fnc<const N: usize = "">(&self) {} //~ ERROR defaults for generic parameters are not allowed here
6+
//~^ ERROR the constant `""` is not of type `usize`
7+
//~| ERROR mismatched types
8+
fn foo<const N: usize = { std::mem::size_of::<T>() }>(&self) {} //~ ERROR defaults for generic parameters are not allowed here
89
}
910

1011
fn main() {}

tests/ui/const-generics/generic_const_exprs/issue-105257.stderr

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,20 @@ error: defaults for generic parameters are not allowed here
44
LL | fn fnc<const N: usize = "">(&self) {}
55
| ^^^^^^^^^^^^^^^^^^^
66

7+
error: the constant `""` is not of type `usize`
8+
--> $DIR/issue-105257.rs:5:12
9+
|
10+
LL | fn fnc<const N: usize = "">(&self) {}
11+
| ^^^^^^^^^^^^^^^^^^^ expected `usize`, found `&'static str`
12+
|
13+
note: required by a const generic parameter in `Trait::fnc`
14+
--> $DIR/issue-105257.rs:5:12
15+
|
16+
LL | fn fnc<const N: usize = "">(&self) {}
17+
| ^^^^^^^^^^^^^^^^^^^ required by this const generic parameter in `Trait::fnc`
18+
719
error: defaults for generic parameters are not allowed here
8-
--> $DIR/issue-105257.rs:7:12
20+
--> $DIR/issue-105257.rs:8:12
921
|
1022
LL | fn foo<const N: usize = { std::mem::size_of::<T>() }>(&self) {}
1123
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -16,6 +28,6 @@ error[E0308]: mismatched types
1628
LL | fn fnc<const N: usize = "">(&self) {}
1729
| ^^ expected `usize`, found `&str`
1830

19-
error: aborting due to 3 previous errors
31+
error: aborting due to 4 previous errors
2032

2133
For more information about this error, try `rustc --explain E0308`.

tests/ui/const-generics/mgca/adt_expr_fields_type_check.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ fn bar<const N: bool>() {
3232
accepts_3::<{ En::Var2::<u8> { field: N } }>();
3333
//~^ ERROR the constant `N` is not of type `i64`
3434
accepts_3::<{ En::Var2::<u8> { field: const { false } } }>();
35-
//~^ ERROR mismatched types
35+
//~^ ERROR the constant `false` is not of type `i64`
36+
//~| ERROR mismatched types
3637
}
3738

3839
fn main() {}

tests/ui/const-generics/mgca/adt_expr_fields_type_check.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,18 @@ error: the constant `N` is not of type `i64`
3434
LL | accepts_3::<{ En::Var2::<u8> { field: N } }>();
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i64`, found `bool`
3636

37+
error: the constant `false` is not of type `i64`
38+
--> $DIR/adt_expr_fields_type_check.rs:34:19
39+
|
40+
LL | accepts_3::<{ En::Var2::<u8> { field: const { false } } }>();
41+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i64`, found `bool`
42+
3743
error[E0308]: mismatched types
3844
--> $DIR/adt_expr_fields_type_check.rs:34:51
3945
|
4046
LL | accepts_3::<{ En::Var2::<u8> { field: const { false } } }>();
4147
| ^^^^^ expected `i64`, found `bool`
4248

43-
error: aborting due to 7 previous errors
49+
error: aborting due to 8 previous errors
4450

4551
For more information about this error, try `rustc --explain E0308`.
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Regression test for <https://github.com/rust-lang/rust/issues/150983>
22
#![expect(incomplete_features)]
33
#![feature(
4+
adt_const_params,
45
generic_const_items,
56
generic_const_parameter_types,
67
min_generic_const_args,
@@ -12,9 +13,7 @@ struct Foo<T> {
1213
field: T,
1314
}
1415

15-
#[type_const]
16-
const WRAP<T : ConstParamTy_> : T = {
17-
Foo::<T>{field : 1} //~ ERROR: type annotations needed for the literal
18-
};
16+
type const WRAP<T : ConstParamTy_> : T = Foo::<T>{field : 1};
17+
//~^ ERROR: type annotations needed for the literal
1918

2019
fn main() {}

0 commit comments

Comments
 (0)