Skip to content

Commit c3243f9

Browse files
committed
Auto merge of rust-lang#11860 - GuillaumeGomez:improve-error-messages, r=flip1995
Improve error messages format Following review in rust-lang/rust-clippy#11845, since there is already suggestions, no need to add the second part of the sentence every time. r? `@flip1995` changelog: Improve some error messages
2 parents 840e227 + 6c84b96 commit c3243f9

11 files changed

+50
-61
lines changed

clippy_lints/src/methods/map_unwrap_or.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ pub(super) fn check<'tcx>(
4444

4545
// lint message
4646
let msg = if is_option {
47-
"called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling \
48-
`map_or_else(<g>, <f>)` instead"
47+
"called `map(<f>).unwrap_or_else(<g>)` on an `Option` value"
4948
} else {
50-
"called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling \
51-
`.map_or_else(<g>, <f>)` instead"
49+
"called `map(<f>).unwrap_or_else(<g>)` on a `Result` value"
5250
};
5351
// get snippets for args to map() and unwrap_or_else()
5452
let map_snippet = snippet(cx, map_arg.span, "..");

clippy_lints/src/methods/option_as_ref_deref.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ pub(super) fn check(
9999
let hint = format!("{}.{method_hint}()", snippet(cx, as_ref_recv.span, ".."));
100100
let suggestion = format!("try using {method_hint} instead");
101101

102-
let msg = format!(
103-
"called `{current_method}` on an Option value. This can be done more directly \
104-
by calling `{hint}` instead"
105-
);
102+
let msg = format!("called `{current_method}` on an `Option` value");
106103
span_lint_and_sugg(
107104
cx,
108105
OPTION_AS_REF_DEREF,

clippy_lints/src/methods/option_map_or_none.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ pub(super) fn check<'tcx>(
6666
&& Some(id) == cx.tcx.lang_items().option_some_variant()
6767
{
6868
let func_snippet = snippet(cx, arg_char.span, "..");
69-
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
70-
`map(..)` instead";
69+
let msg = "called `map_or(None, ..)` on an `Option` value";
7170
return span_lint_and_sugg(
7271
cx,
7372
OPTION_MAP_OR_NONE,
@@ -80,8 +79,7 @@ pub(super) fn check<'tcx>(
8079
}
8180

8281
let func_snippet = snippet(cx, map_arg.span, "..");
83-
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
84-
`and_then(..)` instead";
82+
let msg = "called `map_or(None, ..)` on an `Option` value";
8583
span_lint_and_sugg(
8684
cx,
8785
OPTION_MAP_OR_NONE,
@@ -92,8 +90,7 @@ pub(super) fn check<'tcx>(
9290
Applicability::MachineApplicable,
9391
);
9492
} else if f_arg_is_some {
95-
let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \
96-
`ok()` instead";
93+
let msg = "called `map_or(None, Some)` on a `Result` value";
9794
let self_snippet = snippet(cx, recv.span, "..");
9895
span_lint_and_sugg(
9996
cx,

clippy_lints/src/methods/option_map_unwrap_or.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,7 @@ pub(super) fn check<'tcx>(
9797
} else {
9898
"map_or(<a>, <f>)"
9999
};
100-
let msg = &format!(
101-
"called `map(<f>).unwrap_or({arg})` on an `Option` value. \
102-
This can be done more directly by calling `{suggest}` instead"
103-
);
100+
let msg = &format!("called `map(<f>).unwrap_or({arg})` on an `Option` value");
104101

105102
span_lint_and_then(cx, MAP_UNWRAP_OR, expr.span, msg, |diag| {
106103
let map_arg_span = map_arg.span;

tests/ui/map_unwrap_or.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
1+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
22
--> $DIR/map_unwrap_or.rs:17:13
33
|
44
LL | let _ = opt.map(|x| x + 1)
@@ -15,7 +15,7 @@ LL - let _ = opt.map(|x| x + 1)
1515
LL + let _ = opt.map_or(0, |x| x + 1);
1616
|
1717

18-
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
18+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
1919
--> $DIR/map_unwrap_or.rs:21:13
2020
|
2121
LL | let _ = opt.map(|x| {
@@ -33,7 +33,7 @@ LL | }
3333
LL ~ );
3434
|
3535

36-
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
36+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
3737
--> $DIR/map_unwrap_or.rs:25:13
3838
|
3939
LL | let _ = opt.map(|x| x + 1)
@@ -50,7 +50,7 @@ LL + 0
5050
LL ~ }, |x| x + 1);
5151
|
5252

53-
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
53+
error: called `map(<f>).unwrap_or(None)` on an `Option` value
5454
--> $DIR/map_unwrap_or.rs:30:13
5555
|
5656
LL | let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
@@ -62,7 +62,7 @@ LL - let _ = opt.map(|x| Some(x + 1)).unwrap_or(None);
6262
LL + let _ = opt.and_then(|x| Some(x + 1));
6363
|
6464

65-
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
65+
error: called `map(<f>).unwrap_or(None)` on an `Option` value
6666
--> $DIR/map_unwrap_or.rs:32:13
6767
|
6868
LL | let _ = opt.map(|x| {
@@ -80,7 +80,7 @@ LL | }
8080
LL ~ );
8181
|
8282

83-
error: called `map(<f>).unwrap_or(None)` on an `Option` value. This can be done more directly by calling `and_then(<f>)` instead
83+
error: called `map(<f>).unwrap_or(None)` on an `Option` value
8484
--> $DIR/map_unwrap_or.rs:36:13
8585
|
8686
LL | let _ = opt
@@ -95,7 +95,7 @@ LL - .map(|x| Some(x + 1))
9595
LL + .and_then(|x| Some(x + 1));
9696
|
9797

98-
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
98+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
9999
--> $DIR/map_unwrap_or.rs:47:13
100100
|
101101
LL | let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
@@ -107,7 +107,7 @@ LL - let _ = Some("prefix").map(|p| format!("{}.", p)).unwrap_or(id);
107107
LL + let _ = Some("prefix").map_or(id, |p| format!("{}.", p));
108108
|
109109

110-
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
110+
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value
111111
--> $DIR/map_unwrap_or.rs:51:13
112112
|
113113
LL | let _ = opt.map(|x| {
@@ -117,7 +117,7 @@ LL | | }
117117
LL | | ).unwrap_or_else(|| 0);
118118
| |__________________________^
119119

120-
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
120+
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value
121121
--> $DIR/map_unwrap_or.rs:55:13
122122
|
123123
LL | let _ = opt.map(|x| x + 1)
@@ -127,7 +127,7 @@ LL | | 0
127127
LL | | );
128128
| |_________^
129129

130-
error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
130+
error: called `map(<f>).unwrap_or(false)` on an `Option` value
131131
--> $DIR/map_unwrap_or.rs:61:13
132132
|
133133
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
@@ -139,7 +139,7 @@ LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
139139
LL + let _ = opt.is_some_and(|x| x > 5);
140140
|
141141

142-
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
142+
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
143143
--> $DIR/map_unwrap_or.rs:71:13
144144
|
145145
LL | let _ = res.map(|x| {
@@ -149,7 +149,7 @@ LL | | }
149149
LL | | ).unwrap_or_else(|_e| 0);
150150
| |____________________________^
151151

152-
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
152+
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
153153
--> $DIR/map_unwrap_or.rs:75:13
154154
|
155155
LL | let _ = res.map(|x| x + 1)
@@ -159,13 +159,13 @@ LL | | 0
159159
LL | | });
160160
| |__________^
161161

