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

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

Closed
arturoc opened this issue Mar 12, 2019 · 21 comments · Fixed by #60649
Closed

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

arturoc opened this issue Mar 12, 2019 · 21 comments · Fixed by #60649
Assignees
Labels
A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue.

Comments

@arturoc
Copy link
Contributor

arturoc commented Mar 12, 2019

When using this branch of bitflags: bitflags/bitflags#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
@jonas-schievink jonas-schievink added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. labels Mar 12, 2019
@Xanewok Xanewok added the A-rls label Mar 13, 2019
@Xanewok
Copy link
Member

Xanewok commented Mar 13, 2019

...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.

@arturoc
Copy link
Contributor Author

arturoc commented Mar 13, 2019

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

@jonas-schievink
Copy link
Contributor

This is now causing widespread ICEs in the RLS. Nominating to get this fixed (maybe @Xanewok has an idea?). See #60484 (comment) for a simpler reproducer.

@jonas-schievink jonas-schievink added the T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue. label May 4, 2019
@leonsenft
Copy link

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 #60484 (comment).

@jonas-schievink jonas-schievink changed the title rls crash RLS ICE: "node_type: no type for node" when building bitflags May 5, 2019
@TheJare
Copy link

TheJare commented May 5, 2019

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)

@hcrohland
Copy link

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

@TheJare

This comment has been minimized.

@leonsenft
Copy link

Thanks @hcrohland !

@nishtahir
Copy link

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

@wrenger
Copy link

wrenger commented May 6, 2019

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

@mati865
Copy link
Contributor

mati865 commented May 6, 2019

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

@swgillespie
Copy link
Contributor

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.

@Xanewok
Copy link
Member

Xanewok commented May 7, 2019 via email

@eddyb
Copy link
Member

eddyb commented May 8, 2019

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
Copy link
Contributor

swgillespie commented May 8, 2019

@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

@Xanewok
Copy link
Member

Xanewok commented May 8, 2019

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?

@Xanewok
Copy link
Member

Xanewok commented May 8, 2019

I think this is confirmed by

/// Validate that the given HirId (respectively its `local_id` part) can be
/// safely used as a key in the tables of a TypeckTable. For that to be
/// the case, the HirId must have the same `owner` as all the other IDs in
/// this table (signified by `local_id_root`). Otherwise the HirId
/// would be in a different frame of reference and using its `local_id`
/// would result in lookup errors, or worse, in silently wrong data being
/// stored/returned.
fn validate_hir_id_for_typeck_tables(local_id_root: Option<DefId>,
hir_id: hir::HirId,
mut_access: bool) {
if cfg!(debug_assertions) {
if let Some(local_id_root) = local_id_root {
if hir_id.owner != local_id_root.index {
ty::tls::with(|tcx| {
let node_id = tcx.hir().hir_to_node_id(hir_id);
bug!("node {} with HirId::owner {:?} cannot be placed in \
TypeckTables with local_id_root {:?}",
tcx.hir().node_to_string(node_id),
DefId::local(hir_id.owner),
local_id_root)

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.

@eddyb
Copy link
Member

eddyb commented May 8, 2019

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.

@swgillespie
Copy link
Contributor

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?

@Xanewok
Copy link
Member

Xanewok commented May 8, 2019

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 😅

@Xanewok
Copy link
Member

Xanewok commented May 8, 2019

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

@nikomatsakis nikomatsakis added P-high High priority and removed I-nominated labels May 9, 2019
bors added a commit that referenced this issue May 13, 2019
save-analysis: Fix ICE when processing associated constant

Closes #59134
Closes rust-lang/rls#1449

Thanks @swgillespie for helping tracking this down and fixing it!

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-save-analysis Area: saving results of analyses such as inference and borrowck results to a file. C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-dev-tools Relevant to the dev-tools subteam, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.