-
Notifications
You must be signed in to change notification settings - Fork 13k
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 #78224 - lcnr:repeat-expr, r=varkor
min_const_generics: allow ty param in repeat expr implements https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/repeat.20expressions Even with `min_const_generics` active, now keeps resulting in future compat warnings instead of hard errors. Const parameters, for example `[0; N + 1]`, still result in hard errors during resolve. ```rust #![allow(dead_code)] fn foo<T>() { [0; std::mem::size_of::<*mut T>()]; } struct Foo<T>(T); impl<T> Foo<T> { const ASSOC: usize = 4; fn test() { [0; Self::ASSOC]; } } ``` r? @varkor cc @petrochenkov
- Loading branch information
Showing
10 changed files
with
217 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
error: generic `Self` types are currently not permitted in anonymous constants | ||
error[E0308]: mismatched types | ||
--> $DIR/issue-62504.rs:19:21 | ||
| | ||
LL | ArrayHolder([0; Self::SIZE]) | ||
| ^^^^^^^^^^^^^^^ expected `X`, found `Self::SIZE` | ||
| | ||
= note: expected array `[u32; X]` | ||
found array `[u32; _]` | ||
|
||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-62504.rs:19:25 | ||
| | ||
LL | ArrayHolder([0; Self::SIZE]) | ||
| ^^^^^^^^^^ | ||
| | ||
note: not a concrete type | ||
--> $DIR/issue-62504.rs:17:22 | ||
| | ||
LL | impl<const X: usize> ArrayHolder<X> { | ||
| ^^^^^^^^^^^^^^ | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/issue-67739.rs:12:30 | ||
error: constant expression depends on a generic parameter | ||
--> $DIR/issue-67739.rs:12:15 | ||
| | ||
LL | [0u8; mem::size_of::<Self::Associated>()]; | ||
| ^^^^^^^^^^^^^^^^ cannot perform const operation using `Self` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: type parameters may not be used in const expressions | ||
= note: this may fail depending on what value the parameter takes | ||
|
||
error: aborting due to previous error | ||
|
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
44 changes: 39 additions & 5 deletions
44
src/test/ui/const-generics/min_const_generics/complex-expression.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,34 +1,68 @@ | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:9:38 | ||
--> $DIR/complex-expression.rs:11:38 | ||
| | ||
LL | struct Break0<const N: usize>([u8; { N + 1 }]); | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:12:40 | ||
--> $DIR/complex-expression.rs:14:40 | ||
| | ||
LL | struct Break1<const N: usize>([u8; { { N } }]); | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:16:17 | ||
--> $DIR/complex-expression.rs:18:17 | ||
| | ||
LL | let _: [u8; N + 1]; | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:21:17 | ||
--> $DIR/complex-expression.rs:23:17 | ||
| | ||
LL | let _ = [0; N + 1]; | ||
| ^ cannot perform const operation using `N` | ||
| | ||
= help: const parameters may only be used as standalone arguments, i.e. `N` | ||
|
||
error: aborting due to 4 previous errors | ||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:27:45 | ||
| | ||
LL | struct BreakTy0<T>(T, [u8; { size_of::<*mut T>() }]); | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:30:47 | ||
| | ||
LL | struct BreakTy1<T>(T, [u8; { { size_of::<*mut T>() } }]); | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
|
||
error: generic parameters may not be used in const operations | ||
--> $DIR/complex-expression.rs:34:32 | ||
| | ||
LL | let _: [u8; size_of::<*mut T>() + 1]; | ||
| ^ cannot perform const operation using `T` | ||
| | ||
= note: type parameters may not be used in const expressions | ||
|
||
warning: cannot use constants which depend on generic parameters in types | ||
--> $DIR/complex-expression.rs:39:17 | ||
| | ||
LL | let _ = [0; size_of::<*mut T>() + 1]; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= 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> | ||
|
||
error: aborting due to 7 previous errors; 1 warning emitted | ||
|
35 changes: 35 additions & 0 deletions
35
src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.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,35 @@ | ||
// check-pass | ||
#![feature(min_const_generics)] | ||
#![allow(dead_code)] | ||
|
||
fn foo<T>() { | ||
[0; std::mem::size_of::<*mut T>()]; | ||
//~^ WARN cannot use constants which depend on generic parameters in types | ||
//~| WARN this was previously accepted by the compiler but is being phased out | ||
} | ||
|
||
struct Foo<T>(T); | ||
|
||
impl<T> Foo<T> { | ||
const ASSOC: usize = 4; | ||
|
||
fn test() { | ||
let _ = [0; Self::ASSOC]; | ||
//~^ WARN cannot use constants which depend on generic parameters in types | ||
//~| WARN this was previously accepted by the compiler but is being phased out | ||
} | ||
} | ||
|
||
struct Bar<const N: usize>; | ||
|
||
impl<const N: usize> Bar<N> { | ||
const ASSOC: usize = 4; | ||
|
||
fn test() { | ||
let _ = [0; Self::ASSOC]; | ||
//~^ WARN cannot use constants which depend on generic parameters in types | ||
//~| WARN this was previously accepted by the compiler but is being phased out | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.