mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-21 02:23:19 +00:00
57 lines
1.2 KiB
Rust
57 lines
1.2 KiB
Rust
|
#![allow(unused)]
|
||
|
#![warn(clippy::unnecessary_map_on_constructor)]
|
||
|
|
||
|
use std::ffi::OsStr;
|
||
|
|
||
|
fn fun(t: i32) -> i32 {
|
||
|
t
|
||
|
}
|
||
|
|
||
|
fn notfun(e: SimpleError) -> SimpleError {
|
||
|
e
|
||
|
}
|
||
|
macro_rules! expands_to_fun {
|
||
|
() => {
|
||
|
fun
|
||
|
};
|
||
|
}
|
||
|
|
||
|
#[derive(Copy, Clone)]
|
||
|
struct SimpleError {}
|
||
|
|
||
|
type SimpleResult = std::result::Result<i32, SimpleError>;
|
||
|
|
||
|
fn main() {
|
||
|
let x: i32 = 4;
|
||
|
|
||
|
let err = SimpleError {};
|
||
|
let a = Some(x);
|
||
|
let b: SimpleResult = Ok(x);
|
||
|
let c: SimpleResult = Err(err);
|
||
|
|
||
|
let a = Some(fun(x));
|
||
|
let b: SimpleResult = Ok(fun(x));
|
||
|
let c: SimpleResult = Err(notfun(err));
|
||
|
|
||
|
let a = Option::Some(fun(x));
|
||
|
let b: SimpleResult = SimpleResult::Ok(fun(x));
|
||
|
let c: SimpleResult = SimpleResult::Err(notfun(err));
|
||
|
let b: std::result::Result<i32, SimpleError> = Ok(fun(x));
|
||
|
let c: std::result::Result<i32, SimpleError> = Err(notfun(err));
|
||
|
|
||
|
let a = Some(fun(x));
|
||
|
let b: SimpleResult = Ok(fun(x));
|
||
|
let c: SimpleResult = Err(notfun(err));
|
||
|
|
||
|
// Should not trigger warning
|
||
|
a.map(fun);
|
||
|
b.map(fun);
|
||
|
c.map_err(notfun);
|
||
|
|
||
|
b.map_err(notfun); // Ok(_).map_err
|
||
|
c.map(fun); // Err(_).map()
|
||
|
|
||
|
option_env!("PATH").map(OsStr::new);
|
||
|
Some(x).map(expands_to_fun!());
|
||
|
}
|