@@ -6,6 +6,7 @@ use rustc_errors::codes::*;
66use rustc_errors:: { ErrorGuaranteed , struct_span_code_err} ;
77use rustc_hir:: def_id:: { DefId , LocalDefId } ;
88use rustc_hir:: { AttrArgs , Attribute } ;
9+ use rustc_macros:: LintDiagnostic ;
910use rustc_middle:: bug;
1011use rustc_middle:: ty:: print:: PrintTraitRefExt ;
1112use rustc_middle:: ty:: { self , GenericArgsRef , GenericParamDef , GenericParamDefKind , TyCtxt } ;
@@ -17,7 +18,6 @@ use {rustc_attr_parsing as attr, rustc_hir as hir};
1718use super :: { ObligationCauseCode , PredicateObligation } ;
1819use crate :: error_reporting:: TypeErrCtxt ;
1920use crate :: error_reporting:: traits:: on_unimplemented_condition:: { Condition , ConditionOptions } ;
20- use crate :: error_reporting:: traits:: on_unimplemented_format:: errors:: * ;
2121use crate :: error_reporting:: traits:: on_unimplemented_format:: { Ctx , FormatArgs , FormatString } ;
2222use crate :: errors:: {
2323 EmptyOnClauseInOnUnimplemented , InvalidOnClauseInOnUnimplemented , NoValueInOnUnimplemented ,
@@ -112,10 +112,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
112112 // FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
113113 // but I guess we could synthesize one here. We don't see any errors that rely on
114114 // that yet, though.
115- let item_context = self
116- . describe_enclosure ( obligation. cause . body_id )
117- . map ( |t| t. to_owned ( ) )
118- . unwrap_or ( String :: new ( ) ) ;
115+ let item_context = self . describe_enclosure ( obligation. cause . body_id ) . unwrap_or ( "" ) ;
119116
120117 let direct = match obligation. cause . code ( ) {
121118 ObligationCauseCode :: BuiltinDerived ( ..)
@@ -128,7 +125,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
128125 }
129126 } ;
130127
131- let from_desugaring = obligation. cause . span . desugaring_kind ( ) . map ( |k| format ! ( "{k:?}" ) ) ;
128+ let from_desugaring = obligation. cause . span . desugaring_kind ( ) ;
132129
133130 let cause = if let ObligationCauseCode :: MainFunctionType = obligation. cause . code ( ) {
134131 Some ( "MainFunctionType" . to_string ( ) )
@@ -253,8 +250,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
253250 }
254251 } ) ) ;
255252
256- let this = self . tcx . def_path_str ( trait_pred. trait_ref . def_id ) . to_string ( ) ;
257- let trait_sugared = trait_pred. trait_ref . print_trait_sugared ( ) . to_string ( ) ;
253+ let this = self . tcx . def_path_str ( trait_pred. trait_ref . def_id ) ;
254+ let trait_sugared = trait_pred. trait_ref . print_trait_sugared ( ) ;
258255
259256 let condition_options = ConditionOptions {
260257 self_types,
@@ -268,6 +265,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
268265 // Unlike the generic_args earlier,
269266 // this one is *not* collected under `with_no_trimmed_paths!`
270267 // for printing the type to the user
268+ //
269+ // This includes `Self`, as it is the first parameter in `own_params`.
271270 let generic_args = self
272271 . tcx
273272 . generics_of ( trait_pred. trait_ref . def_id )
@@ -341,6 +340,63 @@ pub enum AppendConstMessage {
341340 Custom ( Symbol , Span ) ,
342341}
343342
343+ #[ derive( LintDiagnostic ) ]
344+ #[ diag( trait_selection_malformed_on_unimplemented_attr) ]
345+ #[ help]
346+ pub struct MalformedOnUnimplementedAttrLint {
347+ #[ label]
348+ pub span : Span ,
349+ }
350+
351+ impl MalformedOnUnimplementedAttrLint {
352+ pub fn new ( span : Span ) -> Self {
353+ Self { span }
354+ }
355+ }
356+
357+ #[ derive( LintDiagnostic ) ]
358+ #[ diag( trait_selection_missing_options_for_on_unimplemented_attr) ]
359+ #[ help]
360+ pub struct MissingOptionsForOnUnimplementedAttr ;
361+
362+ #[ derive( LintDiagnostic ) ]
363+ #[ diag( trait_selection_ignored_diagnostic_option) ]
364+ pub struct IgnoredDiagnosticOption {
365+ pub option_name : & ' static str ,
366+ #[ label]
367+ pub span : Span ,
368+ #[ label( trait_selection_other_label) ]
369+ pub prev_span : Span ,
370+ }
371+
372+ impl IgnoredDiagnosticOption {
373+ pub fn maybe_emit_warning < ' tcx > (
374+ tcx : TyCtxt < ' tcx > ,
375+ item_def_id : DefId ,
376+ new : Option < Span > ,
377+ old : Option < Span > ,
378+ option_name : & ' static str ,
379+ ) {
380+ if let ( Some ( new_item) , Some ( old_item) ) = ( new, old) {
381+ if let Some ( item_def_id) = item_def_id. as_local ( ) {
382+ tcx. emit_node_span_lint (
383+ UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES ,
384+ tcx. local_def_id_to_hir_id ( item_def_id) ,
385+ new_item,
386+ IgnoredDiagnosticOption { span : new_item, prev_span : old_item, option_name } ,
387+ ) ;
388+ }
389+ }
390+ }
391+ }
392+
393+ #[ derive( LintDiagnostic ) ]
394+ #[ diag( trait_selection_wrapped_parser_error) ]
395+ pub struct WrappedParserError {
396+ pub description : String ,
397+ pub label : String ,
398+ }
399+
344400impl < ' tcx > OnUnimplementedDirective {
345401 fn parse (
346402 tcx : TyCtxt < ' tcx > ,
@@ -664,7 +720,7 @@ impl<'tcx> OnUnimplementedDirective {
664720 tcx : TyCtxt < ' tcx > ,
665721 trait_ref : ty:: TraitRef < ' tcx > ,
666722 condition_options : & ConditionOptions ,
667- args : & FormatArgs ,
723+ args : & FormatArgs < ' tcx > ,
668724 ) -> OnUnimplementedNote {
669725 let mut message = None ;
670726 let mut label = None ;
@@ -784,7 +840,7 @@ impl<'tcx> OnUnimplementedFormatString {
784840 & self ,
785841 tcx : TyCtxt < ' tcx > ,
786842 trait_ref : ty:: TraitRef < ' tcx > ,
787- args : & FormatArgs ,
843+ args : & FormatArgs < ' tcx > ,
788844 ) -> String {
789845 let trait_def_id = trait_ref. def_id ;
790846 let ctx = if self . is_diagnostic_namespace_variant {
0 commit comments