mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-24 05:33:27 +00:00
Changed fn body suggestion msg
This commit is contained in:
parent
6165cccf7e
commit
a78271b861
3 changed files with 31 additions and 15 deletions
|
@ -131,11 +131,12 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
|
||||||
});
|
});
|
||||||
|
|
||||||
if can_sugg && !suggs.is_empty() {
|
if can_sugg && !suggs.is_empty() {
|
||||||
let (lint_msg, return_type_suggestion_msg, return_type_suggestion) = if inner_type.is_unit() {
|
let (lint_msg, return_type_sugg_msg, return_type_sugg, body_sugg_msg) = if inner_type.is_unit() {
|
||||||
(
|
(
|
||||||
"this function's return value is unnecessary".to_string(),
|
"this function's return value is unnecessary".to_string(),
|
||||||
"remove the return type...".to_string(),
|
"remove the return type...".to_string(),
|
||||||
snippet(cx, fn_decl.output.span(), "..").to_string(),
|
snippet(cx, fn_decl.output.span(), "..").to_string(),
|
||||||
|
"...and then remove returned values",
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
(
|
(
|
||||||
|
@ -145,21 +146,18 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
|
||||||
),
|
),
|
||||||
format!("remove `{}` from the return type...", return_type_label),
|
format!("remove `{}` from the return type...", return_type_label),
|
||||||
inner_type.to_string(),
|
inner_type.to_string(),
|
||||||
|
"...and then change returning expressions",
|
||||||
)
|
)
|
||||||
};
|
};
|
||||||
|
|
||||||
span_lint_and_then(cx, UNNECESSARY_WRAPS, span, lint_msg.as_str(), |diag| {
|
span_lint_and_then(cx, UNNECESSARY_WRAPS, span, lint_msg.as_str(), |diag| {
|
||||||
diag.span_suggestion(
|
diag.span_suggestion(
|
||||||
fn_decl.output.span(),
|
fn_decl.output.span(),
|
||||||
return_type_suggestion_msg.as_str(),
|
return_type_sugg_msg.as_str(),
|
||||||
return_type_suggestion,
|
return_type_sugg,
|
||||||
Applicability::MaybeIncorrect,
|
|
||||||
);
|
|
||||||
diag.multipart_suggestion(
|
|
||||||
"...and then change the returning expressions",
|
|
||||||
suggs,
|
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
|
diag.multipart_suggestion(body_sugg_msg, suggs, Applicability::MaybeIncorrect);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,6 +141,24 @@ fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should not be linted
|
||||||
|
fn issue_6640_3() -> Option<()> {
|
||||||
|
if true {
|
||||||
|
Some(())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// should not be linted
|
||||||
|
fn issue_6640_4() -> Result<(), ()> {
|
||||||
|
if true {
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// method calls are not linted
|
// method calls are not linted
|
||||||
func1(true, true);
|
func1(true, true);
|
||||||
|
|
|
@ -15,7 +15,7 @@ help: remove `Option` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func1(a: bool, b: bool) -> i32 {
|
LL | fn func1(a: bool, b: bool) -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then change returning expressions
|
||||||
|
|
|
|
||||||
LL | return 42;
|
LL | return 42;
|
||||||
LL | }
|
LL | }
|
||||||
|
@ -41,7 +41,7 @@ help: remove `Option` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func2(a: bool, b: bool) -> i32 {
|
LL | fn func2(a: bool, b: bool) -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then change returning expressions
|
||||||
|
|
|
|
||||||
LL | return 10;
|
LL | return 10;
|
||||||
LL | }
|
LL | }
|
||||||
|
@ -63,7 +63,7 @@ help: remove `Option` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func5() -> i32 {
|
LL | fn func5() -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then change returning expressions
|
||||||
|
|
|
|
||||||
LL | 1
|
LL | 1
|
||||||
|
|
|
|
||||||
|
@ -80,7 +80,7 @@ help: remove `Result` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func7() -> i32 {
|
LL | fn func7() -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then change returning expressions
|
||||||
|
|
|
|
||||||
LL | 1
|
LL | 1
|
||||||
|
|
|
|
||||||
|
@ -97,7 +97,7 @@ help: remove `Option` from the return type...
|
||||||
|
|
|
|
||||||
LL | fn func12() -> i32 {
|
LL | fn func12() -> i32 {
|
||||||
| ^^^
|
| ^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then change returning expressions
|
||||||
|
|
|
|
||||||
LL | 1
|
LL | 1
|
||||||
|
|
|
|
||||||
|
@ -118,7 +118,7 @@ help: remove the return type...
|
||||||
|
|
|
|
||||||
LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> {
|
LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> {
|
||||||
| ^^^^^^^^^^
|
| ^^^^^^^^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then remove returned values
|
||||||
|
|
|
|
||||||
LL | return ;
|
LL | return ;
|
||||||
LL | }
|
LL | }
|
||||||
|
@ -144,7 +144,7 @@ help: remove the return type...
|
||||||
|
|
|
|
||||||
LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
|
||||||
| ^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^
|
||||||
help: ...and then change the returning expressions
|
help: ...and then remove returned values
|
||||||
|
|
|
|
||||||
LL | return ;
|
LL | return ;
|
||||||
LL | }
|
LL | }
|
||||||
|
|
Loading…
Reference in a new issue