Skip to content

Commit 3aea469

Browse files
Emit alias-eq when equating numeric var and projection
1 parent 39f2657 commit 3aea469

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

compiler/rustc_infer/src/infer/combine.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,20 +119,30 @@ impl<'tcx> InferCtxt<'tcx> {
119119
self.unify_float_variable(!a_is_expected, v_id, v)
120120
}
121121

122-
// All other cases of inference are errors
123-
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
124-
Err(TypeError::Sorts(ty::relate::expected_found(relation, a, b)))
122+
// We don't expect `TyVar` or `Fresh*` vars at this point with lazy norm.
123+
(
124+
ty::Alias(AliasKind::Projection, _),
125+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)),
126+
)
127+
| (
128+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)),
129+
ty::Alias(AliasKind::Projection, _),
130+
) if self.tcx.trait_solver_next() => {
131+
bug!()
125132
}
126133

127-
(ty::Alias(AliasKind::Projection, _), _) if self.tcx.trait_solver_next() => {
134+
(_, ty::Alias(AliasKind::Projection, _)) | (ty::Alias(AliasKind::Projection, _), _)
135+
if self.tcx.trait_solver_next() =>
136+
{
128137
relation.register_type_equate_obligation(a, b);
129-
Ok(b)
130-
}
131-
(_, ty::Alias(AliasKind::Projection, _)) if self.tcx.trait_solver_next() => {
132-
relation.register_type_equate_obligation(b, a);
133138
Ok(a)
134139
}
135140

141+
// All other cases of inference are errors
142+
(&ty::Infer(_), _) | (_, &ty::Infer(_)) => {
143+
Err(TypeError::Sorts(ty::relate::expected_found(relation, a, b)))
144+
}
145+
136146
_ => ty::relate::super_relate_tys(relation, a, b),
137147
}
138148
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -995,7 +995,7 @@ impl<'tcx> Term<'tcx> {
995995

996996
pub fn is_infer(&self) -> bool {
997997
match self.unpack() {
998-
TermKind::Ty(ty) => ty.is_ty_or_numeric_infer(),
998+
TermKind::Ty(ty) => ty.is_ty_var(),
999999
TermKind::Const(ct) => ct.is_ct_infer(),
10001000
}
10011001
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
// compile-flags: -Ztrait-solver=next
3+
4+
// HIR typeck ends up equating `<_#0i as Add>::Output == _#0i`.
5+
// Want to make sure that we emit an alias-eq goal for this,
6+
// instead of treating it as a type error and bailing.
7+
8+
fn test() {
9+
// fallback
10+
let x = 1 + 2;
11+
}
12+
13+
fn test2() -> u32 {
14+
// expectation from return ty
15+
1 + 2
16+
}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)