about summary refs log tree commit diff
path: root/src/librustc_middle
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-08-08 01:48:35 +0000
committerbors <bors@rust-lang.org>2020-08-08 01:48:35 +0000
commitf9c2177ddc605f9c75ca1a3e6ddb33835b8a178d (patch)
treed8f6d0b66e018cde836a6fb6faa7a7f38116c84b /src/librustc_middle
parentf3a9de9b08659e20ce7c282ed77bc43ddd149107 (diff)
parent644c8949121da0c16f65b772bf6e217748d94530 (diff)
downloadrust-f9c2177ddc605f9c75ca1a3e6ddb33835b8a178d.tar.gz
rust-f9c2177ddc605f9c75ca1a3e6ddb33835b8a178d.zip
Auto merge of #74877 - lcnr:min_const_generics, r=oli-obk
Implement the `min_const_generics` feature gate

Implements both https://github.com/rust-lang/lang-team/issues/37 and https://github.com/rust-lang/compiler-team/issues/332.

Adds the new feature gate `#![feature(min_const_generics)]`.
This feature gate adds the following limitations to using const generics:
- generic parameters must only be used in types if they are trivial. (either `N` or `{ N }`)
- generic parameters must be either integers, `bool` or `char`.

We do allow arbitrary expressions in associated consts though, meaning that the following is allowed,
even if `<[u8; 0] as Foo>::ASSOC` is not const evaluatable.
```rust
trait Foo {
    const ASSOC: usize;
}

impl<const N: usize> Foo for [u8; N] {
    const ASSOC: usize = 64 / N;
}
```

r? @varkor cc @eddyb @withoutboats
Diffstat (limited to 'src/librustc_middle')
-rw-r--r--src/librustc_middle/ty/context.rs4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs
index 6cbf5db8373..16f5e9a42d3 100644
--- a/src/librustc_middle/ty/context.rs
+++ b/src/librustc_middle/ty/context.rs
@@ -1380,7 +1380,9 @@ impl<'tcx> TyCtxt<'tcx> {
     /// we still evaluate them eagerly.
     #[inline]
     pub fn lazy_normalization(self) -> bool {
-        self.features().const_generics || self.features().lazy_normalization_consts
+        let features = self.features();
+        // Note: We do not enable lazy normalization for `features.min_const_generics`.
+        features.const_generics || features.lazy_normalization_consts
     }
 
     #[inline]