Auto merge of #70107 - lcnr:issue68977, r=eddyb
WF-check all ty::Const's, not just array lengths. fixes #68977 This PR removes the special case for array length in `wf::compute` and checks the well formedness of all consts. Changes `PredicateKind::WellFormed` to take a `GenericArg` and updates `wf::obligations`.
This commit is contained in:
commit
ff4aff6ce0
33 changed files with 388 additions and 176 deletions
|
|
@ -11,7 +11,9 @@ error[E0282]: type annotations needed
|
|||
--> $DIR/cannot-infer-const-args.rs:9:5
|
||||
|
|
||||
LL | foo();
|
||||
| ^^^ cannot infer type for fn item `fn() -> usize {foo::<{_: usize}>}`
|
||||
| ^^^
|
||||
|
|
||||
= note: unable to infer the value of a const parameter
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// check-pass
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
|
||||
|
|
@ -7,6 +5,7 @@ struct Const<const N: usize>;
|
|||
|
||||
impl<const C: usize> Const<{C}> {
|
||||
fn successor() -> Const<{C + 1}> {
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
Const
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-61747.rs:3:12
|
||||
--> $DIR/issue-61747.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -7,5 +7,13 @@ LL | #![feature(const_generics)]
|
|||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-61747.rs:7:23
|
||||
|
|
||||
LL | fn successor() -> Const<{C + 1}> {
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
// check-pass
|
||||
|
||||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
|
||||
|
|
@ -8,6 +6,7 @@ trait Foo {}
|
|||
impl<const N: usize> Foo for [(); N]
|
||||
where
|
||||
Self:FooImpl<{N==0}>
|
||||
//~^ERROR constant expression depends on a generic parameter
|
||||
{}
|
||||
|
||||
trait FooImpl<const IS_ZERO: bool>{}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-61935.rs:3:12
|
||||
--> $DIR/issue-61935.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
@ -7,5 +7,13 @@ LL | #![feature(const_generics)]
|
|||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-61935.rs:8:14
|
||||
|
|
||||
LL | Self:FooImpl<{N==0}>
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// build-pass
|
||||
#![allow(incomplete_features)]
|
||||
|
||||
#![feature(const_generics)]
|
||||
|
||||
pub struct Vector<T, const N: usize>([T; N]);
|
||||
|
||||
pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
|
||||
|
|
@ -9,6 +8,7 @@ pub type TruncatedVector<T, const N: usize> = Vector<T, { N - 1 }>;
|
|||
impl<T, const N: usize> Vector<T, { N }> {
|
||||
/// Drop the last component and return the vector with one fewer dimension.
|
||||
pub fn trunc(self) -> (TruncatedVector<T, { N }>, T) {
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
10
src/test/ui/const-generics/issues/issue-62220.stderr
Normal file
10
src/test/ui/const-generics/issues/issue-62220.stderr
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-62220.rs:10:27
|
||||
|
|
||||
LL | pub fn trunc(self) -> (TruncatedVector<T, { N }>, T) {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(incomplete_features, dead_code, unconditional_recursion)]
|
||||
#![allow(dead_code, unconditional_recursion)]
|
||||
#![feature(const_generics)]
|
||||
#![feature(lazy_normalization_consts)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
|
||||
fn fact<const N: usize>() {
|
||||
fact::<{ N - 1 }>();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,12 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-66205.rs:2:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-66205.rs:6:12
|
||||
|
|
||||
|
|
@ -6,5 +15,5 @@ LL | fact::<{ N - 1 }>();
|
|||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
|
|
|
|||
40
src/test/ui/const-generics/issues/issue-68977.rs
Normal file
40
src/test/ui/const-generics/issues/issue-68977.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
|
||||
struct PhantomU8<const X: u8>;
|
||||
|
||||
trait FxpStorage {
|
||||
type SInt; // Add arithmetic traits as needed.
|
||||
}
|
||||
|
||||
macro_rules! fxp_storage_impls {
|
||||
($($($n:literal)|+ => $sint:ty),* $(,)?) => {
|
||||
$($(impl FxpStorage for PhantomU8<$n> {
|
||||
type SInt = $sint;
|
||||
})*)*
|
||||
}
|
||||
}
|
||||
|
||||
fxp_storage_impls! {
|
||||
1 => i8,
|
||||
2 => i16,
|
||||
3 | 4 => i32,
|
||||
5 | 6 | 7 | 8 => i64,
|
||||
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 => i128,
|
||||
}
|
||||
|
||||
type FxpStorageHelper<const INT_BITS: u8, const FRAC_BITS: u8> =
|
||||
PhantomU8<{(INT_BITS + FRAC_BITS + 7) / 8}>;
|
||||
|
||||
struct Fxp<const INT_BITS: u8, const FRAC_BITS: u8>
|
||||
where
|
||||
FxpStorageHelper<INT_BITS, FRAC_BITS>: FxpStorage,
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
{
|
||||
storage: <FxpStorageHelper<INT_BITS, FRAC_BITS> as FxpStorage>::SInt,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
Fxp::<1, 15> { storage: 0i16 };
|
||||
Fxp::<2, 15> { storage: 0i32 };
|
||||
}
|
||||
19
src/test/ui/const-generics/issues/issue-68977.stderr
Normal file
19
src/test/ui/const-generics/issues/issue-68977.stderr
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-68977.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-68977.rs:31:44
|
||||
|
|
||||
LL | FxpStorageHelper<INT_BITS, FRAC_BITS>: FxpStorage,
|
||||
| ^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
// run-pass
|
||||
#![feature(const_generics)]
|
||||
#![allow(incomplete_features)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
trait Foo {}
|
||||
|
||||
impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
|
||||
trait FooImpl<const IS_ZERO: bool> {}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/issue-71922.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/issue-71922.rs:5:50
|
||||
|
|
||||
LL | impl<const N: usize> Foo for [(); N] where Self: FooImpl<{ N == 0 }> {}
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
16
src/test/ui/const-generics/wf-misc.rs
Normal file
16
src/test/ui/const-generics/wf-misc.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
#![feature(const_generics)]
|
||||
//~^ WARN the feature `const_generics` is incomplete
|
||||
|
||||
pub fn arr_len<const N: usize>() {
|
||||
let _: [u8; N + 1];
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
}
|
||||
|
||||
struct Const<const N: usize>;
|
||||
|
||||
pub fn func_call<const N: usize>() {
|
||||
let _: Const::<{N + 1}>;
|
||||
//~^ ERROR constant expression depends on a generic parameter
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
27
src/test/ui/const-generics/wf-misc.stderr
Normal file
27
src/test/ui/const-generics/wf-misc.stderr
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/wf-misc.rs:1:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/wf-misc.rs:5:12
|
||||
|
|
||||
LL | let _: [u8; N + 1];
|
||||
| ^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/wf-misc.rs:12:12
|
||||
|
|
||||
LL | let _: Const::<{N + 1}>;
|
||||
| ^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: aborting due to 2 previous errors; 1 warning emitted
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue