Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
huonw opened this issue Aug 23, 2014 · 3 comments
Closed

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

huonw opened this issue Aug 23, 2014 · 3 comments
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-plugin Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@huonw
Copy link
Member

huonw commented Aug 23, 2014

// 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() {}
@kmcallister
Copy link
Contributor

I think it comes down to this code:

cx.visit_id(ast::CRATE_NODE_ID);
cx.visit_ids(|v| {
    v.visited_outermost = true;
    visit::walk_crate(v, krate, ());
});

// since the root module isn't visited as an item (because it isn't an
// item), warn for it here.
run_lints!(cx, check_crate, krate);

visit::walk_crate(cx, krate, ());

First the visit_id steps print the lints previously stored with add_lint, then we invoke the dedicated lint passes. Do you still get the ICE if you add_lint before the phase when lint plugins run?

add_lint is only for earlier stages in the compiler; lint plugins aren't meant to use it. On the other hand, I don't think there's any harm in switching the order of these two steps.

@sinistersnare
Copy link
Contributor

Is there an updated minimal test case? I still get an ICE from using huounw/spellck.

@steveklabnik
Copy link
Member

Triage: it's been over a year, no minimal updated test case yet. I'm going to give this one a close as stale; let me know if you have some sort of update I'm missing!

bors added a commit to rust-lang-ci/rust that referenced this issue Mar 3, 2024
…ykril

fix: Ignore generic arguments in intra doc link path resolution

Fixes rust-lang/rust-analyzer#16699
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: Lints (warnings about flaws in source code) such as unused_mut. A-plugin Area: compiler plugins, doc.rust-lang.org/nightly/unstable-book/language-features/plugin.html I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants