11use std:: ops:: Range ;
22
3- use rustc_errors:: E0232 ;
3+ use rustc_errors:: { Diagnostic , E0232 } ;
44use rustc_hir:: AttrPath ;
55use rustc_hir:: attrs:: diagnostic:: {
66 Directive , FilterFormatString , Flag , FormatArg , FormatString , LitOrArg , Name , NameValue ,
@@ -18,6 +18,10 @@ use rustc_span::{Ident, InnerSpan, Span, Symbol, kw, sym};
1818use thin_vec:: { ThinVec , thin_vec} ;
1919
2020use crate :: context:: { AcceptContext , Stage } ;
21+ use crate :: errors:: {
22+ DisallowedPlaceholder , DisallowedPositionalArgument , IgnoredDiagnosticOption ,
23+ InvalidFormatSpecifier , MalFormedDiagnosticAttributeLint , WrappedParserError ,
24+ } ;
2125use crate :: parser:: { ArgParser , MetaItemListParser , MetaItemOrLitParser , MetaItemParser } ;
2226
2327pub ( crate ) mod do_not_recommend;
@@ -112,12 +116,12 @@ fn merge<T, S: Stage>(
112116 match ( first, later) {
113117 ( Some ( _) | None , None ) => { }
114118 ( Some ( ( first_span, _) ) , Some ( ( later_span, _) ) ) => {
115- cx. emit_lint (
119+ let first_span = * first_span;
120+ cx. emit_dyn_lint (
116121 MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
117- AttributeLintKind :: IgnoredDiagnosticOption {
118- first_span : * first_span,
119- later_span,
120- option_name,
122+ move |dcx, level| {
123+ IgnoredDiagnosticOption { first_span, later_span, option_name }
124+ . into_diag ( dcx, level)
121125 } ,
122126 later_span,
123127 ) ;
@@ -157,12 +161,15 @@ fn parse_list<'p, S: Stage>(
157161 ) ;
158162 }
159163 ArgParser :: NameValue ( _) => {
160- cx. emit_lint (
164+ cx. emit_dyn_lint (
161165 MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
162- AttributeLintKind :: MalFormedDiagnosticAttribute {
163- attribute : mode. as_str ( ) ,
164- options : mode. allowed_options ( ) ,
165- span,
166+ move |dcx, level| {
167+ MalFormedDiagnosticAttributeLint {
168+ attribute : mode. as_str ( ) ,
169+ options : mode. allowed_options ( ) ,
170+ span,
171+ }
172+ . into_diag ( dcx, level)
166173 } ,
167174 span,
168175 ) ;
@@ -188,12 +195,15 @@ fn parse_directive_items<'p, S: Stage>(
188195 let span = item. span ( ) ;
189196
190197 macro malformed( ) { {
191- cx. emit_lint (
198+ cx. emit_dyn_lint (
192199 MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
193- AttributeLintKind :: MalFormedDiagnosticAttribute {
194- attribute : mode. as_str ( ) ,
195- options : mode. allowed_options ( ) ,
196- span,
200+ move |dcx, level| {
201+ MalFormedDiagnosticAttributeLint {
202+ attribute : mode. as_str ( ) ,
203+ options : mode. allowed_options ( ) ,
204+ span,
205+ }
206+ . into_diag ( dcx, level)
197207 } ,
198208 span,
199209 ) ;
@@ -210,13 +220,14 @@ fn parse_directive_items<'p, S: Stage>(
210220 } }
211221
212222 macro duplicate( $name: ident, $( $first_span: tt) * ) { {
213- cx. emit_lint (
223+ let first_span = $( $first_span) * ;
224+ cx. emit_dyn_lint (
214225 MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
215- AttributeLintKind :: IgnoredDiagnosticOption {
216- first_span : $ ( $first_span ) * ,
226+ move |dcx , level| IgnoredDiagnosticOption {
227+ first_span,
217228 later_span : span,
218229 option_name : $name,
219- } ,
230+ } . into_diag ( dcx , level ) ,
220231 span,
221232 ) ;
222233 } }
@@ -245,22 +256,35 @@ fn parse_directive_items<'p, S: Stage>(
245256 let ( FormatWarning :: InvalidSpecifier { span, .. }
246257 | FormatWarning :: PositionalArgument { span, .. }
247258 | FormatWarning :: DisallowedPlaceholder { span } ) = warning;
248- cx. emit_lint (
259+ cx. emit_dyn_lint (
249260 MALFORMED_DIAGNOSTIC_FORMAT_LITERALS ,
250- AttributeLintKind :: MalformedDiagnosticFormat { warning } ,
261+ move |dcx, level| match warning {
262+ FormatWarning :: PositionalArgument { .. } => {
263+ DisallowedPositionalArgument . into_diag ( dcx, level)
264+ }
265+ FormatWarning :: InvalidSpecifier { .. } => {
266+ InvalidFormatSpecifier . into_diag ( dcx, level)
267+ }
268+ FormatWarning :: DisallowedPlaceholder { .. } => {
269+ DisallowedPlaceholder . into_diag ( dcx, level)
270+ }
271+ } ,
251272 span,
252273 ) ;
253274 }
254275
255276 f
256277 }
257278 Err ( e) => {
258- cx. emit_lint (
279+ cx. emit_dyn_lint (
259280 MALFORMED_DIAGNOSTIC_FORMAT_LITERALS ,
260- AttributeLintKind :: DiagnosticWrappedParserError {
261- description : e. description ,
262- label : e. label ,
263- span : slice_span ( input. span , e. span , is_snippet) ,
281+ move |dcx, level| {
282+ WrappedParserError {
283+ description : & e. description ,
284+ label : & e. label ,
285+ span : slice_span ( input. span , e. span . clone ( ) , is_snippet) ,
286+ }
287+ . into_diag ( dcx, level)
264288 } ,
265289 input. span ,
266290 ) ;
0 commit comments