Skip to content

Commit

Permalink
Merge spans for the suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-tkach committed May 22, 2020
1 parent 34b5118 commit a9199de
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
17 changes: 11 additions & 6 deletions src/librustc_typeck/check/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ pub fn check_legal_trait_for_method_call(
.and_then(|s| tcx.sess.source_map().span_to_snippet(s).ok())
.unwrap_or_default();

let (suggestion, applicability) = if snippet.is_empty() {
(snippet, Applicability::Unspecified)
} else {
(format!("drop({})", snippet), Applicability::MachineApplicable)
};
let suggestion =
if snippet.is_empty() { "drop".to_string() } else { format!("drop({})", snippet) };

let suggestion_span =
receiver.and_then(|s| tcx.sess.source_map().merge_spans(s, span)).unwrap_or(span);

err.span_suggestion(span, "consider using `drop` function", suggestion, applicability);
err.span_suggestion(
suggestion_span,
"consider using `drop` function",
suggestion,
Applicability::MaybeIncorrect,
);

err.emit();
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/error-codes/E0040.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0040]: explicit use of destructor method
--> $DIR/E0040.rs:13:7
|
LL | x.drop();
| ^^^^
| |
| explicit destructor calls not allowed
| help: consider using `drop` function: `drop(x)`
| --^^^^
| | |
| | explicit destructor calls not allowed
| help: consider using `drop` function: `drop(x)`

error: aborting due to previous error

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/explicit/explicit-call-to-dtor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0040]: explicit use of destructor method
--> $DIR/explicit-call-to-dtor.rs:13:7
|
LL | x.drop();
| ^^^^
| |
| explicit destructor calls not allowed
| help: consider using `drop` function: `drop(x)`
| --^^^^
| | |
| | explicit destructor calls not allowed
| help: consider using `drop` function: `drop(x)`

error: aborting due to previous error

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/explicit/explicit-call-to-supertrait-dtor.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ error[E0040]: explicit use of destructor method
--> $DIR/explicit-call-to-supertrait-dtor.rs:17:14
|
LL | self.drop();
| ^^^^
| |
| explicit destructor calls not allowed
| help: consider using `drop` function: `drop(self)`
| -----^^^^
| | |
| | explicit destructor calls not allowed
| help: consider using `drop` function: `drop(self)`

error: aborting due to previous error

Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/illegal-ufcs-drop.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | Drop::drop(&mut Foo)
| ^^^^^^^^^^
| |
| explicit destructor calls not allowed
| help: consider using `drop` function
| help: consider using `drop` function: `drop`

error: aborting due to previous error

Expand Down

0 comments on commit a9199de

Please sign in to comment.