rust-lang / rust

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

Rust compiler error: 'rustc' panicked at 'Box<Any>', #83949

Closed hderms closed 3 years ago

hderms commented 3 years ago

Code

extern crate glutin_window;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;

use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use piston::event_loop::{EventSettings, Events};
use piston::input::{RenderArgs, RenderEvent, UpdateArgs, UpdateEvent};
use piston::window::WindowSettings;

struct Particle {
    x: f64,
    y: f64,
    color: [f32; 4],
    size: f64,
    velocity: (f64, f64)
}
pub struct App {
    gl: GlGraphics, // OpenGL drawing backend.
    particles: Vec<Particle>,
}

const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
impl App {
    fn render(&mut self, args: &RenderArgs) {
        use graphics::*;

        let (x, y) = (args.window_size[0] / 2.0, args.window_size[1] / 2.0);
        let particles = &self.particles;

        self.gl.draw(args.viewport(), |c, gl| {
            // Clear the screen.
            clear(GREEN, gl);
            for particle in particles {
                let size = particle.size;
                let circle = ellipse::circle(0.0, 0.0, size);
                let transform = c.transform.trans(particle.x, particle.y);

                // Draw a box rotating around the middle of the screen.
                ellipse(particle.color, circle, transform, gl);
            }
        });
    }

    fn update(&mut self, args: &UpdateArgs) {
        // Rotate 2 radians per second.
        let particles = &self.particles;
        for mut particle in particles {
            let new_velocity = (particle.velocity.0, particle.velocity.1 * GRAVITY * args.dt);
            particle.velocity = new_velocity;
            particle.x += new_velocity.0 ;
            particle.x += new_velocity.1;
        }
    }
}
const GRAVITY: f64 = -1.0;

fn main() {
    // Change this to OpenGL::V2_1 if not working.
    let opengl = OpenGL::V3_2;

    // Create an Glutin window.
    let mut window: Window = WindowSettings::new("particular", [1024, 860])
        .graphics_api(opengl)
        .exit_on_esc(true)
        .build()
        .unwrap();

    // Create a new game and run it.
    let particles = vec![
        Particle {
            x: 0.0,
            y: 0.0,
            color: RED,
            size: 50.0,
            velocity: (0f64, 0f64)
        },
        Particle {
            x: 100.0,
            y: 100.0,
            color: RED,
            size: 20.0,
            velocity: (0f64, 0f64)
        },
    ];
    let mut app = App {
        gl: GlGraphics::new(opengl),
        particles: particles,
    };

    let mut events = Events::new(EventSettings::new());
    while let Some(e) = events.next(&mut window) {
        if let Some(args) = e.render_args() {
            app.render(&args);
        }

        if let Some(args) = e.update_args() {
            app.update(&args);
        }
    }

https://gist.github.com/hderms/06ab3dfcb50ef3bc01173205e5959d61

Meta

rustc --version --verbose:

rustc 1.52.0-nightly (3f5aee2d5 2021-02-12)
binary: rustc
commit-hash: 3f5aee2d5241139d808f4fdece0026603489afd1
commit-date: 2021-02-12
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1

Error output

warning: unused variable: `x`
  --> src/main.rs:30:14
   |
30 |         let (x, y) = (args.window_size[0] / 2.0, args.window_size[1] / 2.0);
   |              ^ help: if this is intentional, prefix it with an underscore: `_x`
   |
   = note: `#[warn(unused_variables)]` on by default

warning: unused variable: `y`
  --> src/main.rs:30:17
   |
30 |         let (x, y) = (args.window_size[0] / 2.0, args.window_size[1] / 2.0);
   |                 ^ help: if this is intentional, prefix it with an underscore: `_y`

error: internal compiler error: compiler/rustc_middle/src/hir/map/mod.rs:306:18: impossible case reached

thread 'rustc' panicked at 'Box<Any>', /rustc/3f5aee2d5241139d808f4fdece0026603489afd1/library/std/src/panic.rs:59:5
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/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.52.0-nightly (3f5aee2d5 2021-02-12) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C embed-bitcode=no --crate-type bin

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

query stack during panic:
#0 [mir_borrowck] borrow-checking `App::update`
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error; 2 warnings emitted

error: could not compile `particular`
Backtrace

``` thread 'rustc' panicked at 'Box', /rustc/3f5aee2d5241139d808f4fdece0026603489afd1/library/std/src/panic.rs:59:5 stack backtrace: 0: std::panicking::begin_panic 1: std::panic::panic_any 2: rustc_errors::HandlerInner::bug 3: rustc_errors::Handler::bug 4: rustc_middle::ty::context::tls::with_opt 5: rustc_middle::util::bug::opt_span_bug_fmt 6: rustc_middle::util::bug::bug_fmt 7: rustc_middle::hir::map::Map::item 8: rustc_mir::borrow_check::diagnostics::mutability_errors::::report_mutability_error 9: rustc_mir::borrow_check::MirBorrowckCtxt::access_place 10: rustc_mir::borrow_check::MirBorrowckCtxt::mutate_place 11: ::visit_statement_before_primary_effect 12: ::visit_results_in_block 13: rustc_mir::dataflow::framework::visitor::visit_results 14: rustc_mir::borrow_check::do_mir_borrowck 15: rustc_infer::infer::InferCtxtBuilder::enter 16: rustc_mir::borrow_check::mir_borrowck 17: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::mir_borrowck>::compute 18: rustc_middle::dep_graph::::with_deps 19: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 20: rustc_data_structures::stack::ensure_sufficient_stack 21: rustc_query_system::query::plumbing::force_query_with_job 22: rustc_query_system::query::plumbing::get_query_impl 23: rustc_query_system::query::plumbing::ensure_query_impl 24: rustc_session::utils::::time 25: rustc_interface::passes::analysis 26: rustc_middle::ty::query:: for rustc_middle::ty::query::queries::analysis>::compute 27: rustc_middle::dep_graph::::with_deps 28: rustc_query_system::dep_graph::graph::DepGraph::with_task_impl 29: rustc_data_structures::stack::ensure_sufficient_stack 30: rustc_query_system::query::plumbing::force_query_with_job 31: rustc_query_system::query::plumbing::get_query_impl 32: rustc_interface::passes::QueryContext::enter 33: rustc_interface::queries::::enter 34: rustc_span::with_source_map 35: scoped_tls::ScopedKey::set note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. ```

hderms commented 3 years ago

This may actually not be an issue on the latest nightly release