mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-21 04:03:11 +00:00
Add tests that show: insert() can be a read or not
This commit is contained in:
parent
5770d40d8e
commit
cb3bb8a5b5
@ -1,7 +1,7 @@
|
||||
#![allow(unused)]
|
||||
#![warn(clippy::collection_is_never_read)]
|
||||
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashSet, HashMap};
|
||||
|
||||
fn main() {}
|
||||
|
||||
@ -114,3 +114,15 @@ fn method_argument_but_not_target() {
|
||||
x.reverse();
|
||||
my_struct.my_method(&x);
|
||||
}
|
||||
|
||||
fn insert_is_not_a_read() {
|
||||
let mut x = HashSet::new(); // WARNING
|
||||
x.insert(5);
|
||||
}
|
||||
|
||||
fn insert_is_a_read() {
|
||||
let mut x = HashSet::new(); // Ok
|
||||
if x.insert(5) {
|
||||
println!("5 was inserted");
|
||||
}
|
||||
}
|
||||
|
@ -36,5 +36,11 @@ error: collection is never read
|
||||
LL | let mut x = vec![1, 2, 3]; // WARNING
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
error: collection is never read
|
||||
--> $DIR/collection_is_never_read.rs:119:5
|
||||
|
|
||||
LL | let mut x = HashSet::new(); // WARNING
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user