-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 #97105 - JulianKnodt:const_dep_gen_const_expr, r=lcnr
Add tests for lint on type dependent on consts r? `@lcnr`
- Loading branch information
Showing
6 changed files
with
244 additions
and
134 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
39 changes: 39 additions & 0 deletions
39
src/test/ui/const-generics/generic_const_exprs/dependence_lint.full.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,39 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/dependence_lint.rs:13:32 | ||
| | ||
LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/dependence_lint.rs:20:37 | ||
| | ||
LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
= help: use `#![feature(generic_const_exprs)]` to allow generic const expressions | ||
|
||
warning: cannot use constants which depend on generic parameters in types | ||
--> $DIR/dependence_lint.rs:9:9 | ||
| | ||
LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs` | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(const_evaluatable_unchecked)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200> | ||
|
||
warning: cannot use constants which depend on generic parameters in types | ||
--> $DIR/dependence_lint.rs:16:9 | ||
| | ||
LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200> | ||
|
||
error: aborting due to 2 previous errors; 2 warnings emitted | ||
|
34 changes: 34 additions & 0 deletions
34
src/test/ui/const-generics/generic_const_exprs/dependence_lint.gce.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,34 @@ | ||
error: overly complex generic constant | ||
--> $DIR/dependence_lint.rs:16:9 | ||
| | ||
LL | [0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants | ||
| | ||
= help: consider moving this anonymous constant into a `const` function | ||
|
||
error: overly complex generic constant | ||
--> $DIR/dependence_lint.rs:20:17 | ||
| | ||
LL | let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ control flow is not supported in generic constants | ||
| | ||
= help: consider moving this anonymous constant into a `const` function | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/dependence_lint.rs:13:12 | ||
| | ||
LL | let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); size_of::<*mut T>()]:` | ||
|
||
error: unconstrained generic constant | ||
--> $DIR/dependence_lint.rs:9:9 | ||
| | ||
LL | [0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs` | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= help: try adding a `where` bound using this expression: `where [(); size_of::<*mut T>()]:` | ||
|
||
error: aborting due to 4 previous errors | ||
|
25 changes: 25 additions & 0 deletions
25
src/test/ui/const-generics/generic_const_exprs/dependence_lint.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,25 @@ | ||
// revisions: full gce | ||
|
||
#![cfg_attr(gce, feature(generic_const_exprs))] | ||
#![allow(incomplete_features)] | ||
|
||
use std::mem::size_of; | ||
|
||
fn foo<T>() { | ||
[0; size_of::<*mut T>()]; // lint on stable, error with `generic_const_exprs` | ||
//[gce]~^ ERROR unconstrained | ||
//[full]~^^ WARNING cannot use constants | ||
//[full]~| WARNING this was previously accepted | ||
let _: [u8; size_of::<*mut T>()]; // error on stable, error with gce | ||
//[full]~^ ERROR generic parameters may not be used | ||
//[gce]~^^ ERROR unconstrained generic | ||
[0; if false { size_of::<T>() } else { 3 }]; // lint on stable, error with gce | ||
//[gce]~^ ERROR overly complex | ||
//[full]~^^ WARNING cannot use constants | ||
//[full]~| WARNING this was previously accepted | ||
let _: [u8; if true { size_of::<T>() } else { 3 }]; // error on stable, error with gce | ||
//[full]~^ ERROR generic parameters may not be used | ||
//[gce]~^^ ERROR overly complex | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.