#![warn(clippy::single_option_map)] use std::sync::atomic::{AtomicUsize, Ordering}; static ATOM: AtomicUsize = AtomicUsize::new(42); static MAYBE_ATOMIC: Option<&AtomicUsize> = Some(&ATOM); fn h(arg: Option) -> Option { //~^ single_option_map arg.map(|x| x * 2) } fn j(arg: Option) -> Option { //~^ single_option_map arg.map(|x| x * 2) } fn mul_args(a: String, b: u64) -> String { a } fn mul_args_opt(a: Option, b: u64) -> Option { //~^ single_option_map a.map(|val| mul_args(val, b + 1)) } // No lint: no `Option` argument argument fn maps_static_option() -> Option { MAYBE_ATOMIC.map(|a| a.load(Ordering::Relaxed)) } // No lint: wrapped by another function fn manipulate(i: i32) -> i32 { i + 1 } // No lint: wraps another function to do the optional thing fn manipulate_opt(opt_i: Option) -> Option { opt_i.map(manipulate) } // No lint: maps other than the receiver fn map_not_arg(arg: Option) -> Option { maps_static_option().map(|_| arg.unwrap()) } // No lint: wrapper function with η-expanded form #[allow(clippy::redundant_closure)] fn manipulate_opt_explicit(opt_i: Option) -> Option { opt_i.map(|x| manipulate(x)) } // No lint fn multi_args(a: String, b: bool, c: u64) -> String { a } // No lint: contains only map of a closure that binds other arguments fn multi_args_opt(a: Option, b: bool, c: u64) -> Option { a.map(|a| multi_args(a, b, c)) } fn main() { let answer = Some(42u32); let h_result = h(answer); let answer = Some(42u64); let j_result = j(answer); maps_static_option(); }