Rust: RLS ICE: "node_type: no type for node" when building bitflags

Created on 12 Mar 2019  Â·  21Comments  Â·  Source: rust-lang/rust

When using this branch of bitflags: https://github.com/bitflags/bitflags/pull/172 through a patch in a local directory rls crashes with the following errors:

{"message":"src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::IDENTITY (id=18847)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::IDENTITY (id=18847)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C codegen-units=16 -C debuginfo=2 -C debug-assertions=on --crate-type lib

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

{"message":"src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::Shift (id=43075)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::Shift (id=43075)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C codegen-units=16 -C debuginfo=2 -C debug-assertions=on --crate-type lib

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

{"message":"src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::ZIGZAG_SUBDIVISION (id=144317)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::ZIGZAG_SUBDIVISION (id=144317)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11) running on x86_64-unknown-linux-gnu

{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C codegen-units=16 -C debuginfo=2 -C debug-assertions=on --crate-type lib

note: some of the compiler flags provided by cargo are hidden
A-rls A-save-analysis C-bug I-ICE P-high T-compiler T-dev-tools

Most helpful comment

JFYI I could work around this problem by adding bitflags = "=1.0.4" to my Cargo.toml

All 21 comments

...compiler flags: -C opt-level=3...

That's weird, I don't think RLS runs cargo with --release flag... Is that output from a regular cargo build? I'll try to run the RLS myself and come back with results.

i had enabled dev overrides for dependencies in cargo.toml using:

[profile.dev.overrides."*"]
opt-level = 3
debug = true
codegen-units = 16
incremental = true

removing that out the output from rls is now the normal debug flags but still the same errors:

{"message":"src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::IDENTITY (id=18847)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::IDENTITY (id=18847)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11) running on x86_64-unknown-linux-gnu

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

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

{"message":"src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::Shift (id=43075)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:539: node_type: no type for node `expr <Self>::Shift (id=43075)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:635:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.35.0-nightly (e68bf8ae1 2019-03-11) running on x86_64-unknown-linux-gnu

This is now causing widespread ICEs in the RLS. Nominating to get this fixed (maybe @Xanewok has an idea?). See https://github.com/rust-lang/rust/issues/60484#issuecomment-489072191 for a simpler reproducer.

I encountered this issue trying out winit which causes rustc to crash on this line when invoked by RLS. I can confirm it's the exact same backtrace as https://github.com/rust-lang/rust/issues/60484#issuecomment-489072191.

I ran into this trying out https://github.com/fdehau/tui-rs on Windows 10. RLS inside vscode ends up panicking with this backtrace:

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:620:9
stack backtrace:
query stack during panic:
end of query stack

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.1 (fc50f328b 2019-04-24) running on x86_64-pc-windows-msvc

{"message":"src\\librustc\\ty\\context.rs:541: node_type: no type for node `expr <Self>::SC_NEGATE_REQS (id=50362)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src\\librustc\\ty\\context.rs:541: node_type: no type for node `expr <Self>::SC_NEGATE_REQS (id=50362)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:620:9
stack backtrace:
   0: std::sys_common::alloc::realloc_fallback
   1: std::panicking::take_hook
   2: std::panicking::take_hook
   3: <rustc::ty::sty::Binder<rustc::ty::ProjectionPredicate<'tcx>> as rustc::ty::ToPredicate<'tcx>>::to_predicate
   4: std::panicking::rust_panic_with_hook
   5: <rustc_errors::emitter::ColorConfig as core::fmt::Debug>::fmt
   6: rustc_errors::Handler::bug
   7: rustc::util::bug::bug_fmt
   8: rustc::ty::wf::object_region_bounds
   9: rustc::ty::wf::object_region_bounds
  10: rustc::ty::wf::object_region_bounds
  11: rustc::util::bug::bug_fmt
  12: rustc::util::bug::bug_fmt
  13: rustc::ty::context::TypeckTables::node_type
  14: rustc::ty::context::TypeckTables::expr_ty_adjusted
  15: rustc_save_analysis::SaveContext::get_expr_data
  16: <unknown>
  17: <unknown>
  18: <unknown>
  19: <unknown>
  20: <unknown>
  21: <unknown>
  22: <unknown>
  23: <unknown>
  24: <rustc_save_analysis::DumpHandler<'a> as rustc_save_analysis::SaveHandler>::save
  25: <env_logger::fmt::WriteStyle as core::default::Default>::default
  26: rustc_driver::enable_save_analysis
  27: rustc_driver::enable_save_analysis
  28: <env_logger::fmt::WriteStyle as core::default::Default>::default
  29: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
  30: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
  31: <env_logger::fmt::WriteStyle as core::default::Default>::default
  32: rustc_driver::driver::compile_input
  33: rustc_driver::run_compiler
  34: <rustc_driver::CompilationFailure as core::fmt::Debug>::fmt
  35: rustc_driver::run_compiler
  36: git_libgit2_opts
  37: git_libgit2_opts
  38: _rust_maybe_catch_panic
  39: git_libgit2_opts
  40: std::sys::windows::thread::Thread::new
  41: BaseThreadInitThunk
  42: RtlUserThreadStart
query stack during panic:
end of query stack
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.1 (fc50f328b 2019-04-24) running on x86_64-pc-windows-msvc

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

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

(note for repro: I had changed the default feature in tui-rs Cargo.toml to be "crossterm" because the default feature "termion" doesn't compile on windows - but after the termion compile errors, rustc was giving me a similar panic anyway)

JFYI I could work around this problem by adding bitflags = "=1.0.4" to my Cargo.toml

JFYI I could work around this problem by adding bitflags = "=1.0.4" to my Cargo.toml

I tried that with the tui-rs Cargo.toml (it had bitflags = "1.0") but same panic.

[Edit] you're right, I had missed the = inside the version.

Thanks @hcrohland !

Running into the same issue when trying to build Clap

{"message":"src/librustc/ty/context.rs:541: node_type: no type for node `expr <Self>::SC_NEGATE_REQS (id=49436)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:541: node_type: no type for node `expr <Self>::SC_NEGATE_REQS (id=49436)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:620:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.1 (fc50f328b 2019-04-24) running on x86_64-apple-darwin

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

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

Same issue in vscode on linuxmint and rust 1.34.1 when trying to build glib (dependency of gtk).

{"message":"src/librustc/ty/context.rs:541: node_type: no type for node `expr <Self>::IS_REGULAR (id=87589)`","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":"error: internal compiler error: src/librustc/ty/context.rs:541: node_type: no type for node `expr <Self>::IS_REGULAR (id=87589)`\n\n"}
thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:620:9
note: Run with `RUST_BACKTRACE=1` environment variable to display a backtrace.
{"message":"aborting due to previous error","code":null,"level":"error","spans":[],"children":[],"rendered":"error: aborting due to previous error\n\n"}

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.34.1 (fc50f328b 2019-04-24) running on x86_64-unknown-linux-gnu

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

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

There is no need to list every crate which depends on bitflags, it only clutters the thread and makes the workaround less visible.

Here's a small repro, extracted from what bitflags is doing:

struct BF { bits: u32 }

impl BF {
    pub const F: BF = BF { bits: 0 };
    pub const fn f() {
        trait _BF {
            const FLAG: u32 = 0;
        }

        impl _BF for BF {
            const FLAG: u32 = F.bits;
        }
    }
}
â–¶ RUST_BACKTRACE=1 cargo +nightly rustc --lib -- -Zsave-analysis
   Compiling rlsrepro v0.1.0 (/Users/swgillespie/Documents/workspace/rust/repros/rlsrepro)
error[E0425]: cannot find value `F` in this scope
  --> src/lib.rs:11:31
   |
11 |             const FLAG: u32 = F.bits;
   |                               ^ not found in this scope

error: internal compiler error: src/librustc/ty/context.rs:565: node_type: no type for node `expr F (hir_id=HirId { owner: DefIndex(0:10), local_id: 2 })`

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:643:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::_print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::ty::context::TypeckTables::node_type::{{closure}}
  15: rustc::ty::context::TypeckTables::expr_ty_adjusted
  16: rustc_save_analysis::SaveContext::get_expr_data
  17: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_expr
  18: rustc_save_analysis::dump_visitor::DumpVisitor<O>::process_assoc_const
  19: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_item
  20: rustc_save_analysis::dump_visitor::DumpVisitor<O>::process_method
  21: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_item
  22: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_mod
  23: <rustc_save_analysis::DumpHandler as rustc_save_analysis::SaveHandler>::save
  24: rustc::dep_graph::graph::DepGraph::with_ignore
  25: rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}
  26: rustc::util::common::time
  27: rustc::ty::context::tls::enter_global
  28: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  29: rustc_interface::passes::create_global_ctxt::{{closure}}
  30: rustc_interface::passes::BoxedGlobalCtxt::enter
  31: rustc_interface::interface::run_compiler_in_existing_thread_pool
  32: std::thread::local::LocalKey<T>::with
  33: scoped_tls::ScopedKey<T>::set
  34: syntax::with_globals
query stack during panic:
end of query stack
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0425`.

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.36.0-nightly (a19cf18c7 2019-05-06) running on x86_64-apple-darwin

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

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

error: Could not compile `rlsrepro`.

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

I'm struggling to get a repro without the compile error, though.

Thank you for such a small repro! I’ll take a closer look tomorrow and see
what may be causing that.

On Tue, 7 May 2019 at 22:32, Sean Gillespie notifications@github.com
wrote:

Here's a small repro, extracted from what bitflags is doing:

struct BF { bits: u32 }

impl BF {

pub const F: BF = BF { bits: 0 };

pub const fn f() {

    trait _BF {

        const FLAG: u32 = 0;

    }



    impl _BF for BF {

        const FLAG: u32 = F.bits;

    }

}

}

â–¶ RUST_BACKTRACE=1 cargo +nightly rustc --lib -- -Zsave-analysis

Compiling rlsrepro v0.1.0 (/Users/swgillespie/Documents/workspace/rust/repros/rlsrepro)

error[E0425]: cannot find value F in this scope

--> src/lib.rs:11:31

|

11 | const FLAG: u32 = F.bits;

| ^ not found in this scope

error: internal compiler error: src/librustc/ty/context.rs:565: node_type: no type for node expr F (hir_id=HirId { owner: DefIndex(0:10), local_id: 2 })

thread 'rustc' panicked at 'Box', src/librustc_errors/lib.rs:643:9

note: Some details are omitted, run with RUST_BACKTRACE=full for a verbose backtrace.

stack backtrace:

0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace

1: std::sys_common::backtrace::_print

2: std::panicking::default_hook::{{closure}}

3: std::panicking::default_hook

4: rustc::util::common::panic_hook

5: std::panicking::rust_panic_with_hook

6: std::panicking::begin_panic

7: rustc_errors::Handler::bug

8: rustc::util::bug::opt_span_bug_fmt::{{closure}}

9: rustc::ty::context::tls::with_opt::{{closure}}

10: rustc::ty::context::tls::with_context_opt

11: rustc::ty::context::tls::with_opt

12: rustc::util::bug::opt_span_bug_fmt

13: rustc::util::bug::bug_fmt

14: rustc::ty::context::TypeckTables::node_type::{{closure}}

15: rustc::ty::context::TypeckTables::expr_ty_adjusted

16: rustc_save_analysis::SaveContext::get_expr_data

17: as syntax::visit::Visitor>::visit_expr

18: rustc_save_analysis::dump_visitor::DumpVisitor::process_assoc_const

19: as syntax::visit::Visitor>::visit_item

20: rustc_save_analysis::dump_visitor::DumpVisitor::process_method

21: as syntax::visit::Visitor>::visit_item

22: as syntax::visit::Visitor>::visit_mod

23: ::save

24: rustc::dep_graph::graph::DepGraph::with_ignore

25: rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}

26: rustc::util::common::time

27: rustc::ty::context::tls::enter_global

28: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}

29: rustc_interface::passes::create_global_ctxt::{{closure}}

30: rustc_interface::passes::BoxedGlobalCtxt::enter

31: rustc_interface::interface::run_compiler_in_existing_thread_pool

32: std::thread::local::LocalKey::with

33: scoped_tls::ScopedKey::set

34: syntax::with_globals

query stack during panic:

end of query stack

error: aborting due to 2 previous errors

For more information about this error, try rustc --explain E0425.

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.36.0-nightly (a19cf18c7 2019-05-06) running on x86_64-apple-darwin

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

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

error: Could not compile rlsrepro.

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

I'm struggling to get a repro without the compile error, though.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/rust-lang/rust/issues/59134#issuecomment-490243870,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAXTFXP5WJIJ5CT7FJWYBNTPUHRNNANCNFSM4G5NMYJA
.

Looks like ty::Err isn't written back for a resolution error?
@swgillespie That still repros without pub const F: BF = BF { bits: 0 };, right?

@swgillespie That still repros without pub const F: BF = BF { bits: 0 };, right?

Correct, it does. Further minimized repro:

fn bar() {
    struct Foo;
    trait FooT {
        const FLAG: u32;
    }

    impl FooT for Foo {
        const FLAG: u32 = bogus.baz;
    }
}

â–¶ RUST_BACKTRACE=1 rustc +dev -Z save-analysis --crate-type lib src/lib.rs
error[E0425]: cannot find value `bogus` in this scope
  --> src/lib.rs:26:27
   |
26 |         const FLAG: u32 = bogus.baz;
   |                           ^^^^^ not found in this scope

error: internal compiler error: src/librustc/ty/context.rs:262: node expr bogus.baz (hir_id=HirId { owner: DefIndex(0:8), local_id: 3 }) with HirId::owner DefId(0/0:8 ~ lib[8787]::bar[0]::{{impl}}[0]::FLAG[0]) cannot be placed in TypeckTables with local_id_root DefId(0/0:3 ~ lib[8787]::bar[0])

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:637:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
   1: std::sys_common::backtrace::print
   2: std::panicking::default_hook::{{closure}}
   3: std::panicking::default_hook
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::util::bug::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::util::bug::opt_span_bug_fmt
  13: rustc::util::bug::bug_fmt
  14: rustc::ty::context::validate_hir_id_for_typeck_tables::{{closure}}
  15: rustc::ty::context::tls::with::{{closure}}
  16: rustc::ty::context::tls::with_context::{{closure}}
  17: rustc::ty::context::tls::with_context_opt
  18: rustc::ty::context::tls::with_context
  19: rustc::ty::context::tls::with
  20: rustc::ty::context::TypeckTables::expr_adjustments
  21: rustc::ty::context::TypeckTables::expr_ty_adjusted_opt
  22: rustc_save_analysis::SaveContext::get_expr_data
  23: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_expr
  24: rustc_save_analysis::dump_visitor::DumpVisitor<O>::process_assoc_const
  25: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_item
  26: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_item
  27: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_mod
  28: syntax::visit::walk_crate
  29: <rustc_save_analysis::DumpHandler as rustc_save_analysis::SaveHandler>::save
  30: rustc::dep_graph::graph::DepGraph::with_ignore
  31: rustc_save_analysis::process_crate
  32: rustc_driver::run_compiler::{{closure}}::{{closure}}::{{closure}}
  33: rustc::util::common::time
  34: rustc::ty::context::tls::enter_global
  35: rustc_interface::passes::BoxedGlobalCtxt::access::{{closure}}
  36: rustc_interface::passes::create_global_ctxt::{{closure}}
  37: rustc_interface::passes::BoxedGlobalCtxt::enter
  38: rustc_interface::interface::run_compiler_in_existing_thread_pool
  39: std::thread::local::LocalKey<T>::with
  40: scoped_tls::ScopedKey<T>::set
  41: syntax::with_globals
query stack during panic:
end of query stack

Interesting. I managed to reduce it to:

fn func() {
    trait Trait {
        const CONST: u32 = bogus.field;
    }
}

with:

error[E0425]: cannot find value `bogus` in this scope                                                                                                                                                                                  
 --> src/lib.rs:3:28                                                                                                                                                                                                                   
  |                                                                                                                                                                                                                                    
3 |         const CONST: u32 = bogus.field;                                                                                                                                                                                            
  |                            ^^^^^ not found in this scope                                                                                                                                                                           

error: internal compiler error: src/librustc/ty/context.rs:262: node expr bogus.field (hir_id=HirId { owner: DefIndex(0:5), local_id: 6 }) with HirId::owner DefId(0/0:5 ~ b[6c41]::func[0]::Trait[0]::CONST[0]) cannot be placed in TypeckTables with local_id_root DefId(0/0:3 ~ b[6c41]::func[0]) 
...
  13: rustc::util::bug::bug_fmt
             at src/librustc/util/bug.rs:12
  14: rustc::ty::context::validate_hir_id_for_typeck_tables::{{closure}}
             at src/librustc/ty/context.rs:262
  15: rustc::ty::context::tls::with::{{closure}}
             at src/librustc/ty/context.rs:2101
  16: rustc::ty::context::tls::with_context::{{closure}}
             at src/librustc/ty/context.rs:2055
  17: rustc::ty::context::tls::with_context_opt
             at src/librustc/ty/context.rs:2045
  18: rustc::ty::context::tls::with_context
             at src/librustc/ty/context.rs:2055
  19: rustc::ty::context::tls::with
             at src/librustc/ty/context.rs:2101
  20: rustc::ty::context::TypeckTables::expr_adjustments
             at src/librustc/ty/context.rs:259
             at src/librustc/ty/context.rs:637
  21: rustc::ty::context::TypeckTables::expr_ty_adjusted_opt
             at src/librustc/ty/context.rs:650
  22: rustc_save_analysis::SaveContext::get_expr_data
             at src/librustc_save_analysis/lib.rs:518
  23: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_expr                                                                                                                                        
             at src/librustc_save_analysis/dump_visitor.rs:1548                                                                                                                                                                        
  24: rustc_save_analysis::dump_visitor::DumpVisitor<O>::process_assoc_const                                                                                                                                                           
             at src/librustc_save_analysis/dump_visitor.rs:468                                                                                                                                                                         
  25: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_item                                                                                                                                        
             at src/librustc_save_analysis/dump_visitor.rs:1085                                                                                                                                                                        
             at src/librustc_save_analysis/dump_visitor.rs:765                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:1401                                                                                                                                                                        
  26: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_item                                                                                                                                        
             at /home/xanewok/repos/rust/src/libsyntax/visit.rs:649                                                                                                                                                                    
             at src/librustc_save_analysis/dump_visitor.rs:1630                                                                                                                                                                        
             at /home/xanewok/repos/rust/src/libsyntax/visit.rs:171                                                                                                                                                                    
             at /home/xanewok/repos/rust/src/libsyntax/visit.rs:67                                                                                                                                                                     
             at src/librustc_save_analysis/dump_visitor.rs:408                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:118                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:408                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:131                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:408                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:1389                                                                                                                                                                        
  27: <rustc_save_analysis::dump_visitor::DumpVisitor<O> as syntax::visit::Visitor>::visit_mod                                                                                                                                         
             at /home/xanewok/repos/rust/src/libsyntax/visit.rs:171                                                                                                                                                                    
             at src/librustc_save_analysis/dump_visitor.rs:1350                                                                                                                                                                        
             at src/librustc_save_analysis/dump_visitor.rs:118                                                                                                                                                                         
             at src/librustc_save_analysis/dump_visitor.rs:1350  

Any other combination is okay, it has to be const under trait under fn and it has to be combined with a field access (bare unknown identifier doesn't ICE).

I'm only guessing but it seems that it tries to emplace b[6c41]::func[0]::Trait[0]::CONST[0] def 'path' under a b[6c41]::func[0] which seems to skip a Trait def path segment?

I think this is confirmed by https://github.com/rust-lang/rust/blob/c3694e5ee69247eb1ac10c6d3b187f567303dc8d/src/librustc/ty/context.rs#L246-L266

A, what I believe is, more accurate guess is that we somehow don't correctly nest appropriate typeck tables when visiting mod > fn > trait > assoc_const.

Oh, you need to have one table per body: look in HIR for BodyId fields and map all of those cases back to the AST.

This makes a lot more sense now: so rustc_typeck is not wrong, but rustc_save_analysis is looking in the wrong place.

What about this:

--- a/src/librustc_save_analysis/dump_visitor.rs
+++ b/src/librustc_save_analysis/dump_visitor.rs
@@ -465,7 +465,7 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> DumpVisitor<'l, 'tcx, 'll, O> {
         // walk type and init value
         self.visit_ty(typ);
         if let Some(expr) = expr {
-            self.visit_expr(expr);
+            self.nest_tables(id, |v| v.visit_expr(expr));
         }

Seems like we need to nest_tables before walking the expression of the associated const?

Hm, probably! I imagined the problem is we don't nest it before visiting trait items (hence missing Trait segment) but you may be right! Let's see :sweat_smile:

With the fix applied this still ICEs on (this time for type)

fn func() {
    trait Trait {
        type MyType;
        const CONST: Self::MyType = bogus.field;
    }
}

which means we should nest tables for visit_ty as well

Was this page helpful?
0 / 5 - 0 ratings