@@ -6,6 +6,7 @@ use rustc_errors::codes::*;
6
6
use rustc_errors:: { ErrorGuaranteed , struct_span_code_err} ;
7
7
use rustc_hir:: def_id:: { DefId , LocalDefId } ;
8
8
use rustc_hir:: { AttrArgs , Attribute } ;
9
+ use rustc_macros:: LintDiagnostic ;
9
10
use rustc_middle:: bug;
10
11
use rustc_middle:: ty:: print:: PrintTraitRefExt ;
11
12
use rustc_middle:: ty:: { self , GenericArgsRef , GenericParamDef , GenericParamDefKind , TyCtxt } ;
@@ -17,7 +18,6 @@ use {rustc_attr_parsing as attr, rustc_hir as hir};
17
18
use super :: { ObligationCauseCode , PredicateObligation } ;
18
19
use crate :: error_reporting:: TypeErrCtxt ;
19
20
use crate :: error_reporting:: traits:: on_unimplemented_condition:: { Condition , ConditionOptions } ;
20
- use crate :: error_reporting:: traits:: on_unimplemented_format:: errors:: * ;
21
21
use crate :: error_reporting:: traits:: on_unimplemented_format:: { Ctx , FormatArgs , FormatString } ;
22
22
use crate :: errors:: {
23
23
EmptyOnClauseInOnUnimplemented , InvalidOnClauseInOnUnimplemented , NoValueInOnUnimplemented ,
@@ -112,10 +112,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
112
112
// FIXME(-Zlower-impl-trait-in-trait-to-assoc-ty): HIR is not present for RPITITs,
113
113
// but I guess we could synthesize one here. We don't see any errors that rely on
114
114
// 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 ( "" ) ;
119
116
120
117
let direct = match obligation. cause . code ( ) {
121
118
ObligationCauseCode :: BuiltinDerived ( ..)
@@ -128,7 +125,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
128
125
}
129
126
} ;
130
127
131
- let from_desugaring = obligation. cause . span . desugaring_kind ( ) . map ( |k| format ! ( "{k:?}" ) ) ;
128
+ let from_desugaring = obligation. cause . span . desugaring_kind ( ) ;
132
129
133
130
let cause = if let ObligationCauseCode :: MainFunctionType = obligation. cause . code ( ) {
134
131
Some ( "MainFunctionType" . to_string ( ) )
@@ -253,8 +250,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
253
250
}
254
251
} ) ) ;
255
252
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 ( ) ;
258
255
259
256
let condition_options = ConditionOptions {
260
257
self_types,
@@ -268,6 +265,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
268
265
// Unlike the generic_args earlier,
269
266
// this one is *not* collected under `with_no_trimmed_paths!`
270
267
// for printing the type to the user
268
+ //
269
+ // This includes `Self`, as it is the first parameter in `own_params`.
271
270
let generic_args = self
272
271
. tcx
273
272
. generics_of ( trait_pred. trait_ref . def_id )
@@ -341,6 +340,63 @@ pub enum AppendConstMessage {
341
340
Custom ( Symbol , Span ) ,
342
341
}
343
342
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
+
344
400
impl < ' tcx > OnUnimplementedDirective {
345
401
fn parse (
346
402
tcx : TyCtxt < ' tcx > ,
@@ -664,7 +720,7 @@ impl<'tcx> OnUnimplementedDirective {
664
720
tcx : TyCtxt < ' tcx > ,
665
721
trait_ref : ty:: TraitRef < ' tcx > ,
666
722
condition_options : & ConditionOptions ,
667
- args : & FormatArgs ,
723
+ args : & FormatArgs < ' tcx > ,
668
724
) -> OnUnimplementedNote {
669
725
let mut message = None ;
670
726
let mut label = None ;
@@ -784,7 +840,7 @@ impl<'tcx> OnUnimplementedFormatString {
784
840
& self ,
785
841
tcx : TyCtxt < ' tcx > ,
786
842
trait_ref : ty:: TraitRef < ' tcx > ,
787
- args : & FormatArgs ,
843
+ args : & FormatArgs < ' tcx > ,
788
844
) -> String {
789
845
let trait_def_id = trait_ref. def_id ;
790
846
let ctx = if self . is_diagnostic_namespace_variant {
0 commit comments