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

Type mismatching cased by duplicate associated type resolution #59326

Open
fanzeyi opened this issue Mar 20, 2019 · 14 comments
Open

Type mismatching cased by duplicate associated type resolution #59326

fanzeyi opened this issue Mar 20, 2019 · 14 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-typesystem Area: The type system C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@fanzeyi
Copy link

fanzeyi commented Mar 20, 2019

Apologize that I could not give any code example right now. I'm working on creating one but it seems tricky.

The compiler is complaining about [E0308]: mismatched types where it said it's expecting for a trait SomeTrait<Apple=SomeApple, Apple=SomeApple, Banana=SomeBanana, Banana=SomeBanana> but got SomeTrait<Apple=SomeAPple, Banana=SomeBanana>. Only some of the associated types in that trait are repeated once and there are few others are not repeated.

The example I gave in #59324 is an intermediate result of my attempt to create a minimal reproducible code to this issue. The type mismatch happened at the with_factory method when resolving concrete type for ThriftService.

The error happened when I'm doing the update from 1.32.0 to 1.33.0 so it's clearly a regression.

Also, please let me know if you have any suggestion on bypassing this problem or tips on re-creating the problematic code.

Thanks.

@estebank
Copy link
Contributor

Can you please post the full output from your compiler related to this error? Also, if you could use the flag -Ztreat-err-as-bug and the RUST_BACKTRACE=full env variable to get a backtrace for this error it would also be very helpful. As it stands now we can only guess at what's happening.

@estebank estebank added the A-typesystem Area: The type system label Mar 20, 2019
@fanzeyi
Copy link
Author

fanzeyi commented Mar 20, 2019

@esclear

Here you go:

