Skip to content

Lints added with add_lint to the crate object itself are not processed #16702

Closed
@huonw

Description

@huonw
// crate_lint.rs
#![feature(phase, plugin_registrar)]
#![crate_type = "dylib"]

extern crate syntax;
#[phase(plugin, link)] extern crate rustc;

use syntax::ast;
use rustc::plugin::Registry;
use rustc::lint::{Context, LintArray, LintPass};

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
    reg.register_lint_pass(box CrateTest);
}

declare_lint! { CRATE_TEST, Warn, "..." }

struct CrateTest;

impl LintPass for CrateTest {
    fn get_lints(&self) -> LintArray {
        lint_array!(CRATE_TEST)
    }

    fn check_crate(&mut self, cx: &Context, krate: &ast::Crate) {
        cx.sess().add_lint(CRATE_TEST, ast::CRATE_NODE_ID, krate.span, "test".to_string());
        // cx.span_lint(CRATE_TEST, krate.span, "test");
    }
}
// test_crate_lint.rs
#![feature(phase)]
#[phase(plugin)] extern crate crate_lint;

fn main() {}
$ rustc crate_lint.rs
$ rustc -L . test_crate_lint.rs
test_crate_lint.rs:1:1: 4:12 error: internal compiler error: unprocessed lint crate_test at unknown node (id=0): test
test_crate_lint.rs:1 #![feature(phase)]
test_crate_lint.rs:2 #[phase(plugin)] extern crate crate_lint;
test_crate_lint.rs:3 
test_crate_lint.rs:4 fn main() {}
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/ast_util.rs:776

The commented out .lint(...) call works fine:

test_crate_lint.rs:1:1: 4:12 warning: test, #[warn(crate_test)] on by default
test_crate_lint.rs:1 #![feature(phase)]
test_crate_lint.rs:2 #[phase(plugin)] extern crate crate_lint;
test_crate_lint.rs:3 
test_crate_lint.rs:4 fn main() {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-pluginsArea: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.htmlI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions