Skip to content

Commit 925e304

Browse files
committed
Fix resolve_type_vars_with_obligations not resolving const inference
variables.
1 parent c491875 commit 925e304

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

src/librustc/infer/resolve.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use super::{InferCtxt, FixupError, FixupResult, Span};
22
use super::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
33
use crate::mir::interpret::ConstValue;
4-
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst, TypeFlags};
4+
use crate::ty::{self, Ty, Const, TyCtxt, TypeFoldable, InferConst};
55
use crate::ty::fold::{TypeFolder, TypeVisitor};
66

77
///////////////////////////////////////////////////////////////////////////
@@ -29,7 +29,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
2929
}
3030

3131
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
32-
if !t.has_infer_types() {
32+
if !t.has_infer_types() && !t.has_infer_consts() {
3333
t // micro-optimize -- if there is nothing in this type that this fold affects...
3434
} else {
3535
let t = self.infcx.shallow_resolve(t);
@@ -38,7 +38,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
3838
}
3939

4040
fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> {
41-
if !ct.has_type_flags(TypeFlags::HAS_CT_INFER) {
41+
if !ct.has_infer_consts() {
4242
ct // micro-optimize -- if there is nothing in this const that this fold affects...
4343
} else {
4444
let ct = self.infcx.shallow_resolve(ct);

src/librustc/ty/fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
8888
fn has_infer_types(&self) -> bool {
8989
self.has_type_flags(TypeFlags::HAS_TY_INFER)
9090
}
91+
fn has_infer_consts(&self) -> bool {
92+
self.has_type_flags(TypeFlags::HAS_CT_INFER)
93+
}
9194
fn has_local_value(&self) -> bool {
9295
self.has_type_flags(TypeFlags::KEEP_IN_LOCAL_TCX)
9396
}

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,14 +2448,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
24482448
debug!("resolve_type_vars_with_obligations(ty={:?})", ty);
24492449

24502450
// No Infer()? Nothing needs doing.
2451-
if !ty.has_infer_types() {
2451+
if !ty.has_infer_types() && !ty.has_infer_consts() {
24522452
debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
24532453
return ty;
24542454
}
24552455

24562456
// If `ty` is a type variable, see whether we already know what it is.
24572457
ty = self.resolve_vars_if_possible(&ty);
2458-
if !ty.has_infer_types() {
2458+
if !ty.has_infer_types() && !ty.has_infer_consts() {
24592459
debug!("resolve_type_vars_with_obligations: ty={:?}", ty);
24602460
return ty;
24612461
}

src/test/ui/const-generics/const-argument-cross-crate-mismatch.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
error[E0308]: mismatched types
2-
--> $DIR/const-argument-cross-crate-mismatch.rs:6:41
2+
--> $DIR/const-argument-cross-crate-mismatch.rs:6:67
33
|
44
LL | let _ = const_generic_lib::function(const_generic_lib::Struct([0u8, 1u8]));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `3usize`, found `2usize`
5+
| ^^^^^^^^^^ expected an array with a fixed size of 3 elements, found one with 2 elements
66
|
7-
= note: expected type `const_generic_lib::Struct<3usize>`
8-
found type `const_generic_lib::Struct<_: usize>`
7+
= note: expected type `[u8; 3]`
8+
found type `[u8; 2]`
99

1010
error[E0308]: mismatched types
11-
--> $DIR/const-argument-cross-crate-mismatch.rs:8:39
11+
--> $DIR/const-argument-cross-crate-mismatch.rs:8:65
1212
|
1313
LL | let _: const_generic_lib::Alias = const_generic_lib::Struct([0u8, 1u8, 2u8]);
14-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `2usize`, found `3usize`
14+
| ^^^^^^^^^^^^^^^ expected an array with a fixed size of 2 elements, found one with 3 elements
1515
|
16-
= note: expected type `const_generic_lib::Struct<2usize>`
17-
found type `const_generic_lib::Struct<_: usize>`
16+
= note: expected type `[u8; 2]`
17+
found type `[u8; 3]`
1818

1919
error: aborting due to 2 previous errors
2020

0 commit comments

Comments
 (0)