1
Fork 0

Fix resolve_type_vars_with_obligations not resolving const inference

variables.
This commit is contained in:
ben 2019-10-19 11:57:48 +13:00
parent c49187530d
commit 925e3042f6
4 changed files with 16 additions and 13 deletions

View file

@ -1,7 +1,7 @@
use super::{InferCtxt, FixupError, FixupResult, Span}; use super::{InferCtxt, FixupError, FixupResult, Span};
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind}; use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use crate::mir::interpret::ConstValue; 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}; use crate::ty::fold::{TypeFolder, TypeVisitor};
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
@ -29,7 +29,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
} }
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'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... t // micro-optimize -- if there is nothing in this type that this fold affects...
} else { } else {
let t = self.infcx.shallow_resolve(t); let t = self.infcx.shallow_resolve(t);
@ -38,7 +38,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
} }
fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'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... ct // micro-optimize -- if there is nothing in this const that this fold affects...
} else { } else {
let ct = self.infcx.shallow_resolve(ct); let ct = self.infcx.shallow_resolve(ct);

View file

@ -88,6 +88,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
fn has_infer_types(&self) -> bool { fn has_infer_types(&self) -> bool {
self.has_type_flags(TypeFlags::HAS_TY_INFER) 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 { fn has_local_value(&self) -> bool {
self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX) self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
} }

View file

@ -2448,14 +2448,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
debug!("resolve_type_vars_with_obligations(ty={:?})", ty); debug!("resolve_type_vars_with_obligations(ty={:?})", ty);
// No Infer()? Nothing needs doing. // 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); debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
return ty; return ty;
} }
// If `ty` is a type variable, see whether we already know what it is. // If `ty` is a type variable, see whether we already know what it is.
ty = self.resolve_vars_if_possible(&ty); 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); debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
return ty; return ty;
} }

View file

@ -1,20 +1,20 @@
error[E0308]: mismatched types 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])); 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>` = note: expected type `[u8; 3]`
found type `const_generic_lib::Struct<_: usize>` found type `[u8; 2]`
error[E0308]: mismatched types 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]); 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>` = note: expected type `[u8; 2]`
found type `const_generic_lib::Struct<_: usize>` found type `[u8; 3]`
error: aborting due to 2 previous errors error: aborting due to 2 previous errors