Skip to content

Commit 171d558

Browse files
Don't instantiate the binder twice when assembling object candidate
1 parent 24e14dd commit 171d558

File tree

4 files changed

+45
-17
lines changed

4 files changed

+45
-17
lines changed

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+7-17
Original file line numberDiff line numberDiff line change
@@ -628,18 +628,12 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
628628
}
629629

630630
self.infcx.probe(|_snapshot| {
631-
// FIXME(non_lifetime_binders): Really, we care only to check that we don't
632-
// have any non-region *escaping* bound vars, but that's hard to check and
633-
// we shouldn't really ever encounter those anyways.
634-
if obligation.self_ty().has_non_region_late_bound() {
635-
return;
636-
}
631+
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
632+
let placeholder_trait_predicate =
633+
self.infcx.instantiate_binder_with_placeholders(poly_trait_predicate);
637634

638-
// The code below doesn't care about regions, and the
639-
// self-ty here doesn't escape this probe, so just erase
640-
// any LBR.
641-
let self_ty = self.tcx().erase_late_bound_regions(obligation.self_ty());
642-
let poly_trait_ref = match self_ty.kind() {
635+
let self_ty = placeholder_trait_predicate.self_ty();
636+
let principal_trait_ref = match self_ty.kind() {
643637
ty::Dynamic(ref data, ..) => {
644638
if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
645639
debug!(
@@ -671,18 +665,14 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
671665
_ => return,
672666
};
673667

674-
debug!(?poly_trait_ref, "assemble_candidates_from_object_ty");
675-
676-
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
677-
let placeholder_trait_predicate =
678-
self.infcx.instantiate_binder_with_placeholders(poly_trait_predicate);
668+
debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
679669

680670
// Count only those upcast versions that match the trait-ref
681671
// we are looking for. Specifically, do not only check for the
682672
// correct trait, but also the correct type parameters.
683673
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
684674
// but `Foo` is declared as `trait Foo: Bar<u32>`.
685-
let candidate_supertraits = util::supertraits(self.tcx(), poly_trait_ref)
675+
let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
686676
.enumerate()
687677
.filter(|&(_, upcast_trait_ref)| {
688678
self.infcx.probe(|_| {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/non-lifetime-via-dyn-builtin.rs:5:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/non-lifetime-via-dyn-builtin.rs:5:12
3+
|
4+
LL | #![feature(non_lifetime_binders)]
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// revisions: current next
2+
//[next] compile-flags: -Ztrait-solver=next
3+
// check-pass
4+
5+
#![feature(non_lifetime_binders)]
6+
//~^ WARN the feature `non_lifetime_binders` is incomplete and may not be safe
7+
8+
fn trivial<A>()
9+
where
10+
for<B> dyn Fn(A, *const B): Fn(A, *const B),
11+
{
12+
}
13+
14+
fn main() {
15+
trivial::<u8>();
16+
}

0 commit comments

Comments
 (0)