stack backtrace:
   0:     0x7faa480b38bf - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h491d55826960b433
                               at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:39
   1:     0x7faa480d7317 - std::sys_common::backtrace::print::hc944b112770bad52
                               at src/libstd/sys_common/backtrace.rs:70
                               at src/libstd/sys_common/backtrace.rs:58
   2:     0x7faa480c111d - std::panicking::default_hook::{{closure}}::hd2dc3ad80ef22d72
                               at src/libstd/panicking.rs:200
   3:     0x7faa480c0e93 - std::panicking::default_hook::hf538c2fde927616a
                               at src/libstd/panicking.rs:215
   4:     0x7faa43b8bfbf - rustc::util::common::panic_hook::hc8481fff5a79da47
                               at src/librustc/util/common.rs:39
   5:     0x7faa480c19a9 - std::panicking::rust_panic_with_hook::h832f249017f7afee
                               at src/libstd/panicking.rs:482
   6:     0x7faa42f02cb4 - std::panicking::begin_panic::h0ae094f124031d56
                               at /build/rust/src/libstd/panicking.rs:412
   7:     0x7faa42f1526f - rustc_errors::Handler::emit_db::h49929f998e7c99d0
                               at src/librustc_errors/lib.rs:488
                               at src/librustc_errors/lib.rs:595
                               at src/librustc_errors/lib.rs:712
   8:     0x7faa42f017a7 - rustc_errors::diagnostic_builder::DiagnosticBuilder::emit::h8b5d732f0c8c3789
                               at src/librustc_errors/diagnostic_builder.rs:88
   9:     0x7faa4661d4f4 - <rustc_typeck::check::coercion::CoerceMany<'gcx, 'tcx, 'exprs, E>>::coerce_inner::he1910291388b79d1
                               at src/librustc_typeck/check/coercion.rs:1247
  10:     0x7faa466bb051 - rustc_typeck::check::FnCtxt::check_block_with_expected::h081bee4aeb47b284
                               at src/librustc_typeck/check/coercion.rs:1065
                               at src/librustc_typeck/check/mod.rs:4953
                               at src/librustc_typeck/check/mod.rs:5619
                               at src/librustc_typeck/check/mod.rs:4937
  11:     0x7faa466b014f - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4482
  12:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  13:     0x7faa466af089 - rustc_typeck::check::FnCtxt::check_return_expr::h5a38f595cba97774
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3196
                               at src/librustc_typeck/check/mod.rs:3334
  14:     0x7faa4669f4ac - rustc_typeck::check::check_fn::h2e3a570c9e6f5981
                               at src/librustc_typeck/check/mod.rs:1116
  15:     0x7faa46695ee5 - rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_expr_closure::h091a2b34cd3aa212
                               at src/librustc_typeck/check/closure.rs:84
                               at src/librustc_typeck/check/closure.rs:58
  16:     0x7faa466b12d3 - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4479
  17:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  18:     0x7faa466baf91 - rustc_typeck::check::FnCtxt::check_block_with_expected::h081bee4aeb47b284
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:4944
                               at /build/rust/src/libcore/option.rs:414
                               at src/librustc_typeck/check/mod.rs:4944
                               at src/librustc_typeck/check/mod.rs:5619
                               at src/librustc_typeck/check/mod.rs:4937
  19:     0x7faa466b014f - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4482
  20:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  21:     0x7faa466af089 - rustc_typeck::check::FnCtxt::check_return_expr::h5a38f595cba97774
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3196
                               at src/librustc_typeck/check/mod.rs:3334
  22:     0x7faa4669f4ac - rustc_typeck::check::check_fn::h2e3a570c9e6f5981
                               at src/librustc_typeck/check/mod.rs:1116
  23:     0x7faa46695ee5 - rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_expr_closure::h091a2b34cd3aa212
                               at src/librustc_typeck/check/closure.rs:84
                               at src/librustc_typeck/check/closure.rs:58
  24:     0x7faa466b12d3 - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4479
  25:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  26:     0x7faa466baf91 - rustc_typeck::check::FnCtxt::check_block_with_expected::h081bee4aeb47b284
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:4944
                               at /build/rust/src/libcore/option.rs:414
                               at src/librustc_typeck/check/mod.rs:4944
                               at src/librustc_typeck/check/mod.rs:5619
                               at src/librustc_typeck/check/mod.rs:4937
  27:     0x7faa466b014f - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4482
  28:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  29:     0x7faa466ad37e - rustc_typeck::check::FnCtxt::check_argument_types::hcb1073213f29b05b
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3027
  30:     0x7faa466ac220 - rustc_typeck::check::FnCtxt::check_method_argument_types::h0b75b38da5881056
                               at src/librustc_typeck/check/mod.rs:2784
  31:     0x7faa466b3c80 - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:3318
                               at src/librustc_typeck/check/mod.rs:4488
  32:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  33:     0x7faa466b053e - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:3210
                               at src/librustc_typeck/check/mod.rs:3291
                               at src/librustc_typeck/check/mod.rs:4488
  34:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  35:     0x7faa466baf91 - rustc_typeck::check::FnCtxt::check_block_with_expected::h081bee4aeb47b284
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:4944
                               at /build/rust/src/libcore/option.rs:414
                               at src/librustc_typeck/check/mod.rs:4944
                               at src/librustc_typeck/check/mod.rs:5619
                               at src/librustc_typeck/check/mod.rs:4937
  36:     0x7faa466b014f - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4482
  37:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  38:     0x7faa466af089 - rustc_typeck::check::FnCtxt::check_return_expr::h5a38f595cba97774
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3196
                               at src/librustc_typeck/check/mod.rs:3334
  39:     0x7faa4669f4ac - rustc_typeck::check::check_fn::h2e3a570c9e6f5981
                               at src/librustc_typeck/check/mod.rs:1116
  40:     0x7faa46695ee5 - rustc_typeck::check::closure::<impl rustc_typeck::check::FnCtxt<'a, 'gcx, 'tcx>>::check_expr_closure::h091a2b34cd3aa212
                               at src/librustc_typeck/check/closure.rs:84
                               at src/librustc_typeck/check/closure.rs:58
  41:     0x7faa466b12d3 - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4479
  42:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  43:     0x7faa466baf91 - rustc_typeck::check::FnCtxt::check_block_with_expected::h081bee4aeb47b284
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:4944
                               at /build/rust/src/libcore/option.rs:414
                               at src/librustc_typeck/check/mod.rs:4944
                               at src/librustc_typeck/check/mod.rs:5619
                               at src/librustc_typeck/check/mod.rs:4937
  44:     0x7faa466b014f - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4482
  45:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  46:     0x7faa466ad37e - rustc_typeck::check::FnCtxt::check_argument_types::hcb1073213f29b05b
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3027
  47:     0x7faa466ac220 - rustc_typeck::check::FnCtxt::check_method_argument_types::h0b75b38da5881056
                               at src/librustc_typeck/check/mod.rs:2784
  48:     0x7faa466b3c80 - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:3318
                               at src/librustc_typeck/check/mod.rs:4488
  49:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  50:     0x7faa466baaab - rustc_typeck::check::FnCtxt::check_stmt::h9c7d2ab54b9c4b44
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3206
                               at src/librustc_typeck/check/mod.rs:4874
  51:     0x7faa466baf5a - rustc_typeck::check::FnCtxt::check_block_with_expected::h081bee4aeb47b284
                               at src/librustc_typeck/check/mod.rs:4939
                               at src/librustc_typeck/check/mod.rs:5619
                               at src/librustc_typeck/check/mod.rs:4937
  52:     0x7faa466b014f - rustc_typeck::check::FnCtxt::check_expr_kind::h3a5fa3b7b2d03743
                               at src/librustc_typeck/check/mod.rs:4482
  53:     0x7faa466afee0 - rustc_typeck::check::FnCtxt::check_expr_with_expectation_and_needs::h4f9b69d5c57806da
                               at src/librustc_typeck/check/mod.rs:4013
  54:     0x7faa466af089 - rustc_typeck::check::FnCtxt::check_return_expr::h5a38f595cba97774
                               at src/librustc_typeck/check/mod.rs:3202
                               at src/librustc_typeck/check/mod.rs:3196
                               at src/librustc_typeck/check/mod.rs:3334
  55:     0x7faa4669f4ac - rustc_typeck::check::check_fn::h2e3a570c9e6f5981
                               at src/librustc_typeck/check/mod.rs:1116
  56:     0x7faa46794962 - rustc::ty::context::GlobalCtxt::enter_local::he0008d8af72ec408
                               at src/librustc_typeck/check/mod.rs:868
                               at src/librustc_typeck/check/mod.rs:615
                               at /build/rust/src/librustc/infer/mod.rs:520
                               at /build/rust/src/librustc/ty/context.rs:1685
                               at /build/rust/src/librustc/ty/context.rs:1924
                               at /build/rust/src/librustc/ty/context.rs:1857
                               at /build/rust/src/librustc/ty/context.rs:1923
                               at /build/rust/src/librustc/ty/context.rs:1684
                               at /build/rust/src/librustc/ty/context.rs:2030
                               at /build/rust/src/librustc/ty/context.rs:2014
                               at /build/rust/src/librustc/ty/context.rs:2004
                               at /build/rust/src/librustc/ty/context.rs:2014
                               at /build/rust/src/librustc/ty/context.rs:2026
                               at /build/rust/src/librustc/ty/context.rs:1676
  57:     0x7faa4669e14f - rustc_typeck::check::typeck_tables_of::h0364e7da5abae100
                               at /build/rust/src/librustc/infer/mod.rs:519
                               at src/librustc_typeck/check/mod.rs:615
                               at src/librustc_typeck/check/mod.rs:852
  58:     0x7faa43fd937c - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_tables_of<'tcx>>::compute::h3f1d7feafd2776b9
                               at src/librustc/ty/query/plumbing.rs:990
  59:     0x7faa4406b026 - rustc::dep_graph::graph::DepGraph::with_task_impl::ha97b247d2a229a88
                               at src/librustc/dep_graph/graph.rs:254
                               at src/librustc/ty/context.rs:1924
                               at src/librustc/ty/context.rs:1857
                               at src/librustc/ty/context.rs:1923
                               at src/librustc/dep_graph/graph.rs:253
                               at src/librustc/ty/context.rs:2014
                               at src/librustc/ty/context.rs:2004
                               at src/librustc/ty/context.rs:2014
                               at src/librustc/dep_graph/graph.rs:247
  60:     0x7faa43e8645c - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with::hb0ee0e148c611728
                               at src/librustc/dep_graph/graph.rs:181
                               at src/librustc/ty/query/plumbing.rs:587
                               at src/librustc/ty/query/plumbing.rs:220
                               at src/librustc/ty/context.rs:1924
                               at src/librustc/ty/context.rs:1857
                               at src/librustc/ty/context.rs:1923
                               at src/librustc/ty/query/plumbing.rs:219
                               at src/librustc/ty/context.rs:2030
                               at src/librustc/ty/context.rs:2014
                               at src/librustc/ty/context.rs:2004
                               at src/librustc/ty/context.rs:2014
                               at src/librustc/ty/context.rs:2026
                               at src/librustc/ty/query/plumbing.rs:208
                               at src/librustc/ty/query/plumbing.rs:580
                               at src/librustc/ty/query/plumbing.rs:233
                               at src/librustc/ty/query/plumbing.rs:579
                               at src/librustc/ty/query/plumbing.rs:448
  61:     0x7faa43f243de - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query::h73e08f33e6d1aa10
                               at src/librustc/ty/query/plumbing.rs:686
                               at src/librustc/ty/query/plumbing.rs:635
  62:     0x7faa4652a2ac - rustc::session::Session::track_errors::h3c217a66b10ec749
                               at src/librustc_typeck/check/mod.rs:724
                               at /build/rust/src/librustc/ty/mod.rs:2696
                               at /build/rust/src/libcore/iter/iterator.rs:606
                               at /build/rust/src/libcore/slice/mod.rs:2913
                               at /build/rust/src/libcore/iter/iterator.rs:606
                               at /build/rust/src/librustc/ty/mod.rs:2695
                               at src/librustc_typeck/check/mod.rs:723
                               at /build/rust/src/librustc/session/mod.rs:324
  63:     0x7faa4669dc3e - rustc_typeck::check::typeck_item_bodies::hfaa6e0ab992179a2
                               at src/librustc_typeck/check/mod.rs:722
  64:     0x7faa46614ea6 - rustc::ty::query::__query_compute::typeck_item_bodies::h91dba797adf9377a
                               at /build/rust/src/librustc/ty/query/plumbing.rs:998
                               at /build/rust/src/librustc/ty/query/plumbing.rs:957
  65:     0x7faa46714e08 - rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::typeck_item_bodies<'tcx>>::compute::h43d0ee6521110ffb
                               at /build/rust/src/librustc/ty/query/plumbing.rs:990
  66:     0x7faa467b6e25 - rustc::dep_graph::graph::DepGraph::with_task_impl::ha513f9ddad293b48
                               at /build/rust/src/librustc/dep_graph/graph.rs:254
                               at /build/rust/src/librustc/ty/context.rs:1924
                               at /build/rust/src/librustc/ty/context.rs:1857
                               at /build/rust/src/librustc/ty/context.rs:1923
                               at /build/rust/src/librustc/dep_graph/graph.rs:253
                               at /build/rust/src/librustc/ty/context.rs:2014
                               at /build/rust/src/librustc/ty/context.rs:2004
                               at /build/rust/src/librustc/ty/context.rs:2014
                               at /build/rust/src/librustc/dep_graph/graph.rs:247
  67:     0x7faa4676fc57 - rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_get_with::he823459c511e55c5
                               at /build/rust/src/librustc/dep_graph/graph.rs:181
                               at /build/rust/src/librustc/ty/query/plumbing.rs:587
                               at /build/rust/src/librustc/ty/query/plumbing.rs:220
                               at /build/rust/src/librustc/ty/context.rs:1924
                               at /build/rust/src/librustc/ty/context.rs:1857
                               at /build/rust/src/librustc/ty/context.rs:1923
                               at /build/rust/src/librustc/ty/query/plumbing.rs:219
                               at /build/rust/src/librustc/ty/context.rs:2030
                               at /build/rust/src/librustc/ty/context.rs:2014
                               at /build/rust/src/librustc/ty/context.rs:2004
                               at /build/rust/src/librustc/ty/context.rs:2014
                               at /build/rust/src/librustc/ty/context.rs:2026
                               at /build/rust/src/librustc/ty/query/plumbing.rs:208
                               at /build/rust/src/librustc/ty/query/plumbing.rs:580
                               at /build/rust/src/librustc/ty/query/plumbing.rs:233
                               at /build/rust/src/librustc/ty/query/plumbing.rs:579
                               at /build/rust/src/librustc/ty/query/plumbing.rs:448
  68:     0x7faa46559e84 - rustc::util::common::time::h9951047a13e422d2
                               at /build/rust/src/librustc/ty/query/plumbing.rs:686
                               at /build/rust/src/librustc/ty/query/plumbing.rs:1056
                               at /build/rust/src/librustc/ty/query/plumbing.rs:1048
                               at src/librustc_typeck/check/mod.rs:715
                               at src/librustc_typeck/lib.rs:365
                               at /build/rust/src/librustc/util/common.rs:150
                               at /build/rust/src/librustc/util/common.rs:144
  69:     0x7faa46531a2d - rustc_typeck::check_crate::hff96fb41fa5237f9
                               at src/librustc_typeck/lib.rs:365
  70:     0x7faa484c5235 - <std::thread::local::LocalKey<T>>::with::h29ba31b55ec4d810
                               at src/librustc_driver/driver.rs:1265
                               at /build/rust/src/librustc/ty/context.rs:1958
                               at /build/rust/src/librustc/ty/context.rs:1924
                               at /build/rust/src/librustc/ty/context.rs:1857
                               at /build/rust/src/librustc/ty/context.rs:1923
                               at /build/rust/src/librustc/ty/context.rs:1957
                               at /build/rust/src/librustc/ty/context.rs:1912
                               at /build/rust/src/libstd/thread/local.rs:299
                               at /build/rust/src/libstd/thread/local.rs:245
                               at /build/rust/src/librustc/ty/context.rs:1904
                               at /build/rust/src/libstd/thread/local.rs:299
                               at /build/rust/src/libstd/thread/local.rs:245
  71:     0x7faa4843e9ae - rustc::ty::context::TyCtxt::create_and_enter::h019642ef52479dad
                               at /build/rust/src/librustc/ty/context.rs:1896
                               at /build/rust/src/librustc/ty/context.rs:1935
                               at /build/rust/src/librustc/ty/context.rs:1255
  72:     0x7faa483d077f - rustc_driver::driver::compile_input::hd165033b2a205f4d
                               at src/librustc_driver/driver.rs:1229
                               at src/librustc_driver/driver.rs:275
  73:     0x7faa48468c20 - rustc_driver::run_compiler_with_pool::h9032e7c5f503b5e9
                               at src/librustc_driver/lib.rs:527
  74:     0x7faa48458ef5 - <scoped_tls::ScopedKey<T>>::set::h2b39d1a1d4c4d36d
                               at src/librustc_driver/lib.rs:449
                               at src/librustc_driver/driver.rs:65
                               at /build/rust/vendor/scoped-tls/src/lib.rs:155
  75:     0x7faa48467a6a - rustc_driver::run_compiler::h2eaf4645c8037d02
                               at src/librustc_driver/driver.rs:64
                               at src/librustc_driver/lib.rs:448
  76:     0x7faa484590aa - <scoped_tls::ScopedKey<T>>::set::hc28c1ed216cc584f
                               at src/librustc_driver/lib.rs:1644
                               at src/librustc_driver/lib.rs:171
                               at /build/rust/vendor/scoped-tls/src/lib.rs:155
                               at /build/rust/src/libsyntax/lib.rs:111
                               at /build/rust/vendor/scoped-tls/src/lib.rs:155
  77:     0x7faa484f0302 - std::sys_common::backtrace::__rust_begin_short_backtrace::h8fe9197fc385e149
                               at /build/rust/src/libsyntax/lib.rs:110
                               at src/librustc_driver/lib.rs:170
                               at src/librustc_driver/lib.rs:1560
                               at /build/rust/src/libstd/sys_common/backtrace.rs:135
  78:     0x7faa480db389 - __rust_maybe_catch_panic
                               at src/libpanic_unwind/lib.rs:92
  79:     0x7faa484fa230 - <F as alloc::boxed::FnBox<A>>::call_box::h6d11bf519f2c149a
                               at /build/rust/src/libstd/panicking.rs:276
                               at /build/rust/src/libstd/panic.rs:388
                               at /build/rust/src/libstd/thread/mod.rs:468
                               at /build/rust/src/liballoc/boxed.rs:734
  80:     0x7faa480bbc1d - std::sys_common::thread::start_thread::h7d27c88ec451b131
                               at /build/rust/src/liballoc/boxed.rs:744
                               at src/libstd/sys_common/thread.rs:14
  81:     0x7faa480c82e5 - std::sys::unix::thread::Thread::new::thread_start::h05fffcc062c98212
                               at src/libstd/sys/unix/thread.rs:81
  82:     0x7faa41d0c66d - start_thread
                               at /glibc/2.26/src/glibc-2.26/nptl/pthread_create.c:465
  83:     0x7faa47d92e2e - clone
                               at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95
  84:                0x0 - <unknown>
query stack during panic:
#0 [typeck_tables_of] processing `thrift::make_thrift`
#1 [typeck_item_bodies] type-checking all item bodies
error: internal compiler error: unexpected panic

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.33.0-dev running on x86_64-unknown-linux-gnu

note: compiler flags: -Z treat-err-as-bug -C linker=<redacted>/ld.sh -C link-arg=@<redacted> -C relocation-model=pic -C force-frame-pointers=yes -C debuginfo=2 -C opt-level=1 -C debug-assertions=on -C codegen-units=8 -C linker-flavor=gcc -C incremental -C rpath --crate-type bin

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

@fanzeyi
Copy link
Author

fanzeyi commented Mar 25, 2019

Okay, I'm able to create a small example demonstrating this problem:

Playground

use std::marker::PhantomData;

use bytes::Bytes; // 0.4.11;

trait Service {
    type Request;
    type Response;
}

trait Framing {
    type Request;
    type Response;
}

trait HttpService<B>: Service<Request = B::Request, Response = B::Response>
where
    B: Framing + Send + 'static,
{
    type Handler;
}

pub struct Http2Transport;
impl Framing for Http2Transport {
    type Request = Bytes;
    type Response = Bytes;
}

type BoxService<H> = Box<
    HttpService<Http2Transport, Handler = H, Request = Bytes, Response = Bytes> + Send + 'static,
>;

fn build_server<F, SVC, H>(factory: F)
where
    F: FnOnce() -> SVC + Send + Sync + Clone + 'static,
    SVC: Fn(i32) -> Result<BoxService<H>, std::io::Error>,
    H: 'static,
{
}

pub trait MyAwesomeService: Send + Sync + 'static {}

struct MyServiceImpl;
impl MyAwesomeService for MyServiceImpl {}

trait ProtocolFactory {
    type Frame: Framing;
}

pub struct Http2ProtocolFactory<F> {
    _phantom: PhantomData<F>,
}

impl<F> ProtocolFactory for Http2ProtocolFactory<F>
where
    F: Framing,
{
    type Frame = F;
}

pub struct ServiceProcessor<PF, H> {
    service: H,
    _phantom: PhantomData<(PF, H)>,
}

impl<PF, H> ServiceProcessor<PF, H>
where
    PF: ProtocolFactory + 'static,
    H: MyAwesomeService,
{
    pub fn new(service: H) -> Self {
        Self {
            service,
            _phantom: PhantomData,
        }
    }
}

impl<PF, H> Service for ServiceProcessor<PF, H>
where
    PF: ProtocolFactory + 'static,
    PF::Frame: Send + 'static,
    H: MyAwesomeService,
{
    type Request = <<PF as ProtocolFactory>::Frame as Framing>::Request;
    type Response = <<PF as ProtocolFactory>::Frame as Framing>::Response;
}

impl<PF, H> HttpService<PF::Frame> for ServiceProcessor<PF, H>
where
    PF: ProtocolFactory + 'static,
    PF::Frame: Send + 'static,
    H: MyAwesomeService,
{
    type Handler = H;
}

fn make_server<F, H>(
    proto: i32,
    handler: H,
) -> Result<
    Box<
        HttpService<
                F,
                Handler = H,
                Request = <F as Framing>::Request,
                Response = <F as Framing>::Response,
            > + Send
            + 'static,
    >,
    std::io::Error,
>
where
    F: Framing + Send + 'static,
    H: MyAwesomeService,
{
    Ok(Box::new(
        ServiceProcessor::<Http2ProtocolFactory<F>, H>::new(handler),
    ))
}

fn main() {
    build_server(|| |i: i32| make_server(i, MyServiceImpl {}))
}

This code compiles in 1.32.0 but not in 1.33.0. Tested locally:

type-resolution $ cargo version
cargo 1.32.0 (8610973aa 2019-01-02)
type-resolution $ cargo build
...
    Finished dev [unoptimized + debuginfo] target(s) in 3.36s
type-resolution $ rustup default 1.33.0
...
  1.33.0-x86_64-apple-darwin installed - rustc 1.33.0 (2aa4c46cf 2019-02-28)
