Skip to content

Commit 4e8d1b2

Browse files
Add some documentation
1 parent 6be0a70 commit 4e8d1b2

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/librustc/lint/context.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -155,23 +155,31 @@ impl LintStore {
155155
.collect()
156156
}
157157

158-
pub fn register_early_pass(&mut self,
159-
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync) {
158+
pub fn register_early_pass(
159+
&mut self,
160+
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync
161+
) {
160162
self.early_passes.push(Box::new(pass));
161163
}
162164

163-
pub fn register_pre_expansion_pass(&mut self,
164-
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync) {
165+
pub fn register_pre_expansion_pass(
166+
&mut self,
167+
pass: impl Fn() -> EarlyLintPassObject + 'static + sync::Send + sync::Sync,
168+
) {
165169
self.pre_expansion_passes.push(Box::new(pass));
166170
}
167171

168-
pub fn register_late_pass(&mut self,
169-
pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync) {
172+
pub fn register_late_pass(
173+
&mut self,
174+
pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync,
175+
) {
170176
self.late_passes.push(Box::new(pass));
171177
}
172178

173-
pub fn register_late_mod_pass(&mut self,
174-
pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync) {
179+
pub fn register_late_mod_pass(
180+
&mut self,
181+
pass: impl Fn() -> LateLintPassObject + 'static + sync::Send + sync::Sync,
182+
) {
175183
self.late_module_passes.push(Box::new(pass));
176184
}
177185

src/librustc_driver/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub fn abort_on_err<T>(result: Result<T, ErrorReported>, sess: &Session) -> T {
106106
pub trait Callbacks {
107107
/// Called before creating the compiler instance
108108
fn config(&mut self, _config: &mut interface::Config) {}
109+
/// Called early during compilation to allow other drivers to easily register lints.
109110
fn extra_lints(&mut self, _ls: &mut lint::LintStore) {}
110111
/// Called after parsing. Return value instructs the compiler whether to
111112
/// continue the compilation afterwards (defaults to `Compilation::Continue`)

src/librustc_interface/interface.rs

+5
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ pub struct Config {
8282
pub crate_name: Option<String>,
8383
pub lint_caps: FxHashMap<lint::LintId, lint::Level>,
8484

85+
/// This is a callback from the driver that is called when we're registering lints;
86+
/// it is called during plugin registration when we have the LintStore in a non-shared state.
87+
///
88+
/// Note that if you find a Some here you probably want to call that function in the new
89+
/// function being registered.
8590
pub register_lints: Option<Box<dyn Fn(&Session, &mut lint::LintStore) + Send + Sync>>,
8691
}
8792

src/librustc_plugin/registry.rs

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub struct Registry<'a> {
2525
/// from the plugin registrar.
2626
pub sess: &'a Session,
2727

28+
/// The `LintStore` allows plugins to register new lints.
2829
pub lint_store: &'a mut LintStore,
2930

3031
#[doc(hidden)]

0 commit comments

Comments
 (0)