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

ICE in traits using lifetime elision #56729

Closed
OtaK opened this issue Dec 11, 2018 · 4 comments
Closed

ICE in traits using lifetime elision #56729

OtaK opened this issue Dec 11, 2018 · 4 comments
Labels
A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@OtaK
Copy link

OtaK commented Dec 11, 2018

Hello,

The compiler panics when using this code:

pub struct TriggerICE<'a>(&'a str);
impl From<String> for TriggerICE<'_> {
    fn from(s: String) -> Self {
        TriggerICE(&s)
    }
}

You can check it out on the playground here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=75ef6a4515e975e3ffafcd17373aa8b4

Thanks,

Have a good day

Meta

rustc --version --verbose:

rustc 1.31.0 (abe02cefd 2018-12-04)
binary: rustc
commit-hash: abe02cefd6cd1916df62ad7dc80161bea50b72e8
commit-date: 2018-12-04
host: x86_64-apple-darwin
release: 1.31.0
LLVM version: 8.0

Backtrace:

   Compiling playground v0.0.1 (/playground)
error: internal compiler error: librustc/hir/map/mod.rs:816: expected expr, found method from in <TriggerICE<'_> as std::convert::From<std::string::String>>::from (id=28)

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:600:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:211
   3: std::panicking::default_hook
             at libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:480
   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::map::Map::expect_expr
  15: rustc_mir::borrow_check::nll::region_infer::error_reporting::region_name::<impl rustc_mir::borrow_check::nll::region_infer::RegionInferenceContext<'tcx>>::give_region_a_name
  16: rustc_mir::borrow_check::nll::region_infer::error_reporting::<impl rustc_mir::borrow_check::nll::region_infer::RegionInferenceContext<'tcx>>::free_region_constraint_info
  17: rustc_mir::borrow_check::nll::explain_borrow::<impl rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx>>::explain_why_borrow_contains_point
  18: rustc_mir::borrow_check::error_reporting::<impl rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx>>::report_borrowed_value_does_not_live_long_enough
  19: rustc_mir::borrow_check::path_utils::each_borrow_involving_path
  20: rustc_mir::borrow_check::MirBorrowckCtxt::access_place
  21: <rustc_mir::borrow_check::MirBorrowckCtxt<'cx, 'gcx, 'tcx> as rustc_mir::dataflow::DataflowResultsConsumer<'cx, 'tcx>>::visit_terminator_entry
  22: rustc_mir::borrow_check::do_mir_borrowck
  23: rustc::ty::context::tls::with_related_context
  24: rustc::infer::InferCtxtBuilder::enter
  25: rustc_mir::borrow_check::mir_borrowck
  26: rustc::ty::query::__query_compute::mir_borrowck
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_borrowck<'tcx>>::compute
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  30: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  32: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_borrowck
  33: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
  34: rustc::util::common::time
  35: rustc::ty::context::tls::enter_context
  36: <std::thread::local::LocalKey<T>>::with
  37: rustc::ty::context::TyCtxt::create_and_enter
  38: rustc_driver::driver::compile_input
  39: rustc_driver::run_compiler_with_pool
  40: rustc_driver::driver::spawn_thread_pool
  41: rustc_driver::run_compiler
  42: <scoped_tls::ScopedKey<T>>::set
  43: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  44: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  45: rustc_driver::run
  46: rustc_driver::main
  47: std::rt::lang_start::{{closure}}
  48: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:310
  49: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:102
  50: std::rt::lang_start_internal
             at libstd/panicking.rs:289
             at libstd/panic.rs:392
             at libstd/rt.rs:58
  51: main
  52: __libc_start_main
  53: <unknown>
query stack during panic:
#0 [mir_borrowck] processing `<TriggerICE<'_> as std::convert::From<std::string::String>>::from`
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.31.0 (abe02cefd 2018-12-04) running on x86_64-unknown-linux-gnu

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

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

error: Could not compile `playground`.

To learn more, run the command again with --verbose.
@QuietMisdreavus QuietMisdreavus added A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-NLL Area: Non-lexical lifetimes (NLL) labels Dec 11, 2018
@QuietMisdreavus
Copy link
Member

According to the playground link, it looks like this has been fixed in beta and nightly.

@OtaK
Copy link
Author

OtaK commented Dec 11, 2018

I should add that this code triggers the correct behavior on stable:

pub struct TriggerICE<'a>(&'a str);
impl<'a> From<String> for TriggerICE<'a> {
    fn from(s: String) -> Self {
        TriggerICE(&s)
    }
}

-->

   Compiling playground v0.0.1 (/playground)
error[E0515]: cannot return value referencing function parameter `s`
 --> src/main.rs:4:9
  |
4 |         TriggerICE(&s)
  |         ^^^^^^^^^^^--^
  |         |          |
  |         |          `s` is borrowed here
  |         returns a value referencing data owned by the current function

error: aborting due to previous error

For more information about this error, try `rustc --explain E0515`.
error: Could not compile `playground`.

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

Also, as Q noted above, it has been fixed altogether on beta and nightly channels indeed.

@pnkfelix pnkfelix added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Dec 12, 2018
@pnkfelix
Copy link
Member

i put "needstest" but actually this might just be a dupe of #55394, which would probably mean that the test added for PR #55822 suffices...

@pnkfelix
Copy link
Member

yeah, reviewing PR #55822 and this code, my takeaway is that the test in #55822 suffices.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions A-NLL Area: Non-lexical lifetimes (NLL) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

3 participants