about summary refs log tree commit diff
path: root/src/librustc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-02-20 08:41:17 +0000
committerbors <bors@rust-lang.org>2020-02-20 08:41:17 +0000
commit6af388b25050bca26710be7e4030e17bf6d8d2f7 (patch)
tree7126a3429ceb0e584cdcca8b7b75ecaaebf88d02 /src/librustc
parentde362d88ea17ab23ca2483cb798bc7aeb81a48f5 (diff)
parent19801b12c950f727a4e6938a87b0b2fdece73c07 (diff)
downloadrust-6af388b25050bca26710be7e4030e17bf6d8d2f7.tar.gz
rust-6af388b25050bca26710be7e4030e17bf6d8d2f7.zip
Auto merge of #68847 - ecstatic-morse:const-impl, r=oli-obk
Allow trait methods to be called on concrete types in a const context

This partially implements [RFC 2632](https://github.com/rust-lang/rfcs/pull/2632) by const-checking methods inside an `impl const` block and allowing those methods to be called on concrete types. Calling trait methods on type parameters in a const context is not yet allowed. Implementing this will require much more work. Since we are only concerned with methods on concrete types, we are able to take advantage of the machinery in `Instance::resolve`, which is doing most of the work.

This also propagates `#[rustc_const_unstable]` from parent items to child items, making that attribute behave like `#[stable]` and `#[unstable]` do. This allows trait methods to be marked as unstably const.

cc #67792 #57563
cc @rust-lang/wg-const-eval
r? @oli-obk
Diffstat (limited to 'src/librustc')
-rw-r--r--src/librustc/query/mod.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustc/query/mod.rs b/src/librustc/query/mod.rs
index 45ab3fc0b85..3cee10f1356 100644
--- a/src/librustc/query/mod.rs
+++ b/src/librustc/query/mod.rs
@@ -279,6 +279,14 @@ rustc_queries! {
             desc { |tcx| "checking if item is const fn: `{}`", tcx.def_path_str(key) }
         }
 
+        /// Returns `true` if this is a const `impl`. **Do not call this function manually.**
+        ///
+        /// This query caches the base data for the `is_const_impl` helper function, which also
+        /// takes into account stability attributes (e.g., `#[rustc_const_unstable]`).
+        query is_const_impl_raw(key: DefId) -> bool {
+            desc { |tcx| "checking if item is const impl: `{}`", tcx.def_path_str(key) }
+        }
+
         query asyncness(key: DefId) -> hir::IsAsync {
             desc { |tcx| "checking if the function is async: `{}`", tcx.def_path_str(key) }
         }