forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#116253 - asquared31415:adt_const_params_feature, r=compiler-errors Make `adt_const_params` feature suggestion consistent with other features and improve when it is emitted Makes the suggestion to add `adt_const_params` formatted like every other feature gate (notably this makes it such that the playground recognizes it). Additionally improves the situations in which that help is emitted so that it's only emitted when the type would be valid or the type *could* be valid (using a slightly incorrect heuristic that favors suggesting the feature over not) instead of, for example, implying that adding the feature would allow the use of `String`. Also adds the "the only supported types are integers, `bool` and `char`" note to the errors on fn and raw pointers. r? `@compiler-errors`
- Loading branch information
Showing
40 changed files
with
254 additions
and
84 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
44 changes: 44 additions & 0 deletions
44
tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.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,44 @@ | ||
// Test that when adt_const_params is not enabled, we suggest adding the feature only when | ||
// it would be possible for the type to be used as a const generic or when it's likely | ||
// possible for the user to fix their type to be used. | ||
|
||
// Can never be used as const generics. | ||
fn uwu_0<const N: &'static mut ()>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
|
||
// Needs the feature but can be used, so suggest adding the feature. | ||
fn owo_0<const N: &'static u32>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
//~^^ HELP: add `#![feature(adt_const_params)]` | ||
|
||
// Can only be used in const generics with changes. | ||
struct Meow { | ||
meow: u8, | ||
} | ||
|
||
fn meow_0<const N: Meow>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
//~^^ HELP: add `#![feature(adt_const_params)]` | ||
fn meow_1<const N: &'static Meow>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
//~^^ HELP: add `#![feature(adt_const_params)]` | ||
fn meow_2<const N: [Meow; 100]>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
//~^^ HELP: add `#![feature(adt_const_params)]` | ||
fn meow_3<const N: (Meow, u8)>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
//~^^ HELP: add `#![feature(adt_const_params)]` | ||
|
||
// This is suboptimal that it thinks it can be used | ||
// but better to suggest the feature to the user. | ||
fn meow_4<const N: (Meow, String)>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
//~^^ HELP: add `#![feature(adt_const_params)]` | ||
|
||
// Non-local ADT that does not impl `ConstParamTy` | ||
fn nya_0<const N: String>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
fn nya_1<const N: Vec<u32>>() {} | ||
//~^ ERROR: forbidden as the type of a const generic | ||
|
||
fn main() {} |
80 changes: 80 additions & 0 deletions
80
tests/ui/const-generics/adt_const_params/suggest_feature_only_when_possible.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,80 @@ | ||
error: `&'static mut ()` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:6:19 | ||
| | ||
LL | fn uwu_0<const N: &'static mut ()>() {} | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
|
||
error: `&'static u32` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:10:19 | ||
| | ||
LL | fn owo_0<const N: &'static u32>() {} | ||
| ^^^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | ||
|
||
error: `Meow` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:19:20 | ||
| | ||
LL | fn meow_0<const N: Meow>() {} | ||
| ^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | ||
|
||
error: `&'static Meow` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:22:20 | ||
| | ||
LL | fn meow_1<const N: &'static Meow>() {} | ||
| ^^^^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | ||
|
||
error: `[Meow; 100]` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:25:20 | ||
| | ||
LL | fn meow_2<const N: [Meow; 100]>() {} | ||
| ^^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | ||
|
||
error: `(Meow, u8)` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:28:20 | ||
| | ||
LL | fn meow_3<const N: (Meow, u8)>() {} | ||
| ^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | ||
|
||
error: `(Meow, String)` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:34:20 | ||
| | ||
LL | fn meow_4<const N: (Meow, String)>() {} | ||
| ^^^^^^^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
= help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | ||
|
||
error: `String` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:39:19 | ||
| | ||
LL | fn nya_0<const N: String>() {} | ||
| ^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
|
||
error: `Vec<u32>` is forbidden as the type of a const generic parameter | ||
--> $DIR/suggest_feature_only_when_possible.rs:41:19 | ||
| | ||
LL | fn nya_1<const N: Vec<u32>>() {} | ||
| ^^^^^^^^ | ||
| | ||
= note: the only supported types are integers, `bool` and `char` | ||
|
||
error: aborting due to 9 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
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.