Skip to content

Commit a78271b

Browse files
committed
Changed fn body suggestion msg
1 parent 6165ccc commit a78271b

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

clippy_lints/src/unnecessary_wraps.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
131131
});
132132

133133
if can_sugg && !suggs.is_empty() {
134-
let (lint_msg, return_type_suggestion_msg, return_type_suggestion) = if inner_type.is_unit() {
134+
let (lint_msg, return_type_sugg_msg, return_type_sugg, body_sugg_msg) = if inner_type.is_unit() {
135135
(
136136
"this function's return value is unnecessary".to_string(),
137137
"remove the return type...".to_string(),
138138
snippet(cx, fn_decl.output.span(), "..").to_string(),
139+
"...and then remove returned values",
139140
)
140141
} else {
141142
(
@@ -145,21 +146,18 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
145146
),
146147
format!("remove `{}` from the return type...", return_type_label),
147148
inner_type.to_string(),
149+
"...and then change returning expressions",
148150
)
149151
};
150152

151153
span_lint_and_then(cx, UNNECESSARY_WRAPS, span, lint_msg.as_str(), |diag| {
152154
diag.span_suggestion(
153155
fn_decl.output.span(),
154-
return_type_suggestion_msg.as_str(),
155-
return_type_suggestion,
156-
Applicability::MaybeIncorrect,
157-
);
158-
diag.multipart_suggestion(
159-
"...and then change the returning expressions",
160-
suggs,
156+
return_type_sugg_msg.as_str(),
157+
return_type_sugg,
161158
Applicability::MaybeIncorrect,
162159
);
160+
diag.multipart_suggestion(body_sugg_msg, suggs, Applicability::MaybeIncorrect);
163161
});
164162
}
165163
}

tests/ui/unnecessary_wraps.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
141141
}
142142
}
143143

144+
// should not be linted
145+
fn issue_6640_3() -> Option<()> {
146+
if true {
147+
Some(())
148+
} else {
149+
None
150+
}
151+
}
152+
153+
// should not be linted
154+
fn issue_6640_4() -> Result<(), ()> {
155+
if true {
156+
Ok(())
157+
} else {
158+
Err(())
159+
}
160+
}
161+
144162
fn main() {
145163
// method calls are not linted
146164
func1(true, true);

tests/ui/unnecessary_wraps.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ help: remove `Option` from the return type...
1515
|
1616
LL | fn func1(a: bool, b: bool) -> i32 {
1717
| ^^^
18-
help: ...and then change the returning expressions
18+
help: ...and then change returning expressions
1919
|
2020
LL | return 42;
2121
LL | }
@@ -41,7 +41,7 @@ help: remove `Option` from the return type...
4141
|
4242
LL | fn func2(a: bool, b: bool) -> i32 {
4343
| ^^^
44-
help: ...and then change the returning expressions
44+
help: ...and then change returning expressions
4545
|
4646
LL | return 10;
4747
LL | }
@@ -63,7 +63,7 @@ help: remove `Option` from the return type...
6363
|
6464
LL | fn func5() -> i32 {
6565
| ^^^
66-
help: ...and then change the returning expressions
66+
help: ...and then change returning expressions
6767
|
6868
LL | 1
6969
|
@@ -80,7 +80,7 @@ help: remove `Result` from the return type...
8080
|
8181
LL | fn func7() -> i32 {
8282
| ^^^
83-
help: ...and then change the returning expressions
83+
help: ...and then change returning expressions
8484
|
8585
LL | 1
8686
|
@@ -97,7 +97,7 @@ help: remove `Option` from the return type...
9797
|
9898
LL | fn func12() -> i32 {
9999
| ^^^
100-
help: ...and then change the returning expressions
100+
help: ...and then change returning expressions
101101
|
102102
LL | 1
103103
|
@@ -118,7 +118,7 @@ help: remove the return type...
118118
|
119119
LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> {
120120
| ^^^^^^^^^^
121-
help: ...and then change the returning expressions
121+
help: ...and then remove returned values
122122
|
123123
LL | return ;
124124
LL | }
@@ -144,7 +144,7 @@ help: remove the return type...
144144
|
145145
LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
146146
| ^^^^^^^^^^^^^^^
147-
help: ...and then change the returning expressions
147+
help: ...and then remove returned values
148148
|
149149
LL | return ;
150150
LL | }

0 commit comments

Comments
 (0)