diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:50 +0000 |
commit | 2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35 (patch) | |
tree | d325add32978dbdc1db975a438b3a77d571b1ab8 /tests/ui/nll/closure-requirements | |
parent | Releasing progress-linux version 1.68.2+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.tar.xz rustc-2e00214b3efbdfeefaa0fe9e8b8fd519de7adc35.zip |
Merging upstream version 1.69.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/nll/closure-requirements')
6 files changed, 83 insertions, 0 deletions
diff --git a/tests/ui/nll/closure-requirements/escape-argument.stderr b/tests/ui/nll/closure-requirements/escape-argument.stderr index f67c312b9..5a8462d4d 100644 --- a/tests/ui/nll/closure-requirements/escape-argument.stderr +++ b/tests/ui/nll/closure-requirements/escape-argument.stderr @@ -21,6 +21,9 @@ LL | fn test() { error[E0597]: `y` does not live long enough --> $DIR/escape-argument.rs:27:25 | +LL | let y = 22; + | - binding `y` declared here +LL | let mut closure = expect_sig(|p, y| *p = y); LL | closure(&mut p, &y); | ^^ borrowed value does not live long enough LL | diff --git a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index 7991abeb7..721cd45de 100644 --- a/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/tests/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -53,6 +53,8 @@ LL | fn case2() { error[E0597]: `a` does not live long enough --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:30:26 | +LL | let a = 0; + | - binding `a` declared here LL | let cell = Cell::new(&a); | ^^ borrowed value does not live long enough ... diff --git a/tests/ui/nll/closure-requirements/type-test-subject-non-trivial-region.rs b/tests/ui/nll/closure-requirements/type-test-subject-non-trivial-region.rs new file mode 100644 index 000000000..d8772e868 --- /dev/null +++ b/tests/ui/nll/closure-requirements/type-test-subject-non-trivial-region.rs @@ -0,0 +1,19 @@ +// See #108639 for description. +// check-pass + +trait Trait { + type Item<'a>: 'a; +} + +fn assert_static<T: 'static>(_: T) {} +fn relate<T>(_: T, _: T) {} + +fn test_args<I: Trait>() { + let closure = |a, b| { + relate(&a, b); + assert_static(a); + }; + closure(None::<I::Item<'_>>, &None::<I::Item<'_>>); +} + +fn main() {} diff --git a/tests/ui/nll/closure-requirements/type-test-subject-opaque-1.rs b/tests/ui/nll/closure-requirements/type-test-subject-opaque-1.rs new file mode 100644 index 000000000..fce6f2fee --- /dev/null +++ b/tests/ui/nll/closure-requirements/type-test-subject-opaque-1.rs @@ -0,0 +1,18 @@ +// Regression test for #107426. +// check-pass + +use std::marker::PhantomData; +#[derive(Clone, Copy)] +pub struct Scope<'a>(&'a PhantomData<&'a mut &'a ()>); +fn event<'a, F: FnMut() + 'a>(_: Scope<'a>, _: F) {} +fn make_fn<'a>(_: Scope<'a>) -> impl Fn() + Copy + 'a { + || {} +} + +fn foo(cx: Scope) { + let open_toggle = make_fn(cx); + + || event(cx, open_toggle); +} + +fn main() {} diff --git a/tests/ui/nll/closure-requirements/type-test-subject-opaque-2.rs b/tests/ui/nll/closure-requirements/type-test-subject-opaque-2.rs new file mode 100644 index 000000000..55905850f --- /dev/null +++ b/tests/ui/nll/closure-requirements/type-test-subject-opaque-2.rs @@ -0,0 +1,17 @@ +// Resgression test for #107516. +// check-pass + +fn iter1<'a: 'a>() -> impl Iterator<Item = &'static str> { + None.into_iter() +} + +fn iter2<'a>() -> impl Iterator<Item = &'a str> { + None.into_iter() +} + +struct Bivar<'a, I: Iterator<Item = &'a str> + 'a>(I); + +fn main() { + let _ = || Bivar(iter1()); + let _ = || Bivar(iter2()); +} diff --git a/tests/ui/nll/closure-requirements/type-test-subject-unnamed-region.rs b/tests/ui/nll/closure-requirements/type-test-subject-unnamed-region.rs new file mode 100644 index 000000000..b5a95c170 --- /dev/null +++ b/tests/ui/nll/closure-requirements/type-test-subject-unnamed-region.rs @@ -0,0 +1,24 @@ +// See #108635 for description. +// check-pass + +trait Trait { + type Item<'a>: 'a; +} + +fn assert_static<T: 'static>(_: T) {} + +fn test_args<I: Trait>() { + let closure = |a, _b| assert_static(a); + + closure(None::<I::Item<'_>>, &None::<I::Item<'_>>); +} + +fn test_upvars<I: Trait>() { + let upvars = (None::<I::Item<'_>>, &None::<I::Item<'_>>); + let _closure = || { + let (a, _b) = upvars; + assert_static(a); + }; +} + +fn main() {} |