Skip to content

Commit f7fc0b7

Browse files
committedJan 30, 2023
nits
1 parent c248440 commit f7fc0b7

File tree

4 files changed

+16
-20
lines changed

4 files changed

+16
-20
lines changed
 

Diff for: ‎compiler/rustc_trait_selection/src/solve/assembly.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
184184

185185
// `dyn Trait1` can be unsized to `dyn Trait2` if they are the same trait, or
186186
// if `Trait2` is a (transitive) supertrait of `Trait2`.
187-
fn consider_builtin_dyn_unsize_candidates(
187+
fn consider_builtin_dyn_upcast_candidates(
188188
ecx: &mut EvalCtxt<'_, 'tcx>,
189189
goal: Goal<'tcx, Self>,
190190
) -> Vec<CanonicalResponse<'tcx>>;
@@ -334,7 +334,7 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
334334
// There may be multiple unsize candidates for a trait with several supertraits:
335335
// `trait Foo: Bar<A> + Bar<B>` and `dyn Foo: Unsize<dyn Bar<_>>`
336336
if lang_items.unsize_trait() == Some(trait_def_id) {
337-
for result in G::consider_builtin_dyn_unsize_candidates(self, goal) {
337+
for result in G::consider_builtin_dyn_upcast_candidates(self, goal) {
338338
candidates.push(Candidate { source: CandidateSource::BuiltinImpl, result });
339339
}
340340
}

Diff for: ‎compiler/rustc_trait_selection/src/solve/project_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
562562
bug!("`Unsize` does not have an associated type: {:?}", goal);
563563
}
564564

565-
fn consider_builtin_dyn_unsize_candidates(
565+
fn consider_builtin_dyn_upcast_candidates(
566566
_ecx: &mut EvalCtxt<'_, 'tcx>,
567567
goal: Goal<'tcx, Self>,
568568
) -> Vec<super::CanonicalResponse<'tcx>> {

Diff for: ‎compiler/rustc_trait_selection/src/solve/trait_goals.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
262262
// `T` -> `dyn Trait` unsizing
263263
(_, &ty::Dynamic(data, region, ty::Dyn)) => {
264264
// Can only unsize to an object-safe type
265-
// FIXME: Can auto traits be *not* object safe?
266265
if data
267-
.auto_traits()
268-
.chain(data.principal_def_id())
269-
.any(|def_id| !tcx.is_object_safe(def_id))
266+
.principal_def_id()
267+
.map_or(false, |def_id| !tcx.check_is_object_safe(def_id))
270268
{
271269
return Err(NoSolution);
272270
}
@@ -365,7 +363,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
365363
})
366364
}
367365

368-
fn consider_builtin_dyn_unsize_candidates(
366+
fn consider_builtin_dyn_upcast_candidates(
369367
ecx: &mut EvalCtxt<'_, 'tcx>,
370368
goal: Goal<'tcx, Self>,
371369
) -> Vec<CanonicalResponse<'tcx>> {
@@ -387,9 +385,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
387385
return vec![];
388386
}
389387

390-
let mut responses = vec![];
391388
let mut unsize_dyn_to_principal = |principal: Option<ty::PolyExistentialTraitRef<'tcx>>| {
392-
let _ = ecx.infcx.probe(|_| -> Result<(), NoSolution> {
389+
ecx.infcx.probe(|_| -> Result<_, NoSolution> {
393390
// Require that all of the trait predicates from A match B, except for
394391
// the auto traits. We do this by constructing a new A type with B's
395392
// auto traits, and equating these types.
@@ -414,16 +411,17 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
414411
goal.with(tcx, ty::Binder::dummy(ty::OutlivesPredicate(a_region, b_region))),
415412
);
416413

417-
responses.push(ecx.evaluate_all_and_make_canonical_response(nested_obligations)?);
418-
419-
Ok(())
420-
});
414+
ecx.evaluate_all_and_make_canonical_response(nested_obligations)
415+
})
421416
};
422417

418+
let mut responses = vec![];
423419
// If the principal def ids match (or are both none), then we're not doing
424420
// trait upcasting. We're just removing auto traits (or shortening the lifetime).
425421
if a_data.principal_def_id() == b_data.principal_def_id() {
426-
unsize_dyn_to_principal(a_data.principal());
422+
if let Ok(response) = unsize_dyn_to_principal(a_data.principal()) {
423+
responses.push(response);
424+
}
427425
} else if let Some(a_principal) = a_data.principal()
428426
&& let Some(b_principal) = b_data.principal()
429427
{
@@ -433,7 +431,9 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
433431
}
434432
let erased_trait_ref = super_trait_ref
435433
.map_bound(|trait_ref| ty::ExistentialTraitRef::erase_self_ty(tcx, trait_ref));
436-
unsize_dyn_to_principal(Some(erased_trait_ref));
434+
if let Ok(response) = unsize_dyn_to_principal(Some(erased_trait_ref)) {
435+
responses.push(response);
436+
}
437437
}
438438
}
439439

Diff for: ‎compiler/rustc_ty_utils/src/ty.rs

-4
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,6 @@ fn unsizing_params_for_adt<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> BitSet<u32
426426
},
427427
};
428428

429-
// FIXME(eddyb) cache this (including computing `unsizing_params`)
430-
// by putting it in a query; it would only need the `DefId` as it
431-
// looks at declared field types, not anything substituted.
432-
433429
// The last field of the structure has to exist and contain type/const parameters.
434430
let Some((tail_field, prefix_fields)) =
435431
def.non_enum_variant().fields.split_last() else

0 commit comments

Comments
 (0)
Please sign in to comment.