type-resolution $ cargo version
cargo 1.33.0 (f099fe94b 2019-02-12)
type-resolution $ cargo build
...

error[E0308]: mismatched types
   --> src/main.rs:124:30
    |
124 |     build_server(|| |i: i32| make_server(i, MyServiceImpl {}))
    |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected trait `HttpService<Http2Transport, Response=bytes::bytes::Bytes, Response=bytes::bytes::Bytes, Request=bytes::bytes::Bytes, Request=bytes::bytes::Bytes, Handler=_> + std::marker::Send`, found trait `HttpService<_, Response=_, Request=_, Handler=MyServiceImpl> + std::marker::Send`
    |
    = note: expected type `std::result::Result<std::boxed::Box<(dyn HttpService<Http2Transport, Response=bytes::bytes::Bytes, Response=bytes::bytes::Bytes, Request=bytes::bytes::Bytes, Request=bytes::bytes::Bytes, Handler=_> + std::marker::Send + 'static)>, _>`
               found type `std::result::Result<std::boxed::Box<(dyn HttpService<_, Response=_, Request=_, Handler=MyServiceImpl> + std::marker::Send + 'static)>, _>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `type-resolution`.

@estebank estebank added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Mar 25, 2019
@jonas-schievink jonas-schievink added the C-bug Category: This is a bug. label Apr 13, 2019
@spastorino spastorino added I-prioritize Issue: Indicates that prioritization has been requested for this issue. E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example labels Jun 17, 2020
@spastorino
Copy link
Member

Would be nice to find an mcve and to bisect to find the culprit ...

@rustbot ping cleanup

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Jun 17, 2020
@rustbot
Copy link
Collaborator

rustbot commented Jun 17, 2020

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @camelid @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @kanru @KarlK90 @LeSeulArtichaut @MAdrianMattocks @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

@spastorino
Copy link
Member

Tagging this one as P-high meanwhile we find out what's going on.

@spastorino spastorino added P-high High priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. P-high High priority labels Jun 17, 2020
@senden9
Copy link

senden9 commented Jun 17, 2020

Seems the regression is in nightly-2019-01-06.
Sadly I have not the time currently to investigate just now.

root@ubuntu-cloud-computing-tmp:~/bad_code# cargo bisect-rustc --start 2019-01-04 --end 2019-01-08 --with-src --with-cargo --verbose --preserve                                              
installing nightly-2019-01-04                                                                                                                                                                
testing...                                                                                                                                                                                   
RESULT: nightly-2019-01-04, ===> No                                                                                                                                                          
                                                                                                                                                                                             
installing nightly-2019-01-08                                                                                                                                                                
testing...                                                                                                                                                                                   
RESULT: nightly-2019-01-08, ===> Yes                                                                                                                                                         
                                                                                                                                                                                             
installing nightly-2019-01-06                                                                                                                                                                
testing...                                                                                                                                                                                   
RESULT: nightly-2019-01-06, ===> Yes                                                                                                                                                         
                                                                                                                                                                                             
installing nightly-2019-01-05                                                                                                                                                                
testing...                                                                                                                                                                                   
RESULT: nightly-2019-01-05, ===> No                                                                                                                                                          
                                                                                                                                                                                             
searched toolchains nightly-2019-01-04 through nightly-2019-01-08                                                                                                                            
                                                                                                                                                                                             
                                                                                                                                                                                             
********************************************************************************                                                                                                             
Regression in nightly-2019-01-06                                                                                                                                                             
********************************************************************************                                                                                                             
                                                                                                                                                                                             
fetching https://static.rust-lang.org/dist/2019-01-05/channel-rust-nightly-git-commit-hash.txt                                                                                               
nightly manifest 2019-01-05: 40 B / 40 B [============================================================================================================================] 100.00 % 376.15 KB/s converted 2019-01-05 to f381a962550436f74dd6e9021e4df2fdefb96cfa
fetching https://static.rust-lang.org/dist/2019-01-06/channel-rust-nightly-git-commit-hash.txt 
nightly manifest 2019-01-06: 40 B / 40 B [===========================================================================================================================] 100.00 % 1006.09 KB/s 
converted 2019-01-06 to 68fe5182c967259ef89dbe313e4bf80f45a53e7e
looking for regression commit between 2019-01-05 and 2019-01-06
opening existing repository at "rust.git"
refreshing repository
fetching (via local git) commits from f381a962550436f74dd6e9021e4df2fdefb96cfa to 68fe5182c967259ef89dbe313e4bf80f45a53e7e
opening existing repository at "rust.git"
refreshing repository
looking up first commit
looking up second commit
checking that commits are by bors and thus have ci artifacts...
finding bors merge commits
found 8 bors merge commits in the specified range
  commit[0] 2019-01-04UTC: Auto merge of #56897 - euclio:parse-fatal, r=estebank
  commit[1] 2019-01-04UTC: Auto merge of #56079 - mark-i-m:patch-1, r=nikomatsakis
  commit[2] 2019-01-05UTC: Auto merge of #56145 - weiznich:re_rebalance_coherence, r=nikomatsakis
  commit[3] 2019-01-05UTC: Auto merge of #56837 - arielb1:nonprincipal-trait-objects, r=nikomatsakis
  commit[4] 2019-01-05UTC: Auto merge of #57099 - davidtwco:issue-57098, r=nikomatsakis
  commit[5] 2019-01-05UTC: Auto merge of #57101 - o01eg:fix-57014, r=alexcrichton
  commit[6] 2019-01-05UTC: Auto merge of #57145 - RalfJung:panic-if-uninhabited, r=alexcrichton
  commit[7] 2019-01-05UTC: Auto merge of #57354 - kennytm:rollup, r=kennytm
ERROR: no commits between f381a962550436f74dd6e9021e4df2fdefb96cfa and 68fe5182c967259ef89dbe313e4bf80f45a53e7e within last 167 days

@hellow554
Copy link
Contributor

Not sure, if it is the smallest possible code, but it's pretty darn good

trait Service {
    type S;
}

trait Framing {
    type F;
}

impl Framing for () {
    type F = ();
}

trait HttpService<F: Framing>: Service<S = F::F> {}

type BoxService = Box<dyn HttpService<(), S = ()>>;

fn build_server<F: FnOnce() -> BoxService>(_: F) {}

fn make_server<F: Framing>() -> Box<dyn HttpService<F, S = F::F>> {
    unimplemented!()
}

fn main() {
    build_server(|| make_server())
}
1.32.0    Checking foo v0.1.0 (/tmp/tmp.eBIGDgl0Zm/foo)
    Finished dev [unoptimized + debuginfo] target(s) in 0.30s
1.33.0    Checking foo v0.1.0 (/tmp/tmp.eBIGDgl0Zm/foo)
error[E0308]: mismatched types
  --> src/main.rs:24:21
   |
24 |     build_server(|| make_server())
   |                     ^^^^^^^^^^^^^ expected trait `HttpService<(), S=(), S=()>`, found trait `HttpService<_, S=_>`
   |
   = note: expected type `std::boxed::Box<(dyn HttpService<(), S=(), S=()> + 'static)>`
              found type `std::boxed::Box<(dyn HttpService<_, S=_> + 'static)>`

error: aborting due to previous error

@wesleywiser
Copy link
Member

Out of those rolled-up PRs, #56837 seems like the strongest candidate for the cause of the regression.

@nikomatsakis
Copy link
Contributor

@hellow554 thanks! that's a great reduction. ❤️

@estebank
Copy link
Contributor

estebank commented Jun 18, 2020

I'm pretty sure this is caused because of a duplicated S=() obligation making an early return trigger because the expected and found existential projection lengths don't match:

impl<'tcx> Relate<'tcx> for Vec<ty::PolyExistentialProjection<'tcx>> {
fn relate<R: TypeRelation<'tcx>>(
relation: &mut R,
a: &Vec<ty::PolyExistentialProjection<'tcx>>,
b: &Vec<ty::PolyExistentialProjection<'tcx>>,
) -> RelateResult<'tcx, Vec<ty::PolyExistentialProjection<'tcx>>> {
// To be compatible, `a` and `b` must be for precisely the
// same set of traits and item names. We always require that
// projection bounds lists are sorted by trait-def-id and item-name,
// so we can just iterate through the lists pairwise, so long as they are the
// same length.
if a.len() != b.len() {
Err(TypeError::ProjectionBoundsLength(expected_found(relation, &a.len(), &b.len())))
} else {
a.iter().zip(b).map(|(a, b)| relation.relate(a, b)).collect()
}
}
}

It seems we could perform a sort&dedup on a and b and the repro case will start compiling again, but we would have to perform the deduplication sometime earlier in the process and in such a way that doesn't cause a perf regression.

Edit: ah! We were indeed doing that before #56837.

https://github.com/rust-lang/rust/pull/56837/files#diff-af1c8bc6ae3623b749b5aebeaa1e0bffL609-L631

Created #73485 to do a perf run on the naïve approach. If it doesn't cause a massive regression we can merge it and fix this.

@estebank
Copy link
Contributor

#73485 would solve this and incur no perf regression, but I noticed that with the following code

trait Service {
    type S;
}

trait Framing {
    type F;
}

impl Framing for () {
    type F = ();
}

impl Framing for u32 {
    type F = u32;
}

trait HttpService<F: Framing>: Service<S = F::F> {}

type BoxService = Box<dyn HttpService<u32, S = ()>>;

fn build_server<F: FnOnce() -> BoxService>(_: F) {}

fn make_server<F: Framing>() -> Box<dyn HttpService<F, S = F::F>> {
    unimplemented!()
}

fn main() {
    build_server(|| make_server())
}

we don't get any specialized error, we would still be getting what we get now

error[E0308]: mismatched types
  --> src/main.rs:28:21
   |
28 |     build_server(|| make_server())
   |                     ^^^^^^^^^^^^^ expected trait `HttpService<u32, S = (), S = u32>`, found trait `HttpService<_, S = _>`
   |
   = note: expected struct `std::boxed::Box<(dyn HttpService<u32, S = (), S = u32> + 'static)>`
              found struct `std::boxed::Box<(dyn HttpService<_, S = _> + 'static)>`

but we should still handle the case of multiple predicates having conflicting obligations with a clearer error. This is a tangentially related problem to the raised case of multiple predicates with the same obligation causing the return of ExistentialMismatch instead of succeeding.

@lcnr lcnr removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Jun 19, 2020
Manishearth added a commit to Manishearth/rust that referenced this issue Jun 26, 2020
Perform obligation deduplication to avoid buggy `ExistentialMismatch`

Address rust-lang#59326.
@bors bors closed this as completed in b7f2396 Jun 27, 2020
@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. and removed E-needs-bisection Call for participation: This issue needs bisection: https://github.com/rust-lang/cargo-bisect-rustc ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. labels Jun 27, 2020
@estebank
Copy link
Contributor

The regression is fixed, but reopening as a diagnostics bug for the case outlined in my previous comment where the obligations diverge.

@estebank
Copy link
Contributor

estebank commented Jan 8, 2023

Triage: no change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-typesystem Area: The type system C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. 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

10 participants