diff options
| author | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-10-22 16:53:28 -0400 |
|---|---|---|
| committer | Mark Rousskov <mark.simulacrum@gmail.com> | 2019-10-22 16:53:28 -0400 |
| commit | 4e8d1b229217c7c83ce96b44410ccae9470db973 (patch) | |
| tree | 1ed442ba2b1abe9a515cb283881bc6e0233fa125 /src | |
| parent | 6be0a7081a9aafc4e0b39cae266fbed5eabd8993 (diff) | |
| download | rust-4e8d1b229217c7c83ce96b44410ccae9470db973.tar.gz rust-4e8d1b229217c7c83ce96b44410ccae9470db973.zip | |
Add some documentation
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustc/lint/context.rs | 24 | ||||
| -rw-r--r-- | src/librustc_driver/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_interface/interface.rs | 5 | ||||
| -rw-r--r-- | src/librustc_plugin/registry.rs | 1 |
4 files changed, 23 insertions, 8 deletions
diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 2a0cdba50cb..595b715c02e 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -155,23 +155,31 @@ impl LintStore { .collect() } - pub fn register_early_pass(&mut self, - pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync) { + pub fn register_early_pass( + &mut self, + pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync + ) { self.early_passes.push(Box::new(pass)); } - pub fn register_pre_expansion_pass(&mut self, - pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync) { + pub fn register_pre_expansion_pass( + &mut self, + pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync, + ) { self.pre_expansion_passes.push(Box::new(pass)); } - pub fn register_late_pass(&mut self, - pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync) { + pub fn register_late_pass( + &mut self, + pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync, + ) { self.late_passes.push(Box::new(pass)); } - pub fn register_late_mod_pass(&mut self, - pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync) { + pub fn register_late_mod_pass( + &mut self, + pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync, + ) { self.late_module_passes.push(Box::new(pass)); } diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 2cf1552ed96..a18ef014b4d 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -106,6 +106,7 @@ pub fn abort_on_err<T>(result: Result<T, ErrorReported>, sess: &Session) -> T { pub trait Callbacks { /// Called before creating the compiler instance fn config(&mut self, _config: &mut interface::Config) {} + /// Called early during compilation to allow other drivers to easily register lints. fn extra_lints(&mut self, _ls: &mut lint::LintStore) {} /// Called after parsing. Return value instructs the compiler whether to /// continue the compilation afterwards (defaults to `Compilation::Continue`) diff --git a/src/librustc_interface/interface.rs b/src/librustc_interface/interface.rs index 34ec3c862a3..3f832f95bd4 100644 --- a/src/librustc_interface/interface.rs +++ b/src/librustc_interface/interface.rs @@ -82,6 +82,11 @@ pub struct Config { pub crate_name: Option<String>, pub lint_caps: FxHashMap<lint::LintId, lint::Level>, + /// This is a callback from the driver that is called when we're registering lints; + /// it is called during plugin registration when we have the LintStore in a non-shared state. + /// + /// Note that if you find a Some here you probably want to call that function in the new + /// function being registered. pub register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>, } diff --git a/src/librustc_plugin/registry.rs b/src/librustc_plugin/registry.rs index 223956a4f5e..2e23b8c870c 100644 --- a/src/librustc_plugin/registry.rs +++ b/src/librustc_plugin/registry.rs @@ -25,6 +25,7 @@ pub struct Registry<'a> { /// from the plugin registrar. pub sess: &'a Session, + /// The `LintStore` allows plugins to register new lints. pub lint_store: &'a mut LintStore, #[doc(hidden)] |
