-
Notifications
You must be signed in to change notification settings - Fork 32
/
suggest-option-asderef.rs
43 lines (36 loc) · 1.37 KB
/
suggest-option-asderef.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// this isn't auto-fixable now because we produce two similar suggestions
fn produces_string() -> Option<String> {
Some("my cool string".to_owned())
}
fn takes_str(_: &str) -> Option<()> {
Some(())
}
fn takes_str_mut(_: &mut str) -> Option<()> {
Some(())
}
fn generic<T>(_: T) -> Option<()> {
Some(())
}
fn generic_ref<T>(_: &T) -> Option<()> {
//~^ HELP consider adjusting the signature so it does not borrow its argument
Some(())
}
fn main() {
let _: Option<()> = produces_string().and_then(takes_str);
//~^ ERROR type mismatch in function arguments
//~| HELP call `Option::as_deref()` first
//~| HELP consider wrapping the function in a closure
let _: Option<Option<()>> = produces_string().map(takes_str);
//~^ ERROR type mismatch in function arguments
//~| HELP call `Option::as_deref()` first
//~| HELP consider wrapping the function in a closure
let _: Option<Option<()>> = produces_string().map(takes_str_mut);
//~^ ERROR type mismatch in function arguments
//~| HELP call `Option::as_deref_mut()` first
//~| HELP consider wrapping the function in a closure
let _ = produces_string().and_then(generic);
let _ = produces_string().and_then(generic_ref);
//~^ ERROR type mismatch in function arguments
//~| HELP call `Option::as_deref()` first
//~| HELP consider wrapping the function in a closure
}