rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.34k stars 12.72k forks source link

error: internal compiler error: src/librustc/hir/def.rs:265: attempted .def_id() on invalid def #56202

Closed TheIronBorn closed 5 years ago

TheIronBorn commented 5 years ago

error: internal compiler error: src/librustc/hir/def.rs:265: attempted .def_id() on invalid def: <err>

thread 'main' panicked at 'Box<Any>', src/librustc_errors/lib.rs:600:9
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::hir::def::Def::def_id::{{closure}}
  15: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  16: rustc::hir::intravisit::walk_expr
  17: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  18: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  19: rustc::middle::reachable::reachable_set
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::reachable_set<'tcx>>::compute
  21: rustc::dep_graph::graph::DepGraph::with_task_impl
  22: rustc::ty::context::tls::with_related_context
  23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  25: rustc_codegen_ssa::back::symbol_export::reachable_non_generics_provider
  26: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::reachable_non_generics<'tcx>>::compute
  27: rustc::dep_graph::graph::DepGraph::with_task_impl
  28: rustc::ty::context::tls::with_related_context
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  31: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  32: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::exported_symbols<'tcx>>::compute
  33: rustc::dep_graph::graph::DepGraph::with_task_impl
  34: rustc::ty::context::tls::with_related_context
  35: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  36: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  37: rustc_metadata::encoder::encode_metadata
  38: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
  39: rustc::ty::context::TyCtxt::encode_metadata
  40: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::write_metadata
  41: rustc::util::common::time
  42: rustc_codegen_ssa::base::codegen_crate
  43: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  44: rustc::util::common::time
  45: rustc_driver::driver::phase_4_codegen
  46: rustc_driver::driver::compile_input::{{closure}}
  47: rustc::ty::context::tls::enter_context
  48: <std::thread::local::LocalKey<T>>::with
  49: rustc::ty::context::TyCtxt::create_and_enter
  50: rustc_driver::driver::compile_input
  51: rustc_driver::run_compiler_with_pool
  52: <scoped_tls::ScopedKey<T>>::set
  53: rustc_driver::run_compiler
  54: syntax::with_globals
  55: __rust_maybe_catch_panic
  56: rustc_driver::run
  57: rustc_driver::main
  58: std::rt::lang_start::{{closure}}
  59: std::panicking::try::do_call
  60: __rust_maybe_catch_panic
  61: std::rt::lang_start_internal
  62: main
query stack during panic:
#0 [reachable_set] reachability
#1 [reachable_non_generics] looking up the exported symbols of a crate
#2 [exported_symbols] exported_symbols
end of query stack
error: aborting due to previous error

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.32.0-nightly (1f57e4841 2018-11-23) running on x86_64-apple-darwin

note: compiler flags: -C opt-level=3 -C target-cpu=native -C lto=thin --crate-type lib

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

error: Could not compile <crate>.
estebank commented 5 years ago

Could you post a repro case?

I believe the ICE can be fixed by adding an explicit match arm in

https://github.com/rust-lang/rust/blob/4632cf2a2e8c1720e3ae06920d945c4ac8ecbbd3/src/librustc/middle/reachable.rs#L115

            Some(Def::Err) => {}  // #56202: calling `def.def_id()` would be an error
TheIronBorn commented 5 years ago

I've got no idea where to start for reproducing it. I was compiling a crate I haven't worked on in a while, so I don't know if it's a change in source code or a change in Rust which first triggered it.

TheIronBorn commented 5 years ago

It also occurs with compiler flags: -C debuginfo=2 -C incremental --crate-type lib

estebank commented 5 years ago

Can you check using older stable compilers in order to verify wether this is a stable-to-stable or stable-to-nightly regression?

estebank commented 5 years ago

The line in my prior comment should be enough to fix the problem, but we'll need a repro to be able to close the ticket.

TheIronBorn commented 5 years ago

rustc 1.32.0-nightly (5aff30734 2018-11-19) is the first on which I see the error.


error: internal compiler error: librustc/hir/def.rs:265: attempted .def_id() on invalid def:

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:600:9
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::hir::def::Def::def_id::{{closure}}
  15: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  16: rustc::hir::intravisit::walk_expr
  17: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  18: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  19: rustc::middle::reachable::reachable_set
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::reachable_set<'tcx>>::compute
  21: rustc::ty::context::tls::with_context
  22: rustc::dep_graph::graph::DepGraph::with_task_impl
  23: rustc::ty::context::tls::with_related_context
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  26: rustc_codegen_ssa::back::symbol_export::reachable_non_generics_provider
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::reachable_non_generics<'tcx>>::compute
  28: rustc::ty::context::tls::with_context
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::context::tls::with_related_context
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  33: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  34: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::exported_symbols<'tcx>>::compute
  35: rustc::ty::context::tls::with_context
  36: rustc::dep_graph::graph::DepGraph::with_task_impl
  37: rustc::ty::context::tls::with_related_context
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  40: rustc_metadata::encoder::encode_metadata
  41: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
  42: rustc::ty::context::TyCtxt::encode_metadata
  43: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::write_metadata
  44: rustc::util::common::time
  45: rustc_codegen_ssa::base::codegen_crate
  46: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  47: rustc::util::common::time
  48: rustc_driver::driver::phase_4_codegen
  49: rustc_driver::driver::compile_input::{{closure}}
  50: rustc::ty::context::tls::enter_context
  51: <std::thread::local::LocalKey<T>>::with
  52: rustc::ty::context::TyCtxt::create_and_enter
  53: rustc_driver::driver::compile_input
  54: rustc_driver::run_compiler_with_pool
  55: <scoped_tls::ScopedKey<T>>::set
  56: rustc_driver::run_compiler
  57: syntax::with_globals
  58: __rust_maybe_catch_panic
  59: rustc_driver::run
  60: rustc_driver::main
  61: std::rt::lang_start::{{closure}}
  62: std::panicking::try::do_call
  63: __rust_maybe_catch_panic
  64: std::rt::lang_start_internal
  65: main
