Skip to content

Commit 72e0e17

Browse files
authored
Rollup merge of #113395 - compiler-errors:new-solver-dyn-star-selection, r=oli-obk
Dont ICE for `dyn* Trait: Trait` (built-in object) goals during selection in new trait solver We were ICEing too eagerly during selection for `dyn*` goals -- both for dyn unsizing candidates and for built-in object candidates. The former should only be performed on `dyn` objects, but the latter are totally fine.
2 parents 1bb5dd6 + cd26d10 commit 72e0e17

File tree

2 files changed

+9
-5
lines changed
  • compiler/rustc_trait_selection/src/solve/eval_ctxt
  • tests/ui/dyn-star

2 files changed

+9
-5
lines changed

compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,16 @@ fn rematch_object<'tcx>(
213213
mut nested: Vec<PredicateObligation<'tcx>>,
214214
) -> SelectionResult<'tcx, Selection<'tcx>> {
215215
let self_ty = goal.predicate.self_ty();
216-
let source_trait_ref = if let ty::Dynamic(data, _, ty::Dyn) = self_ty.kind() {
217-
data.principal().unwrap().with_self_ty(infcx.tcx, self_ty)
218-
} else {
216+
let ty::Dynamic(data, _, source_kind) = *self_ty.kind()
217+
else {
219218
bug!()
220219
};
220+
let source_trait_ref = data.principal().unwrap().with_self_ty(infcx.tcx, self_ty);
221221

222222
let (is_upcasting, target_trait_ref_unnormalized) = if Some(goal.predicate.def_id())
223223
== infcx.tcx.lang_items().unsize_trait()
224224
{
225+
assert_eq!(source_kind, ty::Dyn, "cannot upcast dyn*");
225226
if let ty::Dynamic(data, _, ty::Dyn) = goal.predicate.trait_ref.substs.type_at(1).kind() {
226227
(true, data.principal().unwrap().with_self_ty(infcx.tcx, self_ty))
227228
} else {
@@ -288,7 +289,8 @@ fn rematch_object<'tcx>(
288289
bug!();
289290
};
290291

291-
// If we're upcasting, get the offset of the vtable pointer, which is
292+
// If we're upcasting, get the offset of the vtable pointer, otherwise get
293+
// the base of the vtable.
292294
Ok(Some(if is_upcasting {
293295
ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData { vtable_vptr_slot, nested })
294296
} else {

tests/ui/dyn-star/box.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// run-pass
2-
// compile-flags: -C opt-level=0
2+
// revisions: current next
3+
//[current] compile-flags: -C opt-level=0
4+
//[next] compile-flags: -Ztrait-solver=next -C opt-level=0
35

46
#![feature(dyn_star)]
57
#![allow(incomplete_features)]

0 commit comments

Comments
 (0)