Merge spans for the suggestion

This commit is contained in:
Stanislav Tkach 2020-05-23 00:16:17 +03:00
parent 34b51187ce
commit a9199de34d
5 changed files with 24 additions and 19 deletions

View File

@ -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) };
err.span_suggestion(span, "consider using `drop` function", suggestion, applicability);
let suggestion_span =
receiver.and_then(|s| tcx.sess.source_map().merge_spans(s, span)).unwrap_or(span);
err.span_suggestion(
suggestion_span,
"consider using `drop` function",
suggestion,
Applicability::MaybeIncorrect,
);
err.emit();
}

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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