162-
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
162+
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
163163
--> $DIR/map_unwrap_or.rs:99:13
164164
|
165165
LL | let _ = res.map(|x| x + 1).unwrap_or_else(|_e| 0);
166166
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `res.map_or_else(|_e| 0, |x| x + 1)`
167167

168-
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value. This can be done more directly by calling `map_or(<a>, <f>)` instead
168+
error: called `map(<f>).unwrap_or(<a>)` on an `Option` value
169169
--> $DIR/map_unwrap_or.rs:106:13
170170
|
171171
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);
@@ -177,7 +177,7 @@ LL - let _ = opt.map(|x| x > 5).unwrap_or(false);
177177
LL + let _ = opt.map_or(false, |x| x > 5);
178178
|
179179

180-
error: called `map(<f>).unwrap_or(false)` on an `Option` value. This can be done more directly by calling `is_some_and(<f>)` instead
180+
error: called `map(<f>).unwrap_or(false)` on an `Option` value
181181
--> $DIR/map_unwrap_or.rs:113:13
182182
|
183183
LL | let _ = opt.map(|x| x > 5).unwrap_or(false);

tests/ui/map_unwrap_or_fixable.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value. This can be done more directly by calling `map_or_else(<g>, <f>)` instead
1+
error: called `map(<f>).unwrap_or_else(<g>)` on an `Option` value
22
--> $DIR/map_unwrap_or_fixable.rs:16:13
33
|
44
LL | let _ = opt.map(|x| x + 1)
@@ -10,7 +10,7 @@ LL | | .unwrap_or_else(|| 0);
1010
= note: `-D clippy::map-unwrap-or` implied by `-D warnings`
1111
= help: to override `-D warnings` add `#[allow(clippy::map_unwrap_or)]`
1212

