Skip to content

Commit eaaee23

Browse files
committed
UI test cleanup: Extract lint from methods.rs test
1 parent 85ba5f0 commit eaaee23

File tree

5 files changed

+123
-106
lines changed

5 files changed

+123
-106
lines changed

tests/auxiliary/option_helpers.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// Utility macro to test linting behavior in `option_methods()`
2+
/// The lints included in `option_methods()` should not lint if the call to map is partially
3+
/// within a macro
4+
macro_rules! opt_map {
5+
($opt:expr, $map:expr) => {($opt).map($map)};
6+
}

tests/ui/methods.rs

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ use std::iter::FromIterator;
3131
use std::rc::{self, Rc};
3232
use std::sync::{self, Arc};
3333

34+
include!("../auxiliary/option_helpers.rs");
35+
3436
pub struct T;
3537

3638
impl T {
@@ -101,13 +103,6 @@ impl Mul<T> for T {
101103
fn mul(self, other: T) -> T { self } // no error, obviously
102104
}
103105

104-
/// Utility macro to test linting behavior in `option_methods()`
105-
/// The lints included in `option_methods()` should not lint if the call to map is partially
106-
/// within a macro
107-
macro_rules! opt_map {
108-
($opt:expr, $map:expr) => {($opt).map($map)};
109-
}
110-
111106
/// Checks implementation of the following lints:
112107
/// * `OPTION_MAP_UNWRAP_OR`
113108
/// * `OPTION_MAP_UNWRAP_OR_ELSE`
@@ -169,29 +164,6 @@ fn option_methods() {
169164
);
170165
}
171166

172-
/// Checks implementation of the following lints:
173-
/// * `RESULT_MAP_UNWRAP_OR_ELSE`
174-
fn result_methods() {
175-
let res: Result<i32, ()> = Ok(1);
176-
177-
// Check RESULT_MAP_UNWRAP_OR_ELSE
178-
// single line case
179-
let _ = res.map(|x| x + 1)
180-
181-
.unwrap_or_else(|e| 0); // should lint even though this call is on a separate line
182-
// multi line cases
183-
let _ = res.map(|x| {
184-
x + 1
185-
}
186-
).unwrap_or_else(|e| 0);
187-
let _ = res.map(|x| x + 1)
188-
.unwrap_or_else(|e|
189-
0
190-
);
191-
// macro case
192-
let _ = opt_map!(res, |x| x + 1).unwrap_or_else(|e| 0); // should not lint
193-
}
194-
195167
/// Struct to generate false positives for things with .iter()
196168
#[derive(Copy, Clone)]
197169
struct HasIter;

0 commit comments

Comments
 (0)