Panic while trying compiler lint plug-in

This is re-posting from

I got a panic while trying lint plugin.

thread 'rustc' panicked at 'cannot access a scoped thread local variable without calling `set` first', /Users/vsts/.cargo/registry/src/
stack backtrace:

   0:        0x107359725 - <unknown>
   1:        0x10738ff90 - <unknown>
   2:        0x10734ce4b - <unknown>
   3:        0x10735da6a - <unknown>
   4:        0x10735d775 - <unknown>
   5:        0x1049035f2 - <unknown>
   6:        0x10735e2a2 - <unknown>
   7:        0x10bc6dfa5 - std::panicking::begin_panic::hca84fcd70497f4cf
   8:        0x10bb30e44 - scoped_tls::ScopedKey<T>::with::h05001199e9954d8d
   9:        0x10bb340bd - core::ptr::real_drop_in_place::hdac883c03465eb85
  10:        0x10af93395 - <impl2::Pass as rustc::lint::EarlyLintPass>::check_item::h7abd58079d101600
                               at impl2/src/
  11:        0x105adbfa0 - <unknown>
  12:        0x104a27f5c - <unknown>
  13:        0x104973e2c - <unknown>
  14:        0x104a25e92 - <unknown>
  15:        0x104a233c8 - <unknown>
  16:        0x104a07202 - <unknown>
  17:        0x1049a36ae - <unknown>
  18:        0x1049db3ce - <unknown>
  19:        0x1049adbbb - <unknown>
  20:        0x1049a217c - <unknown>
  21:        0x1049a0d24 - <unknown>
  22:        0x104a2e30c - <unknown>
  23:        0x1048d7c84 - <unknown>
  24:        0x1049073b4 - <unknown>
  25:        0x1048f6ae2 - <unknown>
  26:        0x104920eb5 - <unknown>
  27:        0x104933ae9 - <unknown>
  28:        0x10736d44f - <unknown>
  29:        0x1048c9dc7 - <unknown>
  30:        0x10733f67e - <unknown>
  31:        0x10736c25e - <unknown>
  32:     0x7fff634ed2eb - <unknown>
  33:     0x7fff634f0249 - <unknown>

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report:

note: rustc 1.40.0-nightly (702b45e40 2019-10-01) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `lint1`.

To learn more, run the command again with --verbose.

It seems I am doing something wrong here.

My lint code is this.

#![feature(box_syntax, rustc_private)]


extern crate syntax;

// Load rustc as a plugin to get macros
extern crate rustc;
extern crate rustc_plugin;

use rustc::lint::{EarlyContext, LintContext, LintPass, EarlyLintPass,
                  EarlyLintPassObject, LintArray};
use rustc_plugin::Registry;
use syntax::ast;

declare_lint!(TEST_LINT, Warn, "Warn about items named 'lintme'");

struct Pass;

impl LintPass for Pass {
    fn name(&self) -> &'static str {
        return "Lint1";
    fn get_lints(&self) -> LintArray {

impl EarlyLintPass for Pass {
    fn check_item(&mut self, cx: &EarlyContext, it: &ast::Item) {
        if it.ident.as_str() == "lintme" {
            cx.span_lint(TEST_LINT, it.span, "item is named 'lintme'");

pub fn plugin_registrar(reg: &mut Registry) {
    reg.register_early_lint_pass(box Pass as EarlyLintPassObject);

Full source code is also on Github:

Default host: x86_64-apple-darwin
rustup home:  /Users/Dev/.rustup

installed toolchains

nightly-x86_64-apple-darwin (default)

active toolchain

nightly-x86_64-apple-darwin (default)
rustc 1.40.0-nightly (702b45e40 2019-10-01)

How can I make it work? I am writing lint plug just to get fully resolved type information. AFAIK, lint stage is the simplest place to get them.

Please don't add new uses of the lint plug-in mechanism. We want to remove it.

1 Like

@Centril That's sad. That was the best place for me to start accessing code semantic informations.

What should I use to get correct and fully resolved type informations? For example, I like to list all modules, structs enums and their fields and cases with fully qualified type paths.

1 Like

I have to second the sentiment. I too have a custom lint plugin. I am however writing it like the clippy wrapper that lets you avoid needing to annotate your code to trigger the lint plugin, with the understanding that it'll be forever on nightly. My use case is the same: analyzing fully resolved type information.

What's the future plans for clippy / rustc integration / communication?


Okay. I'll try rustc_interface.