Skip to content

Commit dd08f35

Browse files
authored
Rollup merge of rust-lang#107286 - compiler-errors:new-solver-deny-infers, r=lcnr
ICE in new solver if we see an inference variable By construction, we do not expect to see any `ty::Infer(ty::TyVar(_))` inference types in the solver (we treat this as ambiguous, since we need to be able to structurally resolve the self type at least one layer to assemble candidates for it). Additionally, since we're doing no freshening, we also don't expect to see any fresh vars of any kind in the solver. Let's make that an ICE so we can catch any mistakes. When rust-lang#107282 lands, we should also ICE there too if we see a non-int/float infer. r? `@lcnr`
2 parents 5be2f51 + 0f24e11 commit dd08f35

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
@@ -335,9 +335,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
335335
| ty::Tuple(_)
336336
| ty::Param(_)
337337
| ty::Placeholder(..)
338-
| ty::Infer(_)
338+
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
339339
| ty::Error(_) => return,
340-
ty::Bound(..) => bug!("unexpected bound type: {goal:?}"),
340+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
341+
| ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"),
341342
ty::Alias(_, alias_ty) => alias_ty,
342343
};
343344

@@ -385,9 +386,10 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
385386
| ty::Tuple(_)
386387
| ty::Param(_)
387388
| ty::Placeholder(..)
388-
| ty::Infer(_)
389+
| ty::Infer(ty::IntVar(_) | ty::FloatVar(_))
389390
| ty::Error(_) => return,
390-
ty::Bound(..) => bug!("unexpected bound type: {goal:?}"),
391+
ty::Infer(ty::TyVar(_) | ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_))
392+
| ty::Bound(..) => bug!("unexpected self type for `{goal:?}`"),
391393
ty::Dynamic(bounds, ..) => bounds,
392394
};
393395

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

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

0 commit comments

Comments
 (0)