1+ use std:: any:: Any ;
12use std:: borrow:: Cow ;
23
4+ use rustc_data_structures:: sync:: DynSend ;
35use rustc_errors:: {
46 Applicability , Diag , DiagArgValue , DiagCtxtHandle , Diagnostic , Level ,
57 elided_lifetime_in_path_suggestion,
@@ -8,12 +10,24 @@ use rustc_hir::lints::{AttributeLintKind, FormatWarning};
810use rustc_middle:: ty:: TyCtxt ;
911use rustc_session:: Session ;
1012use rustc_session:: lint:: BuiltinLintDiag ;
11- use tracing:: debug;
1213
1314use crate :: lints;
1415
1516mod check_cfg;
1617
18+ pub struct DiagAndSess < ' sess > {
19+ pub callback : Box <
20+ dyn for < ' b > FnOnce ( DiagCtxtHandle < ' b > , Level , & dyn Any ) -> Diag < ' b , ( ) > + DynSend + ' static ,
21+ > ,
22+ pub sess : & ' sess Session ,
23+ }
24+
25+ impl < ' a > Diagnostic < ' a , ( ) > for DiagAndSess < ' _ > {
26+ fn into_diag ( self , dcx : DiagCtxtHandle < ' a > , level : Level ) -> Diag < ' a , ( ) > {
27+ ( self . callback ) ( dcx, level, self . sess )
28+ }
29+ }
30+
1731/// This is a diagnostic struct that will decorate a `BuiltinLintDiag`
1832/// Directly creating the lint structs is expensive, using this will only decorate the lint structs when needed.
1933pub struct DecorateBuiltinLint < ' sess , ' tcx > {
@@ -25,28 +39,6 @@ pub struct DecorateBuiltinLint<'sess, 'tcx> {
2539impl < ' a > Diagnostic < ' a , ( ) > for DecorateBuiltinLint < ' _ , ' _ > {
2640 fn into_diag ( self , dcx : DiagCtxtHandle < ' a > , level : Level ) -> Diag < ' a , ( ) > {
2741 match self . diagnostic {
28- BuiltinLintDiag :: AbsPathWithModule ( mod_span) => {
29- let ( replacement, applicability) =
30- match self . sess . source_map ( ) . span_to_snippet ( mod_span) {
31- Ok ( ref s) => {
32- // FIXME(Manishearth) ideally the emitting code
33- // can tell us whether or not this is global
34- let opt_colon =
35- if s. trim_start ( ) . starts_with ( "::" ) { "" } else { "::" } ;
36-
37- ( format ! ( "crate{opt_colon}{s}" ) , Applicability :: MachineApplicable )
38- }
39- Err ( _) => ( "crate::<path>" . to_string ( ) , Applicability :: HasPlaceholders ) ,
40- } ;
41- lints:: AbsPathWithModule {
42- sugg : lints:: AbsPathWithModuleSugg {
43- span : mod_span,
44- applicability,
45- replacement,
46- } ,
47- }
48- . into_diag ( dcx, level)
49- }
5042 BuiltinLintDiag :: ElidedLifetimesInPaths (
5143 n,
5244 path_span,
@@ -87,36 +79,6 @@ impl<'a> Diagnostic<'a, ()> for DecorateBuiltinLint<'_, '_> {
8779 }
8880 . into_diag ( dcx, level)
8981 }
90- BuiltinLintDiag :: SingleUseLifetime {
91- param_span,
92- use_span,
93- elidable,
94- deletion_span,
95- ident,
96- } => {
97- debug ! ( ?param_span, ?use_span, ?deletion_span) ;
98- let suggestion = if let Some ( deletion_span) = deletion_span {
99- let ( use_span, replace_lt) = if elidable {
100- let use_span =
101- self . sess . source_map ( ) . span_extend_while_whitespace ( use_span) ;
102- ( use_span, String :: new ( ) )
103- } else {
104- ( use_span, "'_" . to_owned ( ) )
105- } ;
106- debug ! ( ?deletion_span, ?use_span) ;
107-
108- // issue 107998 for the case such as a wrong function pointer type
109- // `deletion_span` is empty and there is no need to report lifetime uses here
110- let deletion_span =
111- if deletion_span. is_empty ( ) { None } else { Some ( deletion_span) } ;
112- Some ( lints:: SingleUseLifetimeSugg { deletion_span, use_span, replace_lt } )
113- } else {
114- None
115- } ;
116-
117- lints:: SingleUseLifetime { suggestion, param_span, use_span, ident }
118- . into_diag ( dcx, level)
119- }
12082 BuiltinLintDiag :: NamedArgumentUsedPositionally {
12183 position_sp_to_replace,
12284 position_sp_for_msg,
0 commit comments