about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2020-01-05 08:54:10 +0100
committerMazdak Farrokhzad <twingoow@gmail.com>2020-01-11 03:19:50 +0100
commit82eeb8573a7caa0b3dc4aaa8236e83fcff9779d3 (patch)
tree5508d01f211fee2292763e4b9eb2ae2672231472 /src
parentd247ac4c0d64b278d80296a0dab801238fa3c66b (diff)
downloadrust-82eeb8573a7caa0b3dc4aaa8236e83fcff9779d3.tar.gz
rust-82eeb8573a7caa0b3dc4aaa8236e83fcff9779d3.zip
prepare for moving BuiltinLintDiagnostics to rustc_session
Diffstat (limited to 'src')
-rw-r--r--src/librustc/lint/builtin.rs144
-rw-r--r--src/librustc/lint/context.rs2
2 files changed, 71 insertions, 75 deletions
diff --git a/src/librustc/lint/builtin.rs b/src/librustc/lint/builtin.rs
index 5dea0dbc896..de4992d8e70 100644
--- a/src/librustc/lint/builtin.rs
+++ b/src/librustc/lint/builtin.rs
@@ -514,8 +514,10 @@ declare_lint_pass! {
     ]
 }
 
-// this could be a closure, but then implementing derive traits
-// becomes hacky (and it gets allocated)
+impl LateLintPass<'_, '_> for HardwiredLints {}
+
+// This could be a closure, but then implementing derive trait
+// becomes hacky (and it gets allocated).
 #[derive(PartialEq)]
 pub enum BuiltinLintDiagnostics {
     Normal,
@@ -572,86 +574,80 @@ pub fn add_elided_lifetime_in_path_suggestion(
     );
 }
 
