@@ -2,14 +2,10 @@ use std::any::Any;
22use std:: borrow:: Cow ;
33
44use rustc_data_structures:: sync:: DynSend ;
5- use rustc_errors:: {
6- Applicability , Diag , DiagArgValue , DiagCtxtHandle , Diagnostic , Level ,
7- elided_lifetime_in_path_suggestion,
8- } ;
5+ use rustc_errors:: { Applicability , Diag , DiagArgValue , DiagCtxtHandle , Diagnostic , Level } ;
96use rustc_hir:: lints:: { AttributeLintKind , FormatWarning } ;
107use rustc_middle:: ty:: TyCtxt ;
118use rustc_session:: Session ;
12- use rustc_session:: lint:: BuiltinLintDiag ;
139
1410use crate :: lints;
1511
@@ -28,101 +24,6 @@ impl<'a> Diagnostic<'a, ()> for DiagAndSess<'_> {
2824 }
2925}
3026
31- /// This is a diagnostic struct that will decorate a `BuiltinLintDiag`
32- /// Directly creating the lint structs is expensive, using this will only decorate the lint structs when needed.
33- pub struct DecorateBuiltinLint < ' sess , ' tcx > {
34- pub sess : & ' sess Session ,
35- pub tcx : Option < TyCtxt < ' tcx > > ,
36- pub diagnostic : BuiltinLintDiag ,
37- }
38-
39- impl < ' a > Diagnostic < ' a , ( ) > for DecorateBuiltinLint < ' _ , ' _ > {
40- fn into_diag ( self , dcx : DiagCtxtHandle < ' a > , level : Level ) -> Diag < ' a , ( ) > {
41- match self . diagnostic {
42- BuiltinLintDiag :: ElidedLifetimesInPaths (
43- n,
44- path_span,
45- incl_angl_brckt,
46- insertion_span,
47- ) => lints:: ElidedLifetimesInPaths {
48- subdiag : elided_lifetime_in_path_suggestion (
49- self . sess . source_map ( ) ,
50- n,
51- path_span,
52- incl_angl_brckt,
53- insertion_span,
54- ) ,
55- }
56- . into_diag ( dcx, level) ,
57- BuiltinLintDiag :: UnusedImports {
58- remove_whole_use,
59- num_to_remove,
60- remove_spans,
61- test_module_span,
62- span_snippets,
63- } => {
64- let sugg = if remove_whole_use {
65- lints:: UnusedImportsSugg :: RemoveWholeUse { span : remove_spans[ 0 ] }
66- } else {
67- lints:: UnusedImportsSugg :: RemoveImports { remove_spans, num_to_remove }
68- } ;
69- let test_module_span =
70- test_module_span. map ( |span| self . sess . source_map ( ) . guess_head_span ( span) ) ;
71-
72- lints:: UnusedImports {
73- sugg,
74- test_module_span,
75- num_snippets : span_snippets. len ( ) ,
76- span_snippets : DiagArgValue :: StrListSepByAnd (
77- span_snippets. into_iter ( ) . map ( Cow :: Owned ) . collect ( ) ,
78- ) ,
79- }
80- . into_diag ( dcx, level)
81- }
82- BuiltinLintDiag :: NamedArgumentUsedPositionally {
83- position_sp_to_replace,
84- position_sp_for_msg,
85- named_arg_sp,
86- named_arg_name,
87- is_formatting_arg,
88- } => {
89- let ( suggestion, name) =
90- if let Some ( positional_arg_to_replace) = position_sp_to_replace {
91- let mut name = named_arg_name. clone ( ) ;
92- if is_formatting_arg {
93- name. push ( '$' )
94- } ;
95- let span_to_replace = if let Ok ( positional_arg_content) =
96- self . sess . source_map ( ) . span_to_snippet ( positional_arg_to_replace)
97- && positional_arg_content. starts_with ( ':' )
98- {
99- positional_arg_to_replace. shrink_to_lo ( )
100- } else {
101- positional_arg_to_replace
102- } ;
103- ( Some ( span_to_replace) , name)
104- } else {
105- ( None , String :: new ( ) )
106- } ;
107-
108- lints:: NamedArgumentUsedPositionally {
109- named_arg_sp,
110- position_label_sp : position_sp_for_msg,
111- suggestion,
112- name,
113- named_arg_name,
114- }
115- . into_diag ( dcx, level)
116- }
117-
118- BuiltinLintDiag :: AttributeLint ( kind) => {
119- DecorateAttrLint { sess : self . sess , tcx : self . tcx , diagnostic : & kind }
120- . into_diag ( dcx, level)
121- }
122- }
123- }
124- }
125-
12627/// This is a diagnostic struct that will decorate a `AttributeLintKind`
12728/// Directly creating the lint structs is expensive, using this will only decorate the lint structs when needed.
12829pub struct DecorateAttrLint < ' a , ' sess , ' tcx > {
0 commit comments