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.

24 lines
679 B
Rust
Raw Normal View History

#![warn(unused_lifetimes)]
fn static_id<'a,'b>(t: &'a ()) -> &'static () where 'a: 'static { t }
//~^ WARN lifetime parameter `'b` never used
//~| WARN unnecessary lifetime parameter `'a`
2022-03-14 14:56:37 +00:00
fn static_id_indirect<'a,'b>(t: &'a ()) -> &'static ()
where 'a: 'b, 'b: 'static { t }
2022-03-14 14:56:37 +00:00
//~^ WARN unnecessary lifetime parameter `'b`
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() {}