forked from rust-lang/rust
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Locals which can be partially moved created within the to-be-created closure shouldn't block the use of a closure
- Loading branch information
Showing
11 changed files
with
181 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::map_entry)] | ||
#![allow(dead_code)] | ||
|
||
use std::collections::BTreeMap; | ||
|
||
fn foo() {} | ||
|
||
fn btree_map<K: Eq + Ord + Copy, V: Copy>(m: &mut BTreeMap<K, V>, k: K, v: V) { | ||
// insert then do something, use if let | ||
if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { | ||
e.insert(v); | ||
foo(); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::map_entry)] | ||
#![allow(dead_code)] | ||
|
||
use std::collections::BTreeMap; | ||
|
||
fn foo() {} | ||
|
||
fn btree_map<K: Eq + Ord + Copy, V: Copy>(m: &mut BTreeMap<K, V>, k: K, v: V) { | ||
// insert then do something, use if let | ||
if !m.contains_key(&k) { | ||
m.insert(k, v); | ||
foo(); | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: usage of `contains_key` followed by `insert` on a `BTreeMap` | ||
--> $DIR/entry_btree.rs:12:5 | ||
| | ||
LL | / if !m.contains_key(&k) { | ||
LL | | m.insert(k, v); | ||
LL | | foo(); | ||
LL | | } | ||
| |_____^ | ||
| | ||
= note: `-D clippy::map-entry` implied by `-D warnings` | ||
help: try this | ||
| | ||
LL ~ if let std::collections::btree_map::Entry::Vacant(e) = m.entry(k) { | ||
LL + e.insert(v); | ||
LL + foo(); | ||
LL + } | ||
| | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::manual_map)] | ||
|
||
fn main() { | ||
let _ = Some(0).map(|x| { | ||
let y = (String::new(), String::new()); | ||
(x, y.0) | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// run-rustfix | ||
|
||
#![warn(clippy::manual_map)] | ||
|
||
fn main() { | ||
let _ = match Some(0) { | ||
Some(x) => Some({ | ||
let y = (String::new(), String::new()); | ||
(x, y.0) | ||
}), | ||
None => None, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error: manual implementation of `Option::map` | ||
--> $DIR/manual_map_option_2.rs:6:13 | ||
| | ||
LL | let _ = match Some(0) { | ||
| _____________^ | ||
LL | | Some(x) => Some({ | ||
LL | | let y = (String::new(), String::new()); | ||
LL | | (x, y.0) | ||
LL | | }), | ||
LL | | None => None, | ||
LL | | }; | ||
| |_____^ | ||
| | ||
= note: `-D clippy::manual-map` implied by `-D warnings` | ||
help: try this | ||
| | ||
LL | let _ = Some(0).map(|x| { | ||
LL | let y = (String::new(), String::new()); | ||
LL | (x, y.0) | ||
LL | }); | ||
| | ||
|
||
error: aborting due to previous error | ||
|