about summary refs log tree commit diff
path: root/compiler/rustc_infer
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-07-14 19:24:04 +0530
committerGitHub <noreply@github.com>2022-07-14 19:24:04 +0530
commitecae3d74e26b8f10322060954fbc2a6c4ba92402 (patch)
tree22fce1b96af296f285880e54f300fa8c067cdadf /compiler/rustc_infer
parent8c5c983e5bb491682b57a9bbe33be4f2b94fa2ec (diff)
parent20fb8aba8f39e257e7003918f9a299633511511b (diff)
downloadrust-ecae3d74e26b8f10322060954fbc2a6c4ba92402.tar.gz
rust-ecae3d74e26b8f10322060954fbc2a6c4ba92402.zip
Rollup merge of #99000 - JulianKnodt:allow_resolve_no_substs, r=lcnr
Move abstract const to middle

Moves AbstractConst (and all associated methods) to rustc middle for use in `rustc_infer`.
This allows for const resolution in infer to use abstract consts to walk consts and check if
they are resolvable.

This attempts to resolve the issue where `Foo<{ concrete const }, generic T>` is incorrectly marked as conflicting, and is independent from the other issue where nested abstract consts must be resolved.

r? `@lcnr`
Diffstat (limited to 'compiler/rustc_infer')
-rw-r--r--compiler/rustc_infer/src/infer/mod.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/compiler/rustc_infer/src/infer/mod.rs b/compiler/rustc_infer/src/infer/mod.rs
index 28f037cc61a..881682678db 100644
--- a/compiler/rustc_infer/src/infer/mod.rs
+++ b/compiler/rustc_infer/src/infer/mod.rs
@@ -21,6 +21,7 @@ use rustc_middle::infer::unify_key::{ConstVarValue, ConstVariableValue};
 use rustc_middle::infer::unify_key::{ConstVariableOrigin, ConstVariableOriginKind, ToType};
 use rustc_middle::mir::interpret::{ErrorHandled, EvalToValTreeResult};
 use rustc_middle::traits::select;
+use rustc_middle::ty::abstract_const::AbstractConst;
 use rustc_middle::ty::error::{ExpectedFound, TypeError};
 use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
 use rustc_middle::ty::relate::RelateResult;
@@ -1651,14 +1652,18 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
         unevaluated: ty::Unevaluated<'tcx>,
         span: Option<Span>,
     ) -> EvalToValTreeResult<'tcx> {
-        let substs = self.resolve_vars_if_possible(unevaluated.substs);
+        let mut substs = self.resolve_vars_if_possible(unevaluated.substs);
         debug!(?substs);
 
         // Postpone the evaluation of constants whose substs depend on inference
         // variables
         if substs.has_infer_types_or_consts() {
-            debug!("substs have infer types or consts: {:?}", substs);
-            return Err(ErrorHandled::TooGeneric);
+            let ac = AbstractConst::new(self.tcx, unevaluated.shrink());
+            if let Ok(None) = ac {
+                substs = InternalSubsts::identity_for_item(self.tcx, unevaluated.def.did);
+            } else {
+                return Err(ErrorHandled::TooGeneric);
+            }
         }
 
         let param_env_erased = self.tcx.erase_regions(param_env);