Skip to content

Commit a5d3f37

Browse files
committed
Use compiletest's aux-build header instead of include macro
1 parent c84a894 commit a5d3f37

7 files changed

+87
-79
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
#![allow(dead_code, unused_variables)]
2+
13
/// Utility macro to test linting behavior in `option_methods()`
24
/// The lints included in `option_methods()` should not lint if the call to map is partially
35
/// within a macro
6+
#[macro_export]
47
macro_rules! opt_map {
58
($opt:expr, $map:expr) => {
69
($opt).map($map)
@@ -9,36 +12,36 @@ macro_rules! opt_map {
912

1013
/// Struct to generate false positive for Iterator-based lints
1114
#[derive(Copy, Clone)]
12-
struct IteratorFalsePositives {
13-
foo: u32,
15+
pub struct IteratorFalsePositives {
16+
pub foo: u32,
1417
}
1518

1619
impl IteratorFalsePositives {
17-
fn filter(self) -> IteratorFalsePositives {
20+
pub fn filter(self) -> IteratorFalsePositives {
1821
self
1922
}
2023

21-
fn next(self) -> IteratorFalsePositives {
24+
pub fn next(self) -> IteratorFalsePositives {
2225
self
2326
}
2427

25-
fn find(self) -> Option<u32> {
28+
pub fn find(self) -> Option<u32> {
2629
Some(self.foo)
2730
}
2831

29-
fn position(self) -> Option<u32> {
32+
pub fn position(self) -> Option<u32> {
3033
Some(self.foo)
3134
}
3235

33-
fn rposition(self) -> Option<u32> {
36+
pub fn rposition(self) -> Option<u32> {
3437
Some(self.foo)
3538
}
3639

37-
fn nth(self, n: usize) -> Option<u32> {
40+
pub fn nth(self, n: usize) -> Option<u32> {
3841
Some(self.foo)
3942
}
4043

41-
fn skip(self, _: usize) -> IteratorFalsePositives {
44+
pub fn skip(self, _: usize) -> IteratorFalsePositives {
4245
self
4346
}
4447
}

tests/ui/iter_skip_next.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
// aux-build:option_helpers.rs
11+
1012
#![warn(clippy::iter_skip_next)]
1113
#![allow(clippy::blacklisted_name)]
1214

13-
include!("../auxiliary/option_helpers.rs");
15+
extern crate option_helpers;
16+
17+
use option_helpers::IteratorFalsePositives;
1418

1519
/// Checks implementation of `ITER_SKIP_NEXT` lint
1620
fn iter_skip_next() {

tests/ui/iter_skip_next.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
2-
--> $DIR/iter_skip_next.rs:18:13
2+
--> $DIR/iter_skip_next.rs:22:13
33
|
44
LL | let _ = some_vec.iter().skip(42).next();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `-D clippy::iter-skip-next` implied by `-D warnings`
88

99
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
10-
--> $DIR/iter_skip_next.rs:19:13
10+
--> $DIR/iter_skip_next.rs:23:13
1111
|
1212
LL | let _ = some_vec.iter().cycle().skip(42).next();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1414

1515
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
16-
--> $DIR/iter_skip_next.rs:20:13
16+
--> $DIR/iter_skip_next.rs:24:13
1717
|
1818
LL | let _ = (1..10).skip(10).next();
1919
| ^^^^^^^^^^^^^^^^^^^^^^^
2020

2121
error: called `skip(x).next()` on an iterator. This is more succinctly expressed by calling `nth(x)`
22-
--> $DIR/iter_skip_next.rs:21:14
22+
--> $DIR/iter_skip_next.rs:25:14
2323
|
2424
LL | let _ = &some_vec[..].iter().skip(3).next();
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

tests/ui/methods.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10+
// aux-build:option_helpers.rs
11+
1012
#![warn(clippy::all, clippy::pedantic, clippy::option_unwrap_used)]
1113
#![allow(
1214
clippy::blacklisted_name,
@@ -22,6 +24,9 @@
2224
clippy::useless_format
2325
)]
2426

27+
#[macro_use]
28+
extern crate option_helpers;
29+
2530
use std::collections::BTreeMap;
2631
use std::collections::HashMap;
2732
use std::collections::HashSet;
@@ -31,7 +36,7 @@ use std::iter::FromIterator;
3136
use std::rc::{self, Rc};
3237
use std::sync::{self, Arc};
3338

34-
include!("../auxiliary/option_helpers.rs");
39+
use option_helpers::IteratorFalsePositives;
3540

3641
pub struct T;
3742

0 commit comments

Comments
 (0)