Skip to content

Commit 5ef38a3

Browse files
committed
Do not underline suggestions for code that is already there
When a suggestion part is for already present code, do not highlight it. If after that there are no highlights left, do not show the suggestion at all. Fix clippy lint suggestion incorrectly treated as `span_help`.
1 parent 5faea65 commit 5ef38a3

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

clippy_lints/src/unnecessary_wraps.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryWraps {
145145
(
146146
"this function's return value is unnecessary".to_string(),
147147
"remove the return type...".to_string(),
148-
snippet(cx, fn_decl.output.span(), "..").to_string(),
148+
// FIXME: we should instead get the span including the `->` and suggest an
149+
// empty string for this case.
150+
"()".to_string(),
149151
"...and then remove returned values",
150152
)
151153
} else {

tests/ui/unnecessary_literal_unwrap.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ LL | let _val = None::<()>.expect("this always happens");
6363
help: remove the `None` and `expect()`
6464
|
6565
LL | let _val = panic!("this always happens");
66-
| ~~~~~~~ ~
66+
| ~~~~~~~
6767

6868
error: used `unwrap_or_default()` on `None` value
6969
--> tests/ui/unnecessary_literal_unwrap.rs:22:24
@@ -134,7 +134,7 @@ LL | None::<()>.expect("this always happens");
134134
help: remove the `None` and `expect()`
135135
|
136136
LL | panic!("this always happens");
137-
| ~~~~~~~ ~
137+
| ~~~~~~~
138138

139139
error: used `unwrap_or_default()` on `None` value
140140
--> tests/ui/unnecessary_literal_unwrap.rs:30:5

tests/ui/unnecessary_wraps.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ LL | | }
118118
|
119119
help: remove the return type...
120120
|
121-
LL | fn issue_6640_1(a: bool, b: bool) -> Option<()> {
122-
| ~~~~~~~~~~
121+
LL | fn issue_6640_1(a: bool, b: bool) -> () {
122+
| ~~
123123
help: ...and then remove returned values
124124
|
125125
LL ~ return ;
@@ -145,8 +145,8 @@ LL | | }
145145
|
146146
help: remove the return type...
147147
|
148-
LL | fn issue_6640_2(a: bool, b: bool) -> Result<(), i32> {
149-
| ~~~~~~~~~~~~~~~
148+
LL | fn issue_6640_2(a: bool, b: bool) -> () {
149+
| ~~
150150
help: ...and then remove returned values
151151
|
152152
LL ~ return ;

0 commit comments

Comments
 (0)