@@ -2,8 +2,8 @@ use std::fmt;
22use std:: ops:: Range ;
33
44use errors:: * ;
5- use rustc_middle:: ty:: TyCtxt ;
65use rustc_middle:: ty:: print:: TraitRefPrintSugared ;
6+ use rustc_middle:: ty:: { GenericParamDefKind , TyCtxt } ;
77use rustc_parse_format:: {
88 Alignment , Argument , Count , FormatSpec , ParseError , ParseMode , Parser , Piece as RpfPiece ,
99 Position ,
@@ -232,48 +232,16 @@ fn parse_arg<'tcx>(
232232) -> FormatArg {
233233 let ( Ctx :: RustcOnUnimplemented { tcx, trait_def_id }
234234 | Ctx :: DiagnosticOnUnimplemented { tcx, trait_def_id } ) = ctx;
235- let trait_name = tcx. item_ident ( * trait_def_id) ;
236- let generics = tcx. generics_of ( trait_def_id) ;
235+
237236 let span = slice_span ( input_span, arg. position_span . clone ( ) ) ;
238237
239238 match arg. position {
240239 // Something like "hello {name}"
241240 Position :: ArgumentNamed ( name) => match ( ctx, Symbol :: intern ( name) ) {
242- // accepted, but deprecated
243- ( Ctx :: RustcOnUnimplemented { .. } , sym:: _Self) => {
244- warnings
245- . push ( FormatWarning :: FutureIncompat { span, help : String :: from ( "use {Self}" ) } ) ;
246- FormatArg :: SelfUpper
247- }
248- (
249- Ctx :: RustcOnUnimplemented { .. } ,
250- sym:: from_desugaring
251- | sym:: crate_local
252- | sym:: direct
253- | sym:: cause
254- | sym:: float
255- | sym:: integer_
256- | sym:: integral,
257- ) => {
258- warnings. push ( FormatWarning :: FutureIncompat {
259- span,
260- help : String :: from ( "don't use this in a format string" ) ,
261- } ) ;
262- FormatArg :: AsIs ( String :: new ( ) )
263- }
264-
265241 // Only `#[rustc_on_unimplemented]` can use these
266242 ( Ctx :: RustcOnUnimplemented { .. } , sym:: ItemContext ) => FormatArg :: ItemContext ,
267243 ( Ctx :: RustcOnUnimplemented { .. } , sym:: This ) => FormatArg :: This ,
268244 ( Ctx :: RustcOnUnimplemented { .. } , sym:: Trait ) => FormatArg :: Trait ,
269- // `{ThisTraitsName}`. Some attrs in std use this, but I'd like to change it to the more general `{This}`
270- // because that'll be simpler to parse and extend in the future
271- ( Ctx :: RustcOnUnimplemented { .. } , name) if name == trait_name. name => {
272- warnings
273- . push ( FormatWarning :: FutureIncompat { span, help : String :: from ( "use {This}" ) } ) ;
274- FormatArg :: This
275- }
276-
277245 // Any attribute can use these
278246 (
279247 Ctx :: RustcOnUnimplemented { .. } | Ctx :: DiagnosticOnUnimplemented { .. } ,
@@ -282,7 +250,10 @@ fn parse_arg<'tcx>(
282250 (
283251 Ctx :: RustcOnUnimplemented { .. } | Ctx :: DiagnosticOnUnimplemented { .. } ,
284252 generic_param,
285- ) if generics. own_params . iter ( ) . any ( |param| param. name == generic_param) => {
253+ ) if tcx. generics_of ( trait_def_id) . own_params . iter ( ) . any ( |param| {
254+ !matches ! ( param. kind, GenericParamDefKind :: Lifetime ) && param. name == generic_param
255+ } ) =>
256+ {
286257 FormatArg :: GenericParam { generic_param }
287258 }
288259
@@ -375,39 +346,4 @@ pub mod errors {
375346 #[ diag( trait_selection_missing_options_for_on_unimplemented_attr) ]
376347 #[ help]
377348 pub struct MissingOptionsForOnUnimplementedAttr ;
378-
379- #[ derive( LintDiagnostic ) ]
380- #[ diag( trait_selection_ignored_diagnostic_option) ]
381- pub struct IgnoredDiagnosticOption {
382- pub option_name : & ' static str ,
383- #[ label]
384- pub span : Span ,
385- #[ label( trait_selection_other_label) ]
386- pub prev_span : Span ,
387- }
388-
389- impl IgnoredDiagnosticOption {
390- pub fn maybe_emit_warning < ' tcx > (
391- tcx : TyCtxt < ' tcx > ,
392- item_def_id : DefId ,
393- new : Option < Span > ,
394- old : Option < Span > ,
395- option_name : & ' static str ,
396- ) {
397- if let ( Some ( new_item) , Some ( old_item) ) = ( new, old) {
398- if let Some ( item_def_id) = item_def_id. as_local ( ) {
399- tcx. emit_node_span_lint (
400- UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
401- tcx. local_def_id_to_hir_id ( item_def_id) ,
402- new_item,
403- IgnoredDiagnosticOption {
404- span : new_item,
405- prev_span : old_item,
406- option_name,
407- } ,
408- ) ;
409- }
410- }
411- }
412- }
413349}
0 commit comments