diff options
| author | Jakub Beránek <berykubik@gmail.com> | 2025-08-06 15:55:42 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-06 15:55:42 +0200 |
| commit | e89ae47b978f50b6fc1873d65486d661520bdf28 (patch) | |
| tree | ae387ab4a528a1d83c3816a5da26bc8772bd0723 /tests/ui/closures | |
| parent | dc0bae1db725fbba8524f195f74f680995fd549e (diff) | |
| parent | 7196d8cd661b875401126a81641d2effc40b3d85 (diff) | |
| download | rust-e89ae47b978f50b6fc1873d65486d661520bdf28.tar.gz rust-e89ae47b978f50b6fc1873d65486d661520bdf28.zip | |
Rollup merge of #144552 - Oneirical:uncountable-integer-3, r=jieyouxu
Rehome 33 `tests/ui/issues/` tests to other subdirectories under `tests/ui/` rust-lang/rust#143902 divided into smaller, easier to review chunks. Part of rust-lang/rust#133895 Methodology: 1. Refer to the previously written `tests/ui/SUMMARY.md` 2. Find an appropriate category for the test, using the original issue thread and the test contents. 3. Add the issue URL at the bottom (not at the top, as that would mess up stderr line numbers) 4. Rename the tests to make their purpose clearer Inspired by the methodology that ``@Kivooeo`` was using. r? ``@jieyouxu``
Diffstat (limited to 'tests/ui/closures')
| -rw-r--r-- | tests/ui/closures/aliasability-violation-with-closure-21600.rs | 19 | ||||
| -rw-r--r-- | tests/ui/closures/aliasability-violation-with-closure-21600.stderr | 31 |
2 files changed, 50 insertions, 0 deletions
diff --git a/tests/ui/closures/aliasability-violation-with-closure-21600.rs b/tests/ui/closures/aliasability-violation-with-closure-21600.rs new file mode 100644 index 00000000000..d4c658319ab --- /dev/null +++ b/tests/ui/closures/aliasability-violation-with-closure-21600.rs @@ -0,0 +1,19 @@ +// https://github.com/rust-lang/rust/issues/21600 +fn call_it<F>(f: F) where F: Fn() { f(); } + +struct A; + +impl A { + fn gen(&self) {} + fn gen_mut(&mut self) {} +} + +fn main() { + let mut x = A; + call_it(|| { + call_it(|| x.gen()); + call_it(|| x.gen_mut()); + //~^ ERROR cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure + //~| ERROR cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure + }); +} diff --git a/tests/ui/closures/aliasability-violation-with-closure-21600.stderr b/tests/ui/closures/aliasability-violation-with-closure-21600.stderr new file mode 100644 index 00000000000..2d2397a2141 --- /dev/null +++ b/tests/ui/closures/aliasability-violation-with-closure-21600.stderr @@ -0,0 +1,31 @@ +error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure + --> $DIR/aliasability-violation-with-closure-21600.rs:15:20 + | +LL | fn call_it<F>(f: F) where F: Fn() { f(); } + | - change this to accept `FnMut` instead of `Fn` +... +LL | call_it(|| x.gen_mut()); + | ------- -- ^ cannot borrow as mutable + | | | + | | in this closure + | expects `Fn` instead of `FnMut` + +error[E0596]: cannot borrow `x` as mutable, as it is a captured variable in a `Fn` closure + --> $DIR/aliasability-violation-with-closure-21600.rs:15:17 + | +LL | fn call_it<F>(f: F) where F: Fn() { f(); } + | - change this to accept `FnMut` instead of `Fn` +... +LL | call_it(|| { + | ------- -- in this closure + | | + | expects `Fn` instead of `FnMut` +LL | call_it(|| x.gen()); +LL | call_it(|| x.gen_mut()); + | ^^ - mutable borrow occurs due to use of `x` in closure + | | + | cannot borrow as mutable + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0596`. |
