rust/tests/ui/auxiliary/option_helpers.rs

56 lines
1.1 KiB
Rust
Raw Normal View History

#![allow(dead_code, unused_variables)]
/// Utility macro to test linting behavior in `option_methods()`
/// The lints included in `option_methods()` should not lint if the call to map is partially
/// within a macro
#[macro_export]
macro_rules! opt_map {
2019-01-02 01:15:32 -06:00
($opt:expr, $map:expr) => {
($opt).map($map)
};
}
/// Struct to generate false positive for Iterator-based lints
#[derive(Copy, Clone)]
pub struct IteratorFalsePositives {
pub foo: u32,
}
impl IteratorFalsePositives {
pub fn filter(self) -> IteratorFalsePositives {
self
}
pub fn next(self) -> IteratorFalsePositives {
self
}
pub fn find(self) -> Option<u32> {
Some(self.foo)
}
pub fn position(self) -> Option<u32> {
Some(self.foo)
}
pub fn rposition(self) -> Option<u32> {
Some(self.foo)
}
pub fn nth(self, n: usize) -> Option<u32> {
Some(self.foo)
}
pub fn skip(self, _: usize) -> IteratorFalsePositives {
self
}
2020-01-19 19:54:54 -06:00
pub fn skip_while(self) -> IteratorFalsePositives {
self
}
2021-02-25 08:06:50 -06:00
pub fn count(self) -> usize {
self.foo as usize
}
}