diff --git a/tests/ui/mem_replace.fixed b/tests/ui/mem_replace.fixed new file mode 100644 index 0000000000000..4e47ac95d82d3 --- /dev/null +++ b/tests/ui/mem_replace.fixed @@ -0,0 +1,21 @@ +// Copyright 2014-2019 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// run-rustfix +#![allow(unused_imports)] +#![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)] + +use std::mem; + +fn main() { + let mut an_option = Some(1); + let _ = an_option.take(); + let an_option = &mut Some(1); + let _ = an_option.take(); +} diff --git a/tests/ui/mem_replace.rs b/tests/ui/mem_replace.rs index a0c340bb54b34..6824ab18e7faa 100644 --- a/tests/ui/mem_replace.rs +++ b/tests/ui/mem_replace.rs @@ -7,6 +7,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// run-rustfix +#![allow(unused_imports)] #![warn(clippy::all, clippy::style, clippy::mem_replace_option_with_none)] use std::mem; diff --git a/tests/ui/mem_replace.stderr b/tests/ui/mem_replace.stderr index 9092fa2ea1453..791c4d71dbfc8 100644 --- a/tests/ui/mem_replace.stderr +++ b/tests/ui/mem_replace.stderr @@ -1,5 +1,5 @@ error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:16:13 + --> $DIR/mem_replace.rs:18:13 | LL | let _ = mem::replace(&mut an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()` @@ -7,7 +7,7 @@ LL | let _ = mem::replace(&mut an_option, None); = note: `-D clippy::mem-replace-option-with-none` implied by `-D warnings` error: replacing an `Option` with `None` - --> $DIR/mem_replace.rs:18:13 + --> $DIR/mem_replace.rs:20:13 | LL | let _ = mem::replace(an_option, None); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider `Option::take()` instead: `an_option.take()`