-
-
Save nikomatsakis/acdeb20b0192e2a1f404d514b3002c59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![warn(single_use_lifetime)] | |
#![allow(dead_code)] | |
#![allow(unused_variables)] | |
fn a<'a>(x: &'a u32) { // Warning: used only once | |
} | |
fn b<'a>() -> &'a u32 { // OK: used only in return type | |
&22 | |
} | |
fn c<'a>(x: &'a u32) -> &'a u32 { // OK: used twice | |
&22 | |
} | |
fn d<'a>() { } // Warning: never used at all | |
struct Foo<'f> { | |
data: &'f u32 | |
} | |
impl<'f> Foo<'f> { // OK for *now* FIXME(#15872) | |
fn inherent_a(&self) { | |
} | |
fn inherent_b<'a>(x: &'a u32) { // Warning for `'a` expected | |
} | |
fn inherent_c<'a>() -> &'a u32 { // OK: used only in return type | |
&22 | |
} | |
fn inherent_d<'a>(x: &'a u32) -> &'a u32 { // OK: used twice | |
&22 | |
} | |
} | |
impl<'f> Foo<'f> { // OK | |
fn new(data: &'f u32) -> Self { | |
Foo { data } | |
} | |
} | |
impl<'f> Iterator for Foo<'f> { // OK: used twice | |
type Item = &'f u32; | |
fn next<'g>(&'g mut self) -> Option<Self::Item> { // Warning for `'g` | |
None | |
} | |
} | |
impl<'f> Foo<'f> { // OK: used twice | |
fn get(&self) -> &'f u32 { | |
self.data | |
} | |
} | |
fn main() { } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment