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

Compiler crash when dealing with Any and Ref #60622

Closed
whoiscc opened this issue May 7, 2019 · 9 comments · Fixed by #60892
Closed

Compiler crash when dealing with Any and Ref #60622

whoiscc opened this issue May 7, 2019 · 9 comments · Fixed by #60892
Assignees
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@whoiscc
Copy link

whoiscc commented May 7, 2019

use std::cell::{RefCell, Ref};
use std::any::Any;

trait Foo: Any + AsAny {
    //
}

trait AsAny {
    fn as_any(&self) -> &dyn Any;
}

impl<T: Foo> AsAny for T {
    fn as_any(&self) -> &dyn Any {
        self
    }
}

fn demo<'a, T: 'static>(cell: &'a RefCell<dyn Foo>) -> Option<&T> {
    // this causes compile error correctly
    // let x: Ref<'a, _> = cell.borrow();
    let x = cell.borrow::<'a, _>();
    x.as_any().downcast_ref::<T>()
}

fn main() {
    //
}

Compiler crashes with

warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
   --> src/main.rs:58:27
    |
58  |     let x = cell.borrow::<'a, _>();
    |                           ^^
    |
    = note: #[warn(late_bound_lifetime_arguments)] on by default
    = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
    = note: for more information, see issue #42868 <https://github.com/rust-lang/rust/issues/42868>

error: internal compiler error: src/librustc_typeck/check/mod.rs:2461: no type for node 121: type _ (id=121) in fcx 0x70000a15f458

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:620: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_typeck::check::FnCtxt::node_ty
  15: <rustc_typeck::check::writeback::WritebackCx<'cx, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_ty
  16: rustc::hir::intravisit::walk_expr
  17: <rustc_typeck::check::writeback::WritebackCx<'cx, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr
  18: <rustc_typeck::check::writeback::WritebackCx<'cx, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_local
  19: rustc::hir::intravisit::walk_expr
  20: <rustc_typeck::check::writeback::WritebackCx<'cx, 'gcx, 'tcx> as rustc::hir::intravisit::Visitor<'gcx>>::visit_expr
  21: rustc_typeck::check::writeback::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::resolve_type_vars_in_body
  22: rustc::ty::context::GlobalCtxt::enter_local
  23: rustc_typeck::check::typeck_tables_of
  24: rustc::ty::query::__query_compute::typeck_tables_of
  25: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute
  26: rustc::dep_graph::graph::DepGraph::with_task_impl
  27: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  28: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
  29: rustc_typeck::check::typeck_item_bodies
  30: rustc::ty::query::__query_compute::typeck_item_bodies
  31: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute
  32: rustc::dep_graph::graph::DepGraph::with_task_impl
  33: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  34: rustc::util::common::time
  35: rustc_typeck::check_crate
  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: <scoped_tls::ScopedKey<T>>::set
  41: rustc_driver::run_compiler
  42: syntax::with_globals
  43: __rust_maybe_catch_panic
  44: <F as alloc::boxed::FnBox<A>>::call_box
  45: std::sys::unix::thread::Thread::new::thread_start
  46: _pthread_body
  47: _pthread_start
query stack during panic:
#0 [typeck_tables_of] processing `demo`
#1 [typeck_item_bodies] type-checking all item bodies
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.34.1 (fc50f328b 2019-04-24) running on x86_64-apple-darwin

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

Also, I wonder what is the right way (or is there any way) to write a demo with expected behavior. Thanks.

@Centril
Copy link
Contributor

Centril commented May 8, 2019

Reduced:

trait Any {}

trait AsAny {
    fn as_any(self);
}

impl<T> AsAny for T where T: Any + AsAny {
    fn as_any(self) {}
}

impl dyn AsAny {
    fn borrow<'a>(&'a self) -> &'a dyn AsAny {
        self
    }
}

fn demo<'a>(cell: &'a (dyn AsAny + 'static)) {
    cell.borrow::<'a, _>().as_any();
}

@Centril Centril 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. I-nominated regression-from-stable-to-beta Performance or correctness regression from stable to beta. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-from-stable-to-beta Performance or correctness regression from stable to beta. labels May 8, 2019
@Centril
Copy link
Contributor

Centril commented May 8, 2019

Regression first occurred in 1.30 according to godbolt.

@hellow554
Copy link
Contributor

One can leave out the Any trait in your MCVE, still crashes.

Bug was introduced somewhere between 33b923f...63d6649
Sadly that's a very big range, but there are no nightlys available in between and also no bors artifacts because they are older than 167

@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label May 8, 2019
@nikomatsakis
Copy link
Contributor

triage: P-high

@nikomatsakis nikomatsakis added P-high High priority and removed I-nominated labels May 9, 2019
@jonas-schievink
Copy link
Contributor

Smaller example from #60842:

fn run_wild<T, DL: Borked<T>>(dl: &DL) {
    dl.a::<'_, T>();
}

pub trait Borked<T> {
    fn a(&self);
}

fn main() {}

@AlterionX
Copy link

AlterionX commented May 14, 2019

I was trying to remove as many type parameters as possible, and ended up with this:

struct Borked {}
impl Borked {
    fn a(&self) {}
}

fn run_wild<T>(b: &Borked) {
    b.a::<'_, T>();
}

Removing <T> after run_wild still cuases an ICE. Adding a <T> after a stops causing the ICE. Removing the '_ also stops causing the ICE.

Not sure if it's any more or less helpful, but just putting this here.

@davidtwco
Copy link
Member

davidtwco commented May 16, 2019

@rustbot claim

Looks like that didn't work, either way, I'm taking a look into this issue.

@rustbot
Copy link
Collaborator

rustbot commented May 16, 2019

Error: The feature assign is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please let @rust-lang/release know if you're having trouble with this bot.

1 similar comment
@rustbot
Copy link
Collaborator

rustbot commented May 16, 2019

Error: The feature assign is not enabled in this repository.
To enable it add its section in the triagebot.toml in the root of the repository.

Please let @rust-lang/release know if you're having trouble with this bot.

bors added a commit that referenced this issue May 17, 2019
Checking generic args after late bound region err.

Fixes #60622.

This PR fixes an ICE that occurs when a late bound region error is
emitted and that resulted in the rest of the generic arguments of a
function not being checked.

For example, you could specify a generic type parameter `T` in a function
call `foo<'_, T>()` to a function that doesn't have a generic type
parameter.

Since an error wasn't emitted from the function, compilation
continued to parts of typeck that didn't expect a generic type argument
in a call for a function that didn't have any generic type arguments.
Manishearth added a commit to Manishearth/rust that referenced this issue May 17, 2019
…Mark-Simulacrum

Allow claiming issues with triagebot

Not sure if this was intentionally left out, but it can probably be enabled now that rust-lang/triagebot#3 is fixed (assuming that the deployed commit is recent enough). People have tried to use it already (rust-lang#60622 (comment)).

r? @Mark-Simulacrum
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) ❄️ P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants