11use rustc_errors:: codes:: * ;
2- use rustc_errors:: { Applicability , Diag , EmissionGuarantee , LintDiagnostic , Subdiagnostic , msg} ;
3- use rustc_macros:: { Diagnostic , LintDiagnostic , Subdiagnostic } ;
2+ use rustc_errors:: {
3+ Applicability , Diag , DiagCtxtHandle , Diagnostic , EmissionGuarantee , Level , Subdiagnostic , msg,
4+ } ;
5+ use rustc_macros:: { Diagnostic , Subdiagnostic } ;
46use rustc_middle:: mir:: AssertKind ;
57use rustc_middle:: query:: Key ;
68use rustc_middle:: ty:: TyCtxt ;
@@ -48,7 +50,7 @@ pub(crate) fn emit_inline_always_target_feature_diagnostic<'a, 'tcx>(
4850 ) ;
4951}
5052
51- #[ derive( LintDiagnostic ) ]
53+ #[ derive( Diagnostic ) ]
5254#[ diag( "function cannot return without recursing" ) ]
5355#[ help( "a `loop` may express intention better if this is on purpose" ) ]
5456pub ( crate ) struct UnconditionalRecursion {
@@ -70,7 +72,7 @@ pub(crate) struct InvalidForceInline {
7072 pub reason : & ' static str ,
7173}
7274
73- #[ derive( LintDiagnostic ) ]
75+ #[ derive( Diagnostic ) ]
7476pub ( crate ) enum ConstMutate {
7577 #[ diag( "attempting to modify a `const` item" ) ]
7678 #[ note(
@@ -129,21 +131,26 @@ pub(crate) enum AssertLintKind {
129131 UnconditionalPanic ,
130132}
131133
132- impl < ' a , P : std:: fmt:: Debug > LintDiagnostic < ' a , ( ) > for AssertLint < P > {
133- fn decorate_lint < ' b > ( self , diag : & ' b mut Diag < ' a , ( ) > ) {
134- diag. primary_message ( match self . lint_kind {
135- AssertLintKind :: ArithmeticOverflow => {
136- msg ! ( "this arithmetic operation will overflow" )
137- }
138- AssertLintKind :: UnconditionalPanic => {
139- msg ! ( "this operation will panic at runtime" )
140- }
141- } ) ;
134+ impl < ' a , P : std:: fmt:: Debug > Diagnostic < ' a , ( ) > for AssertLint < P > {
135+ fn into_diag ( self , dcx : DiagCtxtHandle < ' a > , level : Level ) -> Diag < ' a , ( ) > {
136+ let mut diag = Diag :: new (
137+ dcx,
138+ level,
139+ match self . lint_kind {
140+ AssertLintKind :: ArithmeticOverflow => {
141+ msg ! ( "this arithmetic operation will overflow" )
142+ }
143+ AssertLintKind :: UnconditionalPanic => {
144+ msg ! ( "this operation will panic at runtime" )
145+ }
146+ } ,
147+ ) ;
142148 let label = self . assert_kind . diagnostic_message ( ) ;
143149 self . assert_kind . add_args ( & mut |name, value| {
144150 diag. arg ( name, value) ;
145151 } ) ;
146152 diag. span_label ( self . span , label) ;
153+ diag
147154 }
148155}
149156
@@ -156,14 +163,14 @@ impl AssertLintKind {
156163 }
157164}
158165
159- #[ derive( LintDiagnostic ) ]
166+ #[ derive( Diagnostic ) ]
160167#[ diag( "call to inline assembly that may unwind" ) ]
161168pub ( crate ) struct AsmUnwindCall {
162169 #[ label( "call to inline assembly that may unwind" ) ]
163170 pub span : Span ,
164171}
165172
166- #[ derive( LintDiagnostic ) ]
173+ #[ derive( Diagnostic ) ]
167174#[ diag(
168175 "call to {$foreign ->
169176 [true] foreign function
@@ -181,7 +188,7 @@ pub(crate) struct FfiUnwindCall {
181188 pub foreign : bool ,
182189}
183190
184- #[ derive( LintDiagnostic ) ]
191+ #[ derive( Diagnostic ) ]
185192#[ diag( "taking a reference to a function item does not give a function pointer" ) ]
186193pub ( crate ) struct FnItemRef {
187194 #[ suggestion(
@@ -194,14 +201,14 @@ pub(crate) struct FnItemRef {
194201 pub ident : Ident ,
195202}
196203
197- #[ derive( LintDiagnostic ) ]
204+ #[ derive( Diagnostic ) ]
198205#[ diag( "value captured by `{$name}` is never read" ) ]
199206#[ help( "did you mean to capture by reference instead?" ) ]
200207pub ( crate ) struct UnusedCaptureMaybeCaptureRef {
201208 pub name : Symbol ,
202209}
203210
204- #[ derive( LintDiagnostic ) ]
211+ #[ derive( Diagnostic ) ]
205212#[ diag( "variable `{$name}` is assigned to, but never used" ) ]
206213#[ note( "consider using `_{$name}` instead" ) ]
207214pub ( crate ) struct UnusedVarAssignedOnly {
@@ -210,7 +217,7 @@ pub(crate) struct UnusedVarAssignedOnly {
210217 pub typo : Option < PatternTypo > ,
211218}
212219
213- #[ derive( LintDiagnostic ) ]
220+ #[ derive( Diagnostic ) ]
214221#[ diag( "value assigned to `{$name}` is never read" ) ]
215222pub ( crate ) struct UnusedAssign {
216223 pub name : Symbol ,
@@ -237,14 +244,14 @@ pub(crate) struct UnusedAssignSuggestion {
237244 pub rhs_borrow_span : Span ,
238245}
239246
240- #[ derive( LintDiagnostic ) ]
247+ #[ derive( Diagnostic ) ]
241248#[ diag( "value passed to `{$name}` is never read" ) ]
242249#[ help( "maybe it is overwritten before being read?" ) ]
243250pub ( crate ) struct UnusedAssignPassed {
244251 pub name : Symbol ,
245252}
246253
247- #[ derive( LintDiagnostic ) ]
254+ #[ derive( Diagnostic ) ]
248255#[ diag( "unused variable: `{$name}`" ) ]
249256pub ( crate ) struct UnusedVariable {
250257 pub name : Symbol ,
@@ -331,11 +338,13 @@ pub(crate) struct MustNotSupend<'a, 'tcx> {
331338}
332339
333340// Needed for def_path_str
334- impl < ' a > LintDiagnostic < ' a , ( ) > for MustNotSupend < ' _ , ' _ > {
335- fn decorate_lint < ' b > ( self , diag : & ' b mut rustc_errors:: Diag < ' a , ( ) > ) {
336- diag. primary_message ( msg ! (
337- "{$pre}`{$def_path}`{$post} held across a suspend point, but should not be"
338- ) ) ;
341+ impl < ' a > Diagnostic < ' a , ( ) > for MustNotSupend < ' _ , ' _ > {
342+ fn into_diag ( self , dcx : DiagCtxtHandle < ' a > , level : Level ) -> Diag < ' a , ( ) > {
343+ let mut diag = Diag :: new (
344+ dcx,
345+ level,
346+ msg ! ( "{$pre}`{$def_path}`{$post} held across a suspend point, but should not be" ) ,
347+ ) ;
339348 diag. span_label ( self . yield_sp , msg ! ( "the value is held across this suspend point" ) ) ;
340349 if let Some ( reason) = self . reason {
341350 diag. subdiagnostic ( reason) ;
@@ -344,6 +353,7 @@ impl<'a> LintDiagnostic<'a, ()> for MustNotSupend<'_, '_> {
344353 diag. arg ( "pre" , self . pre ) ;
345354 diag. arg ( "def_path" , self . tcx . def_path_str ( self . def_id ) ) ;
346355 diag. arg ( "post" , self . post ) ;
356+ diag
347357 }
348358}
349359
0 commit comments