Skip to content

Commit 0f24e11

Browse files
ICE in new solver if we see an inference variable
1 parent 2a17174 commit 0f24e11

File tree

3 files changed

+33
-22
lines changed

3 files changed

+33
-22
lines changed

compiler/rustc_trait_selection/src/solve/assembly.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
321321
| ty::Tuple(_)
322322
| ty::Param(_)
323323
| ty::Placeholder(..)
324-
| ty::Infer(_)
324+
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
325325
| ty::Error(_) => return,
326-
ty::Bound(..) => bug!("unexpected bound type: {goal:?}"),
326+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
327+
| ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"),
327328
ty::Alias(_, alias_ty) => alias_ty,
328329
};
329330

@@ -371,9 +372,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
371372
| ty::Tuple(_)
372373
| ty::Param(_)
373374
| ty::Placeholder(..)
374-
| ty::Infer(_)
375+
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
375376
| ty::Error(_) => return,
376-
ty::Bound(..) => bug!("unexpected bound type: {goal:?}"),
377+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
378+
| ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"),
377379
ty::Dynamic(bounds, ..) => bounds,
378380
};
379381

compiler/rustc_trait_selection/src/solve/project_goals.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
427427
.subst(tcx, &[ty::GenericArg::from(goal.predicate.self_ty())])
428428
}
429429

430-
ty::Infer(ty::TyVar(..)) | ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
430+
ty::Alias(_, _) | ty::Param(_) | ty::Placeholder(..) => {
431431
// FIXME(ptr_metadata): It would also be possible to return a `Ok(Ambig)` with no constraints.
432432
let sized_predicate = ty::Binder::dummy(tcx.at(DUMMY_SP).mk_trait_ref(
433433
LangItem::Sized,
@@ -470,7 +470,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
470470
}
471471
},
472472

473-
ty::Infer(ty::FreshTy(..) | ty::FreshIntTy(..) | ty::FreshFloatTy(..))
473+
ty::Infer(
474+
ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_),
475+
)
474476
| ty::Bound(..) => bug!(
475477
"unexpected self ty `{:?}` when normalizing `<T as Pointee>::Metadata`",
476478
goal.predicate.self_ty()

compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,16 @@ pub(super) fn instantiate_constituent_tys_for_auto_trait<'tcx>(
2424
| ty::Never
2525
| ty::Char => Ok(vec![]),
2626

27-
ty::Placeholder(..)
28-
| ty::Dynamic(..)
27+
ty::Dynamic(..)
2928
| ty::Param(..)
3029
| ty::Foreign(..)
3130
| ty::Alias(ty::Projection, ..)
32-
| ty::Bound(..)
33-
| ty::Infer(ty::TyVar(_)) => Err(NoSolution),
31+
| ty::Placeholder(..) => Err(NoSolution),
3432

35-
ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!(),
33+
ty::Bound(..)
34+
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
35+
bug!("unexpected type `{ty}`")
36+
}
3637

3738
ty::RawPtr(ty::TypeAndMut { ty: element_ty, .. }) | ty::Ref(_, element_ty, _) => {
3839
Ok(vec![element_ty])
@@ -99,11 +100,12 @@ pub(super) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
99100
| ty::Foreign(..)
100101
| ty::Alias(..)
101102
| ty::Param(_)
102-
| ty::Infer(ty::TyVar(_)) => Err(NoSolution),
103+
| ty::Placeholder(..) => Err(NoSolution),
103104

104-
ty::Placeholder(..)
105-
| ty::Bound(..)
106-
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!(),
105+
ty::Bound(..)
106+
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
107+
bug!("unexpected type `{ty}`")
108+
}
107109

108110
ty::Tuple(tys) => Ok(tys.to_vec()),
109111

@@ -148,11 +150,12 @@ pub(super) fn instantiate_constituent_tys_for_copy_clone_trait<'tcx>(
148150
| ty::Adt(_, _)
149151
| ty::Alias(_, _)
150152
| ty::Param(_)
151-
| ty::Infer(ty::TyVar(_)) => Err(NoSolution),
153+
| ty::Placeholder(..) => Err(NoSolution),
152154

153-
ty::Placeholder(..)
154-
| ty::Bound(..)
155-
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => bug!(),
155+
ty::Bound(..)
156+
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
157+
bug!("unexpected type `{ty}`")
158+
}
156159

157160
ty::Tuple(tys) => Ok(tys.to_vec()),
158161

@@ -215,9 +218,13 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>(
215218
| ty::Tuple(_)
216219
| ty::Alias(_, _)
217220
| ty::Param(_)
218-
| ty::Placeholder(_)
219-
| ty::Bound(_, _)
220-
| ty::Infer(_)
221+
| ty::Placeholder(..)
222+
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
221223
| ty::Error(_) => Err(NoSolution),
224+
225+
ty::Bound(..)
226+
| ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
227+
bug!("unexpected type `{self_ty}`")
228+
}
222229
}
223230
}

0 commit comments

Comments
 (0)