mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rollup merge of #154473 - danieljofficial:move-tests-borrowck, r=Kivooeo
move borrow checker tests Hi, I have moved some tests I think should be in the borrowck category. Please let me know if there are issues. r? @Kivooeo Related to rust-lang/rust#133895
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
||||
// Issue 52126: With respect to variance, the assign-op's like += were
|
||||
//! Test for https://github.com/rust-lang/rust/issues/52126
|
||||
// With respect to variance, the assign-op's like += were
|
||||
// accidentally lumped together with other binary op's. In both cases
|
||||
// we were coercing the LHS of the op to the expected supertype.
|
||||
//
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0597]: `line` does not live long enough
|
||||
--> $DIR/issue-52126-assign-op-invariance.rs:34:28
|
||||
--> $DIR/assign-op-invariance-lifetime.rs:35:28
|
||||
|
|
||||
LL | for line in vec!["123456789".to_string(), "12345678".to_string()] {
|
||||
| ---- binding `line` declared here
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
//@ run-pass
|
||||
// Regression test for #21400 which itself was extracted from
|
||||
// Test for https://github.com/rust-lang/rust/issues/21400 extracted from
|
||||
// stackoverflow.com/questions/28031155/is-my-borrow-checker-drunk/28031580
|
||||
|
||||
fn main() {
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// Issue link https://github.com/rust-lang/rust/issues/45697
|
||||
// Test that assignments to an `&mut` pointer which is found in a
|
||||
// borrowed (but otherwise non-aliasable) location is illegal.
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
error[E0503]: cannot use `*y.pointer` because it was mutably borrowed
|
||||
--> $DIR/issue-45697-1.rs:20:9
|
||||
--> $DIR/borrowed-mut-pointer-assign-overflow-off.rs:21:9
|
||||
|
|
||||
LL | let z = copy_borrowed_ptr(&mut y);
|
||||
| ------ `y` is borrowed here
|
||||
@@ -10,7 +10,7 @@ LL | *z.pointer += 1;
|
||||
| --------------- borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `*y.pointer` because it is borrowed
|
||||
--> $DIR/issue-45697-1.rs:20:9
|
||||
--> $DIR/borrowed-mut-pointer-assign-overflow-off.rs:21:9
|
||||
|
|
||||
LL | let z = copy_borrowed_ptr(&mut y);
|
||||
| ------ `*y.pointer` is borrowed here
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// Issue link https://github.com/rust-lang/rust/issues/45697
|
||||
// Test that assignments to an `&mut` pointer which is found in a
|
||||
// borrowed (but otherwise non-aliasable) location is illegal.
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
error[E0503]: cannot use `*y.pointer` because it was mutably borrowed
|
||||
--> $DIR/issue-45697.rs:20:9
|
||||
--> $DIR/borrowed-mut-pointer-assign-overflow-on.rs:21:9
|
||||
|
|
||||
LL | let z = copy_borrowed_ptr(&mut y);
|
||||
| ------ `y` is borrowed here
|
||||
@@ -10,7 +10,7 @@ LL | *z.pointer += 1;
|
||||
| --------------- borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `*y.pointer` because it is borrowed
|
||||
--> $DIR/issue-45697.rs:20:9
|
||||
--> $DIR/borrowed-mut-pointer-assign-overflow-on.rs:21:9
|
||||
|
|
||||
LL | let z = copy_borrowed_ptr(&mut y);
|
||||
| ------ `*y.pointer` is borrowed here
|
||||
@@ -1,6 +1,5 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/41498
|
||||
//@ run-pass
|
||||
// regression test for issue #41498.
|
||||
|
||||
struct S;
|
||||
impl S {
|
||||
fn mutate(&mut self) {}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/40288
|
||||
fn save_ref<'a>(refr: &'a i32, to: &mut [&'a i32]) {
|
||||
for val in &mut *to {
|
||||
*val = refr;
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0506]: cannot assign to `*refr` because it is borrowed
|
||||
--> $DIR/issue-40288.rs:16:5
|
||||
--> $DIR/cannot-assign-borrowed-ref-in-slice.rs:17:5
|
||||
|
|
||||
LL | save_ref(&*refr, &mut out);
|
||||
| ------ `*refr` is borrowed here
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/41726
|
||||
use std::collections::HashMap;
|
||||
fn main() {
|
||||
let things: HashMap<String, Vec<String>> = HashMap::new();
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0596]: cannot borrow data in an index of `HashMap<String, Vec<String>>` as mutable
|
||||
--> $DIR/issue-41726.rs:5:9
|
||||
--> $DIR/cannot-borrow-index-of-hashmap-in-for.rs:6:9
|
||||
|
|
||||
LL | things[src.as_str()].sort();
|
||||
| ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/44405
|
||||
use std::ops::Index;
|
||||
|
||||
struct Test;
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0596]: cannot borrow data in an index of `Container` as mutable
|
||||
--> $DIR/issue-44405.rs:21:5
|
||||
--> $DIR/cannot-borrow-index-output-mutably.rs:22:5
|
||||
|
|
||||
LL | container[&mut val].test();
|
||||
| ^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/4335
|
||||
#![feature(fn_traits)]
|
||||
|
||||
fn id<T>(t: T) -> T { t }
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
error[E0507]: cannot move out of `*v`, as `v` is a captured variable in an `FnMut` closure
|
||||
--> $DIR/issue-4335.rs:6:20
|
||||
--> $DIR/cannot-move-out-of-borrowed-ref-closure.rs:7:20
|
||||
|
|
||||
LL | fn f<'r, T>(v: &'r T) -> Box<dyn FnMut() -> T + 'r> {
|
||||
| - ----- move occurs because `*v` has type `T`, which does not implement the `Copy` trait
|
||||
@@ -12,7 +12,7 @@ LL | id(Box::new(|| *v))
|
||||
|
|
||||
= help: `Fn` and `FnMut` closures require captured values to be able to be consumed multiple times, but `FnOnce` closures may consume them only once
|
||||
help: if `T` implemented `Clone`, you could clone the value
|
||||
--> $DIR/issue-4335.rs:5:10
|
||||
--> $DIR/cannot-move-out-of-borrowed-ref-closure.rs:6:10
|
||||
|
|
||||
LL | fn f<'r, T>(v: &'r T) -> Box<dyn FnMut() -> T + 'r> {
|
||||
| ^ consider constraining this type parameter with `Clone`
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/26619
|
||||
pub struct History<'a> { pub _s: &'a str }
|
||||
|
||||
impl<'a> History<'a> {
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0515]: cannot return value referencing function parameter
|
||||
--> $DIR/issue-26619.rs:5:76
|
||||
--> $DIR/cannot-return-ref-to-fn-param-in-filter-map.rs:6:76
|
||||
|
|
||||
LL | for s in vec!["1|2".to_string()].into_iter().filter_map(|ref line| self.make_entry(line)) {
|
||||
| -------- ^^^^^^^^^^^^^^^^^^^^^ returns a value referencing data owned by the current function
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
error[E0515]: cannot return reference to temporary value
|
||||
--> $DIR/issue-27592.rs:16:14
|
||||
--> $DIR/cannot-return-ref-to-temporary-format-args.rs:16:14
|
||||
|
|
||||
LL | write(|| format_args!("{}", String::from("Hello world")));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returns a reference to data owned by the current function
|
||||
|
||||
error[E0515]: cannot return value referencing temporary value
|
||||
--> $DIR/issue-27592.rs:16:14
|
||||
--> $DIR/cannot-return-ref-to-temporary-format-args.rs:16:14
|
||||
|
|
||||
LL | write(|| format_args!("{}", String::from("Hello world")));
|
||||
| ^^^^^^^^^^^^^^^^^^^---------------------------^
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/18566
|
||||
use std::ops::Deref;
|
||||
|
||||
struct MyPtr<'a>(&'a mut usize);
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0499]: cannot borrow `*s` as mutable more than once at a time
|
||||
--> $DIR/issue-18566.rs:23:19
|
||||
--> $DIR/deref-and-mut-borrow-conflict.rs:24:19
|
||||
|
|
||||
LL | MyPtr(s).poke(s);
|
||||
| - ---- ^ second mutable borrow occurs here
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/28971
|
||||
enum Foo {
|
||||
Bar(u8)
|
||||
}
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
error[E0599]: no variant, associated function, or constant named `Baz` found for enum `Foo` in the current scope
|
||||
--> $DIR/issue-28971.rs:7:18
|
||||
--> $DIR/fnmut-borrow-error-in-closure-match.rs:8:18
|
||||
|
|
||||
LL | enum Foo {
|
||||
| -------- variant, associated function, or constant `Baz` not found for this enum
|
||||
@@ -14,7 +14,7 @@ LL + Foo::Bar(..) => (),
|
||||
|
|
||||
|
||||
error[E0596]: cannot borrow `f` as mutable, as it is not declared as mutable
|
||||
--> $DIR/issue-28971.rs:15:5
|
||||
--> $DIR/fnmut-borrow-error-in-closure-match.rs:16:5
|
||||
|
|
||||
LL | f();
|
||||
| ^ cannot borrow as mutable
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/42106
|
||||
fn do_something<T>(collection: &mut Vec<T>) {
|
||||
let _a = &collection;
|
||||
collection.swap(1, 2); //~ ERROR also borrowed as immutable
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
error[E0502]: cannot borrow `*collection` as mutable because it is also borrowed as immutable
|
||||
--> $DIR/issue-42106.rs:3:5
|
||||
--> $DIR/immutable-borrow-prevents-mut-method.rs:4:5
|
||||
|
|
||||
LL | let _a = &collection;
|
||||
| ----------- immutable borrow occurs here
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/18783
|
||||
use std::cell::RefCell;
|
||||
|
||||
fn main() {
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
error[E0499]: cannot borrow `y` as mutable more than once at a time
|
||||
--> $DIR/issue-18783.rs:7:21
|
||||
--> $DIR/mut-borrow-conflict-in-closures-vec.rs:8:21
|
||||
|
|
||||
LL | c.push(Box::new(|| y = 0));
|
||||
| -- - first borrow occurs due to use of `y` in closure
|
||||
@@ -14,7 +14,7 @@ LL | }
|
||||
| - first borrow might be used here, when `c` is dropped and runs the destructor for type `RefCell<Vec<Box<dyn FnMut()>>>`
|
||||
|
||||
error[E0499]: cannot borrow `y` as mutable more than once at a time
|
||||
--> $DIR/issue-18783.rs:16:29
|
||||
--> $DIR/mut-borrow-conflict-in-closures-vec.rs:17:29
|
||||
|
|
||||
LL | Push::push(&c, Box::new(|| y = 0));
|
||||
| -- - first borrow occurs due to use of `y` in closure
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/25579
|
||||
//@ check-pass
|
||||
|
||||
enum Sexpression {
|
||||
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/28839
|
||||
//@ run-pass
|
||||
|
||||
pub struct Foo;
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/29053
|
||||
//@ run-pass
|
||||
fn main() {
|
||||
let x: &'static str = "x";
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/47703
|
||||
//@ check-pass
|
||||
|
||||
struct MyStruct<'a> {
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/47703
|
||||
//@ check-pass
|
||||
|
||||
struct AtomicRefMut<'a> {
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
//! Regression test for https://github.com/rust-lang/rust/issues/47703
|
||||
//@ check-pass
|
||||
|
||||
struct WithDrop;
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
error[E0382]: use of moved value: `s`
|
||||
--> $DIR/issue-29723.rs:10:13
|
||||
--> $DIR/use-moved-value-in-match-guard-drop.rs:10:13
|
||||
|
|
||||
LL | let s = String::new();
|
||||
| - move occurs because `s` has type `String`, which does not implement the `Copy` trait
|
||||
@@ -16,7 +16,7 @@ LL | 0 if { drop(s.clone()); false } => String::from("oops"),
|
||||
| ++++++++
|
||||
|
||||
error[E0382]: use of moved value: `s`
|
||||
--> $DIR/issue-29723.rs:18:14
|
||||
--> $DIR/use-moved-value-in-match-guard-drop.rs:18:14
|
||||
|
|
||||
LL | let s = String::new();
|
||||
| - move occurs because `s` has type `String`, which does not implement the `Copy` trait
|
||||
Reference in New Issue
Block a user