]> git.lizzy.rs Git - rust.git/commitdiff
add tests for self with const params
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Fri, 23 Oct 2020 20:08:21 +0000 (22:08 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Fri, 23 Oct 2020 20:10:44 +0000 (22:10 +0200)
compiler/rustc_hir/src/def.rs
src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.rs
src/test/ui/const-generics/min_const_generics/const-evaluatable-unchecked.stderr

index 62b1254287724aedacab6f5a7642124dbfd2bcdb..193247af584bb579d240582f8de712df42b22aed 100644 (file)
@@ -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]`
 
index 4e99a098a34fe1af59b6c3ea49daddaca2e22917..dd82be33a8e80b7be29d5c4c1da7641f28bcd49d 100644 (file)
@@ -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
     }
index f493f0da040b9d95f93b0178537ee670340f6044..4d0cab012f99e1fef4c9ab31b4c6422d4dfa89d0 100644 (file)
@@ -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