From 63f68eef61f991f29dfe95f7277b3ff147279aa4 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 19 Nov 2024 12:16:41 -0500 Subject: [PATCH 1/4] Added an additional example of lifetime elision 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. --- src/lifetime-elision.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index f509f3fee..102a3102e 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -48,6 +48,9 @@ fn get_mut2<'a>(&'a mut self) -> &'a mut dyn T; // expanded fn args1(&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 From 3e034b36e2e6f1d1eadc5f41e34378dadc99bea9 Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 19 Nov 2024 12:18:24 -0500 Subject: [PATCH 2/4] Update lifetime-elision.md --- src/lifetime-elision.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index 102a3102e..acedb9cc1 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -48,8 +48,8 @@ fn get_mut2<'a>(&'a mut self) -> &'a mut dyn T; // expanded fn args1(&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 other_args1<'a>(arg: &T) -> &'a str; // elided +fn other_args2<'a, 'b>(arg: &'b T) -> &'a str; // expanded fn new1(buf: &mut [u8]) -> Thing<'_>; // elided - preferred fn new2(buf: &mut [u8]) -> Thing; // elided From 088b9f0a8921712aff41f4c5db356e10c8203b8a Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 19 Nov 2024 12:20:47 -0500 Subject: [PATCH 3/4] Update lifetime-elision.md --- src/lifetime-elision.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index acedb9cc1..37350158e 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -48,8 +48,8 @@ fn get_mut2<'a>(&'a mut self) -> &'a mut dyn T; // expanded fn args1(&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_args1<'a>(arg: &T) -> &'a str; // elided -fn other_args2<'a, 'b>(arg: &'b T) -> &'a str; // expanded +fn other_args1<'a>(args: &[T]) -> &'a str; // elided +fn other_args2<'a, 'b>(args: &'b [T]) -> &'a str; // expanded fn new1(buf: &mut [u8]) -> Thing<'_>; // elided - preferred fn new2(buf: &mut [u8]) -> Thing; // elided From 6be16ad1005828c11d1c00839b1da77ff389940b Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Tue, 19 Nov 2024 12:22:46 -0500 Subject: [PATCH 4/4] Update lifetime-elision.md --- src/lifetime-elision.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lifetime-elision.md b/src/lifetime-elision.md index 37350158e..a84c34837 100644 --- a/src/lifetime-elision.md +++ b/src/lifetime-elision.md @@ -48,8 +48,8 @@ fn get_mut2<'a>(&'a mut self) -> &'a mut dyn T; // expanded fn args1(&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_args1<'a>(args: &[T]) -> &'a str; // elided -fn other_args2<'a, 'b>(args: &'b [T]) -> &'a str; // expanded +fn other_args1<'a>(arg: &str) -> &'a str; // elided +fn other_args2<'a, 'b>(arg: &'b str) -> &'a str; // expanded fn new1(buf: &mut [u8]) -> Thing<'_>; // elided - preferred fn new2(buf: &mut [u8]) -> Thing; // elided