Skip to content

index out of bounds #117446

Closed
Closed

Description

@enricozb

Code

use std::path::Path;

use anyhow::{Context, Result};
use serde::{
  de::{DeserializeOwned, Deserializer, Error},
  Deserialize,
};
use serde_json::{value::RawValue as RawJson, Value as Json};

#[derive(Debug)]
pub struct Repeated<T>(Vec<T>);

impl<T> Default for Repeated<T> {
  fn default() -> Self {
    Self(Vec::new())
  }
}

impl<'de, T> Deserialize<'de> for Repeated<T>
where
  T: DeserializeOwned,
{
  fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
  where
    D: Deserializer<'de>,
  {
    fn try_deserialize<Q: DeserializeOwned>(json: Json) -> Result<Repeated<Q>> {
      match json {
        array @ Json::Array(_) => Ok(Self(serde_json::from_value(array).context("from array")?)),
        value => Ok(Self(vec![serde_json::from_value(value).context("from value")?])),
      }
    }
  }
}

Meta

rustc --version --verbose:

note: rustc 1.72.0 (5680fa18f 2023-08-23) (built from a source tarball) running on x86_64-unknown-linux-gnu

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

Error output

   Compiling tm_parser v0.1.0 (/home/enricozb/projects/work/freelance/taqtile/repos/tm_parser)
error[E0425]: cannot find value `raw` in this scope
  --> src/xml/de.rs:61:8
   |
61 |     if raw.get().starts_with('[') {
   |        ^^^ not found in this scope

error[E0425]: cannot find value `raw` in this scope
  --> src/xml/de.rs:62:47
   |
62 |       let many: Vec<T> = serde_json::from_str(raw.get()).map_err(D::Error::custom)?;
   |                                               ^^^ not found in this scope

error[E0425]: cannot find value `raw` in this scope
  --> src/xml/de.rs:66:41
   |
66 |       let one: T = serde_json::from_str(raw.get()).map_err(D::Error::custom)?;
   |                                         ^^^ not found in this scope

warning: unused import: `value::RawValue as RawJson`
 --> src/xml/de.rs:8:18
  |
8 | use serde_json::{value::RawValue as RawJson, Value as Json};
  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0277]: the size for values of type `T` cannot be known at compilation time
  --> src/xml/de.rs:53:43
   |
51 | ...lize<T: DeserializeOwned>(json: Json) -> Result<Repeated<T>> {
   |         - this type parameter needs to be `Sized`
52 | ...
53 | ...on::Array(_) => Ok(Self(serde_json::from_value(array).context("from array")?)),
   |                       ---- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |                       |
   |                       required by a bound introduced by this call
   |
note: required by a bound in `Repeated`
  --> src/xml/de.rs:35:21
   |
35 | pub struct Repeated<T>(Vec<T>);
   |                     ^ required by this bound in `Repeated`

error[E0277]: the size for values of type `T` cannot be known at compilation time
  --> src/xml/de.rs:53:43
   |
51 | ...lize<T: DeserializeOwned>(json: Json) -> Result<Repeated<T>> {
   |         - this type parameter needs to be `Sized`
52 | ...
53 | ...on::Array(_) => Ok(Self(serde_json::from_value(array).context("from array")?)),
   |                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
note: required by a bound in `Vec`
  --> /build/rustc-1.72.0-src/library/alloc/src/vec/mod.rs:396:1

error[E0277]: the trait bound `T: Deserialize<'_>` is not satisfied
    --> src/xml/de.rs:53:43
     |
53   | ...lf(serde_json::from_value(array).context("from array")?)),
     |       ^^^^^^^^^^^^^^^^^^^^^^ the trait `Deserialize<'_>` is not implemented for `T`
     |
     = note: required for `Vec<T>` to implement `for<'de> Deserialize<'de>`
     = note: required for `Vec<T>` to implement `DeserializeOwned`
note: required by a bound in `from_value`
    --> /home/enricozb/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_json-1.0.107/src/value/mod.rs:1005:8
     |
1003 | pub fn from_value<T>(value: Value) -> Result<T, Error>
     |        ---------- required by a bound in this function
1004 | where
1005 |     T: DeserializeOwned,
     |        ^^^^^^^^^^^^^^^^ required by this bound in `from_value`
help: consider further restricting this bound
     |
51   |     fn try_deserialize<T: DeserializeOwned + tm::configuration::_::_serde::Deserialize<'_>>(json: Json) -> Result<Repeated<T>> {
     |                                            +++++++++++++++++++++++++++++++++++++++++++++++

error[E0277]: the size for values of type `T` cannot be known at compilation time
  --> src/xml/de.rs:53:38
   |
51 | ...lize<T: DeserializeOwned>(json: Json) -> Result<Repeated<T>> {
   |         - this type parameter needs to be `Sized`
52 | ...
53 | ...on::Array(_) => Ok(Self(serde_json::from_value(array).context("from array")?)),
   |                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
   |
note: required by a bound in `Repeated`
  --> src/xml/de.rs:35:21
   |
35 | pub struct Repeated<T>(Vec<T>);
   |                     ^ required by this bound in `Repeated`
help: consider relaxing the implicit `Sized` restriction
   |
35 | pub struct Repeated<T: ?Sized>(Vec<T>);
   |                      ++++++++

thread 'rustc' panicked at 'index out of bounds: the len is 1 but the index is 1', compiler/rustc_middle/src/ty/generics.rs:227:14
stack backtrace:
   0:     0x7fdbb52f52d0 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hf014552b94f53b0b
   1:     0x7fdbb536411f - core::fmt::write::hd931ce1f65786f99
   2:     0x7fdbb52e7bc7 - std::io::Write::write_fmt::h6a6fd63a04e82ec7
   3:     0x7fdbb52f50d5 - std::sys_common::backtrace::print::h1e42468794e7b82c
   4:     0x7fdbb52c9541 - std::panicking::default_hook::{{closure}}::hbe45423b43205803
   5:     0x7fdbb52c91df - std::panicking::default_hook::h84640917dec96f40
   6:     0x7fdbb5bb99db - rustc_driver_impl[69ef954635c7c183]::install_ice_hook::{closure#0}
   7:     0x7fdbb52c9dc7 - std::panicking::rust_panic_with_hook::h3f828bf7de94854a
   8:     0x7fdbb52f55b7 - std::panicking::begin_panic_handler::{{closure}}::h1494d1b7b833ecd5
   9:     0x7fdbb52f53a6 - std::sys_common::backtrace::__rust_end_short_backtrace::hfb56cb4321fb1fc8
  10:     0x7fdbb52c9962 - rust_begin_unwind
  11:     0x7fdbb52a7653 - core::panicking::panic_fmt::h69ad0a157a771ebb
  12:     0x7fdbb52a77b2 - core::panicking::panic_bounds_check::haf877c0a3aa25dfb
  13:     0x7fdbb8009682 - <rustc_middle[512860564a6950dc]::ty::generics::Generics>::type_param
  14:     0x7fdbb7ea5777 - <rustc_infer[156f5b8e595d5b36]::infer::error_reporting::TypeErrCtxt>::note_and_explain_type_err
  15:     0x7fdbb7ec2eaa - <rustc_infer[156f5b8e595d5b36]::infer::error_reporting::TypeErrCtxt>::note_type_err
  16:     0x7fdbb7eb5db7 - <rustc_infer[156f5b8e595d5b36]::infer::error_reporting::TypeErrCtxt>::report_and_explain_type_error
  17:     0x7fdbb6021f13 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::report_arg_errors
  18:     0x7fdbb601e16a - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_argument_types
  19:     0x7fdbb5fef3b3 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::confirm_builtin_call
  20:     0x7fdbb5fee485 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_call
  21:     0x7fdbb6064e8e - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_expr_kind
  22:     0x7fdbb60043e3 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  23:     0x7fdbb605f467 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_match
  24:     0x7fdbb6064b31 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_expr_kind
  25:     0x7fdbb60043e3 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  26:     0x7fdbb60255d1 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_block_with_expected
  27:     0x7fdbb6064afa - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_expr_kind
  28:     0x7fdbb60043e3 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_expr_with_expectation_and_args
  29:     0x7fdbb6005838 - <rustc_hir_typeck[d63c1205cb23e616]::fn_ctxt::FnCtxt>::check_return_expr
  30:     0x7fdbb619643d - rustc_hir_typeck[d63c1205cb23e616]::check::check_fn
  31:     0x7fdbb60fc789 - rustc_hir_typeck[d63c1205cb23e616]::typeck
  32:     0x7fdbb707af0c - rustc_query_impl[d023734ba8619ee7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d023734ba8619ee7]::query_impl::typeck::dynamic_query::{closure#2}::{closure#0}, rustc_middle[512860564a6950dc]::query::erase::Erased<[u8; 8usize]>>
  33:     0x7fdbb703c9fc - <rustc_query_impl[d023734ba8619ee7]::query_impl::typeck::dynamic_query::{closure#2} as core[5a83ea98d6738c29]::ops::function::FnOnce<(rustc_middle[512860564a6950dc]::ty::context::TyCtxt, rustc_span[1541297d26e31dcb]::def_id::LocalDefId)>>::call_once
  34:     0x7fdbb7295d03 - rustc_query_system[eeadaf18cb45039c]::query::plumbing::try_execute_query::<rustc_query_impl[d023734ba8619ee7]::DynamicConfig<rustc_query_system[eeadaf18cb45039c]::query::caches::VecCache<rustc_span[1541297d26e31dcb]::def_id::LocalDefId, rustc_middle[512860564a6950dc]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d023734ba8619ee7]::plumbing::QueryCtxt, false>
  35:     0x7fdbb7167d07 - rustc_query_impl[d023734ba8619ee7]::query_impl::typeck::get_query_non_incr::__rust_end_short_backtrace
  36:     0x7fdbb60fc075 - rustc_hir_typeck[d63c1205cb23e616]::used_trait_imports
  37:     0x7fdbb7078cbc - rustc_query_impl[d023734ba8619ee7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d023734ba8619ee7]::query_impl::used_trait_imports::dynamic_query::{closure#2}::{closure#0}, rustc_middle[512860564a6950dc]::query::erase::Erased<[u8; 8usize]>>
  38:     0x7fdbb71f04dc - <rustc_query_impl[d023734ba8619ee7]::query_impl::used_trait_imports::dynamic_query::{closure#2} as core[5a83ea98d6738c29]::ops::function::FnOnce<(rustc_middle[512860564a6950dc]::ty::context::TyCtxt, rustc_span[1541297d26e31dcb]::def_id::LocalDefId)>>::call_once
  39:     0x7fdbb7295d03 - rustc_query_system[eeadaf18cb45039c]::query::plumbing::try_execute_query::<rustc_query_impl[d023734ba8619ee7]::DynamicConfig<rustc_query_system[eeadaf18cb45039c]::query::caches::VecCache<rustc_span[1541297d26e31dcb]::def_id::LocalDefId, rustc_middle[512860564a6950dc]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[d023734ba8619ee7]::plumbing::QueryCtxt, false>
  40:     0x7fdbb71faa07 - rustc_query_impl[d023734ba8619ee7]::query_impl::used_trait_imports::get_query_non_incr::__rust_end_short_backtrace
  41:     0x7fdbb6377da9 - rustc_hir_analysis[8376801970c74138]::check_unused::check_crate
  42:     0x7fdbb6310a49 - rustc_hir_analysis[8376801970c74138]::check_crate
  43:     0x7fdbb5dcac31 - rustc_interface[8db0663d394672f7]::passes::analysis
  44:     0x7fdbb707af7a - rustc_query_impl[d023734ba8619ee7]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[d023734ba8619ee7]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[512860564a6950dc]::query::erase::Erased<[u8; 1usize]>>
  45:     0x7fdbb7160478 - <rustc_query_impl[d023734ba8619ee7]::query_impl::analysis::dynamic_query::{closure#2} as core[5a83ea98d6738c29]::ops::function::FnOnce<(rustc_middle[512860564a6950dc]::ty::context::TyCtxt, ())>>::call_once
  46:     0x7fdbb7228733 - rustc_query_system[eeadaf18cb45039c]::query::plumbing::try_execute_query::<rustc_query_impl[d023734ba8619ee7]::DynamicConfig<rustc_query_system[eeadaf18cb45039c]::query::caches::SingleCache<rustc_middle[512860564a6950dc]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[d023734ba8619ee7]::plumbing::QueryCtxt, false>
  47:     0x7fdbb71f5563 - rustc_query_impl[d023734ba8619ee7]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  48:     0x7fdbb5c1652a - <rustc_interface[8db0663d394672f7]::queries::QueryResult<&rustc_middle[512860564a6950dc]::ty::context::GlobalCtxt>>::enter::<core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>, rustc_driver_impl[69ef954635c7c183]::run_compiler::{closure#1}::{closure#2}::{closure#4}>
  49:     0x7fdbb5bbb565 - <rustc_interface[8db0663d394672f7]::interface::Compiler>::enter::<rustc_driver_impl[69ef954635c7c183]::run_compiler::{closure#1}::{closure#2}, core[5a83ea98d6738c29]::result::Result<core[5a83ea98d6738c29]::option::Option<rustc_interface[8db0663d394672f7]::queries::Linker>, rustc_span[1541297d26e31dcb]::ErrorGuaranteed>>
  50:     0x7fdbb5c05a51 - <scoped_tls[e78294f23860c3f5]::ScopedKey<rustc_span[1541297d26e31dcb]::SessionGlobals>>::set::<rustc_interface[8db0663d394672f7]::interface::run_compiler<core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>, rustc_driver_impl[69ef954635c7c183]::run_compiler::{closure#1}>::{closure#0}, core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>>
  51:     0x7fdbb5bdb999 - std[21ad8caf9e5027b5]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[8db0663d394672f7]::util::run_in_thread_pool_with_globals<rustc_interface[8db0663d394672f7]::interface::run_compiler<core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>, rustc_driver_impl[69ef954635c7c183]::run_compiler::{closure#1}>::{closure#0}, core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>>
  52:     0x7fdbb5c0fc81 - <<std[21ad8caf9e5027b5]::thread::Builder>::spawn_unchecked_<rustc_interface[8db0663d394672f7]::util::run_in_thread_pool_with_globals<rustc_interface[8db0663d394672f7]::interface::run_compiler<core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>, rustc_driver_impl[69ef954635c7c183]::run_compiler::{closure#1}>::{closure#0}, core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[5a83ea98d6738c29]::result::Result<(), rustc_span[1541297d26e31dcb]::ErrorGuaranteed>>::{closure#1} as core[5a83ea98d6738c29]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  53:     0x7fdbb52bc175 - std::sys::unix::thread::Thread::new::thread_start::hbe812d50dfbae5d3
  54:     0x7fdbb50d1dd4 - start_thread
  55:     0x7fdbb51539b0 - __clone3
  56:                0x0 - <unknown>

error: 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.72.0 (5680fa18f 2023-08-23) (built from a source tarball) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [typeck] type-checking `xml::de::<impl at src/xml/de.rs:43:1: 43:46>::deserialize::try_deserialize`
#1 [used_trait_imports] finding used_trait_imports `xml::de::<impl at src/xml/de.rs:43:1: 43:46>::deserialize::try_deserialize`
#2 [analysis] running analysis passes on this crate
end of query stack
Some errors have detailed explanations: E0277, E0425.
For more information about an error, try `rustc --explain E0277`.
warning: `tm_parser` (bin "tm_parser") generated 1 warning
error: could not compile `tm_parser` (bin "tm_parser") due to 7 previous errors; 1 warning emitted
Backtrace

<backtrace>

Activity

  1. added
    C-bugCategory: This is a bug.
    I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 31, 2023
  2. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 31, 2023
  3. enricozb commented on Oct 31, 2023

    @enricozb
    Author

    This may have to do with the fact that I'm using Self here inside that try_deserialize, even though I don't think that Self has any meaning there.

  4. removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 31, 2023
  5. Jules-Bertholet commented on Oct 31, 2023

    @Jules-Bertholet
    Contributor

    Seems fixed in latest nightly: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=2c53fe13f6a5780becd70ca9bf7c0047

    (Though the error messages seem suspicious still…)

    @rustbot label A-traits

  6. ranger-ross commented on Oct 19, 2024

    @ranger-ross
    Member

    Appears to be fixed in Rust 1.75 and newer.
    I think this issue is good to be closed

  7. added
    E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.
    on Oct 19, 2024
  8. workingjubilee commented on Oct 19, 2024

    @workingjubilee
    Member

    Since this is a specific ICE, if we don't know if this landed with a regression test, then it should.

  9. added 2 commits that reference this issue on Nov 2, 2024
  10. added 3 commits that reference this issue on Nov 2, 2024
  11. added 2 commits that reference this issue on Nov 3, 2024
  12. added a commit that references this issue on Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions