Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

index out of bounds error #188

Open
ehuss opened this issue Apr 26, 2021 · 5 comments
Open

index out of bounds error #188

ehuss opened this issue Apr 26, 2021 · 5 comments
Labels

Comments

@ehuss
Copy link

ehuss commented Apr 26, 2021

Tried to run cargo semver on the toml-rs crate and got an error:

~/Proj/rust/toml-rs> RUST_BACKTRACE=1 rustup run nightly-2020-12-20-x86_64-apple-darwin cargo semver
    Updating crates.io index
    Finished dev [unoptimized + debuginfo] target(s) in 0.82s
    Finished dev [unoptimized + debuginfo] target(s) in 0.83s
thread 'rustc' panicked at 'index out of bounds: the len is 0 but the index is 0', /rustc/1f5bc176b0e54a8e464704adcd7e571700207fe9/compiler/rustc_middle/src/ty/relate.rs:144:60
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: <core::result::Result<T,E> as rustc_middle::ty::context::InternIteratorElement<T,R>>::intern_with
   4: <semverver::mismatch::MismatchRelation as rustc_middle::ty::relate::TypeRelation>::tys
   5: semverver::mismatch::MismatchRelation::process
   6: semverver::traverse::run_analysis
   7: rustc_interface::passes::QueryContext::enter
   8: <rust_semverver::main::SemverCallbacks as rustc_driver::Callbacks>::after_analysis
   9: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  10: rustc_span::with_source_map
  11: rustc_interface::interface::create_compiler_and_run
  12: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
error: rustc-semverver errored

Details:

  • rust-semverver built from 0bdee60 using nightly-2020-12-20
  • Test against a5dc85d0a38cc55033a367b0f24c7a8c23f314e6 of toml-rs (compared against 0.5.8)
  • Running on x86_64-apple-darwin
@JohnTitor JohnTitor added the bug label Apr 26, 2021
@JohnTitor
Copy link
Member

JohnTitor commented Oct 15, 2021

The relevant part is:

(&TyKind::FnDef(a_def_id, a_substs), &TyKind::FnDef(b_def_id, b_substs)) => {
if self.check_substs(a_substs, b_substs) {
let a_sig = a.fn_sig(self.tcx);
let b_sig = b.fn_sig(self.tcx);
let _ = self.relate_item_substs(a_def_id, a_substs, b_substs)?;
let _ = self.relate(a_sig.skip_binder(), b_sig.skip_binder())?;
}
let a = Res::Def(DefKind::Fn, a_def_id);
let b = Res::Def(DefKind::Fn, b_def_id);
Some((a, b))
}

We should filter them somehow not to relate.

@dario23
Copy link
Contributor

dario23 commented May 20, 2022

so adding && !self.tcx.variances_of(a_def_id).is_empty() to the check in line 215 seems to work around this, but i'm not sure of the wider context, i.e. are we hiding differences by ignoring this? it also doesn't make cargo run --bin cargo-semver -- -S toml:0.5.8 -C toml:0.5.9 succeed, but it runs until an error like #216 / #296 with that.

@JohnTitor do you have any input/thoughts on what/how to filter? in my tests it failed on token::Token enum variants with fields with lifetimes, e.g. Token::Whitespace. i noticed that the debug output had entries for the variant/field, which has an empty variances list and made us fail previously, and a separate one for the variant constructor, with variance like a fn(&'a str) -> Token<'a> function.

@JohnTitor
Copy link
Member

Thanks for investigating but no, I don't. So, that is a deep problem I think, the code here is not actively developed but passive-maintained, so (I assume) some of the code doesn't cooperate with the current rustc code nicely. We have to take a closer look at the code here, and it might be required to re-think the structure itself. It'll need some dedicated time but I don't think I can make it right now, sorry.

@dario23
Copy link
Contributor

dario23 commented May 22, 2022

would you be willing to merge a workaround and leave the issue open?

@JohnTitor
Copy link
Member

JohnTitor commented May 22, 2022

So, currently things don't work on that condition anyway, right? Then it seems fine to me :)

dario23 added a commit to dario23/rust-semverver that referenced this issue May 28, 2022
See rust-lang#188 for some discussion. The proper fix would probably be a bigger
refactoring endeavor, but this avoids the index out of bounds access for
now.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants