Skip to content

Commit 56ab3e7

Browse files
committed
Add builtin impls for int and float inference vars in chalk
1 parent c75e089 commit 56ab3e7

File tree

1 file changed

+19
-14
lines changed
  • src/librustc_traits/chalk_context/program_clauses

1 file changed

+19
-14
lines changed

src/librustc_traits/chalk_context/program_clauses/builtin.rs

+19-14
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ crate fn assemble_builtin_sized_impls<'tcx>(
137137
ty::Int(..) |
138138
ty::Uint(..) |
139139
ty::Float(..) |
140+
ty::Infer(ty::IntVar(_)) |
141+
ty::Infer(ty::FloatVar(_)) |
140142
ty::Error |
141143
ty::Never => push_builtin_impl(ty, &[]),
142144

@@ -188,14 +190,11 @@ crate fn assemble_builtin_sized_impls<'tcx>(
188190
push_builtin_impl(adt, &sized_constraint);
189191
}
190192

191-
// Artificially trigger an ambiguity.
192-
ty::Infer(..) => {
193-
// Everybody can find at least two types to unify against:
194-
// general ty vars, int vars and float vars.
193+
// Artificially trigger an ambiguity by adding two possible types to
194+
// unify against.
195+
ty::Infer(ty::TyVar(_)) => {
195196
push_builtin_impl(tcx.types.i32, &[]);
196-
push_builtin_impl(tcx.types.u32, &[]);
197197
push_builtin_impl(tcx.types.f32, &[]);
198-
push_builtin_impl(tcx.types.f64, &[]);
199198
}
200199

201200
ty::Projection(_projection_ty) => {
@@ -216,7 +215,10 @@ crate fn assemble_builtin_sized_impls<'tcx>(
216215
ty::Opaque(..) => (),
217216

218217
ty::Bound(..) |
219-
ty::GeneratorWitness(..) => bug!("unexpected type {:?}", ty),
218+
ty::GeneratorWitness(..) |
219+
ty::Infer(ty::FreshTy(_)) |
220+
ty::Infer(ty::FreshIntTy(_)) |
221+
ty::Infer(ty::FreshFloatTy(_)) => bug!("unexpected type {:?}", ty),
220222
}
221223
}
222224

@@ -243,7 +245,9 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>(
243245
ty::Never |
244246
ty::Ref(_, _, hir::MutImmutable) => (),
245247

246-
// Non parametric primitive type.
248+
// Non parametric primitive types.
249+
ty::Infer(ty::IntVar(_)) |
250+
ty::Infer(ty::FloatVar(_)) |
247251
ty::Error => push_builtin_impl(ty, &[]),
248252

249253
// These implement `Copy`/`Clone` if their element types do.
@@ -283,13 +287,11 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>(
283287
// These depend on whatever user-defined impls might exist.
284288
ty::Adt(_, _) => (),
285289

286-
// int vars and float vars are always `Copy`.
287-
// Other vars will trigger an ambiguity.
288-
ty::Infer(..) => {
290+
// Artificially trigger an ambiguity by adding two possible types to
291+
// unify against.
292+
ty::Infer(ty::TyVar(_)) => {
289293
push_builtin_impl(tcx.types.i32, &[]);
290-
push_builtin_impl(tcx.types.u32, &[]);
291294
push_builtin_impl(tcx.types.f32, &[]);
292-
push_builtin_impl(tcx.types.f64, &[]);
293295
}
294296

295297
ty::Projection(_projection_ty) => {
@@ -312,6 +314,9 @@ crate fn assemble_builtin_copy_clone_impls<'tcx>(
312314
ty::Ref(_, _, hir::MutMutable) => (),
313315

314316
ty::Bound(..) |
315-
ty::GeneratorWitness(..) => bug!("unexpected type {:?}", ty),
317+
ty::GeneratorWitness(..) |
318+
ty::Infer(ty::FreshTy(_)) |
319+
ty::Infer(ty::FreshIntTy(_)) |
320+
ty::Infer(ty::FreshFloatTy(_)) => bug!("unexpected type {:?}", ty),
316321
}
317322
}

0 commit comments

Comments
 (0)