rust/tests/ui/impl-trait/in-trait/signature-mismatch.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

99 lines
2.7 KiB
Rust
Raw Normal View History

// edition:2021
2023-08-08 14:37:35 -05:00
// revisions: success failure
//[success] check-pass
2023-09-13 11:04:42 -05:00
#![feature(lint_reasons)]
use std::future::Future;
pub trait Captures<'a> {}
2023-06-29 19:38:34 -05:00
impl<T> Captures<'_> for T {}
pub trait Captures2<'a, 'b> {}
2023-06-29 19:38:34 -05:00
impl<T> Captures2<'_, '_> for T {}
pub trait AsyncTrait {
2023-08-08 14:37:35 -05:00
#[cfg(success)]
fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
2023-08-08 14:37:35 -05:00
#[cfg(success)]
2023-06-29 19:38:34 -05:00
fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>;
2023-08-08 14:37:35 -05:00
#[cfg(success)]
2023-06-29 19:38:34 -05:00
fn async_fn_multiple<'a>(&'a self, buff: &[u8])
2023-08-08 14:37:35 -05:00
-> impl Future<Output = Vec<u8>> + Captures<'a>;
#[cfg(failure)]
2023-06-29 19:38:34 -05:00
fn async_fn_reduce_outlive<'a, T>(
&'a self,
buff: &[u8],
t: T,
) -> impl Future<Output = Vec<u8>> + 'a;
2023-08-08 14:37:35 -05:00
#[cfg(success)]
2023-06-29 19:38:34 -05:00
fn async_fn_reduce<'a, T>(
&'a self,
buff: &[u8],
t: T,
) -> impl Future<Output = Vec<u8>> + Captures<'a>;
}
pub struct Struct;
impl AsyncTrait for Struct {
2023-08-08 14:37:35 -05:00
// Does not capture more lifetimes that trait def'n, since trait def'n
// implicitly captures all in-scope lifetimes.
#[cfg(success)]
#[expect(refining_impl_trait)]
fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
async move { buff.to_vec() }
}
2023-06-29 19:38:34 -05:00
2023-08-08 14:37:35 -05:00
// Does not capture more lifetimes that trait def'n, since trait def'n
// implicitly captures all in-scope lifetimes.
#[cfg(success)]
#[expect(refining_impl_trait)]
2023-06-29 19:38:34 -05:00
fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
async move { buff.to_vec() }
}
2023-08-08 14:37:35 -05:00
// Does not capture more lifetimes that trait def'n, since trait def'n
// implicitly captures all in-scope lifetimes.
#[cfg(success)]
#[expect(refining_impl_trait)]
2023-06-29 19:38:34 -05:00
fn async_fn_multiple<'a, 'b>(
&'a self,
buff: &'b [u8],
) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> {
async move { buff.to_vec() }
}
2023-08-08 14:37:35 -05:00
// This error message is awkward, but `impl Future<Output = Vec<u8>>`
// cannot outlive `'a` (from the trait signature) because it captures
// both `T` and `'b`.
#[cfg(failure)]
2023-06-29 19:38:34 -05:00
fn async_fn_reduce_outlive<'a, 'b, T>(
&'a self,
buff: &'b [u8],
t: T,
) -> impl Future<Output = Vec<u8>> {
2023-08-08 14:37:35 -05:00
//[failure]~^ ERROR lifetime mismatch
2023-06-29 19:38:34 -05:00
async move {
let _t = t;
vec![]
}
}
2023-08-08 14:37:35 -05:00
// Does not capture fewer lifetimes that trait def'n (not that it matters),
// since impl also captures all in-scope lifetimes.
#[cfg(success)]
2023-06-29 19:38:34 -05:00
fn async_fn_reduce<'a, 'b, T>(&'a self, buff: &'b [u8], t: T) -> impl Future<Output = Vec<u8>> {
async move {
let _t = t;
vec![]
}
}
}
fn main() {}