]> git.lizzy.rs Git - rust.git/commitdiff
Fix resolve_type_vars_with_obligations not resolving const inference
authorben <benlewisj@gmail.com>
Fri, 18 Oct 2019 22:57:48 +0000 (11:57 +1300)
committerben <benlewisj@gmail.com>
Sat, 19 Oct 2019 20:16:52 +0000 (09:16 +1300)
variables.

src/librustc/infer/resolve.rs
src/librustc/ty/fold.rs
src/librustc_typeck/check/mod.rs
src/test/ui/const-generics/const-argument-cross-crate-mismatch.stderr

index 2db18674e2f53a8a423802b50ae175b681195da5..7c3a338366c9af3f3edf3ab291006e33411875b3 100644 (file)
@@ -1,7 +1,7 @@
 use super::{InferCtxt, FixupError, FixupResult, Span};
 use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
 use crate::mir::interpret::ConstValue;
-use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags};
+use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst};
 use crate::ty::fold::{TypeFolder, TypeVisitor};
 
 ///////////////////////////////////////////////////////////////////////////
@@ -29,7 +29,7 @@ fn tcx<'b>(&'b self) -> TyCtxt<'tcx> {
     }
 
     fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
-        if !t.has_infer_types() {
+        if !t.has_infer_types() && !t.has_infer_consts() {
             t // micro-optimize -- if there is nothing in this type that this fold affects...
         } else {
             let t = self.infcx.shallow_resolve(t);
@@ -38,7 +38,7 @@ fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
     }
 
     fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> {
-        if !ct.has_type_flags(TypeFlags::HAS_CT_INFER) {
+        if !ct.has_infer_consts() {
             ct // micro-optimize -- if there is nothing in this const that this fold affects...
         } else {
             let ct = self.infcx.shallow_resolve(ct);
index 5192075c26e9871068aedc5d7f17fda753228b73..a95ed589c3e2a8950442fb0aabebd81105723f01 100644 (file)
@@ -88,6 +88,9 @@ fn has_param_types(&self) -> bool {
     fn has_infer_types(&self) -> bool {
         self.has_type_flags(TypeFlags::HAS_TY_INFER)
     }
+    fn has_infer_consts(&self) -> bool {
+        self.has_type_flags(TypeFlags::HAS_CT_INFER)
+    }
     fn has_local_value(&self) -> bool {
         self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
     }
index 152edf8dd0e5ad2989be33191a22e7cd5e67f704..013282848226df8765adb9efc85d925feca68725 100644 (file)
@@ -2448,14 +2448,14 @@ fn resolve_type_vars_with_obligations(&self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
         debug!("resolve_type_vars_with_obligations(ty={:?})", ty);
 
         // No Infer()? Nothing needs doing.
-        if !ty.has_infer_types() {
+        if !ty.has_infer_types() && !ty.has_infer_consts() {
             debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
             return ty;
         }
 
         // If `ty` is a type variable, see whether we already know what it is.
         ty = self.resolve_vars_if_possible(&ty);
-        if !ty.has_infer_types() {
+        if !ty.has_infer_types() && !ty.has_infer_consts()  {
             debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
             return ty;
         }
index b7fd29ce7067a266180f3697f0a10fd3a31e52be..7090cb880fd497b3c587a5d2519466bbd061426b 100644 (file)
@@ -1,20 +1,20 @@
 error[E0308]: mismatched types
-  --> $DIR/const-argument-cross-crate-mismatch.rs:6:41
+  --> $DIR/const-argument-cross-crate-mismatch.rs:6:67
    |
 LL |     let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
-   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3usize`, found `2usize`
+   |                                                                   ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
    |
-   = note: expected type `const_generic_lib::Struct<3usize>`
-              found type `const_generic_lib::Struct<_: usize>`
+   = note: expected type `[u8; 3]`
+              found type `[u8; 2]`
 
 error[E0308]: mismatched types
-  --> $DIR/const-argument-cross-crate-mismatch.rs:8:39
+  --> $DIR/const-argument-cross-crate-mismatch.rs:8:65
    |
 LL |     let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
-   |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2usize`, found `3usize`
+   |                                                                 ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
    |
-   = note: expected type `const_generic_lib::Struct<2usize>`
-              found type `const_generic_lib::Struct<_: usize>`
+   = note: expected type `[u8; 2]`
+              found type `[u8; 3]`
 
 error: aborting due to 2 previous errors