13-
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value. This can be done more directly by calling `.map_or_else(<g>, <f>)` instead
13+
error: called `map(<f>).unwrap_or_else(<g>)` on a `Result` value
1414
--> $DIR/map_unwrap_or_fixable.rs:46:13
1515
|
1616
LL | let _ = res.map(|x| x + 1)

tests/ui/option_as_ref_deref.stderr

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
1+
error: called `.as_ref().map(Deref::deref)` on an `Option` value
22
--> $DIR/option_as_ref_deref.rs:11:13
33
|
44
LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
@@ -7,7 +7,7 @@ LL | let _ = opt.clone().as_ref().map(Deref::deref).map(str::len);
77
= note: `-D clippy::option-as-ref-deref` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::option_as_ref_deref)]`
99

10-
error: called `.as_ref().map(Deref::deref)` on an Option value. This can be done more directly by calling `opt.clone().as_deref()` instead
10+
error: called `.as_ref().map(Deref::deref)` on an `Option` value
1111
--> $DIR/option_as_ref_deref.rs:14:13
1212
|
1313
LL | let _ = opt.clone()
@@ -17,97 +17,97 @@ LL | | Deref::deref
1717
LL | | )
1818
| |_________^ help: try using as_deref instead: `opt.clone().as_deref()`
1919

20-
error: called `.as_mut().map(DerefMut::deref_mut)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
20+
error: called `.as_mut().map(DerefMut::deref_mut)` on an `Option` value
2121
--> $DIR/option_as_ref_deref.rs:20:13
2222
|
2323
LL | let _ = opt.as_mut().map(DerefMut::deref_mut);
2424
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
2525

26-
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
26+
error: called `.as_ref().map(String::as_str)` on an `Option` value
2727
--> $DIR/option_as_ref_deref.rs:22:13
2828
|
2929
LL | let _ = opt.as_ref().map(String::as_str);
3030
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
3131

32-
error: called `.as_ref().map(|x| x.as_str())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
32+
error: called `.as_ref().map(|x| x.as_str())` on an `Option` value
3333
--> $DIR/option_as_ref_deref.rs:23:13
3434
|
3535
LL | let _ = opt.as_ref().map(|x| x.as_str());
3636
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
3737

38-
error: called `.as_mut().map(String::as_mut_str)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
38+
error: called `.as_mut().map(String::as_mut_str)` on an `Option` value
3939
--> $DIR/option_as_ref_deref.rs:24:13
4040
|
4141
LL | let _ = opt.as_mut().map(String::as_mut_str);
4242
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
4343

44-
error: called `.as_mut().map(|x| x.as_mut_str())` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
44+
error: called `.as_mut().map(|x| x.as_mut_str())` on an `Option` value
4545
--> $DIR/option_as_ref_deref.rs:25:13
4646
|
4747
LL | let _ = opt.as_mut().map(|x| x.as_mut_str());
4848
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
4949

50-
error: called `.as_ref().map(CString::as_c_str)` on an Option value. This can be done more directly by calling `Some(CString::new(vec![]).unwrap()).as_deref()` instead
50+
error: called `.as_ref().map(CString::as_c_str)` on an `Option` value
5151
--> $DIR/option_as_ref_deref.rs:26:13
5252
|
5353
LL | let _ = Some(CString::new(vec![]).unwrap()).as_ref().map(CString::as_c_str);
5454
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(CString::new(vec![]).unwrap()).as_deref()`
5555

56-
error: called `.as_ref().map(OsString::as_os_str)` on an Option value. This can be done more directly by calling `Some(OsString::new()).as_deref()` instead
56+
error: called `.as_ref().map(OsString::as_os_str)` on an `Option` value
5757
--> $DIR/option_as_ref_deref.rs:27:13
5858
|
5959
LL | let _ = Some(OsString::new()).as_ref().map(OsString::as_os_str);
6060
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(OsString::new()).as_deref()`
6161