query stack during panic:
#0 [reachable_set] reachability
#1 [reachable_non_generics] looking up the exported symbols of a crate
#2 [exported_symbols] exported_symbols
end of query stack
error: aborting due to previous error

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.32.0-nightly (5aff30734 2018-11-19) 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

error: Could not compile `rng_av`.
TheIronBorn commented 5 years ago

I can't test stable compilers as I'm using nightly features

TheIronBorn commented 5 years ago

I've managed to narrow it down to self_struct_ctor

TheIronBorn commented 5 years ago

a semi-minimal example:


#![feature(self_struct_ctor)]

use packed_simd::*;

pub trait Bar {
    fn foo(rng: &mut impl rand::Rng) -> Self;
}

pub struct Foo(u8x16);

impl Bar for Foo {
    fn foo(rng: &mut impl rand::Rng) -> Self {
        Self(u8x16::default())
    }
}
TheIronBorn commented 5 years ago

error: internal compiler error: librustc/hir/def.rs:265: attempted .def_id() on invalid def:

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:600:9
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::hir::def::Def::def_id::{{closure}}
  15: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  16: rustc::hir::intravisit::walk_expr
  17: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  18: <rustc::middle::reachable::ReachableContext<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_expr
  19: rustc::middle::reachable::reachable_set
  20: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::reachable_set<'tcx>>::compute
  21: rustc::ty::context::tls::with_context
  22: rustc::dep_graph::graph::DepGraph::with_task_impl
  23: rustc::ty::context::tls::with_related_context
  24: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  25: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  26: rustc_codegen_ssa::back::symbol_export::reachable_non_generics_provider
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::reachable_non_generics<'tcx>>::compute
  28: rustc::ty::context::tls::with_context
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::context::tls::with_related_context
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  33: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  34: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::exported_symbols<'tcx>>::compute
  35: rustc::ty::context::tls::with_context
  36: rustc::dep_graph::graph::DepGraph::with_task_impl
  37: rustc::ty::context::tls::with_related_context
  38: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  40: rustc_metadata::encoder::encode_metadata
  41: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata
  42: rustc::ty::context::TyCtxt::encode_metadata
  43: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::write_metadata
  44: rustc::util::common::time
  45: rustc_codegen_ssa::base::codegen_crate
  46: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  47: rustc::util::common::time
  48: rustc_driver::driver::phase_4_codegen
  49: rustc_driver::driver::compile_input::{{closure}}
  50: rustc::ty::context::tls::enter_context
  51: <std::thread::local::LocalKey<T>>::with
  52: rustc::ty::context::TyCtxt::create_and_enter
  53: rustc_driver::driver::compile_input
  54: rustc_driver::run_compiler_with_pool
  55: <scoped_tls::ScopedKey<T>>::set
  56: rustc_driver::run_compiler
  57: syntax::with_globals
  58: __rust_maybe_catch_panic
  59: rustc_driver::run
  60: rustc_driver::main
  61: std::rt::lang_start::{{closure}}
  62: std::panicking::try::do_call
  63: __rust_maybe_catch_panic
  64: std::rt::lang_start_internal
  65: main
query stack during panic:
#0 [reachable_set] reachability
#1 [reachable_non_generics] looking up the exported symbols of a crate
#2 [exported_symbols] exported_symbols
end of query stack
error: aborting due to previous error

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.32.0-nightly (5aff30734 2018-11-19) 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

error: Could not compile `test_indexing`.
TheIronBorn commented 5 years ago

better:


#![feature(self_struct_ctor)]

trait FooTrait {}

trait BarTrait {
    fn foo<T: FooTrait>(_: T) -> Self;
}

struct FooStruct(u32);

impl BarTrait for FooStruct {
    fn foo<T: FooTrait>(_: T) -> Self {
        Self(u32::default())
    }
}
burjui commented 5 years ago

Another one, just in case:

#![feature(self_struct_ctor)]
#![no_main]

pub struct Foo<T>(T);

impl<T> From<T> for Foo<T> {
    fn from(value: T) -> Self {
        Self(value)
    }
}

rustc 1.32.0-nightly (edaac35d6 2018-11-24) running on x86_64-unknown-linux-gnu

davidtwco commented 5 years ago

Closing as #56205 has fixed this.