-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Add const_param_ty_unchecked gate
#153536
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
zedddie
wants to merge
1
commit into
rust-lang:main
Choose a base branch
from
zedddie:const-param-ty-unchecked-gate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
19 changes: 19 additions & 0 deletions
19
tests/ui/const-generics/adt_const_params/const_param_ty_unchecked-unsupported.rs
This file contains hidden or 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,19 @@ | ||
| //! Ensure we don't allow Vec<[u8]> as const parameter even with | ||
| //! `const_param_ty_unchecked` feature. | ||
| #![allow(incomplete_features)] | ||
| #![feature(adt_const_params, const_param_ty_unchecked, const_param_ty_trait)] | ||
| use std::marker::ConstParamTy_; | ||
|
|
||
| struct VectorOfBytes { | ||
| a: Vec<[u8]> | ||
| //~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277] | ||
| } | ||
| impl ConstParamTy_ for VectorOfBytes {} | ||
|
|
||
| fn bar<const N: VectorOfBytes>() {} | ||
| fn foo<const N: Vec<[u8]>>() {} | ||
| //~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277] | ||
| //~| ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277] | ||
|
|
||
|
|
||
| fn main() {} |
34 changes: 34 additions & 0 deletions
34
tests/ui/const-generics/adt_const_params/const_param_ty_unchecked-unsupported.stderr
This file contains hidden or 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,34 @@ | ||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/const_param_ty_unchecked-unsupported.rs:8:8 | ||
| | | ||
| LL | a: Vec<[u8]> | ||
| | ^^^^^^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| note: required by an implicit `Sized` bound in `Vec` | ||
| --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
|
|
||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/const_param_ty_unchecked-unsupported.rs:14:8 | ||
| | | ||
| LL | fn foo<const N: Vec<[u8]>>() {} | ||
| | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| note: required by an implicit `Sized` bound in `Vec` | ||
| --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
|
|
||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/const_param_ty_unchecked-unsupported.rs:14:8 | ||
| | | ||
| LL | fn foo<const N: Vec<[u8]>>() {} | ||
| | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| note: required by an implicit `Sized` bound in `Vec` | ||
| --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
| = note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no` | ||
|
|
||
| error: aborting due to 3 previous errors | ||
|
|
||
| For more information about this error, try `rustc --explain E0277`. |
28 changes: 28 additions & 0 deletions
28
tests/ui/const-generics/adt_const_params/const_param_ty_unchecked.rs
This file contains hidden or 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,28 @@ | ||
| //@run-pass | ||
| //! Ensure that const_param_ty_unchecked gate allow | ||
| //! bypassing `ConstParamTy_` implementation check | ||
| #![allow(dead_code, incomplete_features)] | ||
| #![feature(const_param_ty_unchecked, const_param_ty_trait)] | ||
|
|
||
| use std::marker::ConstParamTy_; | ||
|
|
||
| struct Miow; | ||
|
|
||
| struct Meoww(Miow); | ||
|
|
||
| struct Float { | ||
| float: f32, | ||
| } | ||
|
|
||
| impl ConstParamTy_ for Meoww {} | ||
| impl ConstParamTy_ for Float {} | ||
|
|
||
| fn something2<const N: *mut u8>() {} | ||
| fn something<const N: f64>(a: f64) -> f64 { | ||
| N + a | ||
| } | ||
|
|
||
| fn main() { | ||
| assert_eq!(2.0, something::<{1.0}>(1.0)); | ||
| } |
31 changes: 31 additions & 0 deletions
31
tests/ui/const-generics/adt_const_params/const_param_ty_unchecked_fail.rs
This file contains hidden or 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,31 @@ | ||
| // gate-test-const_param_ty_unchecked | ||
| //! Ensure this fails when const_param_ty_unchecked isn't used | ||
| #![allow(incomplete_features)] | ||
| #![feature(const_param_ty_trait)] | ||
|
|
||
| use std::marker::ConstParamTy_; | ||
|
|
||
| struct Miow; | ||
|
|
||
| struct Meoww(Miow); | ||
|
|
||
| struct Float { | ||
| float: f32, | ||
| } | ||
|
|
||
| impl ConstParamTy_ for Meoww {} | ||
| //~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type [E0204] | ||
| impl ConstParamTy_ for Float {} | ||
| //~^ ERROR: the trait `ConstParamTy_` cannot be implemented for this type [E0204] | ||
|
|
||
| fn something2<const N: *mut u8>() {} | ||
| //~^ ERROR: using raw pointers as const generic parameters is forbidden | ||
| fn something<const N: f64>(a: f64) -> f64 { | ||
| //~^ ERROR: `f64` is forbidden as the type of a const generic parameter | ||
| N + a | ||
| } | ||
| fn foo<const N: Vec<[u8]>>() {} | ||
| //~^ ERROR: the size for values of type `[u8]` cannot be known at compilation time [E0277] | ||
| //~^^ ERROR: `Vec<[u8]>` is forbidden as the type of a const generic parameter | ||
|
|
||
| fn main() {} |
56 changes: 56 additions & 0 deletions
56
tests/ui/const-generics/adt_const_params/const_param_ty_unchecked_fail.stderr
This file contains hidden or 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,56 @@ | ||
| error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type | ||
| --> $DIR/const_param_ty_unchecked_fail.rs:16:24 | ||
| | | ||
| LL | struct Meoww(Miow); | ||
| | ---- this field does not implement `ConstParamTy_` | ||
| ... | ||
| LL | impl ConstParamTy_ for Meoww {} | ||
| | ^^^^^ | ||
|
|
||
| error[E0204]: the trait `ConstParamTy_` cannot be implemented for this type | ||
| --> $DIR/const_param_ty_unchecked_fail.rs:18:24 | ||
| | | ||
| LL | float: f32, | ||
| | ---------- this field does not implement `ConstParamTy_` | ||
| ... | ||
| LL | impl ConstParamTy_ for Float {} | ||
| | ^^^^^ | ||
|
|
||
| error: using raw pointers as const generic parameters is forbidden | ||
| --> $DIR/const_param_ty_unchecked_fail.rs:21:24 | ||
| | | ||
| LL | fn something2<const N: *mut u8>() {} | ||
| | ^^^^^^^ | ||
| | | ||
| = note: the only supported types are integers, `bool`, and `char` | ||
|
|
||
| error: `f64` is forbidden as the type of a const generic parameter | ||
| --> $DIR/const_param_ty_unchecked_fail.rs:23:23 | ||
| | | ||
| LL | fn something<const N: f64>(a: f64) -> f64 { | ||
| | ^^^ | ||
| | | ||
| = note: the only supported types are integers, `bool`, and `char` | ||
|
|
||
| error[E0277]: the size for values of type `[u8]` cannot be known at compilation time | ||
| --> $DIR/const_param_ty_unchecked_fail.rs:27:8 | ||
| | | ||
| LL | fn foo<const N: Vec<[u8]>>() {} | ||
| | ^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: the trait `Sized` is not implemented for `[u8]` | ||
| note: required by an implicit `Sized` bound in `Vec` | ||
| --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
|
|
||
| error: `Vec<[u8]>` is forbidden as the type of a const generic parameter | ||
| --> $DIR/const_param_ty_unchecked_fail.rs:27:17 | ||
| | | ||
| LL | fn foo<const N: Vec<[u8]>>() {} | ||
| | ^^^^^^^^^ | ||
| | | ||
| = note: the only supported types are integers, `bool`, and `char` | ||
|
|
||
| error: aborting due to 6 previous errors | ||
|
|
||
| Some errors have detailed explanations: E0204, E0277. | ||
| For more information about an error, try `rustc --explain E0204`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.