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#122802 - estebank:unconstrained-generic-con…
…st, r=Nadrieril Provide structured suggestion for unconstrained generic constant ``` error: unconstrained generic constant --> $DIR/const-argument-if-length.rs:18:10 | LL | pad: [u8; is_zst::<T>()], | ^^^^^^^^^^^^^^^^^^^ | help: try adding a `where` bound | LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: { | ++++++++++++++++++++++++++ ``` Detect when the constant expression isn't `usize` and suggest casting: ``` error: unconstrained generic constant --> f300.rs:6:10 | 6 | bb::<{!N}>(); | ^^^^ -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36 | help: try adding a `where` bound | 5 | fn b<const N: bool>() where [(); {!N} as usize]: { | ++++++++++++++++++++++++++ ``` Fix rust-lang#122395.
- Loading branch information
Showing
41 changed files
with
351 additions
and
111 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
21 changes: 21 additions & 0 deletions
21
tests/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.fixed
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 @@ | ||
//@ run-rustfix | ||
#![feature(generic_const_exprs)] | ||
#![allow(incomplete_features, dead_code)] | ||
|
||
struct Evaluatable<const N: u128> {} | ||
|
||
struct Foo<const N: u8>([u8; N as usize]) | ||
//~^ ERROR unconstrained generic constant | ||
where | ||
Evaluatable<{N as u128}>:, [(); N as usize]:; | ||
//~^ HELP try adding a `where` bound | ||
|
||
struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:, [(); {N as u128} as usize]:; | ||
//~^ ERROR unconstrained generic constant | ||
//~| HELP try adding a `where` bound | ||
|
||
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:, [(); (N + 2) as usize]:; | ||
//~^ ERROR unconstrained generic constant | ||
//~| HELP try adding a `where` bound | ||
|
||
fn main() {} |
15 changes: 8 additions & 7 deletions
15
tests/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.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 |
---|---|---|
@@ -1,20 +1,21 @@ | ||
//@ run-rustfix | ||
#![feature(generic_const_exprs)] | ||
#![allow(incomplete_features)] | ||
#![allow(incomplete_features, dead_code)] | ||
|
||
struct Evaluatable<const N: u128> {} | ||
|
||
struct Foo<const N: u8>([u8; N as usize]) | ||
//~^ Error: unconstrained generic constant | ||
//~| help: try adding a `where` bound using this expression: `where [(); N as usize]:` | ||
//~^ ERROR unconstrained generic constant | ||
where | ||
Evaluatable<{N as u128}>:; | ||
//~^ HELP try adding a `where` bound | ||
|
||
struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:; | ||
//~^ Error: unconstrained generic constant | ||
//~| help: try adding a `where` bound using this expression: `where [(); {N as u128}]:` | ||
//~^ ERROR unconstrained generic constant | ||
//~| HELP try adding a `where` bound | ||
|
||
struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:; | ||
//~^ Error: unconstrained generic constant | ||
//~| help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:` | ||
//~^ ERROR unconstrained generic constant | ||
//~| HELP try adding a `where` bound | ||
|
||
fn main() {} |
21 changes: 15 additions & 6 deletions
21
tests/ui/const-generics/generic_const_exprs/abstract-const-as-cast-2.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 |
---|---|---|
@@ -1,26 +1,35 @@ | ||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-2.rs:6:25 | ||
--> $DIR/abstract-const-as-cast-2.rs:7:25 | ||
| | ||
LL | struct Foo<const N: u8>([u8; N as usize]) | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); N as usize]:` | ||
help: try adding a `where` bound | ||
| | ||
LL | Evaluatable<{N as u128}>:, [(); N as usize]:; | ||
| +++++++++++++++++++ | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-2.rs:12:26 | ||
--> $DIR/abstract-const-as-cast-2.rs:13:26 | ||
| | ||
LL | struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); {N as u128}]:` | ||
help: try adding a `where` bound | ||
| | ||
LL | struct Foo2<const N: u8>(Evaluatable::<{N as u128}>) where Evaluatable<{N as usize as u128 }>:, [(); {N as u128} as usize]:; | ||
| +++++++++++++++++++++++++++++ | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/abstract-const-as-cast-2.rs:16:25 | ||
--> $DIR/abstract-const-as-cast-2.rs:17:25 | ||
| | ||
LL | struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); (N + 2) as usize]:` | ||
help: try adding a `where` bound | ||
| | ||
LL | struct Bar<const N: u8>([u8; (N + 2) as usize]) where [(); (N + 1) as usize]:, [(); (N + 2) as usize]:; | ||
| +++++++++++++++++++++++++ | ||
|
||
error: aborting due to 3 previous errors | ||
|
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
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
Oops, something went wrong.