Skip to content

Commit

Permalink
Added an additional example of lifetime elision
Browse files Browse the repository at this point in the history
The question of how did this behave showed up in a rust-for-linux code review, and it would have been easier to explain had this example been present.
  • Loading branch information
alex authored Nov 19, 2024
1 parent 41ccb0e commit 63f68ee
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/lifetime-elision.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ fn get_mut2<'a>(&'a mut self) -> &'a mut dyn T; // expanded
fn args1<T: ToCStr>(&mut self, args: &[T]) -> &mut Command; // elided
fn args2<'a, 'b, T: ToCStr>(&'a mut self, args: &'b [T]) -> &'a mut Command; // expanded

fn other_args<'a>(arg: &T) -> &'a str; // elided
fn other_args<'a, 'b>(arg: &'b T) -> &'a str; // expanded

fn new1(buf: &mut [u8]) -> Thing<'_>; // elided - preferred
fn new2(buf: &mut [u8]) -> Thing; // elided
fn new3<'a>(buf: &'a mut [u8]) -> Thing<'a>; // expanded
Expand Down

0 comments on commit 63f68ee

Please sign in to comment.