This crate provides the following macros to help in creating Dylint libraries:
dylint_library!declare_late_lint!, declare_early_lint!, declare_pre_expansion_lint!impl_late_lint!, impl_early_lint!, impl_pre_expansion_lint!dylint_library!The dylint_library! macro expands to the following:
```rust
extern crate rustc_driver;
pub extern "C" fn dylintversion() -> *mut std::os::raw::cchar { std::ffi::CString::new($crate::DYLINTVERSION) .unwrap() .intoraw() } ```
If your library uses the dylint_library! macro and the dylint-link tool, then all you should have to do is implement the register_lints function. See the examples in this repository.
declare_late_lint!, etc.If your library contains just one lint, using declare_late_lint!, etc. can make your code more concise. Each of these macros requires the same arguments as declare_lint!, and wraps the following:
dylint_library!register_lints functiondeclare_lint!declare_lint_pass!For example, declare_late_lint!(vis NAME, Level, "description") expands to the following:
```rust dylintlinting::dylintlibrary!();
extern crate rustclint; extern crate rustcsession;
pub fn registerlints(sess: &rustcsession::Session, lintstore: &mut rustclint::LintStore) { lintstore.registerlints(&[NAME]); lintstore.registerlatepass(|| Box::new(Name)); }
rustcsession::declarelint!(vis NAME, Level, "description");
rustcsession::declarelint_pass!(Name => [NAME]); ```
declare_early_lint! and declare_pre_expansion_lint! are defined similarly.
impl_late_lint!, etc.impl_late_lint!, etc. are like declare_late_lint!, etc. except:
impl_lint_pass! instead of declare_lint_pass!;LintPass structure.That is, impl_late_lint!'s additional argument is what goes here:
rust
lint_store.register_late_pass(|| Box::new(...));
^^^
An example use of impl_pre_expansion_lint! can be found in envcargopath in this repository.