diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 4c31363f2c0..a32174a8333 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -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(); } diff --git a/src/test/ui/error-codes/E0040.stderr b/src/test/ui/error-codes/E0040.stderr index 69cf28b2970..3b864d4ea4b 100644 --- a/src/test/ui/error-codes/E0040.stderr +++ b/src/test/ui/error-codes/E0040.stderr @@ -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 diff --git a/src/test/ui/explicit/explicit-call-to-dtor.stderr b/src/test/ui/explicit/explicit-call-to-dtor.stderr index 5ebe4ee4b90..33ce235b30f 100644 --- a/src/test/ui/explicit/explicit-call-to-dtor.stderr +++ b/src/test/ui/explicit/explicit-call-to-dtor.stderr @@ -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 diff --git a/src/test/ui/explicit/explicit-call-to-supertrait-dtor.stderr b/src/test/ui/explicit/explicit-call-to-supertrait-dtor.stderr index cd3fb3119a5..2e7bfac71cd 100644 --- a/src/test/ui/explicit/explicit-call-to-supertrait-dtor.stderr +++ b/src/test/ui/explicit/explicit-call-to-supertrait-dtor.stderr @@ -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 diff --git a/src/test/ui/illegal-ufcs-drop.stderr b/src/test/ui/illegal-ufcs-drop.stderr index 922d50d2595..57c99739afd 100644 --- a/src/test/ui/illegal-ufcs-drop.stderr +++ b/src/test/ui/illegal-ufcs-drop.stderr @@ -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