1
Fork 0

add tests for self with const params

This commit is contained in:
Bastian Kauschke 2020-10-23 22:08:21 +02:00
parent 4a15a25662
commit 83ecbb4a29
3 changed files with 31 additions and 7 deletions

View file

@ -206,8 +206,10 @@ pub enum Res<Id = hir::HirId> {
/// ```rust /// ```rust
/// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] {} } /// impl Foo { fn test() -> [u8; std::mem::size_of::<Self>()] {} }
/// ``` /// ```
/// We do however allow `Self` in repeat expression even if it is generic to not break code
/// which already works on stable while causing the `const_evaluatable_unchecked` future compat lint.
/// ///
/// FIXME(lazy_normalization_consts): Remove this bodge once this feature is stable. /// FIXME(lazy_normalization_consts): Remove this bodge once that feature is stable.
SelfTy(Option<DefId> /* trait */, Option<(DefId, bool)> /* impl */), SelfTy(Option<DefId> /* trait */, Option<(DefId, bool)> /* impl */),
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]` ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`

View file

@ -1,4 +1,5 @@
// check-pass // check-pass
#![feature(min_const_generics)]
#![allow(dead_code)] #![allow(dead_code)]
fn foo<T>() { fn foo<T>() {
@ -13,7 +14,19 @@ impl<T> Foo<T> {
const ASSOC: usize = 4; const ASSOC: usize = 4;
fn test() { fn test() {
[0; Self::ASSOC]; 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 cannot use constants which depend on generic parameters in types
//~| WARN this was previously accepted by the compiler but is being phased out //~| WARN this was previously accepted by the compiler but is being phased out
} }

View file

@ -1,5 +1,5 @@
warning: cannot use constants which depend on generic parameters in types warning: cannot use constants which depend on generic parameters in types
--> $DIR/const-evaluatable-unchecked.rs:5:9 --> $DIR/const-evaluatable-unchecked.rs:6:9
| |
LL | [0; std::mem::size_of::<*mut T>()]; LL | [0; std::mem::size_of::<*mut T>()];
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@ -9,13 +9,22 @@ LL | [0; std::mem::size_of::<*mut T>()];
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200> = 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 warning: cannot use constants which depend on generic parameters in types
--> $DIR/const-evaluatable-unchecked.rs:16:13 --> $DIR/const-evaluatable-unchecked.rs:17:21
| |
LL | [0; Self::ASSOC]; LL | let _ = [0; Self::ASSOC];
| ^^^^^^^^^^^ | ^^^^^^^^^^^
| |
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = 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> = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
warning: 2 warnings emitted warning: cannot use constants which depend on generic parameters in types
--> $DIR/const-evaluatable-unchecked.rs:29:21
|
LL | let _ = [0; Self::ASSOC];
| ^^^^^^^^^^^
|
= 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: 3 warnings emitted