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

Cannot use explicit lifetime in call to mem::size_of #77064

Closed
zakcutner opened this issue Sep 22, 2020 · 2 comments
Closed

Cannot use explicit lifetime in call to mem::size_of #77064

zakcutner opened this issue Sep 22, 2020 · 2 comments
Labels
C-bug Category: This is a bug. 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.

Comments

@zakcutner
Copy link

Hello! I've tried to search for this error in the open issues but couldn't find anything, sorry if I've missed something. Below is a minimal example of the issue — it is to do with using an explicit &'a lifetime in the call to mem::size_of. If I replace the call with mem::size_of::<&i32>() (notice & rather than &'a), it compiles without any errors.

Code

use std::mem;

struct Foo(Box<[u8]>);

impl<'a> From<&'a i32> for Foo {
    fn from(value: &'a i32) -> Self {
        let value = unsafe { mem::transmute::<_, [u8; mem::size_of::<&'a i32>()]>(value) };
        Self(Box::new(value))
    }
}

Meta

rustc --version --verbose:

rustc 1.46.0 (04488afe3 2020-08-24)
binary: rustc
commit-hash: 04488afe34512aa4c33566eb16d8c912a3ae04f9
commit-date: 2020-08-24
host: x86_64-apple-darwin
release: 1.46.0
LLVM version: 10.0

Error output

error: internal compiler error: src/librustc_mir/borrow_check/universal_regions.rs:767:36: cannot convert `ReEarlyBound(0, 'a)` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:916: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.46.0 (04488afe3 2020-08-24) running on x86_64-apple-darwin

error: aborting due to previous error
Backtrace

error: internal compiler error: src/librustc_mir/borrow_check/universal_regions.rs:767:36: cannot convert `ReEarlyBound(0, 'a)` to a region vid

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:916:9
stack backtrace:
   0: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
   1: core::fmt::write
   2: std::io::Write::write_fmt
   3: std::panicking::default_hook::{{closure}}
   4: std::panicking::default_hook
   5: rustc_driver::report_ice
   6: std::panicking::rust_panic_with_hook
   7: std::panicking::begin_panic
   8: rustc_errors::HandlerInner::bug
   9: rustc_errors::Handler::bug
  10: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
  11: rustc_middle::ty::context::tls::with_opt::{{closure}}
  12: rustc_middle::ty::context::tls::with_opt
  13: rustc_middle::util::bug::opt_span_bug_fmt
  14: rustc_middle::util::bug::bug_fmt
  15: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid::{{closure}}
  16: rustc_mir::borrow_check::universal_regions::UniversalRegionIndices::to_region_vid
  17: rustc_mir::borrow_check::type_check::constraint_conversion::ConstraintConversion::convert_all
  18: rustc_mir::borrow_check::type_check::type_check
  19: rustc_mir::borrow_check::nll::compute_regions
  20: rustc_mir::borrow_check::do_mir_borrowck
  21: rustc_infer::infer::InferCtxtBuilder::enter
  22: rustc_mir::borrow_check::mir_borrowck
  23: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_borrowck>::compute
  24: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  25: rustc_data_structures::stack::ensure_sufficient_stack
  26: rustc_query_system::query::plumbing::get_query_impl
  27: rustc_query_system::query::plumbing::ensure_query_impl
  28: rustc_mir::transform::mir_drops_elaborated_and_const_checked
  29: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::mir_drops_elaborated_and_const_checked>::compute
  30: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  31: rustc_data_structures::stack::ensure_sufficient_stack
  32: rustc_query_system::query::plumbing::get_query_impl
  33: rustc_mir::transform::optimized_mir
  34: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::optimized_mir>::compute
  35: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  36: rustc_data_structures::stack::ensure_sufficient_stack
  37: rustc_query_system::query::plumbing::get_query_impl
  38: rustc_mir::interpret::eval_context::InterpCx<M>::load_mir
  39: rustc_mir::const_eval::eval_queries::const_eval_raw_provider
  40: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_raw>::compute
  41: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  42: rustc_data_structures::stack::ensure_sufficient_stack
  43: rustc_query_system::query::plumbing::get_query_impl
  44: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  45: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_validated>::compute
  46: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  47: rustc_data_structures::stack::ensure_sufficient_stack
  48: rustc_query_system::query::plumbing::get_query_impl
  49: rustc_mir::const_eval::eval_queries::const_eval_validated_provider
  50: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::const_eval_validated>::compute
  51: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  52: rustc_data_structures::stack::ensure_sufficient_stack
  53: rustc_query_system::query::plumbing::get_query_impl
  54: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_global_id
  55: rustc_middle::mir::interpret::queries::<impl rustc_middle::ty::context::TyCtxt>::const_eval_resolve
  56: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_const
  57: <rustc_trait_selection::traits::project::AssocTypeNormalizer as rustc_middle::ty::fold::TypeFolder>::fold_ty
  58: rustc_data_structures::stack::ensure_sufficient_stack
  59: rustc_trait_selection::traits::project::normalize
  60: <rustc_infer::infer::InferCtxt as rustc_trait_selection::infer::InferCtxtExt>::partially_normalize_associated_types_in
  61: <rustc_typeck::check::FnCtxt as rustc_typeck::astconv::AstConv>::normalize_ty
  62: <dyn rustc_typeck::astconv::AstConv>::ast_ty_to_ty
  63: <dyn rustc_typeck::astconv::AstConv>::create_substs_for_generic_args
  64: rustc_typeck::check::FnCtxt::instantiate_value_path
  65: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  66: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation
  67: rustc_typeck::check::callee::<impl rustc_typeck::check::FnCtxt>::check_call
  68: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  69: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation
  70: rustc_typeck::check::FnCtxt::check_block_with_expected
  71: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  72: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation
  73: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_coercable_to_type
  74: rustc_typeck::check::FnCtxt::check_decl_local
  75: rustc_typeck::check::FnCtxt::check_stmt
  76: rustc_typeck::check::FnCtxt::check_block_with_expected
  77: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_kind
  78: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_expr_with_expectation
  79: rustc_typeck::check::expr::<impl rustc_typeck::check::FnCtxt>::check_return_expr
  80: rustc_typeck::check::check_fn
  81: rustc_infer::infer::InferCtxtBuilder::enter
  82: rustc_typeck::check::typeck_tables_of
  83: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_tables_of>::compute
  84: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  85: rustc_data_structures::stack::ensure_sufficient_stack
  86: rustc_query_system::query::plumbing::get_query_impl
  87: rustc_query_system::query::plumbing::ensure_query_impl
  88: rustc_typeck::check::typeck_item_bodies
  89: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::typeck_item_bodies>::compute
  90: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  91: rustc_data_structures::stack::ensure_sufficient_stack
  92: rustc_query_system::query::plumbing::get_query_impl
  93: rustc_typeck::check_crate
  94: rustc_interface::passes::analysis
  95: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  96: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  97: rustc_query_system::query::plumbing::get_query_impl
  98: rustc_middle::ty::context::tls::enter_global
  99: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
 100: rustc_span::with_source_map
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.46.0 (04488afe3 2020-08-24) running on x86_64-apple-darwin

query stack during panic:
#0 [mir_borrowck] borrow-checking `<Foo as std::convert::From<&'a i32>>::from::{{constant}}#0`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `<Foo as std::convert::From<&'a i32>>::from::{{constant}}#0`
#2 [optimized_mir] optimizing MIR for `<Foo as std::convert::From<&'a i32>>::from::{{constant}}#0`
#3 [const_eval_raw] const-evaluating `<Foo as std::convert::From<&'a i32>>::from::{{constant}}#0`
#4 [const_eval_validated] const-evaluating + checking `<Foo as std::convert::From<&'a i32>>::from::{{constant}}#0`
#5 [const_eval_validated] const-evaluating + checking `<Foo as std::convert::From<&'a i32>>::from::{{constant}}#0`
#6 [typeck_tables_of] type-checking `<Foo as std::convert::From<&'a i32>>::from`
#7 [typeck_item_bodies] type-checking all item bodies
#8 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

@zakcutner zakcutner added C-bug Category: This is a bug. 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. labels Sep 22, 2020
@zakcutner
Copy link
Author

Using Godbolt, it looks like this bug has been around since 1.19. Before that, this example wouldn't compile because mem::size_of was not callable inside a constant context.

@jonas-schievink
Copy link
Contributor

Duplicate of #43408

@jonas-schievink jonas-schievink marked this as a duplicate of #43408 Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. 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.
Projects
None yet
Development

No branches or pull requests

2 participants