I accidentally stumbled upon this crash with nightly. When reverting to stable, it outputs an error message because I am passing the wrong argument type to chart.draw_series.
use gtk::prelude::*;
use plotters::prelude::*;
use plotters_cairo::CairoBackend;
const GLADE_UI_SOURCE: &'static str = include_str!("app.glade");
fn build_ui(app: >k::Application) {
let builder = gtk::Builder::from_string(GLADE_UI_SOURCE);
let window = builder.object::<gtk::Window>("MainWindow").unwrap();
window.set_application(Some(app));
let drawing_area: gtk::DrawingArea = builder.object("MainDrawingArea").unwrap();
drawing_area.connect_draw(move |widget, cr| {
let w = widget.allocated_width();
let h = widget.allocated_height();
let backend = CairoBackend::new(cr, (w as u32, h as u32)).unwrap();
let root = backend.into_drawing_area();
root.fill(&WHITE).unwrap();
let mut chart = ChartBuilder::on(&root).caption("A test chart", ("sans-serif", 50).into_font())
.build_cartesian_2d(-1f32..1f32, -1f32..1f32).unwrap();
//////////////////////////////////////////////////////////
// Here's the error
chart.draw_series(LineSeries::new(
// Oops, returning iterator of f32 instead of (f32, f32)
(-50..=50).map(|x| x as f32 / 50.0),
// The below would be the correct arg, yielding tuples instead of scalars
//(-50..=50).map(|x| x as f32 / 50.0).map(|x| (x, x * x)),
&RED,
)).unwrap();
root.present().unwrap();
Inhibit(false)
});
window.show_all();
}
fn main() {
let app = gtk::Application::new(
Some("any.app.id.is.fine"),
Default::default(),
);
app.connect_activate(|app| {
build_ui(app);
});
app.run();
}
Meta
The code is incorrect, and on stable rust, I get the following error output:
Compiling rust-crash-demo-20220908 v0.1.0 (/home/jeff/dev/rust-bug-example)
error[E0277]: the trait bound `for<'b> &'b DynElement<'static, CairoBackend<'_>, f32>: PointCollection<'b, (f32, f32)>` is not satisfied
--> src/main.rs:26:15
|
26 | chart.draw_series(LineSeries::new(
| ^^^^^^^^^^^ the trait `for<'b> PointCollection<'b, (f32, f32)>` is not implemented for `&'b DynElement<'static, CairoBackend<'_>, f32>`
|
= help: the following implementations were found:
<&'a DynElement<'b, DB, Coord> as PointCollection<'a, Coord>>
note: required by a bound in `ChartContext::<'a, DB, CT>::draw_series`
--> /home/jeff/.cargo/git/checkouts/plotters-514b572fd2567842/7f8b12d/plotters/src/chart/context.rs:126:24
|
126 | for<'b> &'b E: PointCollection<'b, CT::From, B>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `ChartContext::<'a, DB, CT>::draw_series`
For more information about this error, try `rustc --explain E0277`.
error: could not compile `rust-crash-demo-20220908` due to previous error
I accidentally stumbled upon this crash with nightly. When reverting to stable, it outputs an error message because I am passing the wrong argument type to
chart.draw_series
.Code
Full project which causes the crash here: https://github.com/mcbridejc/rust-crash-demo-20220908
Meta
The code is incorrect, and on stable rust, I get the following error output:
rustc --version --verbose
:Error output
Backtrace
``` thread 'rustc' panicked at 'Box', /rustc/7480389611f9d04bd34adf41a2b3029be4eb815e/compiler/rustc_errors/src/lib.rs:1393:9
stack backtrace:
0: std::panicking::begin_panic::
1: std::panic::panic_any::
2: ::span_bug::
3: ::span_bug::
4: rustc_middle::ty::context::tls::with_context_opt::::{closure#0}, ()>::{closure#0}, ()>
5: rustc_middle::util::bug::opt_span_bug_fmt::
6: rustc_middle::util::bug::span_bug_fmt::
7: ::make_eqregion
8: ::relate_with_variance::
9: rustc_middle::ty::relate::super_relate_tys::
10: ::tys
11: ::eq::
12: ::can_eq::
13: ::suggest_dereferences
14: ::report_selection_error
15: ::report_fulfillment_error
16: ::report_fulfillment_errors
17: ::check_argument_types
18: ::check_expr_with_expectation_and_args
19: ::check_expr_with_expectation_and_args
20: ::check_block_with_expected
21: ::check_expr_with_expectation_and_args
22: ::check_return_expr
23: rustc_typeck::check::check::check_fn
24: ::check_expr_closure
25: ::check_expr_with_expectation_and_args
26: ::check_argument_types
27: ::check_expr_with_expectation_and_args
28: ::check_block_with_expected
29: ::check_expr_with_expectation_and_args
30: ::check_return_expr
31: rustc_typeck::check::check::check_fn
32: ::enter::<&rustc_middle::ty::context::TypeckResults, ::enter::{closure#1}, &rustc_middle::ty::context::TypeckResults>::{closure#0}>
33: rustc_typeck::check::typeck
34: >::with_task::
35: rustc_query_system::query::plumbing::try_execute_query::>
36: ::typeck
37: rustc_data_structures::sync::par_for_each_in::<&[rustc_span::def_id::LocalDefId], ::par_body_owners::{closure#0}>
38: rustc_typeck::check::typeck_item_bodies
39: >::with_task::
40: rustc_query_system::query::plumbing::try_execute_query::>
41: rustc_query_system::query::plumbing::get_query::
42: ::time::<(), rustc_typeck::check_crate::{closure#7}>
43: rustc_typeck::check_crate
44: rustc_interface::passes::analysis
45: >::with_task::>
46: rustc_query_system::query::plumbing::try_execute_query::>>
47: rustc_query_system::query::plumbing::get_query::
48: ::enter::>
49: ::enter::, rustc_errors::ErrorGuaranteed>>
50: rustc_span::with_source_map::, rustc_interface::interface::create_compiler_and_run, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
51: rustc_interface::interface::create_compiler_and_run::, rustc_driver::run_compiler::{closure#1}>
52: >::set::, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>
```