Skip to content

Instantly share code, notes, and snippets.

@matthewjasper
Created May 28, 2018 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewjasper/15eac85086ee6a8adb806450b046c57a to your computer and use it in GitHub Desktop.
Save matthewjasper/15eac85086ee6a8adb806450b046c57a to your computer and use it in GitHub Desktop.
NLL Move errors
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:19:13
|
19 | let b = *a; // Suggest &, or removing *
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `a`
error[E0508]: cannot move out of type `[A; 1]`, a non-copy array
--> src/test/ui/nll/move-errors.rs:24:13
|
24 | let b = a[0]; // Suggest &
| ^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&a[0]`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:30:13
|
30 | let s = **r; // Suggest &
| ^^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `*r`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:36:13
|
36 | let s = *r; // Suggest &
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `r`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:43:13
|
43 | let s = *r; // Suggest &
| ^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*r`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:48:16
|
48 | let A(s) = *a; // Would prefer to suggest removing *
| ^^
| |
| cannot move out of borrowed content
| help: consider removing this dereference operator: `a`
error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:53:19
|
53 | let C(D(s)) = c; // Can either suggest ref or &, ref is maybe better
| - ^ cannot move out of here
| |
| help: to prevent move, use ref or ref mut: `ref s`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:60:9
|
60 | b = *a; // Don't suggest anything
| ^^ cannot move out of borrowed content
error[E0508]: cannot move out of type `[B; 1]`, a non-copy array
--> src/test/ui/nll/move-errors.rs:82:11
|
82 | match x[0] { // Can just suggest using & here?
| ^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&x[0]`
83 | B::U(d) => (), // Combine suggestions of ref if that's what ends up being suggested.
| - move occurs here
84 | B::V(s) => (),
| - move occurs here
error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:90:11
|
90 | match x { // Don't suggest `&`!
| ^ cannot move out of here
91 | B::V(s) => drop(s),
92 | B::U(D(s)) => (), // Suggest ref or ref mut here!
| - help: to prevent move, use ref or ref mut: `ref s`
error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:98:11
|
98 | match x {
| ^ cannot move out of here
99 | (D(s), &t) => (), // Also suggest removing &?
| - help: to prevent move, use ref or ref mut: `ref s`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:98:11
|
98 | match x {
| ^ cannot move out of borrowed content
99 | (D(s), &t) => (), // Also suggest removing &?
| - help: to prevent move, use ref or ref mut: `ref t`
error[E0509]: cannot move out of type `F`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:106:11
|
106 | match x {
| ^ cannot move out of here
help: to prevent move, use ref or ref mut
|
108 | F(ref s, mut t) => (),
| ^^^^^
help: to prevent move, use ref or ref mut
|
108 | F(s, ref mut t) => (),
| ^^^^^^^^^
error: aborting due to 13 previous errors
Some errors occurred: E0507, E0508, E0509.
For more information about an error, try `rustc --explain E0507`.
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:19:13
|
19 | let b = *a; // Suggest &, or removing *
| ^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*a`
error[E0508]: cannot move out of type `[A; 1]`, a non-copy array
--> src/test/ui/nll/move-errors.rs:24:13
|
24 | let b = a[0]; // Suggest &
| ^^^^
| |
| cannot move out of here
| help: consider using a reference instead: `&a[0]`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:30:13
|
30 | let s = **r; // Suggest &
| ^^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&**r`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:36:13
|
36 | let s = *r; // Suggest &
| ^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*r`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:43:13
|
43 | let s = *r; // Suggest &
| ^^
| |
| cannot move out of borrowed content
| help: consider using a reference instead: `&*r`
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:48:16
|
48 | let A(s) = *a; // Would prefer to suggest removing *
| - ^^ cannot move out of borrowed content
| |
| hint: to prevent move, use `ref s` or `ref mut s`
error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:53:11
|
53 | let C(D(s)) = c; // Can either suggest ref or &, ref is maybe better
| ^^-^
| | |
| | hint: to prevent move, use `ref s` or `ref mut s`
| cannot move out of here
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:60:9
|
60 | b = *a; // Don't suggest anything
| ^^ cannot move out of borrowed content
error[E0508]: cannot move out of type `[B; 1]`, a non-copy array
--> src/test/ui/nll/move-errors.rs:82:11
|
82 | match x[0] { // Can just suggest using & here?
| ^^^^ cannot move out of here
83 | B::U(d) => (), // Combine suggestions of ref if that's what ends up being suggested.
| - hint: to prevent move, use `ref d` or `ref mut d`
84 | B::V(s) => (),
| - ...and here (use `ref s` or `ref mut s`)
error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:92:14
|
92 | B::U(D(s)) => (), // Suggest ref or ref mut here!
| ^^-^
| | |
| | hint: to prevent move, use `ref s` or `ref mut s`
| cannot move out of here
error[E0509]: cannot move out of type `D`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:99:10
|
99 | (D(s), &t) => (), // Also suggest removing &?
| ^^-^
| | |
| | hint: to prevent move, use `ref s` or `ref mut s`
| cannot move out of here
error[E0507]: cannot move out of borrowed content
--> src/test/ui/nll/move-errors.rs:99:16
|
99 | (D(s), &t) => (), // Also suggest removing &?
| ^-
| ||
| |hint: to prevent move, use `ref t` or `ref mut t`
| cannot move out of borrowed content
error[E0509]: cannot move out of type `F`, which implements the `Drop` trait
--> src/test/ui/nll/move-errors.rs:108:9
|
108 | F(s, mut t) => (),
| ^^-^^-----^
| | | |
| | | ...and here (use `ref t` or `ref mut t`)
| | hint: to prevent move, use `ref s` or `ref mut s`
| cannot move out of here
error: aborting due to 13 previous errors
Some errors occurred: E0507, E0508, E0509.
For more information about an error, try `rustc --explain E0507`.
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![allow(unused)]
struct A(String);
struct C(D);
fn suggest_remove_deref() {
let a = &A("".to_string());
let b = *a; // Suggest &, or removing *
}
fn suggest_borrow() {
let a = [A("".to_string())];
let b = a[0]; // Suggest &
}
fn suggest_borrow2() {
let mut a = A("".to_string());
let r = &&mut a;
let s = **r; // Suggest &
}
fn suggest_borrow3() {
let mut a = A("".to_string());
let r = &&mut a;
let s = *r; // Suggest &
}
fn suggest_borrow4() {
use std::rc::Rc;
let mut a = A("".to_string());
let r = Rc::new(a);
let s = *r; // Suggest &
}
fn suggest_any() {
let a = &A("".to_string());
let A(s) = *a; // Would prefer to suggest removing *
}
fn suggest_either() {
let c = C(D(String::new()));
let C(D(s)) = c; // Can either suggest ref or &, ref is maybe better
// for a future where patterns can mix move and ref.
}
fn shouldnt_have_message() {
let a = &A("".to_string());
let b;
b = *a; // Don't suggest anything
}
enum B {
V(String),
U(D),
}
struct D(String);
impl Drop for D {
fn drop(&mut self) {}
}
struct F(String, String);
impl Drop for F {
fn drop(&mut self) {}
}
fn probably_suggest_borrow() {
let x = [B::V(String::new())];
match x[0] { // Can just suggest using & here?
B::U(d) => (), // Combine suggestions of ref if that's what ends up being suggested.
B::V(s) => (),
}
}
fn have_to_suggest_ref() {
let x = B::V(String::new());
match x { // Don't suggest `&`!
B::V(s) => drop(s),
B::U(D(s)) => (), // Suggest ref or ref mut here!
};
}
fn have_to_suggest_ref_twice() {
let x = (D(String::new()), &String::new());
match x {
(D(s), &t) => (), // Also suggest removing &?
_ => (),
}
}
fn have_to_suggest_double_ref() {
let x = F(String::new(), String::new());
match x {
// Second suggestion should be ref mut.
F(s, mut t) => (),
_ => (),
}
}
fn use_suggested_ref() {
let x = B::V(String::new());
match x {
B::V(s) => (),
B::U(D(ref s)) => (),
};
}
fn main() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment