add tests for self with const params
This commit is contained in:
parent
4a15a25662
commit
83ecbb4a29
@ -206,8 +206,10 @@ pub enum Res<Id = hir::HirId> {
|
||||
/// ```rust
|
||||
/// 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 */),
|
||||
ToolMod, // e.g., `rustfmt` in `#[rustfmt::skip]`
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
// check-pass
|
||||
#![feature(min_const_generics)]
|
||||
#![allow(dead_code)]
|
||||
|
||||
fn foo<T>() {
|
||||
@ -13,7 +14,19 @@ impl<T> Foo<T> {
|
||||
const ASSOC: usize = 4;
|
||||
|
||||
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 this was previously accepted by the compiler but is being phased out
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
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>()];
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -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>
|
||||
|
||||
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!
|
||||
= 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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user