]> git.lizzy.rs Git - rust.git/commitdiff
add tracking issue, fix rebase
authorBastian Kauschke <bastian_kauschke@hotmail.de>
Tue, 1 Sep 2020 14:17:41 +0000 (16:17 +0200)
committerBastian Kauschke <bastian_kauschke@hotmail.de>
Tue, 8 Sep 2020 14:39:12 +0000 (16:39 +0200)
compiler/rustc_session/src/lint/builtin.rs
compiler/rustc_trait_selection/src/traits/const_evaluatable.rs [new file with mode: 0644]
src/librustc_trait_selection/traits/const_evaluatable.rs [deleted file]
src/test/ui/const_evaluatable/function-call.stderr
src/test/ui/enum-discriminant/issue-70453-polymorphic-ctfe.stderr
src/test/ui/lazy_normalization_consts/issue-73980.stderr

index 66497df66cad50b205380aa1c09eb70e856720b6..2bcf10b8b38789290203f503bb9ff32eecad2bbd 100644 (file)
     Warn,
     "detects a generic constant is used in a type without a emitting a warning",
     @future_incompatible = FutureIncompatibleInfo {
-        reference: "TODO",
+        reference: "issue #76200 <https://github.com/rust-lang/rust/issues/76200>",
         edition: None,
     };
 }
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
new file mode 100644 (file)
index 0000000..013cd71
--- /dev/null
@@ -0,0 +1,61 @@
+use rustc_hir::def::DefKind;
+use rustc_infer::infer::InferCtxt;
+use rustc_middle::mir::interpret::ErrorHandled;
+use rustc_middle::ty::subst::SubstsRef;
+use rustc_middle::ty::{self, TypeFoldable};
+use rustc_session::lint;
+use rustc_span::def_id::DefId;
+use rustc_span::Span;
+
+pub fn is_const_evaluatable<'cx, 'tcx>(
+    infcx: &InferCtxt<'cx, 'tcx>,
+    def: ty::WithOptConstParam<DefId>,
+    substs: SubstsRef<'tcx>,
+    param_env: ty::ParamEnv<'tcx>,
+    span: Span,
+) -> Result<(), ErrorHandled> {
+    let future_compat_lint = || {
+        if let Some(local_def_id) = def.did.as_local() {
+            infcx.tcx.struct_span_lint_hir(
+                lint::builtin::CONST_EVALUATABLE_UNCHECKED,
+                infcx.tcx.hir().local_def_id_to_hir_id(local_def_id),
+                span,
+                |err| {
+                    err.build("cannot use constants which depend on generic parameters in types")
+                        .emit();
+                },
+            );
+        }
+    };
+
+    // FIXME: We should only try to evaluate a given constant here if it is fully concrete
+    // as we don't want to allow things like `[u8; std::mem::size_of::<*mut T>()]`.
+    //
+    // We previously did not check this, so we only emit a future compat warning if
+    // const evaluation succeeds and the given constant is still polymorphic for now
+    // and hopefully soon change this to an error.
+    //
+    // See #74595 for more details about this.
+    let concrete = infcx.const_eval_resolve(param_env, def, substs, None, Some(span));
+
+    let def_kind = infcx.tcx.def_kind(def.did);
+    match def_kind {
+        DefKind::AnonConst => {
+            let mir_body = if let Some(def) = def.as_const_arg() {
+                infcx.tcx.optimized_mir_of_const_arg(def)
+            } else {
+                infcx.tcx.optimized_mir(def.did)
+            };
+            if mir_body.is_polymorphic && concrete.is_ok() {
+                future_compat_lint();
+            }
+        }
+        _ => {
+            if substs.has_param_types_or_consts() && concrete.is_ok() {
+                future_compat_lint();
+            }
+        }
+    }
+
+    concrete.map(drop)
+}
diff --git a/src/librustc_trait_selection/traits/const_evaluatable.rs b/src/librustc_trait_selection/traits/const_evaluatable.rs
deleted file mode 100644 (file)
index 87762cc..0000000
+++ /dev/null
@@ -1,61 +0,0 @@
-use rustc_hir::def::DefKind;
-use rustc_infer::infer::InferCtxt;
-use rustc_middle::mir::interpret::ErrorHandled;
-use rustc_middle::ty::subst::SubstsRef;
-use rustc_middle::ty::{self, TypeFoldable};
-use rustc_session::lint;
-use rustc_span::def_id::DefId;
-use rustc_span::Span;
-
-pub fn is_const_evaluatable<'cx, 'tcx>(
-    infcx: &InferCtxt<'cx, 'tcx>,
-    def: ty::WithOptConstParam<DefId>,
-    substs: SubstsRef<'tcx>,
-    param_env: ty::ParamEnv<'tcx>,
-    span: Span,
-) -> Result<(), ErrorHandled> {
-    let future_compat_lint = || {
-        if let Some(local_def_id) = def.did.as_local() {
-            infcx.tcx.struct_span_lint_hir(
-                lint::builtin::CONST_EVALUATABLE_UNCHECKED,
-                infcx.tcx.hir().as_local_hir_id(local_def_id),
-                span,
-                |err| {
-                    err.build("cannot use constants which depend on generic parameters in types")
-                        .emit();
-                },
-            );
-        }
-    };
-
-    // FIXME: We should only try to evaluate a given constant here if it is fully concrete
-    // as we don't want to allow things like `[u8; std::mem::size_of::<*mut T>()]`.
-    //
-    // We previously did not check this, so we only emit a future compat warning if
-    // const evaluation succeeds and the given constant is still polymorphic for now
-    // and hopefully soon change this to an error.
-    //
-    // See #74595 for more details about this.
-    let concrete = infcx.const_eval_resolve(param_env, def, substs, None, Some(span));
-
-    let def_kind = infcx.tcx.def_kind(def.did);
-    match def_kind {
-        DefKind::AnonConst => {
-            let mir_body = if let Some(def) = def.as_const_arg() {
-                infcx.tcx.optimized_mir_of_const_arg(def)
-            } else {
-                infcx.tcx.optimized_mir(def.did)
-            };
-            if mir_body.is_polymorphic && concrete.is_ok() {
-                future_compat_lint();
-            }
-        }
-        _ => {
-            if substs.has_param_types_or_consts() && concrete.is_ok() {
-                future_compat_lint();
-            }
-        }
-    }
-
-    concrete.map(drop)
-}
index 5240015c37a343b8d82d2d1f68976179df6b18e8..a15637196062fdc443f5a1f9f06cb1e635e89537 100644 (file)
@@ -6,7 +6,7 @@ LL |     let _ = [0; foo::<T>()];
    |
    = note: `#[warn(const_evaluatable_unchecked)]` on by default
    = 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 TODO
+   = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
 
 warning: 1 warning emitted
 
index 2aeb1b32bcb0a7c41b47dbb1239181ac86bbafe2..906927e705ee8cbb75212d6f0fc4cf9e310bede6 100644 (file)
@@ -6,7 +6,7 @@ LL |     Some(T) = core::mem::size_of::<*mut T>(),
    |
    = note: `#[warn(const_evaluatable_unchecked)]` on by default
    = 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 TODO
+   = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
 
 warning: 1 warning emitted
 
index 8636407a3a102dc9bdc4519c17886994c165dbe2..5ed1ca362f411c69cf1a02321fcdc7082f217a96 100644 (file)
@@ -6,7 +6,7 @@ LL | impl<T> X<T, [u8; L::<T>::S]> {}
    |
    = note: `#[warn(const_evaluatable_unchecked)]` on by default
    = 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 TODO
+   = note: for more information, see issue #76200 <https://github.com/rust-lang/rust/issues/76200>
 
 warning: 1 warning emitted