mirror of
https://github.com/rust-lang/rust
synced 2024-09-15 22:50:55 +00:00
Auto merge of #117610 - compiler-errors:object-hmm, r=aliemjay
Only instantiate binder during dyn's built-in trait candidate probe once See UI test for demonstration of the issue. This was "caused" by #117131, but only because we're using the `normalize_param_env` (which has been augmented with a projection clause used to normalize GATs) which features non-lifetime bound vars in it. Fixes #117602 technically, though that's also fixed by #117542. r? types
This commit is contained in:
commit
114f1f6838
|
@ -628,15 +628,12 @@ fn assemble_candidates_from_object_ty(
|
|||
}
|
||||
|
||||
self.infcx.probe(|_snapshot| {
|
||||
if obligation.has_non_region_late_bound() {
|
||||
return;
|
||||
}
|
||||
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
|
||||
let placeholder_trait_predicate =
|
||||
self.infcx.instantiate_binder_with_placeholders(poly_trait_predicate);
|
||||
|
||||
// The code below doesn't care about regions, and the
|
||||
// self-ty here doesn't escape this probe, so just erase
|
||||
// any LBR.
|
||||
let self_ty = self.tcx().erase_late_bound_regions(obligation.self_ty());
|
||||
let poly_trait_ref = match self_ty.kind() {
|
||||
let self_ty = placeholder_trait_predicate.self_ty();
|
||||
let principal_trait_ref = match self_ty.kind() {
|
||||
ty::Dynamic(ref data, ..) => {
|
||||
if data.auto_traits().any(|did| did == obligation.predicate.def_id()) {
|
||||
debug!(
|
||||
|
@ -668,18 +665,14 @@ fn assemble_candidates_from_object_ty(
|
|||
_ => return,
|
||||
};
|
||||
|
||||
debug!(?poly_trait_ref, "assemble_candidates_from_object_ty");
|
||||
|
||||
let poly_trait_predicate = self.infcx.resolve_vars_if_possible(obligation.predicate);
|
||||
let placeholder_trait_predicate =
|
||||
self.infcx.instantiate_binder_with_placeholders(poly_trait_predicate);
|
||||
debug!(?principal_trait_ref, "assemble_candidates_from_object_ty");
|
||||
|
||||
// Count only those upcast versions that match the trait-ref
|
||||
// we are looking for. Specifically, do not only check for the
|
||||
// correct trait, but also the correct type parameters.
|
||||
// For example, we may be trying to upcast `Foo` to `Bar<i32>`,
|
||||
// but `Foo` is declared as `trait Foo: Bar<u32>`.
|
||||
let candidate_supertraits = util::supertraits(self.tcx(), poly_trait_ref)
|
||||
let candidate_supertraits = util::supertraits(self.tcx(), principal_trait_ref)
|
||||
.enumerate()
|
||||
.filter(|&(_, upcast_trait_ref)| {
|
||||
self.infcx.probe(|_| {
|
||||
|
|
11
tests/ui/traits/non-lifetime-via-dyn-builtin.current.stderr
Normal file
11
tests/ui/traits/non-lifetime-via-dyn-builtin.current.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/non-lifetime-via-dyn-builtin.rs:5:12
|
||||
|
|
||||
LL | #![feature(non_lifetime_binders)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
11
tests/ui/traits/non-lifetime-via-dyn-builtin.next.stderr
Normal file
11
tests/ui/traits/non-lifetime-via-dyn-builtin.next.stderr
Normal file
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `non_lifetime_binders` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/non-lifetime-via-dyn-builtin.rs:5:12
|
||||
|
|
||||
LL | #![feature(non_lifetime_binders)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: see issue #108185 <https://github.com/rust-lang/rust/issues/108185> for more information
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
16
tests/ui/traits/non-lifetime-via-dyn-builtin.rs
Normal file
16
tests/ui/traits/non-lifetime-via-dyn-builtin.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
// revisions: current next
|
||||
//[next] compile-flags: -Ztrait-solver=next
|
||||
// check-pass
|
||||
|
||||
#![feature(non_lifetime_binders)]
|
||||
//~^ WARN the feature `non_lifetime_binders` is incomplete and may not be safe
|
||||
|
||||
fn trivial<A>()
|
||||
where
|
||||
for<B> dyn Fn(A, *const B): Fn(A, *const B),
|
||||
{
|
||||
}
|
||||
|
||||
fn main() {
|
||||
trivial::<u8>();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// check-pass
|
||||
|
||||
trait Foo {
|
||||
type Bar<T>
|
||||
where
|
||||
dyn Send + 'static: Send;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
type Bar<T> = i32;
|
||||
// We take `<() as Foo>::Bar<T>: Sized` and normalize it under the where clause
|
||||
// of `for<S> <() as Foo>::Bar<S> = i32`. This gives us back `i32: Send` with
|
||||
// the nested obligation `(dyn Send + 'static): Send`. However, during candidate
|
||||
// assembly for object types, we disqualify any obligations that has non-region
|
||||
// late-bound vars in the param env(!), rather than just the predicate. This causes
|
||||
// the where clause to not hold even though it trivially should.
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
Reference in a new issue