diff options
| author | bors <bors@rust-lang.org> | 2019-05-27 01:10:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2019-05-27 01:10:22 +0000 |
| commit | ed2a5115daaffdab30b102405ffcfb222decf444 (patch) | |
| tree | 3b4999c145e6b84429035e422d0bf5a2e9e4e8f4 /src/test | |
| parent | 37c45ec3980f97ecd06617d3315105eec9247432 (diff) | |
| parent | 1cc42ea6750affbef2bca699bde30ac321e15939 (diff) | |
| download | rust-ed2a5115daaffdab30b102405ffcfb222decf444.tar.gz rust-ed2a5115daaffdab30b102405ffcfb222decf444.zip | |
Auto merge of #61147 - estebank:suggest-as-ref, r=oli-obk
When encountering move error on an `Option`, suggest using `as_ref` Fix #61109, cc #15457.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/ui/suggestions/option-content-move.fixed | 39 | ||||
| -rw-r--r-- | src/test/ui/suggestions/option-content-move.rs | 39 | ||||
| -rw-r--r-- | src/test/ui/suggestions/option-content-move.stderr | 21 |
3 files changed, 99 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/option-content-move.fixed b/src/test/ui/suggestions/option-content-move.fixed new file mode 100644 index 00000000000..f163cd104ff --- /dev/null +++ b/src/test/ui/suggestions/option-content-move.fixed @@ -0,0 +1,39 @@ +//run-rustfix + +pub struct LipogramCorpora { + selections: Vec<(char, Option<String>)>, +} + +impl LipogramCorpora { + pub fn validate_all(&mut self) -> Result<(), char> { + for selection in &self.selections { + if selection.1.is_some() { + if selection.1.as_ref().unwrap().contains(selection.0) { + //~^ ERROR cannot move out of borrowed content + return Err(selection.0); + } + } + } + Ok(()) + } +} + +pub struct LipogramCorpora2 { + selections: Vec<(char, Result<String, String>)>, +} + +impl LipogramCorpora2 { + pub fn validate_all(&mut self) -> Result<(), char> { + for selection in &self.selections { + if selection.1.is_ok() { + if selection.1.as_ref().unwrap().contains(selection.0) { + //~^ ERROR cannot move out of borrowed content + return Err(selection.0); + } + } + } + Ok(()) + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/option-content-move.rs b/src/test/ui/suggestions/option-content-move.rs new file mode 100644 index 00000000000..350486a802d --- /dev/null +++ b/src/test/ui/suggestions/option-content-move.rs @@ -0,0 +1,39 @@ +//run-rustfix + +pub struct LipogramCorpora { + selections: Vec<(char, Option<String>)>, +} + +impl LipogramCorpora { + pub fn validate_all(&mut self) -> Result<(), char> { + for selection in &self.selections { + if selection.1.is_some() { + if selection.1.unwrap().contains(selection.0) { + //~^ ERROR cannot move out of borrowed content + return Err(selection.0); + } + } + } + Ok(()) + } +} + +pub struct LipogramCorpora2 { + selections: Vec<(char, Result<String, String>)>, +} + +impl LipogramCorpora2 { + pub fn validate_all(&mut self) -> Result<(), char> { + for selection in &self.selections { + if selection.1.is_ok() { + if selection.1.unwrap().contains(selection.0) { + //~^ ERROR cannot move out of borrowed content + return Err(selection.0); + } + } + } + Ok(()) + } +} + +fn main() {} diff --git a/src/test/ui/suggestions/option-content-move.stderr b/src/test/ui/suggestions/option-content-move.stderr new file mode 100644 index 00000000000..0a325ac54ea --- /dev/null +++ b/src/test/ui/suggestions/option-content-move.stderr @@ -0,0 +1,21 @@ +error[E0507]: cannot move out of borrowed content + --> $DIR/option-content-move.rs:11:20 + | +LL | if selection.1.unwrap().contains(selection.0) { + | ^^^^^^^^^^^ + | | + | cannot move out of borrowed content + | help: consider borrowing the `Option`'s content: `selection.1.as_ref()` + +error[E0507]: cannot move out of borrowed content + --> $DIR/option-content-move.rs:29:20 + | +LL | if selection.1.unwrap().contains(selection.0) { + | ^^^^^^^^^^^ + | | + | cannot move out of borrowed content + | help: consider borrowing the `Result`'s content: `selection.1.as_ref()` + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0507`. |