62-
error: called `.as_ref().map(PathBuf::as_path)` on an Option value. This can be done more directly by calling `Some(PathBuf::new()).as_deref()` instead
62+
error: called `.as_ref().map(PathBuf::as_path)` on an `Option` value
6363
--> $DIR/option_as_ref_deref.rs:28:13
6464
|
6565
LL | let _ = Some(PathBuf::new()).as_ref().map(PathBuf::as_path);
6666
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(PathBuf::new()).as_deref()`
6767

68-
error: called `.as_ref().map(Vec::as_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref()` instead
68+
error: called `.as_ref().map(Vec::as_slice)` on an `Option` value
6969
--> $DIR/option_as_ref_deref.rs:29:13
7070
|
7171
LL | let _ = Some(Vec::<()>::new()).as_ref().map(Vec::as_slice);
7272
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `Some(Vec::<()>::new()).as_deref()`
7373

74-
error: called `.as_mut().map(Vec::as_mut_slice)` on an Option value. This can be done more directly by calling `Some(Vec::<()>::new()).as_deref_mut()` instead
74+
error: called `.as_mut().map(Vec::as_mut_slice)` on an `Option` value
7575
--> $DIR/option_as_ref_deref.rs:30:13
7676
|
7777
LL | let _ = Some(Vec::<()>::new()).as_mut().map(Vec::as_mut_slice);
7878
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `Some(Vec::<()>::new()).as_deref_mut()`
7979

80-
error: called `.as_ref().map(|x| x.deref())` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
80+
error: called `.as_ref().map(|x| x.deref())` on an `Option` value
8181
--> $DIR/option_as_ref_deref.rs:32:13
8282
|
8383
LL | let _ = opt.as_ref().map(|x| x.deref());
8484
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
8585

86-
error: called `.as_mut().map(|x| x.deref_mut())` on an Option value. This can be done more directly by calling `opt.clone().as_deref_mut()` instead
86+
error: called `.as_mut().map(|x| x.deref_mut())` on an `Option` value
8787
--> $DIR/option_as_ref_deref.rs:33:13
8888
|
8989
LL | let _ = opt.clone().as_mut().map(|x| x.deref_mut()).map(|x| x.len());
9090
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.clone().as_deref_mut()`
9191

92-
error: called `.as_ref().map(|x| &**x)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
92+
error: called `.as_ref().map(|x| &**x)` on an `Option` value
9393
--> $DIR/option_as_ref_deref.rs:40:13
9494
|
9595
LL | let _ = opt.as_ref().map(|x| &**x);
9696
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
9797

98-
error: called `.as_mut().map(|x| &mut **x)` on an Option value. This can be done more directly by calling `opt.as_deref_mut()` instead
98+
error: called `.as_mut().map(|x| &mut **x)` on an `Option` value
9999
--> $DIR/option_as_ref_deref.rs:41:13
100100
|
101101
LL | let _ = opt.as_mut().map(|x| &mut **x);
102102
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref_mut instead: `opt.as_deref_mut()`
103103

104-
error: called `.as_ref().map(std::ops::Deref::deref)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
104+
error: called `.as_ref().map(std::ops::Deref::deref)` on an `Option` value
105105
--> $DIR/option_as_ref_deref.rs:44:13
106106
|
107107
LL | let _ = opt.as_ref().map(std::ops::Deref::deref);
108108
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using as_deref instead: `opt.as_deref()`
109109

110-
error: called `.as_ref().map(String::as_str)` on an Option value. This can be done more directly by calling `opt.as_deref()` instead
110+
error: called `.as_ref().map(String::as_str)` on an `Option` value
111111
--> $DIR/option_as_ref_deref.rs:56:13
112112
|
113113
LL | let _ = opt.as_ref().map(String::as_str);

tests/ui/option_map_or_none.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
1+
error: called `map_or(None, ..)` on an `Option` value
22
--> $DIR/option_map_or_none.rs:10:26
33
|
44
LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
@@ -7,7 +7,7 @@ LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
77
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
88
= help: to override `-D warnings` add `#[allow(clippy::option_map_or_none)]`
99

10-
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
10+
error: called `map_or(None, ..)` on an `Option` value
1111
--> $DIR/option_map_or_none.rs:13:26
1212
|
1313
LL | let _: Option<i32> = opt.map_or(None, |x| {
@@ -16,13 +16,13 @@ LL | | Some(x + 1)
1616
LL | | });
1717
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
1818

19-
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
19+
error: called `map_or(None, ..)` on an `Option` value
2020
--> $DIR/option_map_or_none.rs:17:26
2121
|
2222
LL | let _: Option<i32> = opt.map_or(None, bar);
2323
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
2424

25-
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
25+
error: called `map_or(None, ..)` on an `Option` value
2626
--> $DIR/option_map_or_none.rs:18:26
2727
|
2828
LL | let _: Option<i32> = opt.map_or(None, |x| {
@@ -42,7 +42,7 @@ LL + Some(offset + height)
4242
LL ~ });
4343
|
4444

45-
error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
45+
error: called `map_or(None, Some)` on a `Result` value
4646
--> $DIR/option_map_or_none.rs:25:26
4747
|
4848
LL | let _: Option<i32> = r.map_or(None, Some);

tests/ui/result_map_or_into_option.fixed

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
fn main() {
44
let opt: Result<u32, &str> = Ok(1);
55
let _ = opt.ok();
6-
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
6+
//~^ ERROR: called `map_or(None, Some)` on a `Result` value
77
let _ = opt.ok();
88
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
99
#[rustfmt::skip]

0 commit comments

Comments
 (0)