From 44b68073204a10a71adf2ae79e2fa698130a515c Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 31 Oct 2023 21:43:19 +0000 Subject: [PATCH] Don't check for alias bounds in liveness when aliases have escaping bound vars --- .../src/infer/outlives/for_liveness.rs | 10 +++++++++- .../alias-bounds-when-bounds-escape.rs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/ui/type-alias-impl-trait/alias-bounds-when-bounds-escape.rs diff --git a/compiler/rustc_infer/src/infer/outlives/for_liveness.rs b/compiler/rustc_infer/src/infer/outlives/for_liveness.rs index ebc51b98be53f..398ac94ee3685 100644 --- a/compiler/rustc_infer/src/infer/outlives/for_liveness.rs +++ b/compiler/rustc_infer/src/infer/outlives/for_liveness.rs @@ -1,4 +1,6 @@ -use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor}; +use rustc_middle::ty::{ + self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, +}; use std::ops::ControlFlow; @@ -49,6 +51,12 @@ where return ControlFlow::Continue(()); } + // FIXME: Don't consider alias bounds on types that have escaping bound + // vars. See #117455. + if ty.has_escaping_bound_vars() { + return ty.super_visit_with(self); + } + match ty.kind() { // We can prove that an alias is live two ways: // 1. All the components are live. diff --git a/tests/ui/type-alias-impl-trait/alias-bounds-when-bounds-escape.rs b/tests/ui/type-alias-impl-trait/alias-bounds-when-bounds-escape.rs new file mode 100644 index 0000000000000..59b9a79da6e8a --- /dev/null +++ b/tests/ui/type-alias-impl-trait/alias-bounds-when-bounds-escape.rs @@ -0,0 +1,16 @@ +// check-pass + +trait Foo { + type Assoc<'a, 'b>: 'static; +} + +struct MentionsLifetimeAndType<'a, T>(&'a (), T); + +fn foo<'a, 'b, T: Foo>(_: ::Assoc<'a, 'b>) {} + +fn test<'b, T: Foo>() { + let y: MentionsLifetimeAndType<'_, for<'a> fn(::Assoc<'a, 'b>)> = + MentionsLifetimeAndType(&(), foo); +} + +fn main() {}