From cdf66060666fa53cbca9647ac7434bdfd2cc37a5 Mon Sep 17 00:00:00 2001 From: Aaron Kofsky Date: Thu, 9 Jun 2022 14:03:35 -0400 Subject: Use `multipart_suggestion` to create an applicable suggestion. The "consider explicitly droping" can now suggest a machine applicable suggestion now. --- compiler/rustc_lint/src/let_underscore.rs | 10 ++++++---- src/test/ui/lint/let_underscore/let_underscore_drop.stderr | 4 ++-- src/test/ui/lint/let_underscore/let_underscore_lock.stderr | 4 ++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_lint/src/let_underscore.rs b/compiler/rustc_lint/src/let_underscore.rs index 520c865cc19..18661e8c505 100644 --- a/compiler/rustc_lint/src/let_underscore.rs +++ b/compiler/rustc_lint/src/let_underscore.rs @@ -154,11 +154,13 @@ fn build_and_emit_lint( "_unused", Applicability::MachineApplicable, ) - .span_suggestion_verbose( - init_span, + .multipart_suggestion( "consider explicitly droping with `std::mem::drop`", - "drop(...)", - Applicability::HasPlaceholders, + vec![ + (init_span.shrink_to_lo(), "drop(".to_string()), + (init_span.shrink_to_hi(), ")".to_string()), + ], + Applicability::MachineApplicable, ) .emit(); } diff --git a/src/test/ui/lint/let_underscore/let_underscore_drop.stderr b/src/test/ui/lint/let_underscore/let_underscore_drop.stderr index 5034f682bb7..dfac6d3f741 100644 --- a/src/test/ui/lint/let_underscore/let_underscore_drop.stderr +++ b/src/test/ui/lint/let_underscore/let_underscore_drop.stderr @@ -11,8 +11,8 @@ LL | let _unused = NontrivialDrop; | ~~~~~~~ help: consider explicitly droping with `std::mem::drop` | -LL | let _ = drop(...); - | ~~~~~~~~~ +LL | let _ = drop(NontrivialDrop); + | +++++ + warning: 1 warning emitted diff --git a/src/test/ui/lint/let_underscore/let_underscore_lock.stderr b/src/test/ui/lint/let_underscore/let_underscore_lock.stderr index 7ff42cb1524..f37483ddd96 100644 --- a/src/test/ui/lint/let_underscore/let_underscore_lock.stderr +++ b/src/test/ui/lint/let_underscore/let_underscore_lock.stderr @@ -11,8 +11,8 @@ LL | let _unused = data.lock().unwrap(); | ~~~~~~~ help: consider explicitly droping with `std::mem::drop` | -LL | let _ = drop(...); - | ~~~~~~~~~ +LL | let _ = drop(data.lock().unwrap()); + | +++++ + error: aborting due to previous error -- cgit 1.4.1-3-g733a5