Skip to content

Commit 83ecbb4

Browse files
committed
add tests for self with const params
1 parent 4a15a25 commit 83ecbb4

File tree

3 files changed

+31
-7
lines changed

3 files changed

+31
-7
lines changed

compiler/rustc_hir/src/def.rs

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

src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// check-pass
2+
#![feature(min_const_generics)]
23
#![allow(dead_code)]
34

45
fn foo<T>() {
@@ -13,7 +14,19 @@ impl<T> Foo<T> {
1314
const ASSOC: usize = 4;
1415

1516
fn test() {
16-
[0; Self::ASSOC];
17+
let _ = [0; Self::ASSOC];
18+
//~^ WARN cannot use constants which depend on generic parameters in types
19+
//~| WARN this was previously accepted by the compiler but is being phased out
20+
}
21+
}
22+
23+
struct Bar<const N: usize>;
24+
25+
impl<const N: usize> Bar<N> {
26+
const ASSOC: usize = 4;
27+
28+
fn test() {
29+
let _ = [0; Self::ASSOC];
1730
//~^ WARN cannot use constants which depend on generic parameters in types
1831
//~| WARN this was previously accepted by the compiler but is being phased out
1932
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
warning: cannot use constants which depend on generic parameters in types
2-
--> $DIR/const-evaluatable-unchecked.rs:5:9
2+
--> $DIR/const-evaluatable-unchecked.rs:6:9
33
|
44
LL | [0; std::mem::size_of::<*mut T>()];
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -9,13 +9,22 @@ LL | [0; std::mem::size_of::<*mut T>()];
99
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
1010

1111
warning: cannot use constants which depend on generic parameters in types
12-
--> $DIR/const-evaluatable-unchecked.rs:16:13
12+
--> $DIR/const-evaluatable-unchecked.rs:17:21
1313
|
14-
LL | [0; Self::ASSOC];
15-
| ^^^^^^^^^^^
14+
LL | let _ = [0; Self::ASSOC];
15+
| ^^^^^^^^^^^
1616
|
1717
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
1818
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
1919

20-
warning: 2 warnings emitted
20+
warning: cannot use constants which depend on generic parameters in types
21+
--> $DIR/const-evaluatable-unchecked.rs:29:21
22+
|
23+
LL | let _ = [0; Self::ASSOC];
24+
| ^^^^^^^^^^^
25+
|
26+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
27+
= note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
28+
29+
warning: 3 warnings emitted
2130

0 commit comments

Comments
 (0)