about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBoxy <supbscripter@gmail.com>2022-11-24 11:25:19 +0000
committerkadmin <julianknodt@gmail.com>2022-11-25 09:28:44 +0000
commit677bdcb8a907d4e348e34c40479976e0f0446de8 (patch)
treedeaa8f33b578ccff32cdf64400e07bcf20878003
parent2ac5d91d63e0cd2da3f0535163638bd9fe3020b2 (diff)
downloadrust-677bdcb8a907d4e348e34c40479976e0f0446de8.tar.gz
rust-677bdcb8a907d4e348e34c40479976e0f0446de8.zip
only emit "enable gce" error if it would fix compile error
-rw-r--r--compiler/rustc_trait_selection/src/traits/const_evaluatable.rs25
1 files changed, 17 insertions, 8 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
index a26653b3184..e9e65336299 100644
--- a/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
+++ b/compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
@@ -52,7 +52,7 @@ pub fn is_const_evaluatable<'tcx>(
         };
 
         if !is_anon_ct {
-            if satisfied_from_param_env(tcx, infcx, ct, param_env)? {
+            if satisfied_from_param_env(tcx, infcx, ct, param_env) {
                 return Ok(());
             }
             if ct.has_non_region_infer() {
@@ -87,8 +87,14 @@ pub fn is_const_evaluatable<'tcx>(
             // If we're evaluating a generic foreign constant, under a nightly compiler while
             // the current crate does not enable `feature(generic_const_exprs)`, abort
             // compilation with a useful error.
-            Err(_) if tcx.sess.is_nightly_build()
-                && let ty::ConstKind::Expr(_) = tcx.expand_abstract_consts(ct).kind() =>
+            Err(_)
+                if tcx.sess.is_nightly_build()
+                    && satisfied_from_param_env(
+                        tcx,
+                        infcx,
+                        tcx.expand_abstract_consts(ct),
+                        param_env,
+                    ) =>
             {
                 tcx.sess
                     .struct_span_fatal(
@@ -112,12 +118,15 @@ pub fn is_const_evaluatable<'tcx>(
                 } else if uv.has_non_region_param() {
                     NotConstEvaluatable::MentionsParam
                 } else {
-                    let guar = infcx.tcx.sess.delay_span_bug(span, format!("Missing value for constant, but no error reported?"));
+                    let guar = infcx.tcx.sess.delay_span_bug(
+                        span,
+                        format!("Missing value for constant, but no error reported?"),
+                    );
                     NotConstEvaluatable::Error(guar)
                 };
 
                 Err(err)
-            },
+            }
             Err(ErrorHandled::Reported(e)) => Err(NotConstEvaluatable::Error(e)),
             Ok(_) => Ok(()),
         }
@@ -130,7 +139,7 @@ fn satisfied_from_param_env<'tcx>(
     infcx: &InferCtxt<'tcx>,
     ct: ty::Const<'tcx>,
     param_env: ty::ParamEnv<'tcx>,
-) -> Result<bool, NotConstEvaluatable> {
+) -> bool {
     // Try to unify with each subtree in the AbstractConst to allow for
     // `N + 1` being const evaluatable even if theres only a `ConstEvaluatable`
     // predicate for `(N + 1) * 2`
@@ -179,12 +188,12 @@ fn satisfied_from_param_env<'tcx>(
 
                 if let ControlFlow::Break(()) = result {
                     debug!("is_const_evaluatable: abstract_const ~~> ok");
-                    return Ok(true);
+                    return true;
                 }
             }
             _ => {} // don't care
         }
     }
 
-    Ok(false)
+    false
 }