summaryrefslogtreecommitdiffstats
path: root/tests/ui/closures
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/closures')
-rw-r--r--tests/ui/closures/2229_closure_analysis/array_subslice.rs13
-rw-r--r--tests/ui/closures/2229_closure_analysis/array_subslice.stderr26
-rw-r--r--tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.rs18
-rw-r--r--tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.stderr14
-rw-r--r--tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.rs31
-rw-r--r--tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.stderr15
-rw-r--r--tests/ui/closures/issue-109188.rs22
-rw-r--r--tests/ui/closures/issue-109188.stderr19
-rw-r--r--tests/ui/closures/self-supertrait-bounds.rs14
9 files changed, 172 insertions, 0 deletions
diff --git a/tests/ui/closures/2229_closure_analysis/array_subslice.rs b/tests/ui/closures/2229_closure_analysis/array_subslice.rs
new file mode 100644
index 000000000..5f244ea89
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/array_subslice.rs
@@ -0,0 +1,13 @@
+// regression test for #109298
+// edition: 2021
+
+pub fn subslice_array(x: [u8; 3]) {
+ let f = || {
+ let [_x @ ..] = x;
+ let [ref y, ref mut z @ ..] = x; //~ ERROR cannot borrow `x[..]` as mutable
+ };
+
+ f(); //~ ERROR cannot borrow `f` as mutable
+}
+
+fn main() {}
diff --git a/tests/ui/closures/2229_closure_analysis/array_subslice.stderr b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr
new file mode 100644
index 000000000..888c60d5e
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/array_subslice.stderr
@@ -0,0 +1,26 @@
+error[E0596]: cannot borrow `x[..]` as mutable, as `x` is not declared as mutable
+ --> $DIR/array_subslice.rs:7:21
+ |
+LL | pub fn subslice_array(x: [u8; 3]) {
+ | - help: consider changing this to be mutable: `mut x`
+...
+LL | let [ref y, ref mut z @ ..] = x;
+ | ^^^^^^^^^ cannot borrow as mutable
+
+error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
+ --> $DIR/array_subslice.rs:10:5
+ |
+LL | let [ref y, ref mut z @ ..] = x;
+ | - calling `f` requires mutable binding due to mutable borrow of `x`
+...
+LL | f();
+ | ^ cannot borrow as mutable
+ |
+help: consider changing this to be mutable
+ |
+LL | let mut f = || {
+ | +++
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0596`.
diff --git a/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.rs b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.rs
new file mode 100644
index 000000000..f21ef43fb
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.rs
@@ -0,0 +1,18 @@
+// edition:2021
+
+// regression test for #112056
+
+fn extend_lifetime<'a, 'b>(x: &mut (&'a str,), y: &'b str) {
+ let mut closure = |input| x.0 = input;
+ //~^ ERROR: lifetime may not live long enough
+ closure(y);
+}
+
+fn main() {
+ let mut tuple = ("static",);
+ {
+ let x = String::from("temporary");
+ extend_lifetime(&mut tuple, &x);
+ }
+ println!("{}", tuple.0);
+}
diff --git a/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.stderr b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.stderr
new file mode 100644
index 000000000..730823281
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-1.stderr
@@ -0,0 +1,14 @@
+error: lifetime may not live long enough
+ --> $DIR/unique-borrows-are-invariant-1.rs:6:31
+ |
+LL | fn extend_lifetime<'a, 'b>(x: &mut (&'a str,), y: &'b str) {
+ | -- -- lifetime `'b` defined here
+ | |
+ | lifetime `'a` defined here
+LL | let mut closure = |input| x.0 = input;
+ | ^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
+ |
+ = help: consider adding the following bound: `'b: 'a`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.rs b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.rs
new file mode 100644
index 000000000..dd9d986c2
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.rs
@@ -0,0 +1,31 @@
+// edition:2021
+
+// regression test for #112056
+
+struct Spooky<'b> {
+ owned: Option<&'static u32>,
+ borrowed: &'b &'static u32,
+}
+
+impl<'b> Spooky<'b> {
+ fn create_self_reference<'a>(&'a mut self) {
+ let mut closure = || {
+ if let Some(owned) = &self.owned {
+ let borrow: &'a &'static u32 = owned;
+ self.borrowed = borrow;
+ //~^ ERROR: lifetime may not live long enough
+ }
+ };
+ closure();
+ }
+}
+
+fn main() {
+ let mut spooky: Spooky<'static> = Spooky {
+ owned: Some(&1),
+ borrowed: &&1,
+ };
+ spooky.create_self_reference();
+ spooky.owned = None;
+ println!("{}", **spooky.borrowed);
+}
diff --git a/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.stderr b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.stderr
new file mode 100644
index 000000000..66ba0fe35
--- /dev/null
+++ b/tests/ui/closures/2229_closure_analysis/unique-borrows-are-invariant-2.stderr
@@ -0,0 +1,15 @@
+error: lifetime may not live long enough
+ --> $DIR/unique-borrows-are-invariant-2.rs:15:17
+ |
+LL | impl<'b> Spooky<'b> {
+ | -- lifetime `'b` defined here
+LL | fn create_self_reference<'a>(&'a mut self) {
+ | -- lifetime `'a` defined here
+...
+LL | self.borrowed = borrow;
+ | ^^^^^^^^^^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
+ |
+ = help: consider adding the following bound: `'a: 'b`
+
+error: aborting due to previous error
+
diff --git a/tests/ui/closures/issue-109188.rs b/tests/ui/closures/issue-109188.rs
new file mode 100644
index 000000000..cae1ced99
--- /dev/null
+++ b/tests/ui/closures/issue-109188.rs
@@ -0,0 +1,22 @@
+enum Either {
+ One(X),
+ Two(X),
+}
+
+struct X(Y);
+
+struct Y;
+
+fn consume_fnmut(f: &dyn FnMut()) {
+ f();
+}
+
+fn move_into_fnmut() {
+ let x = move_into_fnmut();
+ consume_fnmut(&|| {
+ let Either::One(_t) = x; //~ ERROR mismatched types
+ let Either::Two(_t) = x; //~ ERROR mismatched types
+ });
+}
+
+fn main() { }
diff --git a/tests/ui/closures/issue-109188.stderr b/tests/ui/closures/issue-109188.stderr
new file mode 100644
index 000000000..d52b51629
--- /dev/null
+++ b/tests/ui/closures/issue-109188.stderr
@@ -0,0 +1,19 @@
+error[E0308]: mismatched types
+ --> $DIR/issue-109188.rs:17:13
+ |
+LL | let Either::One(_t) = x;
+ | ^^^^^^^^^^^^^^^ - this expression has type `()`
+ | |
+ | expected `()`, found `Either`
+
+error[E0308]: mismatched types
+ --> $DIR/issue-109188.rs:18:13
+ |
+LL | let Either::Two(_t) = x;
+ | ^^^^^^^^^^^^^^^ - this expression has type `()`
+ | |
+ | expected `()`, found `Either`
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0308`.
diff --git a/tests/ui/closures/self-supertrait-bounds.rs b/tests/ui/closures/self-supertrait-bounds.rs
new file mode 100644
index 000000000..f4f1cea6b
--- /dev/null
+++ b/tests/ui/closures/self-supertrait-bounds.rs
@@ -0,0 +1,14 @@
+// check-pass
+
+// Makes sure that we only consider `Self` supertrait predicates while
+// elaborating during closure signature deduction.
+
+#![feature(trait_alias)]
+
+trait Confusing<F> = Fn(i32) where F: Fn(u32);
+
+fn alias<T: Confusing<F>, F>(_: T, _: F) {}
+
+fn main() {
+ alias(|_| {}, |_| {});
+}