1- use crate :: { LateContext , LateLintPass , LintContext } ;
2- use rustc_errors:: { Applicability , DiagnosticBuilder , MultiSpan } ;
1+ #![ deny( rustc:: untranslatable_diagnostic) ]
2+ #![ deny( rustc:: diagnostic_outside_of_impl) ]
3+ use crate :: {
4+ lints:: { NonBindingLet , NonBindingLetSub } ,
5+ LateContext , LateLintPass , LintContext ,
6+ } ;
7+ use rustc_errors:: MultiSpan ;
38use rustc_hir as hir;
49use rustc_middle:: ty;
510use rustc_span:: Symbol ;
@@ -119,6 +124,11 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
119124 _ => false ,
120125 } ;
121126
127+ let sub = NonBindingLetSub {
128+ suggestion : local. pat . span ,
129+ multi_suggestion_start : local. span . until ( init. span ) ,
130+ multi_suggestion_end : init. span . shrink_to_hi ( ) ,
131+ } ;
122132 if is_sync_lock {
123133 let mut span = MultiSpan :: from_spans ( vec ! [ local. pat. span, init. span] ) ;
124134 span. push_span_label (
@@ -129,41 +139,14 @@ impl<'tcx> LateLintPass<'tcx> for LetUnderscore {
129139 init. span ,
130140 "this binding will immediately drop the value assigned to it" . to_string ( ) ,
131141 ) ;
132- cx. struct_span_lint (
133- LET_UNDERSCORE_LOCK ,
134- span,
135- "non-binding let on a synchronization lock" ,
136- |lint| build_lint ( lint, local, init. span ) ,
137- )
142+ cx. emit_spanned_lint ( LET_UNDERSCORE_LOCK , span, NonBindingLet :: SyncLock { sub } ) ;
138143 } else {
139- cx. struct_span_lint (
144+ cx. emit_spanned_lint (
140145 LET_UNDERSCORE_DROP ,
141146 local. span ,
142- "non-binding let on a type that implements `Drop`" ,
143- |lint| build_lint ( lint, local, init. span ) ,
144- )
147+ NonBindingLet :: DropType { sub } ,
148+ ) ;
145149 }
146150 }
147151 }
148152}
149-
150- fn build_lint < ' a , ' b > (
151- lint : & ' a mut DiagnosticBuilder < ' b , ( ) > ,
152- local : & hir:: Local < ' _ > ,
153- init_span : rustc_span:: Span ,
154- ) -> & ' a mut DiagnosticBuilder < ' b , ( ) > {
155- lint. span_suggestion_verbose (
156- local. pat . span ,
157- "consider binding to an unused variable to avoid immediately dropping the value" ,
158- "_unused" ,
159- Applicability :: MachineApplicable ,
160- )
161- . multipart_suggestion (
162- "consider immediately dropping the value" ,
163- vec ! [
164- ( local. span. until( init_span) , "drop(" . to_string( ) ) ,
165- ( init_span. shrink_to_hi( ) , ")" . to_string( ) ) ,
166- ] ,
167- Applicability :: MachineApplicable ,
168- )
169- }
0 commit comments