rust/tests/ui/regions/regions-static-bound.rs

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

25 lines
746 B
Rust
Raw Normal View History

#![warn(unused_lifetimes, redundant_lifetimes)]
2023-11-29 02:41:31 +00:00
fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
2023-11-29 02:41:31 +00:00
//~^ WARN unnecessary lifetime parameter `'a`
//~| WARN lifetime parameter `'b` never used
2022-03-14 14:56:37 +00:00
fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static ()
2023-11-29 02:41:31 +00:00
//~^ WARN unnecessary lifetime parameter `'a`
//~| WARN unnecessary lifetime parameter `'b`
where 'a: 'b, 'b: 'static { t }
2022-03-14 14:56:37 +00:00
fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a {
t
2022-04-01 17:13:25 +00:00
//~^ ERROR lifetime may not live long enough
}
fn error(u: &(), v: &()) {
static_id(&u);
2022-04-01 17:13:25 +00:00
//~^ ERROR borrowed data escapes outside of function [E0521]
static_id_indirect(&v);
2022-04-01 17:13:25 +00:00
//~^ ERROR borrowed data escapes outside of function [E0521]
}
fn main() {}