diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-07-06 12:12:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-07-06 12:12:12 +0200 |
| commit | 72e0e177d583cb9bd3879e0776e01291ec7563d3 (patch) | |
| tree | a6e73afdc0c12b56a7da89112785fd7c7d61a3e5 | |
| parent | 1bb5dd65759218b889f72f39e7b09eef1e389873 (diff) | |
| parent | cd26d10edfa8df69266e85b5ab7b991de0a10b38 (diff) | |
| download | rust-72e0e177d583cb9bd3879e0776e01291ec7563d3.tar.gz rust-72e0e177d583cb9bd3879e0776e01291ec7563d3.zip | |
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.
| -rw-r--r-- | compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs | 10 | ||||
| -rw-r--r-- | tests/ui/dyn-star/box.rs | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs index 18332d6811d..366e9aa793d 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt/select.rs @@ -213,15 +213,16 @@ fn rematch_object<'tcx>( mut nested: Vec<PredicateObligation<'tcx>>, ) -> SelectionResult<'tcx, Selection<'tcx>> { let self_ty = goal.predicate.self_ty(); - let source_trait_ref = if let ty::Dynamic(data, _, ty::Dyn) = self_ty.kind() { - data.principal().unwrap().with_self_ty(infcx.tcx, self_ty) - } else { + let ty::Dynamic(data, _, source_kind) = *self_ty.kind() + else { bug!() }; + let source_trait_ref = data.principal().unwrap().with_self_ty(infcx.tcx, self_ty); let (is_upcasting, target_trait_ref_unnormalized) = if Some(goal.predicate.def_id()) == infcx.tcx.lang_items().unsize_trait() { + assert_eq!(source_kind, ty::Dyn, "cannot upcast dyn*"); if let ty::Dynamic(data, _, ty::Dyn) = goal.predicate.trait_ref.substs.type_at(1).kind() { (true, data.principal().unwrap().with_self_ty(infcx.tcx, self_ty)) } else { @@ -288,7 +289,8 @@ fn rematch_object<'tcx>( bug!(); }; - // If we're upcasting, get the offset of the vtable pointer, which is + // If we're upcasting, get the offset of the vtable pointer, otherwise get + // the base of the vtable. Ok(Some(if is_upcasting { ImplSource::TraitUpcasting(ImplSourceTraitUpcastingData { vtable_vptr_slot, nested }) } else { diff --git a/tests/ui/dyn-star/box.rs b/tests/ui/dyn-star/box.rs index d1f1819d9f3..87c8356a174 100644 --- a/tests/ui/dyn-star/box.rs +++ b/tests/ui/dyn-star/box.rs @@ -1,5 +1,7 @@ // run-pass -// compile-flags: -C opt-level=0 +// revisions: current next +//[current] compile-flags: -C opt-level=0 +//[next] compile-flags: -Ztrait-solver=next -C opt-level=0 #![feature(dyn_star)] #![allow(incomplete_features)] |