-impl BuiltinLintDiagnostics {
-    pub fn run(self, sess: &Session, db: &mut DiagnosticBuilder<'_>) {
-        match self {
-            BuiltinLintDiagnostics::Normal => (),
-            BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
-                let (sugg, app) = match sess.source_map().span_to_snippet(span) {
-                    Ok(ref s) if is_global => {
-                        (format!("dyn ({})", s), Applicability::MachineApplicable)
-                    }
-                    Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
-                    Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders),
-                };
-                db.span_suggestion(span, "use `dyn`", sugg, app);
-            }
-            BuiltinLintDiagnostics::AbsPathWithModule(span) => {
-                let (sugg, app) = match sess.source_map().span_to_snippet(span) {
-                    Ok(ref s) => {
-                        // FIXME(Manishearth) ideally the emitting code
-                        // can tell us whether or not this is global
-                        let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" };
-
-                        (format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable)
-                    }
-                    Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
-                };
-                db.span_suggestion(span, "use `crate`", sugg, app);
-            }
-            BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => {
-                db.span_label(
-                    span,
-                    "names from parent modules are not \
-                                     accessible without an explicit import",
-                );
-            }
-            BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
-                db.span_note(span_def, "the macro is defined here");
-            }
-            BuiltinLintDiagnostics::ElidedLifetimesInPaths(
+pub fn run_builtin_lint_diagnostics(
+    this: BuiltinLintDiagnostics,
+    sess: &Session,
+    db: &mut DiagnosticBuilder<'_>,
+) {
+    match this {
+        BuiltinLintDiagnostics::Normal => (),
+        BuiltinLintDiagnostics::BareTraitObject(span, is_global) => {
+            let (sugg, app) = match sess.source_map().span_to_snippet(span) {
+                Ok(s) if is_global => (format!("dyn ({})", s), Applicability::MachineApplicable),
+                Ok(s) => (format!("dyn {}", s), Applicability::MachineApplicable),
+                Err(_) => ("dyn <type>".to_string(), Applicability::HasPlaceholders),
+            };
+            db.span_suggestion(span, "use `dyn`", sugg, app);
+        }
+        BuiltinLintDiagnostics::AbsPathWithModule(span) => {
+            let (sugg, app) = match sess.source_map().span_to_snippet(span) {
+                Ok(ref s) => {
+                    // FIXME(Manishearth) ideally the emitting code
+                    // can tell us whether or not this is global
+                    let opt_colon = if s.trim_start().starts_with("::") { "" } else { "::" };
+
+                    (format!("crate{}{}", opt_colon, s), Applicability::MachineApplicable)
+                }
+                Err(_) => ("crate::<path>".to_string(), Applicability::HasPlaceholders),
+            };
+            db.span_suggestion(span, "use `crate`", sugg, app);
+        }
+        BuiltinLintDiagnostics::ProcMacroDeriveResolutionFallback(span) => {
+            db.span_label(
+                span,
+                "names from parent modules are not accessible without an explicit import",
+            );
+        }
+        BuiltinLintDiagnostics::MacroExpandedMacroExportsAccessedByAbsolutePaths(span_def) => {
+            db.span_note(span_def, "the macro is defined here");
+        }
+        BuiltinLintDiagnostics::ElidedLifetimesInPaths(
+            n,
+            path_span,
+            incl_angl_brckt,
+            insertion_span,
+            anon_lts,
+        ) => {
+            add_elided_lifetime_in_path_suggestion(
+                sess,
+                db,
                 n,
                 path_span,
                 incl_angl_brckt,
                 insertion_span,
                 anon_lts,
-            ) => {
-                add_elided_lifetime_in_path_suggestion(
-                    sess,
-                    db,
-                    n,
-                    path_span,
-                    incl_angl_brckt,
-                    insertion_span,
-                    anon_lts,
+            );
+        }
+        BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
+            db.span_suggestion(span, &note, sugg, Applicability::MaybeIncorrect);
+        }
+        BuiltinLintDiagnostics::UnusedImports(message, replaces) => {
+            if !replaces.is_empty() {
+                db.tool_only_multipart_suggestion(
+                    &message,
+                    replaces,
+                    Applicability::MachineApplicable,
                 );
             }
-            BuiltinLintDiagnostics::UnknownCrateTypes(span, note, sugg) => {
-                db.span_suggestion(span, &note, sugg, Applicability::MaybeIncorrect);
-            }
-            BuiltinLintDiagnostics::UnusedImports(message, replaces) => {
-                if !replaces.is_empty() {
-                    db.tool_only_multipart_suggestion(
-                        &message,
-                        replaces,
-                        Applicability::MachineApplicable,
-                    );
-                }
-            }
-            BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
-                for (span, is_imported) in spans {
-                    let introduced = if is_imported { "imported" } else { "defined" };
-                    db.span_label(
-                        span,
-                        format!("the item `{}` is already {} here", ident, introduced),
-                    );
-                }
-            }
-            BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
-                stability::deprecation_suggestion(db, suggestion, span)
+        }
+        BuiltinLintDiagnostics::RedundantImport(spans, ident) => {
+            for (span, is_imported) in spans {
+                let introduced = if is_imported { "imported" } else { "defined" };
+                db.span_label(span, format!("the item `{}` is already {} here", ident, introduced));
             }
         }
+        BuiltinLintDiagnostics::DeprecatedMacro(suggestion, span) => {
+            stability::deprecation_suggestion(db, suggestion, span)
+        }
     }
 }
-
-impl<'a, 'tcx> LateLintPass<'a, 'tcx> for HardwiredLints {}
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs
index 492d8f1f8a5..90575f71ff5 100644
--- a/src/librustc/lint/context.rs
+++ b/src/librustc/lint/context.rs
@@ -495,7 +495,7 @@ pub trait LintContext: Sized {
         diagnostic: BuiltinLintDiagnostics,
     ) {
         let mut db = self.lookup(lint, span, msg);
-        diagnostic.run(self.sess(), &mut db);
+        super::builtin::run_builtin_lint_diagnostics(diagnostic, self.sess(), &mut db);
         db.emit();
     }