From 8427cb5e21a84525d50f987f482e571e2fa300cd Mon Sep 17 00:00:00 2001 From: zakrad <49591476+zakrad@users.noreply.github.com> Date: Wed, 5 Aug 2026 17:56:19 +0330 Subject: [PATCH] Add regression test for associated type outlives bound at call site --- ...oc-type-outlives-via-where-clause-63253.rs | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 tests/ui/associated-types/assoc-type-outlives-via-where-clause-63253.rs diff --git a/tests/ui/associated-types/assoc-type-outlives-via-where-clause-63253.rs b/tests/ui/associated-types/assoc-type-outlives-via-where-clause-63253.rs new file mode 100644 index 0000000000000..ad675d4bc848e --- /dev/null +++ b/tests/ui/associated-types/assoc-type-outlives-via-where-clause-63253.rs @@ -0,0 +1,33 @@ +//! Regression test for . +//! +//! A `where Self::Ty: 'a` bound on the callee was not being used to prove the +//! associated type outlives `'a` at the call site, so both of these calls used +//! to fail with E0309 ("the associated type `>::Ty` may not live +//! long enough"). + +//@ check-pass + +#![allow(unused)] + +// The associated function is reached through a method-call path. +trait Trait<'a> { + type Ty; + fn method(ty_ref: &'a Self::Ty) where Self::Ty: 'a {} +} + +fn caller<'a, T: Trait<'a>>(arg: &'a T::Ty) where T::Ty: 'a { + T::method(arg) +} + +// The same bound, reached through a free function instead. +trait Trait2<'a> { + type Ty; +} + +fn free_fn<'a, T: Trait2<'a>>(_arg: &'a T::Ty) where T::Ty: 'a {} + +fn free_fn_caller<'a, T: Trait2<'a>>(arg: &'a T::Ty) where T::Ty: 'a { + free_fn::(arg) +} + +fn main() {}