From a4b7ed7a42c716ab9f05e351f003d589124fd55d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:18:58 +0200 Subject: Adding upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/nll/lub-match.rs | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/ui/nll/lub-match.rs (limited to 'tests/ui/nll/lub-match.rs') diff --git a/tests/ui/nll/lub-match.rs b/tests/ui/nll/lub-match.rs new file mode 100644 index 000000000..454dd1fc6 --- /dev/null +++ b/tests/ui/nll/lub-match.rs @@ -0,0 +1,47 @@ +// Test that we correctly consider the type of `match` to be the LUB +// of the various arms, particularly in the case where regions are +// involved. + +pub fn opt_str0<'a>(maybestr: &'a Option) -> &'a str { + match *maybestr { + Some(ref s) => { + let s: &'a str = s; + s + } + None => "(none)", + } +} + +pub fn opt_str1<'a>(maybestr: &'a Option) -> &'a str { + match *maybestr { + None => "(none)", + Some(ref s) => { + let s: &'a str = s; + s + } + } +} + +pub fn opt_str2<'a>(maybestr: &'a Option) -> &'static str { + match *maybestr { + None => "(none)", + Some(ref s) => { + let s: &'a str = s; + s + //~^ ERROR lifetime may not live long enough + } + } +} + +pub fn opt_str3<'a>(maybestr: &'a Option) -> &'static str { + match *maybestr { + Some(ref s) => { + let s: &'a str = s; + s + //~^ ERROR lifetime may not live long enough + } + None => "(none)", + } +} + +fn main() {} -- cgit v1.2.3