@@ -514,8 +514,10 @@ declare_lint_pass! {
514
514
]
515
515
}
516
516
517
- // this could be a closure, but then implementing derive traits
518
- // becomes hacky (and it gets allocated)
517
+ impl LateLintPass < ' _ , ' _ > for HardwiredLints { }
518
+
519
+ // This could be a closure, but then implementing derive trait
520
+ // becomes hacky (and it gets allocated).
519
521
#[ derive( PartialEq ) ]
520
522
pub enum BuiltinLintDiagnostics {
521
523
Normal ,
@@ -572,86 +574,80 @@ pub fn add_elided_lifetime_in_path_suggestion(
572
574
) ;
573
575
}
574
576
575
- impl BuiltinLintDiagnostics {
576
- pub fn run ( self , sess : & Session , db : & mut DiagnosticBuilder < ' _ > ) {
577
- match self {
578
- BuiltinLintDiagnostics :: Normal => ( ) ,
579
- BuiltinLintDiagnostics :: BareTraitObject ( span, is_global) => {
580
- let ( sugg, app) = match sess. source_map ( ) . span_to_snippet ( span) {
581
- Ok ( ref s) if is_global => {
582
- ( format ! ( "dyn ({})" , s) , Applicability :: MachineApplicable )
583
- }
584
- Ok ( s) => ( format ! ( "dyn {}" , s) , Applicability :: MachineApplicable ) ,
585
- Err ( _) => ( "dyn <type>" . to_string ( ) , Applicability :: HasPlaceholders ) ,
586
- } ;
587
- db. span_suggestion ( span, "use `dyn`" , sugg, app) ;
588
- }
589
- BuiltinLintDiagnostics :: AbsPathWithModule ( span) => {
590
- let ( sugg, app) = match sess. source_map ( ) . span_to_snippet ( span) {
591
- Ok ( ref s) => {
592
- // FIXME(Manishearth) ideally the emitting code
593
- // can tell us whether or not this is global
594
- let opt_colon = if s. trim_start ( ) . starts_with ( "::" ) { "" } else { "::" } ;
595
-
596
- ( format ! ( "crate{}{}" , opt_colon, s) , Applicability :: MachineApplicable )
597
- }
598
- Err ( _) => ( "crate::<path>" . to_string ( ) , Applicability :: HasPlaceholders ) ,
599
- } ;
600
- db. span_suggestion ( span, "use `crate`" , sugg, app) ;
601
- }
602
- BuiltinLintDiagnostics :: ProcMacroDeriveResolutionFallback ( span) => {
603
- db. span_label (
604
- span,
605
- "names from parent modules are not \
606
- accessible without an explicit import",
607
- ) ;
608
- }
609
- BuiltinLintDiagnostics :: MacroExpandedMacroExportsAccessedByAbsolutePaths ( span_def) => {
610
- db. span_note ( span_def, "the macro is defined here" ) ;
611
- }
612
- BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
577
+ pub fn run_builtin_lint_diagnostics (
578
+ this : BuiltinLintDiagnostics ,
579
+ sess : & Session ,
580
+ db : & mut DiagnosticBuilder < ' _ > ,
581
+ ) {
582
+ match this {
583
+ BuiltinLintDiagnostics :: Normal => ( ) ,
584
+ BuiltinLintDiagnostics :: BareTraitObject ( span, is_global) => {
585
+ let ( sugg, app) = match sess. source_map ( ) . span_to_snippet ( span) {
586
+ Ok ( s) if is_global => ( format ! ( "dyn ({})" , s) , Applicability :: MachineApplicable ) ,
587
+ Ok ( s) => ( format ! ( "dyn {}" , s) , Applicability :: MachineApplicable ) ,
588
+ Err ( _) => ( "dyn <type>" . to_string ( ) , Applicability :: HasPlaceholders ) ,
589
+ } ;
590
+ db. span_suggestion ( span, "use `dyn`" , sugg, app) ;
591
+ }
592
+ BuiltinLintDiagnostics :: AbsPathWithModule ( span) => {
593
+ let ( sugg, app) = match sess. source_map ( ) . span_to_snippet ( span) {
594
+ Ok ( ref s) => {
595
+ // FIXME(Manishearth) ideally the emitting code
596
+ // can tell us whether or not this is global
597
+ let opt_colon = if s. trim_start ( ) . starts_with ( "::" ) { "" } else { "::" } ;
598
+
599
+ ( format ! ( "crate{}{}" , opt_colon, s) , Applicability :: MachineApplicable )
600
+ }
601
+ Err ( _) => ( "crate::<path>" . to_string ( ) , Applicability :: HasPlaceholders ) ,
602
+ } ;
603
+ db. span_suggestion ( span, "use `crate`" , sugg, app) ;
604
+ }
605
+ BuiltinLintDiagnostics :: ProcMacroDeriveResolutionFallback ( span) => {
606
+ db. span_label (
607
+ span,
608
+ "names from parent modules are not accessible without an explicit import" ,
609
+ ) ;
610
+ }
611
+ BuiltinLintDiagnostics :: MacroExpandedMacroExportsAccessedByAbsolutePaths ( span_def) => {
612
+ db. span_note ( span_def, "the macro is defined here" ) ;
613
+ }
614
+ BuiltinLintDiagnostics :: ElidedLifetimesInPaths (
615
+ n,
616
+ path_span,
617
+ incl_angl_brckt,
618
+ insertion_span,
619
+ anon_lts,
620
+ ) => {
621
+ add_elided_lifetime_in_path_suggestion (
622
+ sess,
623
+ db,
613
624
n,
614
625
path_span,
615
626
incl_angl_brckt,
616
627
insertion_span,
617
628
anon_lts,
618
- ) => {
619
- add_elided_lifetime_in_path_suggestion (
620
- sess,
621
- db,
622
- n,
623
- path_span,
624
- incl_angl_brckt,
625
- insertion_span,
626
- anon_lts,
629
+ ) ;
630
+ }
631
+ BuiltinLintDiagnostics :: UnknownCrateTypes ( span, note, sugg) => {
632
+ db. span_suggestion ( span, & note, sugg, Applicability :: MaybeIncorrect ) ;
633
+ }
634
+ BuiltinLintDiagnostics :: UnusedImports ( message, replaces) => {
635
+ if !replaces. is_empty ( ) {
636
+ db. tool_only_multipart_suggestion (
637
+ & message,
638
+ replaces,
639
+ Applicability :: MachineApplicable ,
627
640
) ;
628
641
}
629
- BuiltinLintDiagnostics :: UnknownCrateTypes ( span, note, sugg) => {
630
- db. span_suggestion ( span, & note, sugg, Applicability :: MaybeIncorrect ) ;
631
- }
632
- BuiltinLintDiagnostics :: UnusedImports ( message, replaces) => {
633
- if !replaces. is_empty ( ) {
634
- db. tool_only_multipart_suggestion (
635
- & message,
636
- replaces,
637
- Applicability :: MachineApplicable ,
638
- ) ;
639
- }
640
- }
641
- BuiltinLintDiagnostics :: RedundantImport ( spans, ident) => {
642
- for ( span, is_imported) in spans {
643
- let introduced = if is_imported { "imported" } else { "defined" } ;
644
- db. span_label (
645
- span,
646
- format ! ( "the item `{}` is already {} here" , ident, introduced) ,
647
- ) ;
648
- }
649
- }
650
- BuiltinLintDiagnostics :: DeprecatedMacro ( suggestion, span) => {
651
- stability:: deprecation_suggestion ( db, suggestion, span)
642
+ }
643
+ BuiltinLintDiagnostics :: RedundantImport ( spans, ident) => {
644
+ for ( span, is_imported) in spans {
645
+ let introduced = if is_imported { "imported" } else { "defined" } ;
646
+ db. span_label ( span, format ! ( "the item `{}` is already {} here" , ident, introduced) ) ;
652
647
}
653
648
}
649
+ BuiltinLintDiagnostics :: DeprecatedMacro ( suggestion, span) => {
650
+ stability:: deprecation_suggestion ( db, suggestion, span)
651
+ }
654
652
}
655
653
}
656
-
657
- impl < ' a , ' tcx > LateLintPass < ' a , ' tcx > for HardwiredLints { }
0 commit comments